mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-16 13:11:19 +01:00
2.47.2 update
This commit is contained in:
parent
9b28b6b232
commit
0dcb81210d
@ -22,202 +22,208 @@ import com.gamingmesh.jobs.i18n.Language;
|
||||
|
||||
public class SignUtil {
|
||||
|
||||
public static SignInfo Signs = new SignInfo();
|
||||
public static SignInfo Signs = new SignInfo();
|
||||
|
||||
// Sign file
|
||||
public static void LoadSigns() {
|
||||
Thread threadd = new Thread() {
|
||||
public void run() {
|
||||
// Sign file
|
||||
public static void LoadSigns() {
|
||||
Thread threadd = new Thread() {
|
||||
public void run() {
|
||||
|
||||
Signs.GetAllSigns().clear();
|
||||
File file = new File(JobsPlugin.instance.getDataFolder(), "Signs.yml");
|
||||
YamlConfiguration f = YamlConfiguration.loadConfiguration(file);
|
||||
Signs.GetAllSigns().clear();
|
||||
File file = new File(JobsPlugin.instance.getDataFolder(), "Signs.yml");
|
||||
YamlConfiguration f = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
if (!f.isConfigurationSection("Signs"))
|
||||
return;
|
||||
if (!f.isConfigurationSection("Signs"))
|
||||
return;
|
||||
|
||||
ConfigurationSection ConfCategory = f.getConfigurationSection("Signs");
|
||||
ArrayList<String> categoriesList = new ArrayList<String>(ConfCategory.getKeys(false));
|
||||
if (categoriesList.size() == 0)
|
||||
return;
|
||||
for (String category : categoriesList) {
|
||||
ConfigurationSection NameSection = ConfCategory.getConfigurationSection(category);
|
||||
Signs.Sign newTemp = new Signs.Sign();
|
||||
newTemp.setCategory(Integer.valueOf(category));
|
||||
newTemp.setWorld(NameSection.getString("World"));
|
||||
newTemp.setX(NameSection.getDouble("X"));
|
||||
newTemp.setY(NameSection.getDouble("Y"));
|
||||
newTemp.setZ(NameSection.getDouble("Z"));
|
||||
newTemp.setNumber(NameSection.getInt("Number"));
|
||||
newTemp.setJobName(NameSection.getString("JobName"));
|
||||
newTemp.setSpecial(NameSection.getBoolean("Special"));
|
||||
Signs.addSign(newTemp);
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
threadd.start();
|
||||
}
|
||||
|
||||
// Signs save file
|
||||
public static void saveSigns() {
|
||||
|
||||
Thread threadd = new Thread() {
|
||||
public void run() {
|
||||
File f = new File(JobsPlugin.instance.getDataFolder(), "Signs.yml");
|
||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(f);
|
||||
|
||||
CommentedYamlConfiguration writer = new CommentedYamlConfiguration();
|
||||
conf.options().copyDefaults(true);
|
||||
|
||||
writer.addComment("Signs", "DO NOT EDIT THIS FILE BY HAND!");
|
||||
|
||||
if (!conf.isConfigurationSection("Signs"))
|
||||
conf.createSection("Signs");
|
||||
|
||||
for (Signs.Sign one : Signs.GetAllSigns()) {
|
||||
String path = "Signs." + String.valueOf(one.GetCategory());
|
||||
writer.set(path + ".World", one.GetWorld());
|
||||
writer.set(path + ".X", one.GetX());
|
||||
writer.set(path + ".Y", one.GetY());
|
||||
writer.set(path + ".Z", one.GetZ());
|
||||
writer.set(path + ".Number", one.GetNumber());
|
||||
writer.set(path + ".JobName", one.GetJobName());
|
||||
writer.set(path + ".Special", one.isSpecial());
|
||||
}
|
||||
|
||||
try {
|
||||
writer.save(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();;
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
threadd.start();
|
||||
}
|
||||
|
||||
public static boolean SignUpdate(String JobName) {
|
||||
List<Signs.Sign> Copy = new ArrayList<Signs.Sign>(Signs.GetAllSigns().size());
|
||||
for (Signs.Sign foo : Signs.GetAllSigns()) {
|
||||
Copy.add(foo);
|
||||
ConfigurationSection ConfCategory = f.getConfigurationSection("Signs");
|
||||
ArrayList<String> categoriesList = new ArrayList<String>(ConfCategory.getKeys(false));
|
||||
if (categoriesList.size() == 0)
|
||||
return;
|
||||
for (String category : categoriesList) {
|
||||
ConfigurationSection NameSection = ConfCategory.getConfigurationSection(category);
|
||||
Signs.Sign newTemp = new Signs.Sign();
|
||||
newTemp.setCategory(Integer.valueOf(category));
|
||||
newTemp.setWorld(NameSection.getString("World"));
|
||||
newTemp.setX(NameSection.getDouble("X"));
|
||||
newTemp.setY(NameSection.getDouble("Y"));
|
||||
newTemp.setZ(NameSection.getDouble("Z"));
|
||||
newTemp.setNumber(NameSection.getInt("Number"));
|
||||
newTemp.setJobName(NameSection.getString("JobName"));
|
||||
newTemp.setSpecial(NameSection.getBoolean("Special"));
|
||||
Signs.addSign(newTemp);
|
||||
}
|
||||
int timelapse = 1;
|
||||
for (Signs.Sign one : Copy) {
|
||||
String SignJobName = one.GetJobName();
|
||||
if (JobName.equalsIgnoreCase(SignJobName)) {
|
||||
String SignsWorld = one.GetWorld();
|
||||
double SignsX = one.GetX();
|
||||
double SignsY = one.GetY();
|
||||
double SignsZ = one.GetZ();
|
||||
int number = one.GetNumber() - 1;
|
||||
return;
|
||||
}
|
||||
};
|
||||
threadd.start();
|
||||
}
|
||||
|
||||
List<TopList> PlayerList = new ArrayList<TopList>();
|
||||
if (!JobName.equalsIgnoreCase("gtoplist")) {
|
||||
PlayerList = Jobs.getJobsDAO().toplist(SignJobName, number);
|
||||
} else {
|
||||
PlayerList = Jobs.getJobsDAO().getGlobalTopList(number);
|
||||
}
|
||||
if (PlayerList.size() != 0) {
|
||||
World world = Bukkit.getWorld(SignsWorld);
|
||||
Location nloc = new Location(world, SignsX, SignsY, SignsZ);
|
||||
Block block = nloc.getBlock();
|
||||
if (!(block.getState() instanceof org.bukkit.block.Sign)) {
|
||||
Signs.GetAllSigns().remove(one);
|
||||
saveSigns();
|
||||
} else {
|
||||
org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState();
|
||||
if (!one.isSpecial()) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (i >= PlayerList.size()) {
|
||||
break;
|
||||
}
|
||||
String PlayerName = ((TopList) PlayerList.get(i)).getPlayerName();
|
||||
if (PlayerName.length() > 8) {
|
||||
String PlayerNameStrip = PlayerName.split("(?<=\\G.{7})")[0];
|
||||
PlayerName = PlayerNameStrip + "~";
|
||||
}
|
||||
String line = Language.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()));
|
||||
// Signs save file
|
||||
public static void saveSigns() {
|
||||
|
||||
sign.setLine(i, line);
|
||||
}
|
||||
sign.update();
|
||||
UpdateHead(sign.getLocation(), ((TopList) PlayerList.get(0)).getPlayerName(), timelapse);
|
||||
} else {
|
||||
String PlayerName = ((TopList) PlayerList.get(0)).getPlayerName();
|
||||
if (PlayerName.length() > 18) {
|
||||
String PlayerNameStrip = PlayerName.split("(?<=\\G.{13})")[0];
|
||||
PlayerName = PlayerNameStrip + "~";
|
||||
}
|
||||
String line1 = Language.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()));
|
||||
Thread threadd = new Thread() {
|
||||
public void run() {
|
||||
File f = new File(JobsPlugin.instance.getDataFolder(), "Signs.yml");
|
||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(f);
|
||||
|
||||
sign.setLine(0, line1);
|
||||
CommentedYamlConfiguration writer = new CommentedYamlConfiguration();
|
||||
conf.options().copyDefaults(true);
|
||||
|
||||
line1 = Language.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()));
|
||||
writer.addComment("Signs", "DO NOT EDIT THIS FILE BY HAND!");
|
||||
|
||||
sign.setLine(1, line1);
|
||||
if (!conf.isConfigurationSection("Signs"))
|
||||
conf.createSection("Signs");
|
||||
|
||||
line1 = Language.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()));
|
||||
|
||||
sign.setLine(2, line1);
|
||||
|
||||
line1 = Language.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()));
|
||||
|
||||
sign.setLine(3, line1);
|
||||
sign.update();
|
||||
UpdateHead(sign.getLocation(), ((TopList) PlayerList.get(0)).getPlayerName(), timelapse);
|
||||
}
|
||||
|
||||
timelapse++;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Signs.Sign one : Signs.GetAllSigns()) {
|
||||
String path = "Signs." + String.valueOf(one.GetCategory());
|
||||
writer.set(path + ".World", one.GetWorld());
|
||||
writer.set(path + ".X", one.GetX());
|
||||
writer.set(path + ".Y", one.GetY());
|
||||
writer.set(path + ".Z", one.GetZ());
|
||||
writer.set(path + ".Number", one.GetNumber());
|
||||
writer.set(path + ".JobName", one.GetJobName());
|
||||
writer.set(path + ".Special", one.isSpecial());
|
||||
}
|
||||
return true;
|
||||
|
||||
try {
|
||||
writer.save(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
;
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
threadd.start();
|
||||
}
|
||||
|
||||
public static boolean SignUpdate(String JobName) {
|
||||
List<Signs.Sign> Copy = new ArrayList<Signs.Sign>(Signs.GetAllSigns().size());
|
||||
for (Signs.Sign foo : Signs.GetAllSigns()) {
|
||||
Copy.add(foo);
|
||||
}
|
||||
int timelapse = 1;
|
||||
for (Signs.Sign one : Copy) {
|
||||
String SignJobName = one.GetJobName();
|
||||
if (JobName.equalsIgnoreCase(SignJobName)) {
|
||||
String SignsWorld = one.GetWorld();
|
||||
double SignsX = one.GetX();
|
||||
double SignsY = one.GetY();
|
||||
double SignsZ = one.GetZ();
|
||||
int number = one.GetNumber() - 1;
|
||||
|
||||
public static void UpdateHead(final Location loc, final String Playername, final int timelapse) {
|
||||
List<TopList> PlayerList = new ArrayList<TopList>();
|
||||
if (!JobName.equalsIgnoreCase("gtoplist")) {
|
||||
PlayerList = Jobs.getJobsDAO().toplist(SignJobName, number);
|
||||
} else {
|
||||
PlayerList = Jobs.getJobsDAO().getGlobalTopList(number);
|
||||
}
|
||||
if (PlayerList.size() != 0) {
|
||||
World world = Bukkit.getWorld(SignsWorld);
|
||||
Location nloc = new Location(world, SignsX, SignsY, SignsZ);
|
||||
Block block = nloc.getBlock();
|
||||
if (!(block.getState() instanceof org.bukkit.block.Sign)) {
|
||||
Signs.GetAllSigns().remove(one);
|
||||
saveSigns();
|
||||
} else {
|
||||
org.bukkit.block.Sign sign = (org.bukkit.block.Sign) block.getState();
|
||||
if (!one.isSpecial()) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (i >= PlayerList.size()) {
|
||||
break;
|
||||
}
|
||||
String PlayerName = ((TopList) PlayerList.get(i)).getPlayerName();
|
||||
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(JobsPlugin.instance, new Runnable() {
|
||||
public void run() {
|
||||
if (PlayerName != null && PlayerName.length() > 8) {
|
||||
String PlayerNameStrip = PlayerName.split("(?<=\\G.{7})")[0];
|
||||
PlayerName = PlayerNameStrip + "~";
|
||||
}
|
||||
|
||||
loc.setY(loc.getY() + 1);
|
||||
if (PlayerName == null)
|
||||
PlayerName = "Unknown";
|
||||
|
||||
if (Playername == null)
|
||||
return;
|
||||
String line = Language.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()));
|
||||
|
||||
Block block = loc.getBlock();
|
||||
sign.setLine(i, line);
|
||||
}
|
||||
sign.update();
|
||||
UpdateHead(sign.getLocation(), ((TopList) PlayerList.get(0)).getPlayerName(), timelapse);
|
||||
} else {
|
||||
String PlayerName = ((TopList) PlayerList.get(0)).getPlayerName();
|
||||
if (PlayerName.length() > 18) {
|
||||
String PlayerNameStrip = PlayerName.split("(?<=\\G.{13})")[0];
|
||||
PlayerName = PlayerNameStrip + "~";
|
||||
}
|
||||
String line1 = Language.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()));
|
||||
|
||||
if (block == null)
|
||||
return;
|
||||
sign.setLine(0, line1);
|
||||
|
||||
if (!(block.getState() instanceof Skull))
|
||||
return;
|
||||
line1 = Language.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()));
|
||||
|
||||
Skull skull = (Skull) block.getState();
|
||||
sign.setLine(1, line1);
|
||||
|
||||
if (skull == null)
|
||||
return;
|
||||
line1 = Language.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()));
|
||||
|
||||
skull.setOwner(Playername);
|
||||
skull.update();
|
||||
return;
|
||||
sign.setLine(2, line1);
|
||||
|
||||
line1 = Language.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()));
|
||||
|
||||
sign.setLine(3, line1);
|
||||
sign.update();
|
||||
UpdateHead(sign.getLocation(), ((TopList) PlayerList.get(0)).getPlayerName(), timelapse);
|
||||
}
|
||||
}, timelapse * ConfigManager.getJobsConfiguration().InfoUpdateInterval * 20L);
|
||||
|
||||
timelapse++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void UpdateHead(final Location loc, final String Playername, final int timelapse) {
|
||||
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(JobsPlugin.instance, new Runnable() {
|
||||
public void run() {
|
||||
|
||||
loc.setY(loc.getY() + 1);
|
||||
|
||||
if (Playername == null)
|
||||
return;
|
||||
|
||||
Block block = loc.getBlock();
|
||||
|
||||
if (block == null)
|
||||
return;
|
||||
|
||||
if (!(block.getState() instanceof Skull))
|
||||
return;
|
||||
|
||||
Skull skull = (Skull) block.getState();
|
||||
|
||||
if (skull == null)
|
||||
return;
|
||||
|
||||
skull.setOwner(Playername);
|
||||
skull.update();
|
||||
return;
|
||||
}
|
||||
}, timelapse * ConfigManager.getJobsConfiguration().InfoUpdateInterval * 20L);
|
||||
}
|
||||
}
|
||||
|
@ -34,125 +34,125 @@ import com.gamingmesh.jobs.container.JobProgression;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
|
||||
public class PermissionHandler {
|
||||
private JobsPlugin plugin;
|
||||
private JobsPlugin plugin;
|
||||
|
||||
public PermissionHandler(JobsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
public PermissionHandler(JobsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void recalculatePermissions(JobsPlayer jPlayer) {
|
||||
|
||||
if (jPlayer == null)
|
||||
return;
|
||||
Player player = (Player) jPlayer.getPlayer();
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
// remove old permissions
|
||||
String permName = "jobs.players." + player.getName();
|
||||
Permission permission = plugin.getServer().getPluginManager().getPermission(permName);
|
||||
if (permission != null) {
|
||||
plugin.getServer().getPluginManager().removePermission(permission);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
public void recalculatePermissions(JobsPlayer jPlayer) {
|
||||
|
||||
if (jPlayer == null)
|
||||
return;
|
||||
Player player = (Player) jPlayer.getPlayer();
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
// remove old permissions
|
||||
String permName = "jobs.players." + player.getName();
|
||||
Permission permission = plugin.getServer().getPluginManager().getPermission(permName);
|
||||
if (permission != null) {
|
||||
plugin.getServer().getPluginManager().removePermission(permission);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
// Permissions should only apply if we have permission to use jobs in this world
|
||||
if (hasWorldPermission(player, player.getWorld().getName())) {
|
||||
List<JobProgression> progression = jPlayer.getJobProgression();
|
||||
// calculate new permissions
|
||||
HashMap<String, Boolean> permissions = new HashMap<String, Boolean>();
|
||||
if (progression.size() == 0) {
|
||||
Job job = Jobs.getNoneJob();
|
||||
if (job != null) {
|
||||
for (JobPermission perm : job.getPermissions()) {
|
||||
if (perm.getLevelRequirement() <= 0) {
|
||||
if (perm.getValue()) {
|
||||
permissions.put(perm.getNode(), true);
|
||||
} else {
|
||||
/*
|
||||
* If the key exists, don't put a false node in
|
||||
* This is in case we already have a true node there
|
||||
*/
|
||||
if (!permissions.containsKey(perm.getNode())) {
|
||||
permissions.put(perm.getNode(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Permissions should only apply if we have permission to use jobs in this world
|
||||
if (hasWorldPermission(player, player.getWorld().getName())) {
|
||||
List<JobProgression> progression = jPlayer.getJobProgression();
|
||||
// calculate new permissions
|
||||
HashMap<String, Boolean> permissions = new HashMap<String, Boolean>();
|
||||
if (progression.size() == 0) {
|
||||
Job job = Jobs.getNoneJob();
|
||||
if (job != null) {
|
||||
for (JobPermission perm : job.getPermissions()) {
|
||||
if (perm.getLevelRequirement() <= 0) {
|
||||
if (perm.getValue()) {
|
||||
permissions.put(perm.getNode(), true);
|
||||
} else {
|
||||
/*
|
||||
* If the key exists, don't put a false node in
|
||||
* This is in case we already have a true node there
|
||||
*/
|
||||
if (!permissions.containsKey(perm.getNode())) {
|
||||
permissions.put(perm.getNode(), false);
|
||||
}
|
||||
} else {
|
||||
for (JobProgression prog : progression) {
|
||||
for (JobPermission perm : prog.getJob().getPermissions()) {
|
||||
if (prog.getLevel() >= perm.getLevelRequirement()) {
|
||||
/*
|
||||
* If the key exists, don't put a false node in
|
||||
* This is in case we already have a true node there
|
||||
*/
|
||||
if (perm.getValue()) {
|
||||
permissions.put(perm.getNode(), true);
|
||||
} else {
|
||||
if (!permissions.containsKey(perm.getNode())) {
|
||||
permissions.put(perm.getNode(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (JobProgression prog : progression) {
|
||||
for (JobPermission perm : prog.getJob().getPermissions()) {
|
||||
if (prog.getLevel() >= perm.getLevelRequirement()) {
|
||||
/*
|
||||
* If the key exists, don't put a false node in
|
||||
* This is in case we already have a true node there
|
||||
*/
|
||||
if (perm.getValue()) {
|
||||
permissions.put(perm.getNode(), true);
|
||||
} else {
|
||||
if (!permissions.containsKey(perm.getNode())) {
|
||||
permissions.put(perm.getNode(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add new permissions (if applicable)
|
||||
if (permissions.size() > 0) {
|
||||
plugin.getServer().getPluginManager().addPermission(new Permission(permName, PermissionDefault.FALSE, permissions));
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the permissions changed, recalculate them
|
||||
if (!changed)
|
||||
return;
|
||||
}
|
||||
|
||||
// find old attachment
|
||||
PermissionAttachment attachment = null;
|
||||
for (PermissionAttachmentInfo pai : player.getEffectivePermissions()) {
|
||||
if (pai.getAttachment() != null && pai.getAttachment().getPlugin() instanceof JobsPlugin) {
|
||||
attachment = pai.getAttachment();
|
||||
}
|
||||
}
|
||||
|
||||
// create if attachment doesn't exist
|
||||
if (attachment == null) {
|
||||
attachment = player.addAttachment(plugin);
|
||||
attachment.setPermission(permName, true);
|
||||
}
|
||||
|
||||
// recalculate!
|
||||
player.recalculatePermissions();
|
||||
// add new permissions (if applicable)
|
||||
if (permissions.size() > 0) {
|
||||
plugin.getServer().getPluginManager().addPermission(new Permission(permName, PermissionDefault.FALSE, permissions));
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void registerPermissions() {
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
for (World world : plugin.getServer().getWorlds()) {
|
||||
if (pm.getPermission("jobs.world." + world.getName().toLowerCase()) == null)
|
||||
pm.addPermission(new Permission("jobs.world." + world.getName().toLowerCase(), PermissionDefault.TRUE));
|
||||
}
|
||||
for (Job job : Jobs.getJobs()) {
|
||||
if (pm.getPermission("jobs.join." + job.getName().toLowerCase()) == null)
|
||||
pm.addPermission(new Permission("jobs.join." + job.getName().toLowerCase(), PermissionDefault.TRUE));
|
||||
}
|
||||
// If the permissions changed, recalculate them
|
||||
if (!changed)
|
||||
return;
|
||||
|
||||
// find old attachment
|
||||
PermissionAttachment attachment = null;
|
||||
for (PermissionAttachmentInfo pai : player.getEffectivePermissions()) {
|
||||
if (pai.getAttachment() != null && pai.getAttachment().getPlugin() instanceof JobsPlugin) {
|
||||
attachment = pai.getAttachment();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check World permissions
|
||||
*/
|
||||
public boolean hasWorldPermission(Player player, String world) {
|
||||
if (!player.hasPermission("jobs.use")) {
|
||||
return false;
|
||||
} else {
|
||||
return player.hasPermission("jobs.world." + world.toLowerCase());
|
||||
}
|
||||
// create if attachment doesn't exist
|
||||
if (attachment == null) {
|
||||
attachment = player.addAttachment(plugin);
|
||||
attachment.setPermission(permName, true);
|
||||
}
|
||||
|
||||
// recalculate!
|
||||
player.recalculatePermissions();
|
||||
}
|
||||
|
||||
public void registerPermissions() {
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
for (World world : plugin.getServer().getWorlds()) {
|
||||
if (pm.getPermission("jobs.world." + world.getName().toLowerCase()) == null)
|
||||
pm.addPermission(new Permission("jobs.world." + world.getName().toLowerCase(), PermissionDefault.TRUE));
|
||||
}
|
||||
for (Job job : Jobs.getJobs()) {
|
||||
if (pm.getPermission("jobs.join." + job.getName().toLowerCase()) == null)
|
||||
pm.addPermission(new Permission("jobs.join." + job.getName().toLowerCase(), PermissionDefault.TRUE));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check World permissions
|
||||
*/
|
||||
public boolean hasWorldPermission(Player player, String world) {
|
||||
if (!player.hasPermission("jobs.use")) {
|
||||
return false;
|
||||
} else {
|
||||
return player.hasPermission("jobs.world." + world.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,480 +45,482 @@ import com.gamingmesh.jobs.stuff.ChatColor;
|
||||
import com.gamingmesh.jobs.stuff.PerformCommands;
|
||||
|
||||
public class PlayerManager {
|
||||
// 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 = Collections.synchronizedMap(new HashMap<String, JobsPlayer>());
|
||||
private Map<String, JobsPlayer> players = new HashMap<String, JobsPlayer>();
|
||||
|
||||
/**
|
||||
* Handles join of new player
|
||||
* @param playername
|
||||
/**
|
||||
* Handles join of new player
|
||||
* @param playername
|
||||
*/
|
||||
public void playerJoin(final Player player) {
|
||||
//synchronized (players) {
|
||||
JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
|
||||
if (jPlayer == null) {
|
||||
jPlayer = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), player);
|
||||
players.put(player.getName().toLowerCase(), jPlayer);
|
||||
}
|
||||
jPlayer.onConnect();
|
||||
jPlayer.reloadHonorific();
|
||||
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
|
||||
return;
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles player quit
|
||||
* @param playername
|
||||
*/
|
||||
public void playerQuit(Player player) {
|
||||
//synchronized (players) {
|
||||
if (ConfigManager.getJobsConfiguration().saveOnDisconnect()) {
|
||||
JobsPlayer jPlayer = players.remove(player.getName().toLowerCase());
|
||||
if (jPlayer != null) {
|
||||
jPlayer.save(Jobs.getJobsDAO());
|
||||
jPlayer.onDisconnect();
|
||||
}
|
||||
} else {
|
||||
JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
|
||||
if (jPlayer != null) {
|
||||
jPlayer.onDisconnect();
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all the information of all of the players in the game
|
||||
*/
|
||||
public void saveAll() {
|
||||
JobsDAO dao = Jobs.getJobsDAO();
|
||||
|
||||
/*
|
||||
* Saving is a three step process to minimize synchronization locks when called asynchronously.
|
||||
*
|
||||
* 1) Safely copy list for saving.
|
||||
* 2) Perform save on all players on copied list.
|
||||
* 3) Garbage collect the real list to remove any offline players with saved data
|
||||
*/
|
||||
public void playerJoin(final Player player) {
|
||||
//synchronized (players) {
|
||||
Thread threadd = new Thread() {
|
||||
public void run() {
|
||||
JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
|
||||
if (jPlayer == null) {
|
||||
jPlayer = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), player);
|
||||
players.put(player.getName().toLowerCase(), jPlayer);
|
||||
}
|
||||
jPlayer.onConnect();
|
||||
jPlayer.reloadHonorific();
|
||||
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
|
||||
return;
|
||||
}
|
||||
};
|
||||
threadd.start();
|
||||
threadd.interrupt();
|
||||
//}
|
||||
ArrayList<JobsPlayer> list = null;
|
||||
synchronized (players) {
|
||||
list = new ArrayList<JobsPlayer>(players.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles player quit
|
||||
* @param playername
|
||||
*/
|
||||
public void playerQuit(Player player) {
|
||||
//synchronized (players) {
|
||||
if (ConfigManager.getJobsConfiguration().saveOnDisconnect()) {
|
||||
JobsPlayer jPlayer = players.remove(player.getName().toLowerCase());
|
||||
if (jPlayer != null) {
|
||||
jPlayer.save(Jobs.getJobsDAO());
|
||||
jPlayer.onDisconnect();
|
||||
}
|
||||
} else {
|
||||
JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
|
||||
if (jPlayer != null) {
|
||||
jPlayer.onDisconnect();
|
||||
}
|
||||
}
|
||||
//}
|
||||
for (JobsPlayer jPlayer : list) {
|
||||
jPlayer.save(dao);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all the information of all of the players in the game
|
||||
*/
|
||||
public void saveAll() {
|
||||
JobsDAO dao = Jobs.getJobsDAO();
|
||||
|
||||
/*
|
||||
* Saving is a three step process to minimize synchronization locks when called asynchronously.
|
||||
*
|
||||
* 1) Safely copy list for saving.
|
||||
* 2) Perform save on all players on copied list.
|
||||
* 3) Garbage collect the real list to remove any offline players with saved data
|
||||
*/
|
||||
ArrayList<JobsPlayer> list = null;
|
||||
synchronized (players) {
|
||||
list = new ArrayList<JobsPlayer>(players.values());
|
||||
}
|
||||
|
||||
for (JobsPlayer jPlayer : list) {
|
||||
jPlayer.save(dao);
|
||||
}
|
||||
|
||||
synchronized (players) {
|
||||
Iterator<JobsPlayer> iter = players.values().iterator();
|
||||
while (iter.hasNext()) {
|
||||
JobsPlayer jPlayer = iter.next();
|
||||
synchronized (jPlayer.saveLock) {
|
||||
if (!jPlayer.isOnline() && jPlayer.isSaved()) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player job info for specific player
|
||||
* @param player - the player who's job you're getting
|
||||
* @return the player job info of the player
|
||||
*/
|
||||
public JobsPlayer getJobsPlayer(Player player) {
|
||||
return players.get(player.getName().toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player job info for specific player
|
||||
* @param player name - the player name who's job you're getting
|
||||
* @return the player job info of the player
|
||||
*/
|
||||
public JobsPlayer getJobsPlayer(String playerName) {
|
||||
return players.get(playerName.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player job info for specific player
|
||||
* @param player - the player who's job you're getting
|
||||
* @return the player job info of the player
|
||||
*/
|
||||
public JobsPlayer getJobsPlayerOffline(OfflinePlayer offlinePlayer) {
|
||||
JobsPlayer jPlayer = players.get(offlinePlayer.getName().toLowerCase());
|
||||
if (jPlayer != null)
|
||||
return jPlayer;
|
||||
|
||||
return JobsPlayer.loadFromDao(Jobs.getJobsDAO(), offlinePlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes player to join their job
|
||||
* @param jPlayer
|
||||
* @param job
|
||||
*/
|
||||
public void joinJob(JobsPlayer jPlayer, Job job) {
|
||||
synchronized (players) {
|
||||
Iterator<JobsPlayer> iter = players.values().iterator();
|
||||
while (iter.hasNext()) {
|
||||
JobsPlayer jPlayer = iter.next();
|
||||
synchronized (jPlayer.saveLock) {
|
||||
if (jPlayer.isInJob(job))
|
||||
return;
|
||||
// let the user join the job
|
||||
if (!jPlayer.joinJob(job, jPlayer))
|
||||
return;
|
||||
|
||||
// JobsJoin event
|
||||
JobsJoinEvent jobsjoinevent = new JobsJoinEvent(jPlayer, job);
|
||||
Bukkit.getServer().getPluginManager().callEvent(jobsjoinevent);
|
||||
// If event is canceled, dont do anything
|
||||
if (jobsjoinevent.isCancelled())
|
||||
return;
|
||||
|
||||
Jobs.getJobsDAO().joinJob(jPlayer, job);
|
||||
PerformCommands.PerformCommandsOnJoin(jPlayer, job);
|
||||
Jobs.takeSlot(job);
|
||||
Signs.SignUtil.SignUpdate(job.getName());
|
||||
Signs.SignUtil.SignUpdate("gtoplist");
|
||||
job.updateTotalPlayers();
|
||||
if (!jPlayer.isOnline() && jPlayer.isSaved()) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes player to leave their job
|
||||
* @param jPlayer
|
||||
* @param job
|
||||
*/
|
||||
public void leaveJob(JobsPlayer jPlayer, Job job) {
|
||||
synchronized (jPlayer.saveLock) {
|
||||
if (!jPlayer.isInJob(job))
|
||||
return;
|
||||
Jobs.getJobsDAO().recordToArchive(jPlayer, job);
|
||||
// let the user leave the job
|
||||
if (!jPlayer.leaveJob(job))
|
||||
return;
|
||||
/**
|
||||
* Get the player job info for specific player
|
||||
* @param player - the player who's job you're getting
|
||||
* @return the player job info of the player
|
||||
*/
|
||||
public JobsPlayer getJobsPlayer(Player player) {
|
||||
return players.get(player.getName().toLowerCase());
|
||||
}
|
||||
|
||||
// JobsJoin event
|
||||
JobsLeaveEvent jobsleaveevent = new JobsLeaveEvent(jPlayer, job);
|
||||
Bukkit.getServer().getPluginManager().callEvent(jobsleaveevent);
|
||||
// If event is canceled, dont do anything
|
||||
if (jobsleaveevent.isCancelled())
|
||||
return;
|
||||
/**
|
||||
* Get the player job info for specific player
|
||||
* @param player name - the player name who's job you're getting
|
||||
* @return the player job info of the player
|
||||
*/
|
||||
public JobsPlayer getJobsPlayer(String playerName) {
|
||||
return players.get(playerName.toLowerCase());
|
||||
}
|
||||
|
||||
Jobs.getJobsDAO().quitJob(jPlayer, job);
|
||||
PerformCommands.PerformCommandsOnLeave(jPlayer, job);
|
||||
Jobs.leaveSlot(job);
|
||||
/**
|
||||
* Get the player job info for specific player
|
||||
* @param player - the player who's job you're getting
|
||||
* @return the player job info of the player
|
||||
*/
|
||||
public JobsPlayer getJobsPlayerOffline(OfflinePlayer offlinePlayer) {
|
||||
JobsPlayer jPlayer = players.get(offlinePlayer.getName().toLowerCase());
|
||||
if (jPlayer != null)
|
||||
return jPlayer;
|
||||
|
||||
Signs.SignUtil.SignUpdate(job.getName());
|
||||
Signs.SignUtil.SignUpdate("gtoplist");
|
||||
job.updateTotalPlayers();
|
||||
}
|
||||
return JobsPlayer.loadFromDao(Jobs.getJobsDAO(), offlinePlayer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes player to join their job
|
||||
* @param jPlayer
|
||||
* @param job
|
||||
*/
|
||||
public void joinJob(JobsPlayer jPlayer, Job job) {
|
||||
synchronized (jPlayer.saveLock) {
|
||||
if (jPlayer.isInJob(job))
|
||||
return;
|
||||
// let the user join the job
|
||||
if (!jPlayer.joinJob(job, jPlayer))
|
||||
return;
|
||||
|
||||
// JobsJoin event
|
||||
JobsJoinEvent jobsjoinevent = new JobsJoinEvent(jPlayer, job);
|
||||
Bukkit.getServer().getPluginManager().callEvent(jobsjoinevent);
|
||||
// If event is canceled, dont do anything
|
||||
if (jobsjoinevent.isCancelled())
|
||||
return;
|
||||
|
||||
Jobs.getJobsDAO().joinJob(jPlayer, job);
|
||||
PerformCommands.PerformCommandsOnJoin(jPlayer, job);
|
||||
Jobs.takeSlot(job);
|
||||
Signs.SignUtil.SignUpdate(job.getName());
|
||||
Signs.SignUtil.SignUpdate("gtoplist");
|
||||
job.updateTotalPlayers();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes player to leave all their jobs
|
||||
* @param jPlayer
|
||||
*/
|
||||
public void leaveAllJobs(JobsPlayer jPlayer) {
|
||||
synchronized (jPlayer.saveLock) {
|
||||
for (JobProgression job : jPlayer.getJobProgression()) {
|
||||
Jobs.getJobsDAO().quitJob(jPlayer, job.getJob());
|
||||
PerformCommands.PerformCommandsOnLeave(jPlayer, job.getJob());
|
||||
Jobs.leaveSlot(job.getJob());
|
||||
/**
|
||||
* Causes player to leave their job
|
||||
* @param jPlayer
|
||||
* @param job
|
||||
*/
|
||||
public void leaveJob(JobsPlayer jPlayer, Job job) {
|
||||
synchronized (jPlayer.saveLock) {
|
||||
if (!jPlayer.isInJob(job))
|
||||
return;
|
||||
Jobs.getJobsDAO().recordToArchive(jPlayer, job);
|
||||
// let the user leave the job
|
||||
if (!jPlayer.leaveJob(job))
|
||||
return;
|
||||
|
||||
Signs.SignUtil.SignUpdate(job.getJob().getName());
|
||||
Signs.SignUtil.SignUpdate("gtoplist");
|
||||
job.getJob().updateTotalPlayers();
|
||||
}
|
||||
// JobsJoin event
|
||||
JobsLeaveEvent jobsleaveevent = new JobsLeaveEvent(jPlayer, job);
|
||||
Bukkit.getServer().getPluginManager().callEvent(jobsleaveevent);
|
||||
// If event is canceled, dont do anything
|
||||
if (jobsleaveevent.isCancelled())
|
||||
return;
|
||||
|
||||
jPlayer.leaveAllJobs();
|
||||
}
|
||||
Jobs.getJobsDAO().quitJob(jPlayer, job);
|
||||
PerformCommands.PerformCommandsOnLeave(jPlayer, job);
|
||||
Jobs.leaveSlot(job);
|
||||
|
||||
Signs.SignUtil.SignUpdate(job.getName());
|
||||
Signs.SignUtil.SignUpdate("gtoplist");
|
||||
job.updateTotalPlayers();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers player job
|
||||
* @param jPlayer
|
||||
* @param oldjob - the old job
|
||||
* @param newjob - the new job
|
||||
*/
|
||||
public void transferJob(JobsPlayer jPlayer, Job oldjob, Job newjob) {
|
||||
synchronized (jPlayer.saveLock) {
|
||||
if (!jPlayer.transferJob(oldjob, newjob, jPlayer))
|
||||
return;
|
||||
/**
|
||||
* Causes player to leave all their jobs
|
||||
* @param jPlayer
|
||||
*/
|
||||
public void leaveAllJobs(JobsPlayer jPlayer) {
|
||||
synchronized (jPlayer.saveLock) {
|
||||
for (JobProgression job : jPlayer.getJobProgression()) {
|
||||
Jobs.getJobsDAO().quitJob(jPlayer, job.getJob());
|
||||
PerformCommands.PerformCommandsOnLeave(jPlayer, job.getJob());
|
||||
Jobs.leaveSlot(job.getJob());
|
||||
|
||||
JobsDAO dao = Jobs.getJobsDAO();
|
||||
dao.quitJob(jPlayer, oldjob);
|
||||
oldjob.updateTotalPlayers();
|
||||
dao.joinJob(jPlayer, newjob);
|
||||
newjob.updateTotalPlayers();
|
||||
jPlayer.save(dao);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Promotes player in their job
|
||||
* @param jPlayer
|
||||
* @param job - the job
|
||||
* @param levels - number of levels to promote
|
||||
*/
|
||||
public void promoteJob(JobsPlayer jPlayer, Job job, int levels) {
|
||||
synchronized (jPlayer.saveLock) {
|
||||
jPlayer.promoteJob(job, levels, jPlayer);
|
||||
jPlayer.save(Jobs.getJobsDAO());
|
||||
|
||||
Signs.SignUtil.SignUpdate(job.getName());
|
||||
Signs.SignUtil.SignUpdate("gtoplist");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Demote player in their job
|
||||
* @param jPlayer
|
||||
* @param job - the job
|
||||
* @param levels - number of levels to demote
|
||||
*/
|
||||
public void demoteJob(JobsPlayer jPlayer, Job job, int levels) {
|
||||
synchronized (jPlayer.saveLock) {
|
||||
jPlayer.demoteJob(job, levels);
|
||||
jPlayer.save(Jobs.getJobsDAO());
|
||||
Signs.SignUtil.SignUpdate(job.getName());
|
||||
Signs.SignUtil.SignUpdate("gtoplist");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds experience to the player
|
||||
* @param jPlayer
|
||||
* @param job - the job
|
||||
* @param experience - experience gained
|
||||
*/
|
||||
public void addExperience(JobsPlayer jPlayer, Job job, double experience) {
|
||||
synchronized (jPlayer.saveLock) {
|
||||
JobProgression prog = jPlayer.getJobProgression(job);
|
||||
if (prog == null)
|
||||
return;
|
||||
int oldLevel = prog.getLevel();
|
||||
if (prog.addExperience(experience))
|
||||
performLevelUp(jPlayer, job, oldLevel);
|
||||
|
||||
jPlayer.save(Jobs.getJobsDAO());
|
||||
Signs.SignUtil.SignUpdate(job.getName());
|
||||
Signs.SignUtil.SignUpdate("gtoplist");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes experience to the player
|
||||
* @param jPlayer
|
||||
* @param job - the job
|
||||
* @param experience - experience gained
|
||||
*/
|
||||
public void removeExperience(JobsPlayer jPlayer, Job job, double experience) {
|
||||
synchronized (jPlayer.saveLock) {
|
||||
JobProgression prog = jPlayer.getJobProgression(job);
|
||||
if (prog == null)
|
||||
return;
|
||||
prog.addExperience(-experience);
|
||||
|
||||
jPlayer.save(Jobs.getJobsDAO());
|
||||
Signs.SignUtil.SignUpdate(job.getName());
|
||||
Signs.SignUtil.SignUpdate("gtoplist");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts level up about a player
|
||||
* @param jPlayer
|
||||
* @param job
|
||||
* @param oldLevel
|
||||
*/
|
||||
public void performLevelUp(JobsPlayer jPlayer, Job job, int oldLevel) {
|
||||
|
||||
Player player = (Player) jPlayer.getPlayer();
|
||||
JobProgression prog = jPlayer.getJobProgression(job);
|
||||
if (prog == null)
|
||||
return;
|
||||
|
||||
// LevelUp event
|
||||
JobsLevelUpEvent levelUpEvent = new JobsLevelUpEvent(jPlayer, job.getName(), prog.getLevel(), ConfigManager.getJobsConfiguration().getTitleForLevel(oldLevel, job.getName()), ConfigManager.getJobsConfiguration().getTitleForLevel(prog.getLevel(), job.getName()), ConfigManager.getJobsConfiguration().SoundLevelupSound.toUpperCase(), ConfigManager.getJobsConfiguration().SoundLevelupVolume, ConfigManager.getJobsConfiguration().SoundLevelupPitch, ConfigManager.getJobsConfiguration().SoundTitleChangeSound.toUpperCase(), ConfigManager.getJobsConfiguration().SoundTitleChangeVolume, ConfigManager.getJobsConfiguration().SoundTitleChangePitch);
|
||||
Bukkit.getServer().getPluginManager().callEvent(levelUpEvent);
|
||||
// If event is canceled, dont do anything
|
||||
if (levelUpEvent.isCancelled())
|
||||
return;
|
||||
|
||||
if (ConfigManager.getJobsConfiguration().SoundLevelupUse)
|
||||
player.getWorld().playSound(player.getLocation(), Sound.valueOf(levelUpEvent.getSoundName()), levelUpEvent.getSoundVolume(), levelUpEvent.getSoundPitch());
|
||||
|
||||
String message;
|
||||
if (ConfigManager.getJobsConfiguration().isBroadcastingLevelups()) {
|
||||
message = Language.getMessage("message.levelup.broadcast");
|
||||
} else {
|
||||
message = Language.getMessage("message.levelup.nobroadcast");
|
||||
}
|
||||
|
||||
message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
|
||||
|
||||
if (levelUpEvent.getOldTitle() != null) {
|
||||
message = message.replace("%titlename%", levelUpEvent.getOldTitleColor() + levelUpEvent.getOldTitleName() + ChatColor.WHITE);
|
||||
}
|
||||
if (player != null) {
|
||||
message = message.replace("%playername%", player.getDisplayName());
|
||||
} else {
|
||||
message = message.replace("%playername%", jPlayer.getUserName());
|
||||
}
|
||||
message = message.replace("%joblevel%", "" + prog.getLevel());
|
||||
for (String line : message.split("\n")) {
|
||||
if (ConfigManager.getJobsConfiguration().isBroadcastingLevelups()) {
|
||||
if (ConfigManager.getJobsConfiguration().BroadcastingLevelUpLevels.contains(oldLevel + 1) || ConfigManager.getJobsConfiguration().BroadcastingLevelUpLevels.contains(0))
|
||||
Bukkit.getServer().broadcastMessage(line);
|
||||
} else if (player != null) {
|
||||
if (ConfigManager.getJobsConfiguration().LevelChangeActionBar)
|
||||
ActionBar.send(player, line);
|
||||
if (ConfigManager.getJobsConfiguration().LevelChangeChat)
|
||||
player.sendMessage(line);
|
||||
}
|
||||
}
|
||||
|
||||
if (levelUpEvent.getNewTitle() != null && !levelUpEvent.getNewTitle().equals(levelUpEvent.getOldTitle())) {
|
||||
|
||||
if (ConfigManager.getJobsConfiguration().SoundTitleChangeUse)
|
||||
player.getWorld().playSound(player.getLocation(), Sound.valueOf(levelUpEvent.getTitleChangeSoundName()), levelUpEvent.getTitleChangeVolume(), levelUpEvent.getTitleChangePitch());
|
||||
|
||||
// user would skill up
|
||||
if (ConfigManager.getJobsConfiguration().isBroadcastingSkillups()) {
|
||||
message = Language.getMessage("message.skillup.broadcast");
|
||||
} else {
|
||||
message = Language.getMessage("message.skillup.nobroadcast");
|
||||
}
|
||||
if (player != null) {
|
||||
message = message.replace("%playername%", player.getDisplayName());
|
||||
} else {
|
||||
message = message.replace("%playername%", jPlayer.getUserName());
|
||||
}
|
||||
message = message.replace("%titlename%", levelUpEvent.getNewTitleColor() + levelUpEvent.getNewTitleName() + ChatColor.WHITE);
|
||||
message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
|
||||
for (String line : message.split("\n")) {
|
||||
if (ConfigManager.getJobsConfiguration().isBroadcastingLevelups()) {
|
||||
Bukkit.getServer().broadcastMessage(line);
|
||||
} else if (player != null) {
|
||||
if (ConfigManager.getJobsConfiguration().TitleChangeActionBar)
|
||||
ActionBar.send(player, line);
|
||||
if (ConfigManager.getJobsConfiguration().TitleChangeChat)
|
||||
player.sendMessage(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
jPlayer.reloadHonorific();
|
||||
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
|
||||
performCommandOnLevelUp(jPlayer, prog.getJob(), oldLevel);
|
||||
Signs.SignUtil.SignUpdate(job.getName());
|
||||
Signs.SignUtil.SignUpdate(job.getJob().getName());
|
||||
Signs.SignUtil.SignUpdate("gtoplist");
|
||||
job.getJob().updateTotalPlayers();
|
||||
}
|
||||
|
||||
jPlayer.leaveAllJobs();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers player job
|
||||
* @param jPlayer
|
||||
* @param oldjob - the old job
|
||||
* @param newjob - the new job
|
||||
*/
|
||||
public void transferJob(JobsPlayer jPlayer, Job oldjob, Job newjob) {
|
||||
synchronized (jPlayer.saveLock) {
|
||||
if (!jPlayer.transferJob(oldjob, newjob, jPlayer))
|
||||
return;
|
||||
|
||||
JobsDAO dao = Jobs.getJobsDAO();
|
||||
dao.quitJob(jPlayer, oldjob);
|
||||
oldjob.updateTotalPlayers();
|
||||
dao.joinJob(jPlayer, newjob);
|
||||
newjob.updateTotalPlayers();
|
||||
jPlayer.save(dao);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Promotes player in their job
|
||||
* @param jPlayer
|
||||
* @param job - the job
|
||||
* @param levels - number of levels to promote
|
||||
*/
|
||||
public void promoteJob(JobsPlayer jPlayer, Job job, int levels) {
|
||||
synchronized (jPlayer.saveLock) {
|
||||
jPlayer.promoteJob(job, levels, jPlayer);
|
||||
jPlayer.save(Jobs.getJobsDAO());
|
||||
|
||||
Signs.SignUtil.SignUpdate(job.getName());
|
||||
Signs.SignUtil.SignUpdate("gtoplist");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Demote player in their job
|
||||
* @param jPlayer
|
||||
* @param job - the job
|
||||
* @param levels - number of levels to demote
|
||||
*/
|
||||
public void demoteJob(JobsPlayer jPlayer, Job job, int levels) {
|
||||
synchronized (jPlayer.saveLock) {
|
||||
jPlayer.demoteJob(job, levels);
|
||||
jPlayer.save(Jobs.getJobsDAO());
|
||||
Signs.SignUtil.SignUpdate(job.getName());
|
||||
Signs.SignUtil.SignUpdate("gtoplist");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds experience to the player
|
||||
* @param jPlayer
|
||||
* @param job - the job
|
||||
* @param experience - experience gained
|
||||
*/
|
||||
public void addExperience(JobsPlayer jPlayer, Job job, double experience) {
|
||||
synchronized (jPlayer.saveLock) {
|
||||
JobProgression prog = jPlayer.getJobProgression(job);
|
||||
if (prog == null)
|
||||
return;
|
||||
int oldLevel = prog.getLevel();
|
||||
if (prog.addExperience(experience))
|
||||
performLevelUp(jPlayer, job, oldLevel);
|
||||
|
||||
jPlayer.save(Jobs.getJobsDAO());
|
||||
Signs.SignUtil.SignUpdate(job.getName());
|
||||
Signs.SignUtil.SignUpdate("gtoplist");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes experience to the player
|
||||
* @param jPlayer
|
||||
* @param job - the job
|
||||
* @param experience - experience gained
|
||||
*/
|
||||
public void removeExperience(JobsPlayer jPlayer, Job job, double experience) {
|
||||
synchronized (jPlayer.saveLock) {
|
||||
JobProgression prog = jPlayer.getJobProgression(job);
|
||||
if (prog == null)
|
||||
return;
|
||||
prog.addExperience(-experience);
|
||||
|
||||
jPlayer.save(Jobs.getJobsDAO());
|
||||
Signs.SignUtil.SignUpdate(job.getName());
|
||||
Signs.SignUtil.SignUpdate("gtoplist");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts level up about a player
|
||||
* @param jPlayer
|
||||
* @param job
|
||||
* @param oldLevel
|
||||
*/
|
||||
public void performLevelUp(JobsPlayer jPlayer, Job job, int oldLevel) {
|
||||
|
||||
Player player = (Player) jPlayer.getPlayer();
|
||||
JobProgression prog = jPlayer.getJobProgression(job);
|
||||
if (prog == null)
|
||||
return;
|
||||
|
||||
// LevelUp event
|
||||
JobsLevelUpEvent levelUpEvent = new JobsLevelUpEvent(jPlayer, job.getName(), prog.getLevel(), ConfigManager.getJobsConfiguration().getTitleForLevel(oldLevel, job
|
||||
.getName()), ConfigManager.getJobsConfiguration().getTitleForLevel(prog.getLevel(), job.getName()), ConfigManager.getJobsConfiguration().SoundLevelupSound
|
||||
.toUpperCase(), ConfigManager.getJobsConfiguration().SoundLevelupVolume, ConfigManager.getJobsConfiguration().SoundLevelupPitch, ConfigManager
|
||||
.getJobsConfiguration().SoundTitleChangeSound.toUpperCase(), ConfigManager.getJobsConfiguration().SoundTitleChangeVolume, ConfigManager
|
||||
.getJobsConfiguration().SoundTitleChangePitch);
|
||||
Bukkit.getServer().getPluginManager().callEvent(levelUpEvent);
|
||||
// If event is canceled, dont do anything
|
||||
if (levelUpEvent.isCancelled())
|
||||
return;
|
||||
|
||||
if (ConfigManager.getJobsConfiguration().SoundLevelupUse)
|
||||
player.getWorld().playSound(player.getLocation(), Sound.valueOf(levelUpEvent.getSoundName()), levelUpEvent.getSoundVolume(), levelUpEvent.getSoundPitch());
|
||||
|
||||
String message;
|
||||
if (ConfigManager.getJobsConfiguration().isBroadcastingLevelups()) {
|
||||
message = Language.getMessage("message.levelup.broadcast");
|
||||
} else {
|
||||
message = Language.getMessage("message.levelup.nobroadcast");
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs command on level up
|
||||
* @param jPlayer
|
||||
* @param job
|
||||
* @param oldLevel
|
||||
*/
|
||||
public void performCommandOnLevelUp(JobsPlayer jPlayer, Job job, int oldLevel) {
|
||||
int newLevel = oldLevel + 1;
|
||||
Player player = Bukkit.getServer().getPlayer(jPlayer.getPlayerUUID());
|
||||
JobProgression prog = jPlayer.getJobProgression(job);
|
||||
if (prog == null)
|
||||
return;
|
||||
for (JobCommands command : job.getCommands()) {
|
||||
if (newLevel >= command.getLevelFrom() && newLevel <= command.getLevelUntil()) {
|
||||
String commandString = command.getCommand();
|
||||
commandString = commandString.replace("[player]", player.getName());
|
||||
commandString = commandString.replace("[oldlevel]", String.valueOf(oldLevel));
|
||||
commandString = commandString.replace("[newlevel]", String.valueOf(newLevel));
|
||||
commandString = commandString.replace("[jobname]", job.getName());
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandString);
|
||||
}
|
||||
message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
|
||||
|
||||
if (levelUpEvent.getOldTitle() != null) {
|
||||
message = message.replace("%titlename%", levelUpEvent.getOldTitleColor() + levelUpEvent.getOldTitleName() + ChatColor.WHITE);
|
||||
}
|
||||
if (player != null) {
|
||||
message = message.replace("%playername%", player.getDisplayName());
|
||||
} else {
|
||||
message = message.replace("%playername%", jPlayer.getUserName());
|
||||
}
|
||||
message = message.replace("%joblevel%", "" + prog.getLevel());
|
||||
for (String line : message.split("\n")) {
|
||||
if (ConfigManager.getJobsConfiguration().isBroadcastingLevelups()) {
|
||||
if (ConfigManager.getJobsConfiguration().BroadcastingLevelUpLevels.contains(oldLevel + 1) || ConfigManager
|
||||
.getJobsConfiguration().BroadcastingLevelUpLevels.contains(0))
|
||||
Bukkit.getServer().broadcastMessage(line);
|
||||
} else if (player != null) {
|
||||
if (ConfigManager.getJobsConfiguration().LevelChangeActionBar)
|
||||
ActionBar.send(player, line);
|
||||
if (ConfigManager.getJobsConfiguration().LevelChangeChat)
|
||||
player.sendMessage(line);
|
||||
}
|
||||
}
|
||||
|
||||
if (levelUpEvent.getNewTitle() != null && !levelUpEvent.getNewTitle().equals(levelUpEvent.getOldTitle())) {
|
||||
|
||||
if (ConfigManager.getJobsConfiguration().SoundTitleChangeUse)
|
||||
player.getWorld().playSound(player.getLocation(), Sound.valueOf(levelUpEvent.getTitleChangeSoundName()), levelUpEvent.getTitleChangeVolume(), levelUpEvent
|
||||
.getTitleChangePitch());
|
||||
|
||||
// user would skill up
|
||||
if (ConfigManager.getJobsConfiguration().isBroadcastingSkillups()) {
|
||||
message = Language.getMessage("message.skillup.broadcast");
|
||||
} else {
|
||||
message = Language.getMessage("message.skillup.nobroadcast");
|
||||
}
|
||||
if (player != null) {
|
||||
message = message.replace("%playername%", player.getDisplayName());
|
||||
} else {
|
||||
message = message.replace("%playername%", jPlayer.getUserName());
|
||||
}
|
||||
message = message.replace("%titlename%", levelUpEvent.getNewTitleColor() + levelUpEvent.getNewTitleName() + ChatColor.WHITE);
|
||||
message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
|
||||
for (String line : message.split("\n")) {
|
||||
if (ConfigManager.getJobsConfiguration().isBroadcastingLevelups()) {
|
||||
Bukkit.getServer().broadcastMessage(line);
|
||||
} else if (player != null) {
|
||||
if (ConfigManager.getJobsConfiguration().TitleChangeActionBar)
|
||||
ActionBar.send(player, line);
|
||||
if (ConfigManager.getJobsConfiguration().TitleChangeChat)
|
||||
player.sendMessage(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
jPlayer.reloadHonorific();
|
||||
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
|
||||
performCommandOnLevelUp(jPlayer, prog.getJob(), oldLevel);
|
||||
Signs.SignUtil.SignUpdate(job.getName());
|
||||
Signs.SignUtil.SignUpdate("gtoplist");
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs command on level up
|
||||
* @param jPlayer
|
||||
* @param job
|
||||
* @param oldLevel
|
||||
*/
|
||||
public void performCommandOnLevelUp(JobsPlayer jPlayer, Job job, int oldLevel) {
|
||||
int newLevel = oldLevel + 1;
|
||||
Player player = Bukkit.getServer().getPlayer(jPlayer.getPlayerUUID());
|
||||
JobProgression prog = jPlayer.getJobProgression(job);
|
||||
if (prog == null)
|
||||
return;
|
||||
for (JobCommands command : job.getCommands()) {
|
||||
if (newLevel >= command.getLevelFrom() && newLevel <= command.getLevelUntil()) {
|
||||
String commandString = command.getCommand();
|
||||
commandString = commandString.replace("[player]", player.getName());
|
||||
commandString = commandString.replace("[oldlevel]", String.valueOf(oldLevel));
|
||||
commandString = commandString.replace("[newlevel]", String.valueOf(newLevel));
|
||||
commandString = commandString.replace("[jobname]", job.getName());
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), commandString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get job exp boost
|
||||
* @param player
|
||||
* @param job
|
||||
* @return double of boost
|
||||
*/
|
||||
public Double GetExpBoost(Player dude, Job job) {
|
||||
Double ExpBoost = 1.0;
|
||||
if (dude == null || job.getName() == null)
|
||||
return 1.0;
|
||||
if (Perm(dude, "jobs.boost." + job.getName() + ".exp") || Perm(dude, "jobs.boost." + job.getName() + ".both") || Perm(dude, "jobs.boost.all.both") || Perm(dude,
|
||||
"jobs.boost.all.exp")) {
|
||||
ExpBoost = ConfigManager.getJobsConfiguration().BoostExp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get job exp boost
|
||||
* @param player
|
||||
* @param job
|
||||
* @return double of boost
|
||||
*/
|
||||
public Double GetExpBoost(Player dude, Job job) {
|
||||
Double ExpBoost = 1.0;
|
||||
if (dude == null || job.getName() == null)
|
||||
return 1.0;
|
||||
if (Perm(dude, "jobs.boost." + job.getName() + ".exp") || Perm(dude, "jobs.boost." + job.getName() + ".both") || Perm(dude, "jobs.boost.all.both") || Perm(dude, "jobs.boost.all.exp")) {
|
||||
ExpBoost = ConfigManager.getJobsConfiguration().BoostExp;
|
||||
return ExpBoost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max jobs
|
||||
* @param player
|
||||
* @return True if he have permission
|
||||
*/
|
||||
public boolean getJobsLimit(Player player, Short currentCount) {
|
||||
|
||||
if (Perm(player, "jobs.max.*"))
|
||||
return true;
|
||||
|
||||
short count = (short) ConfigManager.getJobsConfiguration().getMaxJobs();
|
||||
for (short ctr = 0; ctr < 255; ctr++) {
|
||||
if (Perm(player, "jobs.max." + ctr))
|
||||
count = ctr;
|
||||
if (count > currentCount)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean Perm(Player player, String permission) {
|
||||
Permission p = new Permission(permission, PermissionDefault.FALSE);
|
||||
return player.hasPermission(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get job money boost
|
||||
* @param player
|
||||
* @param job
|
||||
* @return double of boost
|
||||
*/
|
||||
public Double GetMoneyBoost(Player dude, Job job) {
|
||||
Double MoneyBoost = 1.0;
|
||||
if (dude != null && job.getName() != null) {
|
||||
if (Perm(dude, "jobs.boost." + job.getName() + ".money") || Perm(dude, "jobs.boost." + job.getName() + ".both") || Perm(dude, "jobs.boost.all.both") || Perm(
|
||||
dude, "jobs.boost.all.money")) {
|
||||
MoneyBoost = ConfigManager.getJobsConfiguration().BoostMoney;
|
||||
}
|
||||
}
|
||||
return MoneyBoost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform reload
|
||||
*/
|
||||
public void reload() {
|
||||
synchronized (players) {
|
||||
for (JobsPlayer jPlayer : players.values()) {
|
||||
for (JobProgression progression : jPlayer.getJobProgression()) {
|
||||
String jobName = progression.getJob().getName();
|
||||
Job job = Jobs.getJob(jobName);
|
||||
if (job != null) {
|
||||
progression.setJob(job);
|
||||
}
|
||||
}
|
||||
|
||||
return ExpBoost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max jobs
|
||||
* @param player
|
||||
* @return True if he have permission
|
||||
*/
|
||||
public boolean getJobsLimit(Player player, Short currentCount) {
|
||||
|
||||
if (Perm(player, "jobs.max.*"))
|
||||
return true;
|
||||
|
||||
short count = (short) ConfigManager.getJobsConfiguration().getMaxJobs();
|
||||
for (short ctr = 0; ctr < 255; ctr++) {
|
||||
if (Perm(player, "jobs.max." + ctr))
|
||||
count = ctr;
|
||||
if (count > currentCount)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean Perm(Player player, String permission) {
|
||||
Permission p = new Permission(permission, PermissionDefault.FALSE);
|
||||
return player.hasPermission(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get job money boost
|
||||
* @param player
|
||||
* @param job
|
||||
* @return double of boost
|
||||
*/
|
||||
public Double GetMoneyBoost(Player dude, Job job) {
|
||||
Double MoneyBoost = 1.0;
|
||||
if (dude != null && job.getName() != null) {
|
||||
if (Perm(dude, "jobs.boost." + job.getName() + ".money") || Perm(dude, "jobs.boost." + job.getName() + ".both") || Perm(dude, "jobs.boost.all.both") || Perm(dude, "jobs.boost.all.money")) {
|
||||
MoneyBoost = ConfigManager.getJobsConfiguration().BoostMoney;
|
||||
}
|
||||
}
|
||||
return MoneyBoost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform reload
|
||||
*/
|
||||
public void reload() {
|
||||
synchronized (players) {
|
||||
for (JobsPlayer jPlayer : players.values()) {
|
||||
for (JobProgression progression : jPlayer.getJobProgression()) {
|
||||
String jobName = progression.getJob().getName();
|
||||
Job job = Jobs.getJob(jobName);
|
||||
if (job != null) {
|
||||
progression.setJob(job);
|
||||
}
|
||||
}
|
||||
if (jPlayer.isOnline()) {
|
||||
jPlayer.reloadHonorific();
|
||||
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
|
||||
}
|
||||
}
|
||||
if (jPlayer.isOnline()) {
|
||||
jPlayer.reloadHonorific();
|
||||
Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,9 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
|
||||
public class Schedule {
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
name: Jobs
|
||||
description: Jobs Plugin for the BukkitAPI
|
||||
main: com.gamingmesh.jobs.JobsPlugin
|
||||
version: 2.47.0
|
||||
version: 2.47.2
|
||||
author: phrstbrn
|
||||
softdepend: [Vault]
|
||||
commands:
|
||||
|
Loading…
Reference in New Issue
Block a user