1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 05:55:27 +01:00

Added jobs action logging

Small improvements
Small change for getting players permissions
This commit is contained in:
Zrips 2015-09-17 18:28:23 +03:00
parent 26c42852e7
commit 02d6b5e0c2
15 changed files with 290 additions and 141 deletions

View File

@ -39,7 +39,6 @@ import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobItems; import com.gamingmesh.jobs.container.JobItems;
import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.container.Log;
import com.gamingmesh.jobs.dao.JobsDAO; import com.gamingmesh.jobs.dao.JobsDAO;
import com.gamingmesh.jobs.economy.BufferedEconomy; import com.gamingmesh.jobs.economy.BufferedEconomy;
import com.gamingmesh.jobs.economy.Economy; import com.gamingmesh.jobs.economy.Economy;
@ -382,9 +381,6 @@ public class Jobs {
} else { } else {
PaymentData data = ExpLimit.get(playername); PaymentData data = ExpLimit.get(playername);
if (data.IsReachedExpLimit(ConfigManager.getJobsConfiguration().EconomyExpTimeLimit, ConfigManager.getJobsConfiguration().EconomyExpLimit)) { if (data.IsReachedExpLimit(ConfigManager.getJobsConfiguration().EconomyExpTimeLimit, ConfigManager.getJobsConfiguration().EconomyExpLimit)) {
Debug.D("exp limit reached");
if (player.isOnline() && !data.Informed && !data.isReseted()) { if (player.isOnline() && !data.Informed && !data.isReseted()) {
((Player) player).sendMessage(Language.getMessage("command.limit.output.reachedExplimit")); ((Player) player).sendMessage(Language.getMessage("command.limit.output.reachedExplimit"));
((Player) player).sendMessage(Language.getMessage("command.limit.output.reachedExplimit2")); ((Player) player).sendMessage(Language.getMessage("command.limit.output.reachedExplimit2"));
@ -445,6 +441,8 @@ public class Jobs {
Jobs.getEconomy().pay(jPlayer, amount, 0.0); Jobs.getEconomy().pay(jPlayer, amount, 0.0);
if (ConfigManager.getJobsConfiguration().LoggingUse)
Loging.recordToLog(jPlayer, info, amount, 0);
} }
} }
} else { } else {
@ -564,11 +562,11 @@ public class Jobs {
Jobs.getEconomy().pay(jPlayer, amount, expAmount); Jobs.getEconomy().pay(jPlayer, amount, expAmount);
int oldLevel = prog.getLevel(); int oldLevel = prog.getLevel();
Loging.recordToLog(jPlayer, info, amount, expAmount); if (ConfigManager.getJobsConfiguration().LoggingUse)
Loging.recordToLog(jPlayer, info, amount, expAmount);
if (prog.addExperience(expAmount)) if (prog.addExperience(expAmount))
Jobs.getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel); Jobs.getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel);
} }
} }
} }

View File

