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,149 +1,169 @@
package com.gamingmesh.jobs.api;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.container.Title;
public final class JobsLevelUpEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private JobsPlayer player;
private String JobName;
private Title OldTitle;
private Title NewTitle;
private int level;
private String soundLevelupSound;
private int soundLevelupVolume;
private int soundLevelupPitch;
private String 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) {
this.player = jPlayer;
this.JobName = JobName;
this.OldTitle = OldTitle;
this.NewTitle = NewTitle;
this.level = level;
this.soundLevelupSound = soundLevelupSound;
this.soundLevelupVolume = soundLevelupVolume;
this.soundLevelupPitch = soundLevelupPitch;
this.soundTitleChangeSound = soundTitleChangeSound;
this.soundTitleChangeVolume = soundTitleChangeVolume;
this.soundTitleChangePitch = soundTitleChangePitch;
}
public JobsPlayer getPlayer() {
return this.player;
}
public String getJobName() {
return this.JobName;
}
public Title getOldTitle() {
return this.OldTitle;
}
public String getOldTitleName() {
return this.OldTitle.getName();
}
public String getOldTitleShort() {
return this.OldTitle.getShortName();
}
public String getOldTitleColor() {
return this.OldTitle.getChatColor().toString();
}
public Title getNewTitle() {
return this.NewTitle;
}
public String getNewTitleName() {
return this.NewTitle.getName();
}
public String getNewTitleShort() {
return this.NewTitle.getShortName();
}
public String getNewTitleColor() {
return this.NewTitle.getChatColor().toString();
}
public String getSoundName() {
return this.soundLevelupSound;
}
public void setSoundName(String sound) {
this.soundLevelupSound = sound;
}
public int getSoundVolume() {
return this.soundLevelupVolume;
}
public void setSoundVolume(int volume) {
this.soundLevelupVolume = volume;
}
public int getSoundPitch() {
return this.soundLevelupPitch;
}
public void setSoundPitch(int pitch) {
this.soundLevelupPitch = pitch;
}
public String getTitleChangeSoundName() {
return this.soundTitleChangeSound;
}
public void setTitleChangeSoundName(String sound) {
this.soundTitleChangeSound = sound;
}
public int getTitleChangeVolume() {
return this.soundTitleChangeVolume;
}
public void setTitleChangeVolume(int volume) {
this.soundTitleChangeVolume = volume;
}
public int getTitleChangePitch() {
return this.soundTitleChangePitch;
}
public void setTitleChangePitch(int pitch) {
this.soundTitleChangePitch = pitch;
}
public int getLevel() {
return this.level;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
package com.gamingmesh.jobs.api;
import org.bukkit.Sound;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.container.Title;
public final class JobsLevelUpEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private JobsPlayer player;
private String JobName;
private Title OldTitle;
private Title NewTitle;
private int level;
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) {
this.player = jPlayer;
this.JobName = JobName;
this.OldTitle = OldTitle;
this.NewTitle = NewTitle;
this.level = level;
this.soundLevelupSound = getSound(soundLevelupSound);
this.soundLevelupVolume = soundLevelupVolume;
this.soundLevelupPitch = soundLevelupPitch;
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;
}
public String getJobName() {
return this.JobName;
}
public Title getOldTitle() {
return this.OldTitle;
}
public String getOldTitleName() {
return this.OldTitle.getName();
}
public String getOldTitleShort() {
return this.OldTitle.getShortName();
}
public String getOldTitleColor() {
return this.OldTitle.getChatColor().toString();
}
public Title getNewTitle() {
return this.NewTitle;
}
public String getNewTitleName() {
return this.NewTitle.getName();
}
public String getNewTitleShort() {
return this.NewTitle.getShortName();
}
public String getNewTitleColor() {
return this.NewTitle.getChatColor().toString();
}
@Deprecated
public String getSoundName() {
return this.soundLevelupSound.name();
}
public Sound getSound() {
return this.soundLevelupSound;
}
public void setSound(Sound sound) {
this.soundLevelupSound = sound;
}
public int getSoundVolume() {
return this.soundLevelupVolume;
}
public void setSoundVolume(int volume) {
this.soundLevelupVolume = volume;
}
public int getSoundPitch() {
return this.soundLevelupPitch;
}
public void setSoundPitch(int pitch) {
this.soundLevelupPitch = pitch;
}
@Deprecated
public String getTitleChangeSoundName() {
return this.soundTitleChangeSound.name();
}
public Sound getTitleChangeSound() {
return this.soundTitleChangeSound;
}
public void setTitleChangeSound(Sound sound) {
this.soundTitleChangeSound = sound;
}
public int getTitleChangeVolume() {
return this.soundTitleChangeVolume;
}
public void setTitleChangeVolume(int volume) {
this.soundTitleChangeVolume = volume;
}
public int getTitleChangePitch() {
return this.soundTitleChangePitch;
}
public void setTitleChangePitch(int pitch) {
this.soundTitleChangePitch = pitch;
}
public int getLevel() {
return this.level;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

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,8 +100,8 @@ public abstract class JobsDAO {
checkUpdate9();
// creating block protection database
checkUpdate10();
if (version <= 10)
checkUpdate11();
// adding seen field into users table
checkUpdate11();
}
version = 11;
@ -1196,7 +1196,7 @@ public abstract class JobsDAO {
ii++;
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);
ii = 0;
}

View File

@ -713,32 +713,7 @@ 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();
createDefaultBlockProtection();
}
@Override
@ -751,12 +726,11 @@ 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 {
}
PreparedStatement prest = null;
try {
prest = conn.prepareStatement("UPDATE `" + getPrefix() + "users` SET `seen` = ?;");
@ -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,45 +778,20 @@ 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();
createDefaultBlockProtection();
}
@Override
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,11 +852,16 @@ 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)
for (JobProgression job : jobs) {
Jobs.action(jDamager, new CustomKillInfo(job.getJob().getName(), ActionType.CUSTOMKILL), multiplier);
}
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