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

EntityDeath issue

try to add seen collumn every time
create blocks table if not exist
sound optimization
This commit is contained in:
Zrips 2016-09-30 13:19:57 +03:00
parent d5113847f0
commit 3a46bfb491
8 changed files with 199 additions and 264 deletions

View File

@ -403,20 +403,13 @@ public class PlayerManager {
// } // }
} }
private static Sound getSound(String soundName) {
for (Sound one : Sound.values()) {
if (one.name().equalsIgnoreCase(soundName))
return one;
}
return null;
}
/** /**
* Broadcasts level up about a player * Broadcasts level up about a player
* @param jPlayer * @param jPlayer
* @param job * @param job
* @param oldLevel * @param oldLevel
*/ */
@SuppressWarnings("deprecation")
public void performLevelUp(JobsPlayer jPlayer, Job job, int oldLevel) { public void performLevelUp(JobsPlayer jPlayer, Job job, int oldLevel) {
Player player = jPlayer.getPlayer(); Player player = jPlayer.getPlayer();
@ -435,8 +428,8 @@ public class PlayerManager {
return; return;
if (Jobs.getGCManager().SoundLevelupUse) { if (Jobs.getGCManager().SoundLevelupUse) {
Sound sound = getSound(levelUpEvent.getSoundName()); Sound sound = levelUpEvent.getSound();
if (sound != null) if (sound != null && player != null && player.getLocation() != null)
player.getWorld().playSound(player.getLocation(), sound, levelUpEvent.getSoundVolume(), levelUpEvent.getSoundPitch()); player.getWorld().playSound(player.getLocation(), sound, levelUpEvent.getSoundVolume(), levelUpEvent.getSoundPitch());
else else
Bukkit.getConsoleSender().sendMessage("[Jobs] Cant find sound by name: " + levelUpEvent.getTitleChangeSoundName() + ". Please update it"); Bukkit.getConsoleSender().sendMessage("[Jobs] Cant find sound by name: " + levelUpEvent.getTitleChangeSoundName() + ". Please update it");
@ -475,7 +468,7 @@ public class PlayerManager {
if (levelUpEvent.getNewTitle() != null && !levelUpEvent.getNewTitle().equals(levelUpEvent.getOldTitle())) { if (levelUpEvent.getNewTitle() != null && !levelUpEvent.getNewTitle().equals(levelUpEvent.getOldTitle())) {
if (Jobs.getGCManager().SoundTitleChangeUse) { if (Jobs.getGCManager().SoundTitleChangeUse) {
Sound sound = getSound(levelUpEvent.getTitleChangeSoundName()); Sound sound = levelUpEvent.getTitleChangeSound();
if (sound != null && player != null) if (sound != null && player != null)
player.getWorld().playSound(player.getLocation(), sound, levelUpEvent.getTitleChangeVolume(), player.getWorld().playSound(player.getLocation(), sound, levelUpEvent.getTitleChangeVolume(),
levelUpEvent.getTitleChangePitch()); levelUpEvent.getTitleChangePitch());

View File

@ -1,5 +1,6 @@
package com.gamingmesh.jobs.api; package com.gamingmesh.jobs.api;
import org.bukkit.Sound;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -14,28 +15,37 @@ public final class JobsLevelUpEvent extends Event implements Cancellable {
private Title OldTitle; private Title OldTitle;
private Title NewTitle; private Title NewTitle;
private int level; private int level;
private String soundLevelupSound; private Sound soundLevelupSound;
private int soundLevelupVolume; private int soundLevelupVolume = 1;
private int soundLevelupPitch; private int soundLevelupPitch = 3;
private String soundTitleChangeSound; private Sound soundTitleChangeSound;
private int soundTitleChangeVolume; private int soundTitleChangeVolume;
private int soundTitleChangePitch; private int soundTitleChangePitch;
private boolean cancelled; private boolean cancelled;
public JobsLevelUpEvent(JobsPlayer jPlayer, String JobName, int level, Title OldTitle, Title NewTitle, String soundLevelupSound, Integer soundLevelupVolume, Integer soundLevelupPitch, String soundTitleChangeSound, Integer soundTitleChangeVolume, Integer soundTitleChangePitch) { public JobsLevelUpEvent(JobsPlayer jPlayer, String JobName, int level, Title OldTitle, Title NewTitle, String soundLevelupSound, Integer soundLevelupVolume,
Integer soundLevelupPitch, String soundTitleChangeSound, Integer soundTitleChangeVolume, Integer soundTitleChangePitch) {
this.player = jPlayer; this.player = jPlayer;
this.JobName = JobName; this.JobName = JobName;
this.OldTitle = OldTitle; this.OldTitle = OldTitle;
this.NewTitle = NewTitle; this.NewTitle = NewTitle;
this.level = level; this.level = level;
this.soundLevelupSound = soundLevelupSound; this.soundLevelupSound = getSound(soundLevelupSound);
this.soundLevelupVolume = soundLevelupVolume; this.soundLevelupVolume = soundLevelupVolume;
this.soundLevelupPitch = soundLevelupPitch; this.soundLevelupPitch = soundLevelupPitch;
this.soundTitleChangeSound = soundTitleChangeSound; this.soundTitleChangeSound = getSound(soundTitleChangeSound);
this.soundTitleChangeVolume = soundTitleChangeVolume; this.soundTitleChangeVolume = soundTitleChangeVolume;
this.soundTitleChangePitch = soundTitleChangePitch; this.soundTitleChangePitch = soundTitleChangePitch;
} }
private static Sound getSound(String soundName) {
for (Sound one : Sound.values()) {
if (one.name().equalsIgnoreCase(soundName))
return one;
}
return null;
}
public JobsPlayer getPlayer() { public JobsPlayer getPlayer() {
return this.player; return this.player;
} }
@ -76,11 +86,16 @@ public final class JobsLevelUpEvent extends Event implements Cancellable {
return this.NewTitle.getChatColor().toString(); return this.NewTitle.getChatColor().toString();
} }
@Deprecated
public String getSoundName() { public String getSoundName() {
return this.soundLevelupSound.name();
}
public Sound getSound() {
return this.soundLevelupSound; return this.soundLevelupSound;
} }
public void setSoundName(String sound) { public void setSound(Sound sound) {
this.soundLevelupSound = sound; this.soundLevelupSound = sound;
} }
@ -100,11 +115,16 @@ public final class JobsLevelUpEvent extends Event implements Cancellable {
this.soundLevelupPitch = pitch; this.soundLevelupPitch = pitch;
} }
@Deprecated
public String getTitleChangeSoundName() { public String getTitleChangeSoundName() {
return this.soundTitleChangeSound.name();
}
public Sound getTitleChangeSound() {
return this.soundTitleChangeSound; return this.soundTitleChangeSound;
} }
public void setTitleChangeSoundName(String sound) { public void setTitleChangeSound(Sound sound) {
this.soundTitleChangeSound = sound; this.soundTitleChangeSound = sound;
} }

View File

@ -429,13 +429,16 @@ public class GeneralConfigManager {
if (MultiServerCompatability) if (MultiServerCompatability)
saveOnDisconnect = true; saveOnDisconnect = true;
c.getW().addComment("Optimizations.DBCleaning.Jobs.Use", "When set to true, jobs data base will be cleaned on each startup to avoid having not used jobs", c.getW().addComment("Optimizations.DBCleaning.Jobs.Use",
"Warning!!! before enabling this feature, please make data base backup, just in case there will be some issues with data base cleaning",
"When set to true, jobs data base will be cleaned on each startup to avoid having not used jobs",
"keep in mind that this will only clean actual jobs, but not recorded players"); "keep in mind that this will only clean actual jobs, but not recorded players");
DBCleaningJobsUse = c.get("Optimizations.DBCleaning.Jobs.Use", false); DBCleaningJobsUse = c.get("Optimizations.DBCleaning.Jobs.Use", false);
c.getW().addComment("Optimizations.DBCleaning.Jobs.Level", "Any one who has jobs level equal or less then set, hies job will be removed from data base"); c.getW().addComment("Optimizations.DBCleaning.Jobs.Level", "Any one who has jobs level equal or less then set, hies job will be removed from data base");
DBCleaningJobsLvl = c.get("Optimizations.DBCleaning.Jobs.Level", 1); DBCleaningJobsLvl = c.get("Optimizations.DBCleaning.Jobs.Level", 1);
c.getW().addComment("Optimizations.DBCleaning.Users.Use", c.getW().addComment("Optimizations.DBCleaning.Users.Use",
"Warning!!! before enabling this feature, please make data base backup, just in case there will be some issues with data base cleaning",
"When set to true, data base will be cleaned on each startup from user data to avoid having old player data"); "When set to true, data base will be cleaned on each startup from user data to avoid having old player data");
DBCleaningUsersUse = c.get("Optimizations.DBCleaning.Users.Use", false); DBCleaningUsersUse = c.get("Optimizations.DBCleaning.Users.Use", false);
c.getW().addComment("Optimizations.DBCleaning.Users.Days", "Any one who not playied for defined amount of days, will be removed from data base"); c.getW().addComment("Optimizations.DBCleaning.Users.Days", "Any one who not playied for defined amount of days, will be removed from data base");

View File

@ -100,7 +100,7 @@ public abstract class JobsDAO {
checkUpdate9(); checkUpdate9();
// creating block protection database // creating block protection database
checkUpdate10(); checkUpdate10();
if (version <= 10) // adding seen field into users table
checkUpdate11(); checkUpdate11();
} }
@ -1196,7 +1196,7 @@ public abstract class JobsDAO {
ii++; ii++;
if (ii >= 100000) { if (ii >= 100000) {
String message = ChatColor.translateAlternateColorCodes('&', "&6[Jobs] Loading (" + i +") BP"); String message = ChatColor.translateAlternateColorCodes('&', "&6[Jobs] Loading (" + i + ") BP");
Bukkit.getServer().getConsoleSender().sendMessage(message); Bukkit.getServer().getConsoleSender().sendMessage(message);
ii = 0; ii = 0;
} }

View File

@ -713,31 +713,6 @@ public class JobsDAOMySQL extends JobsDAO {
@Override @Override
protected synchronized void checkUpdate10() { protected synchronized void checkUpdate10() {
JobsConnection conn = getConnection();
if (conn == null) {
Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to MySQL!");
return;
}
PreparedStatement prest = null;
ResultSet res = null;
int rows = 0;
try {
// Check for jobs table
prest = conn.prepareStatement("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ?;");
prest.setString(1, database);
prest.setString(2, getPrefix() + "blocks");
res = prest.executeQuery();
if (res.next()) {
rows = res.getInt(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
close(res);
close(prest);
}
if (rows == 0)
createDefaultBlockProtection(); createDefaultBlockProtection();
} }
@ -751,8 +726,7 @@ public class JobsDAOMySQL extends JobsDAO {
try { try {
executeSQL("ALTER TABLE `" + getPrefix() + "users` ADD COLUMN `seen` bigint;"); executeSQL("ALTER TABLE `" + getPrefix() + "users` ADD COLUMN `seen` bigint;");
} catch (SQLException e) { } catch (Exception e) {
e.printStackTrace();
return; return;
} finally { } finally {
} }
@ -833,7 +807,7 @@ public class JobsDAOMySQL extends JobsDAO {
private boolean createDefaultBlockProtection() { private boolean createDefaultBlockProtection() {
try { try {
executeSQL("CREATE TABLE `" + getPrefix() executeSQL("CREATE TABLE IF NOT EXISTS `" + getPrefix()
+ "blocks` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `world` varchar(36) NOT NULL, `x` int, `y` int, `z` int, `recorded` bigint, `resets` bigint);"); + "blocks` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `world` varchar(36) NOT NULL, `x` int, `y` int, `z` int, `recorded` bigint, `resets` bigint);");
} catch (SQLException e) { } catch (SQLException e) {
return false; return false;

View File

@ -778,30 +778,6 @@ public class JobsDAOSQLite extends JobsDAO {
@Override @Override
protected synchronized void checkUpdate10() { protected synchronized void checkUpdate10() {
JobsConnection conn = getConnection();
if (conn == null) {
Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to MySQL!");
return;
}
PreparedStatement prest = null;
ResultSet res = null;
int rows = 0;
try {
// Check for jobs table
prest = conn.prepareStatement("SELECT COUNT(*) FROM sqlite_master WHERE name = ?;");
prest.setString(1, getPrefix() + "blocks");
res = prest.executeQuery();
if (res.next()) {
rows = res.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(res);
close(prest);
}
if (rows == 0)
createDefaultBlockProtection(); createDefaultBlockProtection();
} }
@ -809,14 +785,13 @@ public class JobsDAOSQLite extends JobsDAO {
protected synchronized void checkUpdate11() { protected synchronized void checkUpdate11() {
JobsConnection conn = getConnection(); JobsConnection conn = getConnection();
if (conn == null) { if (conn == null) {
Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to MySQL!"); Jobs.getPluginLogger().severe("Could not run database updates! Could not connect to SQLITE!");
return; return;
} }
try { try {
executeSQL("ALTER TABLE `" + getPrefix() + "users` ADD COLUMN `seen` bigint;"); executeSQL("ALTER TABLE `" + getPrefix() + "users` ADD COLUMN `seen` bigint;");
} catch (SQLException e) { } catch (Exception e) {
e.printStackTrace();
return; return;
} finally { } finally {
} }
@ -832,41 +807,6 @@ public class JobsDAOSQLite extends JobsDAO {
close(prest); close(prest);
} }
// HashMap<UUID, Long> map = new HashMap<UUID, Long>();
// Jobs.getPluginLogger().info("Updating player last seen value");
// for (OfflinePlayer one : Bukkit.getOfflinePlayers()) {
// map.put(one.getUniqueId(), one.getLastPlayed());
// }
//
// PreparedStatement prestJobsT = null;
// try {
// prestJobsT = conn.prepareStatement("UPDATE `" + getPrefix() + "users` SET `seen` = ? WHERE `player_uuid` = ?;");
// conn.setAutoCommit(false);
//
// int i = 0;
// int y = 0;
// for (Entry<UUID, Long> users : map.entrySet()) {
// prestJobsT.setLong(1, users.getValue());
// prestJobsT.setString(2, users.getKey().toString());
// prestJobsT.addBatch();
//
// i++;
// y++;
// if (i >= 1000) {
// Jobs.getPluginLogger().info("Updated " + y + "/" + map.size());
// i = 0;
// }
// }
// prestJobsT.executeBatch();
// conn.commit();
// conn.setAutoCommit(true);
// Jobs.getPluginLogger().info("Finished");
// } catch (SQLException e) {
// e.printStackTrace();
// } finally {
// close(prestJobsT);
// }
} }
private boolean createDefaultExploreBase() { private boolean createDefaultExploreBase() {
@ -933,7 +873,7 @@ public class JobsDAOSQLite extends JobsDAO {
private boolean createDefaultBlockProtection() { private boolean createDefaultBlockProtection() {
try { try {
executeSQL("CREATE TABLE `" + getPrefix() executeSQL("CREATE TABLE IF NOT EXISTS `" + getPrefix()
+ "blocks` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `world` varchar(36) NOT NULL, `x` int, `y` int, `z` int, `recorded` bigint, `resets` bigint);"); + "blocks` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `world` varchar(36) NOT NULL, `x` int, `y` int, `z` int, `recorded` bigint, `resets` bigint);");
} catch (SQLException e) { } catch (SQLException e) {
return false; return false;

View File

@ -852,8 +852,13 @@ public class JobsPaymentListener implements Listener {
// Payment for killing player with particular job, except NPC's // Payment for killing player with particular job, except NPC's
if (lVictim instanceof Player && !lVictim.hasMetadata("NPC")) { if (lVictim instanceof Player && !lVictim.hasMetadata("NPC")) {
List<JobProgression> jobs = Jobs.getPlayerManager().getJobsPlayer((Player) lVictim).getJobProgression(); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) lVictim);
if (jobs != null) if (jPlayer == null)
return;
List<JobProgression> jobs = jPlayer.getJobProgression();
if (jobs == null)
return;
for (JobProgression job : jobs) { for (JobProgression job : jobs) {
Jobs.action(jDamager, new CustomKillInfo(job.getJob().getName(), ActionType.CUSTOMKILL), multiplier); Jobs.action(jDamager, new CustomKillInfo(job.getJob().getName(), ActionType.CUSTOMKILL), multiplier);
} }

View File

@ -1,10 +1,10 @@
name: Jobs name: Jobs
description: Jobs Plugin for the BukkitAPI description: Jobs Plugin for the BukkitAPI
main: com.gamingmesh.jobs.Jobs main: com.gamingmesh.jobs.Jobs
version: 3.6.0 version: 3.6.1
author: phrstbrn author: phrstbrn
depend: [Vault] depend: [Vault]
softdepend: [CoreProtect, MythicMobs, McMMO] softdepend: [MythicMobs, McMMO]
commands: commands:
jobs: jobs:
description: Jobs description: Jobs