@ -37,6 +37,7 @@ import com.gamingmesh.jobs.listeners.JobsListener;
import com.gamingmesh.jobs.listeners.JobsPaymentListener; import com.gamingmesh.jobs.listeners.JobsPaymentListener;
import com.gamingmesh.jobs.listeners.McMMOlistener; import com.gamingmesh.jobs.listeners.McMMOlistener;
import com.gamingmesh.jobs.listeners.PistonProtectionListener; import com.gamingmesh.jobs.listeners.PistonProtectionListener;
import com.gamingmesh.jobs.stuff.OfflinePlayerList;
import com.gamingmesh.jobs.stuff.ScheduleUtil; import com.gamingmesh.jobs.stuff.ScheduleUtil;
import com.gamingmesh.jobs.stuff.TabComplete; import com.gamingmesh.jobs.stuff.TabComplete;
import com.gamingmesh.jobs.config.YmlMaker; import com.gamingmesh.jobs.config.YmlMaker;
@ -47,66 +48,66 @@ public class JobsPlugin extends JavaPlugin {
public static boolean CPPresent = false; public static boolean CPPresent = false;
@Override @Override
public void onEnable() { public void onEnable() {
instance = this; instance = this;
YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml"); OfflinePlayerList.fillList();
jobConfig.saveDefaultConfig(); YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml");
jobConfig.saveDefaultConfig();
YmlMaker jobSigns = new YmlMaker(this, "Signs.yml");
jobSigns.saveDefaultConfig();
YmlMaker jobSchedule = new YmlMaker(this, "schedule.yml");
jobSchedule.saveDefaultConfig();
Jobs.setPermissionHandler(new PermissionHandler(this));
Jobs.setPluginLogger(getLogger()); YmlMaker jobSigns = new YmlMaker(this, "Signs.yml");
jobSigns.saveDefaultConfig();
Jobs.setDataFolder(getDataFolder()); YmlMaker jobSchedule = new YmlMaker(this, "schedule.yml");
jobSchedule.saveDefaultConfig();
ConfigManager.registerJobsConfiguration(new JobsConfiguration(this)); Jobs.setPermissionHandler(new PermissionHandler(this));
ConfigManager.registerJobConfig(new JobConfig(this));
getCommand("jobs").setExecutor(new JobsCommands()); Jobs.setPluginLogger(getLogger());
this.getCommand("jobs").setTabCompleter(new TabComplete()); Jobs.setDataFolder(getDataFolder());
try { ConfigManager.registerJobsConfiguration(new JobsConfiguration(this));
Jobs.startup(); ConfigManager.registerJobConfig(new JobConfig(this));
} catch (IOException e) {
e.printStackTrace();
}
// register the listeners getCommand("jobs").setExecutor(new JobsCommands());
getServer().getPluginManager().registerEvents(new JobsListener(this), this);
getServer().getPluginManager().registerEvents(new JobsPaymentListener(this), this);
if (McMMOlistener.CheckmcMMO()) this.getCommand("jobs").setTabCompleter(new TabComplete());
getServer().getPluginManager().registerEvents(new McMMOlistener(this), this);
if (ConfigManager.getJobsConfiguration().useBlockProtection) try {
getServer().getPluginManager().registerEvents(new PistonProtectionListener(this), this); Jobs.startup();
} catch (IOException e) {
// register economy e.printStackTrace();
Bukkit.getScheduler().runTask(this, new HookEconomyTask(this));
if (getServer().getPluginManager().getPlugin("CoreProtect") != null) {
CPPresent = true;
CPAPI = ((CoreProtect) getServer().getPluginManager().getPlugin("CoreProtect")).getAPI();
}
// all loaded properly.
if (ConfigManager.getJobsConfiguration().useGlobalBoostScheduler)
ScheduleUtil.scheduler();
ScheduleUtil.DateUpdater();
String message = ChatColor.translateAlternateColorCodes('&', "&2Plugin has been enabled succesfully.");
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
console.sendMessage(message);
} }
// register the listeners
getServer().getPluginManager().registerEvents(new JobsListener(this), this);
getServer().getPluginManager().registerEvents(new JobsPaymentListener(this), this);
if (McMMOlistener.CheckmcMMO())
getServer().getPluginManager().registerEvents(new McMMOlistener(this), this);
if (ConfigManager.getJobsConfiguration().useBlockProtection)
getServer().getPluginManager().registerEvents(new PistonProtectionListener(this), this);
// register economy
Bukkit.getScheduler().runTask(this, new HookEconomyTask(this));
if (getServer().getPluginManager().getPlugin("CoreProtect") != null) {
CPPresent = true;
CPAPI = ((CoreProtect) getServer().getPluginManager().getPlugin("CoreProtect")).getAPI();
}
// all loaded properly.
if (ConfigManager.getJobsConfiguration().useGlobalBoostScheduler)
ScheduleUtil.scheduler();
ScheduleUtil.DateUpdater();
String message = ChatColor.translateAlternateColorCodes('&', "&2Plugin has been enabled succesfully.");
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
console.sendMessage(message);
}
@Override @Override
public void onDisable() { public void onDisable() {
Jobs.shutdown(); Jobs.shutdown();

View File

@ -46,6 +46,8 @@ import com.gamingmesh.jobs.stuff.ActionBar;
import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.PerformCommands; import com.gamingmesh.jobs.stuff.PerformCommands;
import net.milkbowl.vault.Vault;
public class PlayerManager { public class PlayerManager {
private Map<String, JobsPlayer> players = Collections.synchronizedMap(new HashMap<String, JobsPlayer>()); private Map<String, JobsPlayer> players = Collections.synchronizedMap(new HashMap<String, JobsPlayer>());
//private Map<String, JobsPlayer> players = new HashMap<String, JobsPlayer>(); //private Map<String, JobsPlayer> players = new HashMap<String, JobsPlayer>();
@ -153,7 +155,9 @@ public class PlayerManager {
if (jPlayer != null) if (jPlayer != null)
return jPlayer; return jPlayer;
return JobsPlayer.loadFromDao(Jobs.getJobsDAO(), offlinePlayer); JobsPlayer player = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), offlinePlayer);
JobsPlayer.loadLogFromDao(player);
return player;
} }
/** /**
@ -525,7 +529,7 @@ public class PlayerManager {
return true; return true;
short count = (short) ConfigManager.getJobsConfiguration().getMaxJobs(); short count = (short) ConfigManager.getJobsConfiguration().getMaxJobs();
for (short ctr = 0; ctr < 255; ctr++) { for (short ctr = 0; ctr < 30; ctr++) {
if (Perm(player, "jobs.max." + ctr)) if (Perm(player, "jobs.max." + ctr))
count = ctr; count = ctr;
if (count > currentCount) if (count > currentCount)
@ -535,8 +539,7 @@ public class PlayerManager {
} }
private boolean Perm(Player player, String permission) { private boolean Perm(Player player, String permission) {
Permission p = new Permission(permission, PermissionDefault.FALSE); return player.isPermissionSet(permission);
return player.hasPermission(p);
} }
/** /**

View File

@ -61,9 +61,11 @@ import com.gamingmesh.jobs.i18n.Language;
import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.Debug;
import com.gamingmesh.jobs.stuff.GiveItem; import com.gamingmesh.jobs.stuff.GiveItem;
import com.gamingmesh.jobs.stuff.OfflinePlayerList;
import com.gamingmesh.jobs.stuff.Perm; import com.gamingmesh.jobs.stuff.Perm;
import com.gamingmesh.jobs.stuff.Scboard; import com.gamingmesh.jobs.stuff.Scboard;
import com.gamingmesh.jobs.stuff.Sorting; import com.gamingmesh.jobs.stuff.Sorting;
import com.gamingmesh.jobs.stuff.TimeManage;
import com.gamingmesh.jobs.stuff.TranslateName; import com.gamingmesh.jobs.stuff.TranslateName;
public class JobsCommands implements CommandExecutor { public class JobsCommands implements CommandExecutor {
@ -364,9 +366,12 @@ public class JobsCommands implements CommandExecutor {
sender.sendMessage(ChatColor.RED + Language.getMessage("command.error.permission")); sender.sendMessage(ChatColor.RED + Language.getMessage("command.error.permission"));
return true; return true;
} }
@SuppressWarnings("deprecation") // @SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]); // OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
OfflinePlayer offlinePlayer = OfflinePlayerList.getPlayer(args[0]);
if (offlinePlayer != null)
jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
} else if (sender instanceof Player) { } else if (sender instanceof Player) {
jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender); jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender);
} }
@ -1368,13 +1373,22 @@ public class JobsCommands implements CommandExecutor {
return true; return true;
} }
JobsPlayer JPlayer = null; JobsPlayer JPlayer = null;
if (args.length == 1)
JPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
if (args.length == 0) if (args.length == 0)
JPlayer = Jobs.getPlayerManager().getJobsPlayer(sender.getName()); JPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender);
else if (args.length == 1 ) {
if (!sender.hasPermission("jobs.commands.log.others")){
sender.sendMessage(Language.getMessage("command.error.permission"));
return true;
}
JPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
if (JPlayer == null)
JPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(OfflinePlayerList.getPlayer(args[0]));
}
if (JPlayer == null) if (JPlayer == null) {
sendUsage(sender, "log");
return true; return true;
}
List<Log> logList = JPlayer.getLog(); List<Log> logList = JPlayer.getLog();
@ -1393,15 +1407,20 @@ public class JobsCommands implements CommandExecutor {
unsortMap = Sorting.sortDoubleDESC(unsortMap); unsortMap = Sorting.sortDoubleDESC(unsortMap);
int count = 0; int count = 0;
int max = 10; int max = 10;
sender.sendMessage("******************* " + JPlayer.getUserName() + " *******************"); sender.sendMessage(Language.getMessage("command.log.output.topline").replace("%playername%", JPlayer.getUserName()));
for (Log one : logList) { for (Log one : logList) {
HashMap<String, LogAmounts> AmountList = one.getAmountList(); HashMap<String, LogAmounts> AmountList = one.getAmountList();
for (Entry<String, Double> oneSorted : unsortMap.entrySet()) { for (Entry<String, Double> oneSorted : unsortMap.entrySet()) {
for (Entry<String, LogAmounts> oneMap : AmountList.entrySet()) { for (Entry<String, LogAmounts> oneMap : AmountList.entrySet()) {
if (oneMap.getKey().equalsIgnoreCase(oneSorted.getKey())) { if (oneMap.getKey().equalsIgnoreCase(oneSorted.getKey())) {
count++; count++;
String msg = "&6" + count + ". &e" + one.getActionType() + ": &6" + oneMap.getValue().getItemName() + " &ecount: &6" + oneMap.getValue() String msg = Language.getMessage("command.log.output.list")
.getCount() + " &emoney: &6" + oneMap.getValue().getMoney() + " &eexp: &6" + oneMap.getValue().getExp(); .replace("%number%", String.valueOf(count))
.replace("%action%", one.getActionType())
.replace("%item%", oneMap.getValue().getItemName().replace(":0", "").toLowerCase())
.replace("%qty%", String.valueOf(oneMap.getValue().getCount()))
.replace("%money%", String.valueOf(oneMap.getValue().getMoney()))
.replace("%exp%", String.valueOf(oneMap.getValue().getExp()));
msg = org.bukkit.ChatColor.translateAlternateColorCodes('&', msg); msg = org.bukkit.ChatColor.translateAlternateColorCodes('&', msg);
sender.sendMessage(msg); sender.sendMessage(msg);
break; break;
@ -1413,7 +1432,7 @@ public class JobsCommands implements CommandExecutor {
if (count > max) if (count > max)
break; break;
} }
sender.sendMessage("***********************************************"); sender.sendMessage(Language.getMessage("command.log.output.bottomline"));
return true; return true;
} }
@ -1429,12 +1448,15 @@ public class JobsCommands implements CommandExecutor {
public void run() { public void run() {
Map<LogAmounts, Double> unsortMap = new HashMap<LogAmounts, Double>(); Map<LogAmounts, Double> unsortMap = new HashMap<LogAmounts, Double>();
Collection<? extends Player> onlineP = Bukkit.getOnlinePlayers(); int time = TimeManage.timeInInt();
sender.sendMessage("Looking for players data");
for (Player OneP : onlineP) {
for (String OneP : Jobs.getJobsDAO().getLognameList(time, time)) {
JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(OneP); JobsPlayer JPlayer = Jobs.getPlayerManager().getJobsPlayer(OneP);
if (JPlayer == null) {
OfflinePlayer offp = OfflinePlayerList.getPlayer(OneP);
if (offp != null)
JPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(OfflinePlayerList.getPlayer(OneP));
}
if (JPlayer == null) if (JPlayer == null)
continue; continue;
List<Log> logList = JPlayer.getLog(); List<Log> logList = JPlayer.getLog();
@ -1444,7 +1466,7 @@ public class JobsCommands implements CommandExecutor {
for (Log one : logList) { for (Log one : logList) {
HashMap<String, LogAmounts> AmountList = one.getAmountList(); HashMap<String, LogAmounts> AmountList = one.getAmountList();
for (Entry<String, LogAmounts> oneMap : AmountList.entrySet()) { for (Entry<String, LogAmounts> oneMap : AmountList.entrySet()) {
oneMap.getValue().setUsername(OneP.getName()); oneMap.getValue().setUsername(OneP);
oneMap.getValue().setAction(one.getActionType()); oneMap.getValue().setAction(one.getActionType());
unsortMap.put(oneMap.getValue(), oneMap.getValue().getMoney()); unsortMap.put(oneMap.getValue(), oneMap.getValue().getMoney());
} }
@ -1453,14 +1475,21 @@ public class JobsCommands implements CommandExecutor {
unsortMap = Sorting.sortDoubleDESCByLog(unsortMap); unsortMap = Sorting.sortDoubleDESCByLog(unsortMap);
int count = 0; int count = 1;
int max = 10; int max = 10;
sender.sendMessage(Language.getMessage("command.glog.output.topline"));
for (Entry<LogAmounts, Double> one : unsortMap.entrySet()) { for (Entry<LogAmounts, Double> one : unsortMap.entrySet()) {
LogAmounts info = one.getKey(); LogAmounts info = one.getKey();
String msg = "&3" + info.getUsername() + " &e" + info.getAction() + ": &6" + (info.getItemName().toString().contains(":0") ? info.getItemName()
.toString().replace(":0", "") : info.getItemName()) + " &ecount: &6" + info.getCount() + " &emoney: &6" + info.getMoney() + " &eexp: &6" + info String msg = Language.getMessage("command.glog.output.list")
.getExp(); .replace("%username%", one.getKey().getUsername())
.replace("%number%", String.valueOf(count))
.replace("%action%", info.getAction())
.replace("%item%", one.getKey().getItemName().replace(":0", "").toLowerCase())
.replace("%qty%", String.valueOf(one.getKey().getCount()))
.replace("%money%", String.valueOf(one.getKey().getMoney()))
.replace("%exp%", String.valueOf(one.getKey().getExp()));
msg = org.bukkit.ChatColor.translateAlternateColorCodes('&', msg); msg = org.bukkit.ChatColor.translateAlternateColorCodes('&', msg);
sender.sendMessage(msg); sender.sendMessage(msg);
count++; count++;
@ -1471,6 +1500,7 @@ public class JobsCommands implements CommandExecutor {
if (unsortMap.size() == 0) { if (unsortMap.size() == 0) {
sender.sendMessage("No data found"); sender.sendMessage("No data found");
} }
sender.sendMessage(Language.getMessage("command.glog.output.bottomline"));
return; return;
} }

View File

@ -69,6 +69,8 @@ public class JobsConfiguration {
protected boolean modifyChat; protected boolean modifyChat;
protected int economyBatchDelay; protected int economyBatchDelay;
protected boolean saveOnDisconnect; protected boolean saveOnDisconnect;
public boolean LocalOfflinePlayersData;
public boolean LoggingUse;
public boolean EconomyLimitUse, EconomyExpLimitUse, PayForRenaming, PayForEachCraft, SignsEnabled, public boolean EconomyLimitUse, EconomyExpLimitUse, PayForRenaming, PayForEachCraft, SignsEnabled,
SignsColorizeJobName, ShowToplistInScoreboard, useGlobalTimer, useCoreProtect, BlockPlaceUse, SignsColorizeJobName, ShowToplistInScoreboard, useGlobalTimer, useCoreProtect, BlockPlaceUse,
EnableAnounceMessage, useBlockPiston, useSilkTouchProtection, UseCustomNames, EconomyMoneyStop, EnableAnounceMessage, useBlockPiston, useSilkTouchProtection, UseCustomNames, EconomyMoneyStop,
@ -369,6 +371,16 @@ public class JobsConfiguration {
"Only enable this if you have a multi-server setup, or have a really good reason for enabling this.", "Turning this on will decrease database performance."); "Only enable this if you have a multi-server setup, or have a really good reason for enabling this.", "Turning this on will decrease database performance.");
saveOnDisconnect = getBoolean("save-on-disconnect", false, config, writer); saveOnDisconnect = getBoolean("save-on-disconnect", false, config, writer);
writer.addComment("Optimizations.UseLocalOfflinePlayersData", "With this set to true, offline player data will be taken from local player data files",
"This will eliminate small lag spikes when request is being send to mojangs servers for offline players data",
"Theroticali this should work without issues, but if you havving some, just disable",
"But then you can feal some small (100-200ms) lag spikes while performings some jobs commands");
LocalOfflinePlayersData = getBoolean("Optimizations.UseLocalOfflinePlayersData", true, config, writer);
writer.addComment("Logging.Use", "With this set to true all players jobs actions will be logged to database for easy to see statistics",
"This is still in development and in feature it will expand");
LoggingUse = getBoolean("Logging.Use", false, config, writer);
writer.addComment("broadcast.on-skill-up.use", "Do all players get a message when somone goes up a skill level?"); writer.addComment("broadcast.on-skill-up.use", "Do all players get a message when somone goes up a skill level?");
isBroadcastingSkillups = getBoolean("broadcast.on-skill-up.use", false, config, writer); isBroadcastingSkillups = getBoolean("broadcast.on-skill-up.use", false, config, writer);
@ -1289,6 +1301,20 @@ public class JobsConfiguration {
GetConfigString("command.gtop.output.next", "&2|&e Next Page >>>>", writer, conf, true); GetConfigString("command.gtop.output.next", "&2|&e Next Page >>>>", writer, conf, true);
GetConfigString("command.gtop.output.show", "&2Show from &e[from] &2until &e[until] &2global top list", writer, conf, true); GetConfigString("command.gtop.output.show", "&2Show from &e[from] &2until &e[until] &2global top list", writer, conf, true);
GetConfigString("command.log.help.info", "Shows statistics.", writer, conf, true);
GetConfigString("command.log.help.args", "[playername]", writer, conf, true);
GetConfigString("command.log.output.topline", "&7************************* &6%playername% &7*************************", writer, conf, true);
GetConfigString("command.log.output.list", "&7* &6%number%. &3%action%: &6%item% &eqty: %qty% &6money: %money% &eexp: %exp%", writer, conf, true);
GetConfigString("command.log.output.bottomline", "&7***********************************************************", writer, conf, true);
GetConfigString("command.log.output.prev", "&e<<<<< Prev page &2|", writer, conf, true);
GetConfigString("command.log.output.next", "&2|&e Next Page >>>>", writer, conf, true);
GetConfigString("command.glog.help.info", "Shows global statistics.", writer, conf, true);
GetConfigString("command.glog.help.args", "", writer, conf, true);
GetConfigString("command.glog.output.topline", "&7*********************** &6Global statistics &7***********************", writer, conf, true);
GetConfigString("command.glog.output.list", "&7* &6%number%. &3%username% &e%action%: &6%item% &eqty: %qty% &6money: %money% &eexp: %exp%", writer, conf, true);
GetConfigString("command.glog.output.bottomline", "&7**************************************************************", writer, conf, true);
GetConfigString("command.transfer.help.info", "Transfer a player's job from an old job to a new job.", writer, conf, true); GetConfigString("command.transfer.help.info", "Transfer a player's job from an old job to a new job.", writer, conf, true);
GetConfigString("command.transfer.help.args", "[playername] [oldjob] [newjob]", writer, conf, true); GetConfigString("command.transfer.help.args", "[playername] [oldjob] [newjob]", writer, conf, true);
GetConfigString("command.transfer.output.target", "You have been transferred from %oldjobname% to %newjobname%.", writer, conf, true); GetConfigString("command.transfer.output.target", "You have been transferred from %oldjobname% to %newjobname%.", writer, conf, true);

View File

@ -4,42 +4,43 @@ import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gamingmesh.jobs.stuff.OfflinePlayerList;
import com.gamingmesh.jobs.stuff.UUIDUtil; import com.gamingmesh.jobs.stuff.UUIDUtil;
public final class TopList { public final class TopList {
private String player; private String player;
private int level; private int level;
private int exp; private int exp;
private byte[] uuid; private byte[] uuid;
public TopList(String player, int level, int exp, byte[] uuid) { public TopList(String player, int level, int exp, byte[] uuid) {
this.player = player; this.player = player;
this.level = level; this.level = level;
this.exp = exp; this.exp = exp;
this.uuid = uuid; this.uuid = uuid;
} }
public String getPlayerName() { public String getPlayerName() {
if (this.player == null || this.player == "") { if (this.player == null || this.player == "") {
Player player = Bukkit.getPlayer(UUIDUtil.fromBytes(this.uuid)); Player player = Bukkit.getPlayer(UUIDUtil.fromBytes(this.uuid));
if (player != null) if (player != null)
return player.getName(); return player.getName();
else { else {
OfflinePlayer Offlineplayer = Bukkit.getOfflinePlayer(UUIDUtil.fromBytes(this.uuid)); OfflinePlayer Offlineplayer = OfflinePlayerList.getPlayer(UUIDUtil.fromBytes(this.uuid));
if (Offlineplayer != null) if (Offlineplayer != null)
return Offlineplayer.getName(); return Offlineplayer.getName();
else else
return "Unknown"; return "Unknown";
} }
}
return this.player;
} }
return this.player;
}
public int getLevel() { public int getLevel() {
return this.level; return this.level;
} }
public int getExp() { public int getExp() {
return this.exp; return this.exp;
} }
} }

View File

@ -587,12 +587,43 @@ public abstract class JobsDAO {
while (res.next()) { while (res.next()) {
Loging.loadToLog(player, res.getString("action"), res.getString("itemname"), res.getInt("count"), res.getDouble("money"), res.getDouble("exp")); Loging.loadToLog(player, res.getString("action"), res.getString("itemname"), res.getInt("count"), res.getDouble("money"), res.getDouble("exp"));
} }
res.close();
prest.close(); prest.close();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
/**
* Save player-job information
* @param jobInfo - the information getting saved
* @return
*/
public List<String> getLognameList(int fromtime, int untiltime) {
JobsConnection conn = getConnection();
if (conn == null)
return null;
try {
List<String> nameList = new ArrayList<String>();
PreparedStatement prest = conn.prepareStatement("SELECT `username` FROM `" + prefix
+ "log` WHERE `time` >= ? AND `time` <= ? ;");
prest.setInt(1, fromtime);
prest.setInt(2, untiltime);
ResultSet res = prest.executeQuery();
while (res.next()) {
if (!nameList.contains(res.getString("username")))
nameList.add(res.getString("username"));
}
res.close();
prest.close();
return nameList;
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
/** /**
* Show top list * Show top list
* @param toplist - toplist by jobs name * @param toplist - toplist by jobs name

View File

@ -25,9 +25,11 @@ import java.util.ArrayList;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.OfflinePlayerList;
import com.gamingmesh.jobs.stuff.UUIDUtil; import com.gamingmesh.jobs.stuff.UUIDUtil;
public class JobsDAOMySQL extends JobsDAO { public class JobsDAOMySQL extends JobsDAO {
@ -186,7 +188,12 @@ public class JobsDAOMySQL extends JobsDAO {
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "" + y + " of " + usernames.size()); Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "" + y + " of " + usernames.size());
i = 0; i = 0;
} }
pst2.setBytes(1, UUIDUtil.toBytes(UUID.fromString(Bukkit.getOfflinePlayer(names).getUniqueId().toString())));
OfflinePlayer offPlayer = OfflinePlayerList.getPlayer(names);
if (offPlayer == null)
continue;
pst2.setBytes(1, UUIDUtil.toBytes(offPlayer.getUniqueId()));
pst2.setString(2, names); pst2.setString(2, names);
pst2.execute(); pst2.execute();
} }

View File

@ -26,9 +26,11 @@ import java.util.ArrayList;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.OfflinePlayerList;
import com.gamingmesh.jobs.stuff.UUIDUtil; import com.gamingmesh.jobs.stuff.UUIDUtil;
public class JobsDAOSQLite extends JobsDAO { public class JobsDAOSQLite extends JobsDAO {
@ -152,7 +154,12 @@ public class JobsDAOSQLite extends JobsDAO {
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "" + y + " of " + usernames.size()); Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "" + y + " of " + usernames.size());
i = 0; i = 0;
} }
pst2.setBytes(1, UUIDUtil.toBytes(UUID.fromString(Bukkit.getOfflinePlayer(names).getUniqueId().toString())));
OfflinePlayer offPlayer = OfflinePlayerList.getPlayer(names);
if (offPlayer == null)
continue;
pst2.setBytes(1, UUIDUtil.toBytes(offPlayer.getUniqueId()));
pst2.setString(2, names); pst2.setString(2, names);
pst2.execute(); pst2.execute();
} }

View File

@ -36,6 +36,7 @@ import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.i18n.Language;
import com.gamingmesh.jobs.stuff.ActionBar; import com.gamingmesh.jobs.stuff.ActionBar;
import com.gamingmesh.jobs.stuff.ChatColor; import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.OfflinePlayerList;
import com.gamingmesh.jobs.tasks.BufferedPaymentTask; import com.gamingmesh.jobs.tasks.BufferedPaymentTask;
public class BufferedEconomy { public class BufferedEconomy {
@ -80,7 +81,6 @@ public class BufferedEconomy {
/** /**
* Payout all players the amount they are going to be paid * Payout all players the amount they are going to be paid
*/ */
@SuppressWarnings("deprecation")
public void payAll() { public void payAll() {
if (payments.isEmpty()) if (payments.isEmpty())
return; return;
@ -128,10 +128,10 @@ public class BufferedEconomy {
String ServerAccountname = ConfigManager.getJobsConfiguration().ServerAcountName; String ServerAccountname = ConfigManager.getJobsConfiguration().ServerAcountName;
String ServerTaxesAccountname = ConfigManager.getJobsConfiguration().ServertaxesAcountName; String ServerTaxesAccountname = ConfigManager.getJobsConfiguration().ServertaxesAcountName;
if (this.ServerAccount == null) if (this.ServerAccount == null)
this.ServerAccount = Bukkit.getOfflinePlayer(ServerAccountname); this.ServerAccount = OfflinePlayerList.getPlayer(ServerAccountname);
if (this.ServerTaxesAccount == null) if (this.ServerTaxesAccount == null)
this.ServerTaxesAccount = Bukkit.getOfflinePlayer(ServerAccountname); this.ServerTaxesAccount = OfflinePlayerList.getPlayer(ServerAccountname);
if (ConfigManager.getJobsConfiguration().UseTaxes && ConfigManager.getJobsConfiguration().TransferToServerAccount && ServerTaxesAccount != null) { if (ConfigManager.getJobsConfiguration().UseTaxes && ConfigManager.getJobsConfiguration().TransferToServerAccount && ServerTaxesAccount != null) {

View File

@ -51,6 +51,7 @@ import com.gamingmesh.jobs.config.ConfigManager;
import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.i18n.Language;
import com.gamingmesh.jobs.stuff.OfflinePlayerList;
public class JobsListener implements Listener { public class JobsListener implements Listener {
// hook to the main plugin // hook to the main plugin
@ -185,6 +186,7 @@ public class JobsListener implements Listener {
if (!plugin.isEnabled()) if (!plugin.isEnabled())
return; return;
Jobs.getPlayerManager().playerQuit(event.getPlayer()); Jobs.getPlayerManager().playerQuit(event.getPlayer());
OfflinePlayerList.addPlayer(event.getPlayer());
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
@ -205,15 +207,9 @@ public class JobsListener implements Listener {
if (!ConfigManager.getJobsConfiguration().SignsEnabled) if (!ConfigManager.getJobsConfiguration().SignsEnabled)
return; return;
Player player = (Player) event.getPlayer();
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
return; return;
Material material = event.getClickedBlock().getType();
if (material != Material.WALL_SIGN && material != Material.SIGN && material != Material.SIGN_POST)
return;
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
if (block == null) if (block == null)
@ -237,6 +233,7 @@ public class JobsListener implements Listener {
} }
} }
Player player = (Player) event.getPlayer();
Bukkit.dispatchCommand(player, "jobs " + command + " " + ChatColor.stripColor(sign.getLine(2)) + " " + ChatColor.stripColor(sign.getLine(3))); Bukkit.dispatchCommand(player, "jobs " + command + " " + ChatColor.stripColor(sign.getLine(2)) + " " + ChatColor.stripColor(sign.getLine(3)));
} }
@ -249,11 +246,6 @@ public class JobsListener implements Listener {
if (!ConfigManager.getJobsConfiguration().SignsEnabled) if (!ConfigManager.getJobsConfiguration().SignsEnabled)
return; return;
Material material = event.getBlock().getType();
if (material != Material.WALL_SIGN && material != Material.SIGN && material != Material.SIGN_POST)
return;
Block block = event.getBlock(); Block block = event.getBlock();
if (block == null) if (block == null)

View File

@ -26,3 +26,5 @@
/TimeManage.class /TimeManage.class
/Loging.class /Loging.class
/ScheduleUtil$2.class /ScheduleUtil$2.class
/OfflinePlayerList.class
/OfflinePlayerList$1.class

View File

@ -19,9 +19,7 @@ public class Loging {
if (jPlayer.getLog().size() > 0 && ScheduleUtil.dateByInt != jPlayer.getLog().get(0).getDate()) { if (jPlayer.getLog().size() > 0 && ScheduleUtil.dateByInt != jPlayer.getLog().get(0).getDate()) {
ScheduleUtil.dateByInt = TimeManage.timeInInt(); ScheduleUtil.dateByInt = TimeManage.timeInInt();
Debug.D("1 Not equals " + ScheduleUtil.dateByInt + " " + jPlayer.getLog().get(0).getDate());
if (ScheduleUtil.dateByInt != jPlayer.getLog().get(0).getDate()) { if (ScheduleUtil.dateByInt != jPlayer.getLog().get(0).getDate()) {
Debug.D("Not equals " + ScheduleUtil.dateByInt + " " + jPlayer.getLog().get(0).getDate());
Jobs.getJobsDAO().saveLog(jPlayer); Jobs.getJobsDAO().saveLog(jPlayer);
jPlayer.getLog().clear(); jPlayer.getLog().clear();
} }
@ -30,19 +28,13 @@ public class Loging {
for (Log one : logList) { for (Log one : logList) {
if (!one.getActionType().equalsIgnoreCase(ActionName)) if (!one.getActionType().equalsIgnoreCase(ActionName))
continue; continue;
one.add(item, amount, expAmount); one.add(item, amount, expAmount);
found = true; found = true;
Debug.D(item + " : " + one.getCount(item) + " money: " + one.getMoney(item) + " exp:" + one.getExp(item));
} }
if (!found) { if (!found) {
Log log = new Log(ActionName); Log log = new Log(ActionName);
log.add(item, amount, expAmount); log.add(item, amount, expAmount);
logList.add(log); logList.add(log);
String msg = item + " : " + log.getCount(item) + " money: " + log.getMoney(item) + " exp:" + log.getExp(item);
Debug.D(msg);
} }
} }
@ -52,19 +44,13 @@ public class Loging {
for (Log one : logList) { for (Log one : logList) {
if (!one.getActionType().equalsIgnoreCase(ActionName)) if (!one.getActionType().equalsIgnoreCase(ActionName))
continue; continue;
one.add(item, count, money, expAmount); one.add(item, count, money, expAmount);
found = true; found = true;
Debug.D(item + " : " + one.getCount(item) + " money: " + one.getMoney(item) + " exp:" + one.getExp(item));
} }
if (!found) { if (!found) {
Log log = new Log(ActionName); Log log = new Log(ActionName);
log.add(item, count, money, expAmount); log.add(item, count, money, expAmount);
logList.add(log); logList.add(log);
String msg = item + " : " + log.getCount(item) + " money: " + log.getMoney(item) + " exp:" + log.getExp(item);
Debug.D(msg);
} }
} }
} }

View File

@ -0,0 +1,56 @@
package com.gamingmesh.jobs.stuff;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import com.gamingmesh.jobs.JobsPlugin;
import com.gamingmesh.jobs.config.ConfigManager;
public class OfflinePlayerList {
private static HashMap<String, OfflinePlayer> map = new HashMap<String, OfflinePlayer>();
private static HashMap<UUID, OfflinePlayer> uuidmap = new HashMap<UUID, OfflinePlayer>();
public static void fillList() {
Bukkit.getScheduler().runTaskAsynchronously(JobsPlugin.instance, new Runnable() {
@Override
public void run() {
OfflinePlayer[] players = Bukkit.getOfflinePlayers();
for (OfflinePlayer one : players) {
if (one == null)
continue;
map.put(one.getName().toLowerCase(), one);
uuidmap.put(one.getUniqueId(), one);
}
return;
}
});
}
public static OfflinePlayer getPlayer(UUID uuid) {
if (!ConfigManager.getJobsConfiguration().LocalOfflinePlayersData)
return Bukkit.getOfflinePlayer(uuid);
if (uuidmap.containsKey(uuid))
return uuidmap.get(uuid);
return null;
}
public static OfflinePlayer getPlayer(String name) {
if (!ConfigManager.getJobsConfiguration().LocalOfflinePlayersData)
return Bukkit.getOfflinePlayer(name);
if (map.containsKey(name.toLowerCase()))
return map.get(name.toLowerCase());
return null;
}
public static void addPlayer(OfflinePlayer player) {
map.put(player.getName().toLowerCase(), player);
uuidmap.put(player.getUniqueId(), player);
}
}

View File

@ -1,7 +1,7 @@
name: Jobs name: Jobs
description: Jobs Plugin for the BukkitAPI description: Jobs Plugin for the BukkitAPI
main: com.gamingmesh.jobs.JobsPlugin main: com.gamingmesh.jobs.JobsPlugin
version: 2.50.1 version: 2.51.0
author: phrstbrn author: phrstbrn
softdepend: [Vault] softdepend: [Vault]
commands: commands:
@ -138,4 +138,13 @@ permissions:
default: true default: true
jobs.command.limit: jobs.command.limit:
description: Grants access to the limit command description: Grants access to the limit command
default: true default: true
jobs.command.log:
description: Grants access to the log command
default: true
jobs.command.log.others:
description: Grants access to the log command
default: op
jobs.command.glog:
description: Grants access to the glog command
default: op