1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-25 20:16:13 +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
* @param jPlayer
* @param job
* @param oldLevel
*/
@SuppressWarnings("deprecation")
public void performLevelUp(JobsPlayer jPlayer, Job job, int oldLevel) {
Player player = jPlayer.getPlayer();
@ -435,8 +428,8 @@ public class PlayerManager {
return;
if (Jobs.getGCManager().SoundLevelupUse) {
Sound sound = getSound(levelUpEvent.getSoundName());
if (sound != null)
Sound sound = levelUpEvent.getSound();
if (sound != null && player != null && player.getLocation() != null)
player.getWorld().playSound(player.getLocation(), sound, levelUpEvent.getSoundVolume(), levelUpEvent.getSoundPitch());
else
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 (Jobs.getGCManager().SoundTitleChangeUse) {
Sound sound = getSound(levelUpEvent.getTitleChangeSoundName());
Sound sound = levelUpEvent.getTitleChangeSound();
if (sound != null && player != null)
player.getWorld().playSound(player.getLocation(), sound, levelUpEvent.getTitleChangeVolume(),
levelUpEvent.getTitleChangePitch());

View File

@ -1,5 +1,6 @@
package com.gamingmesh.jobs.api;
import org.bukkit.Sound;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@ -14,28 +15,37 @@ public final class JobsLevelUpEvent extends Event implements Cancellable {
private Title OldTitle;
private Title NewTitle;
private int level;
private String soundLevelupSound;
private int soundLevelupVolume;
private int soundLevelupPitch;
private String soundTitleChangeSound;
private Sound soundLevelupSound;
private int soundLevelupVolume = 1;
private int soundLevelupPitch = 3;
private Sound soundTitleChangeSound;
private int soundTitleChangeVolume;
private int soundTitleChangePitch;
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.JobName = JobName;
this.OldTitle = OldTitle;
this.NewTitle = NewTitle;
this.level = level;
this.soundLevelupSound = soundLevelupSound;
this.soundLevelupSound = getSound(soundLevelupSound);
this.soundLevelupVolume = soundLevelupVolume;
this.soundLevelupPitch = soundLevelupPitch;
this.soundTitleChangeSound = soundTitleChangeSound;
this.soundTitleChangeSound = getSound(soundTitleChangeSound);
this.soundTitleChangeVolume = soundTitleChangeVolume;
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() {
return this.player;
}
@ -76,11 +86,16 @@ public final class JobsLevelUpEvent extends Event implements Cancellable {
return this.NewTitle.getChatColor().toString();
}
@Deprecated
public String getSoundName() {
return this.soundLevelupSound.name();
}
public Sound getSound() {
return this.soundLevelupSound;
}
public void setSoundName(String sound) {
public void setSound(Sound sound) {
this.soundLevelupSound = sound;
}
@ -100,11 +115,16 @@ public final class JobsLevelUpEvent extends Event implements Cancellable {
this.soundLevelupPitch = pitch;
}
@Deprecated
public String getTitleChangeSoundName() {
return this.soundTitleChangeSound.name();
}
public Sound getTitleChangeSound() {
return this.soundTitleChangeSound;
}
public void setTitleChangeSoundName(String sound) {
public void setTitleChangeSound(Sound sound) {
this.soundTitleChangeSound = sound;
}

View File

@ -429,13 +429,16 @@ public class GeneralConfigManager {
if (MultiServerCompatability)
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");
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");
DBCleaningJobsLvl = c.get("Optimizations.DBCleaning.Jobs.Level", 1);
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");
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");

View File

@ -100,7 +100,7 @@ public abstract class JobsDAO {
checkUpdate9();
// creating block protection database
checkUpdate10();
if (version <= 10)
// adding seen field into users table
checkUpdate11();
}

View File

@ -713,31 +713,6 @@ public class JobsDAOMySQL extends JobsDAO {
@Override
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();
}
@ -751,8 +726,7 @@ public class JobsDAOMySQL extends JobsDAO {
try {
executeSQL("ALTER TABLE `" + getPrefix() + "users` ADD COLUMN `seen` bigint;");
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
return;
} finally {
}
@ -833,7 +807,7 @@ public class JobsDAOMySQL extends JobsDAO {
private boolean createDefaultBlockProtection() {
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);");
} catch (SQLException e) {
return false;

View File

@ -778,30 +778,6 @@ public class JobsDAOSQLite extends JobsDAO {
@Override
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();
}
@ -809,14 +785,13 @@ public class JobsDAOSQLite extends JobsDAO {
protected synchronized void checkUpdate11() {
JobsConnection conn = getConnection();
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;
}
try {
executeSQL("ALTER TABLE `" + getPrefix() + "users` ADD COLUMN `seen` bigint;");
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
return;
} finally {
}
@ -832,41 +807,6 @@ public class JobsDAOSQLite extends JobsDAO {
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() {
@ -933,7 +873,7 @@ public class JobsDAOSQLite extends JobsDAO {
private boolean createDefaultBlockProtection() {
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);");
} catch (SQLException e) {
return false;

View File

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

View File

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