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

Fixed the plugin not disabling

- Fix some file creation problems
- Fixed when the player has not joined a job, milk a cow and get paid, https://www.spigotmc.org/threads/jobs-reborn.50989/page-231#post-3240788
This commit is contained in:
montlikadani 2018-12-04 18:16:55 +01:00
parent ed0eadad69
commit e52c4fa43b
3 changed files with 42 additions and 52 deletions

View File

@ -841,10 +841,6 @@ public class Jobs extends JavaPlugin {
@Override
public void onDisable() {
// it will not run longer if it is a server error
if (!isEnabled())
return;
GUIManager.CloseInventories();
shopManager.CloseInventories();
dao.saveExplore();
@ -854,7 +850,7 @@ public class Jobs extends JavaPlugin {
shutdown();
consoleMsg("&e[Jobs] &2Plugin has been disabled successfully.");
this.setEnabled(false);
setEnabled(false);
}
@SuppressWarnings("unused")

View File

@ -12,43 +12,34 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import com.gamingmesh.jobs.Jobs;
public class YmlMaker {
Jobs Plugin;
public String fileName;
private JavaPlugin plugin;
public File ConfigFile;
private FileConfiguration Configuration;
public YmlMaker(Jobs Plugin) {
this.Plugin = Plugin;
}
public YmlMaker(JavaPlugin plugin, String fileName) {
if (plugin == null) {
throw new IllegalArgumentException("plugin cannot be null");
}
this.plugin = plugin;
this.fileName = fileName;
File dataFolder = plugin.getDataFolder();
if (dataFolder == null) {
throw new IllegalStateException();
}
this.ConfigFile = new File(dataFolder.toString() + File.separatorChar + this.fileName);
if (!dataFolder.exists())
dataFolder.mkdirs();
ConfigFile = new File(dataFolder, fileName);
}
public void reloadConfig() {
InputStreamReader f = null;
try {
f = new InputStreamReader(new FileInputStream(this.ConfigFile), "UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
} catch (FileNotFoundException e1) {
f = new InputStreamReader(new FileInputStream(ConfigFile), "UTF-8");
} catch (UnsupportedEncodingException | FileNotFoundException e1) {
e1.printStackTrace();
}
this.Configuration = YamlConfiguration.loadConfiguration(f);
Configuration = YamlConfiguration.loadConfiguration(f);
if (f != null)
try {
f.close();
@ -58,31 +49,35 @@ public class YmlMaker {
}
public FileConfiguration getConfig() {
if (this.Configuration == null) {
if (Configuration == null)
reloadConfig();
return Configuration;
}
return this.Configuration;
public File getConfigFile() {
if (ConfigFile == null)
ConfigFile = new File(plugin.getDataFolder(), fileName);
return ConfigFile;
}
public void saveConfig() {
if ((this.Configuration == null) || (this.ConfigFile == null)) {
if ((Configuration == null) || (ConfigFile == null))
return;
}
try {
getConfig().save(this.ConfigFile);
getConfig().save(ConfigFile);
} catch (IOException ex) {
this.plugin.getLogger().log(Level.SEVERE, "Could not save config to " + this.ConfigFile, ex);
plugin.getLogger().log(Level.SEVERE, "Could not save config to " + ConfigFile, ex);
}
}
public boolean exists() {
return this.ConfigFile.exists();
return ConfigFile != null && ConfigFile.exists() ? false : ConfigFile.exists();
}
public void createNewFile() {
if (!this.ConfigFile.exists()) {
if (ConfigFile != null && !ConfigFile.exists()) {
try {
this.ConfigFile.createNewFile();
ConfigFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
@ -90,8 +85,7 @@ public class YmlMaker {
}
public void saveDefaultConfig() {
if (!this.ConfigFile.exists()) {
this.plugin.saveResource(this.fileName, false);
}
if (ConfigFile != null && !ConfigFile.exists())
plugin.saveResource(fileName, false);
}
}

View File

@ -222,26 +222,9 @@ public class JobsPaymentListener implements Listener {
if (!player.isOnline())
return;
if (Jobs.getGCManager().CowMilkingTimer > 0)
if (cow.hasMetadata(CowMetadata)) {
long time = cow.getMetadata(CowMetadata).get(0).asLong();
if (System.currentTimeMillis() < time + Jobs.getGCManager().CowMilkingTimer) {
long timer = ((Jobs.getGCManager().CowMilkingTimer - (System.currentTimeMillis() - time)) / 1000);
player.sendMessage(Jobs.getLanguage().getMessage("message.cowtimer", "%time%", timer));
if (Jobs.getGCManager().CancelCowMilking)
event.setCancelled(true);
return;
}
}
ItemStack itemInHand = Jobs.getNms().getItemInMainHand(player);
if (itemInHand == null)
return;
if (itemInHand.getType() != Material.BUCKET)
if (itemInHand != null && itemInHand.getType() != Material.BUCKET)
return;
// check if in creative
@ -256,6 +239,23 @@ public class JobsPaymentListener implements Listener {
if (jPlayer == null)
return;
// Fix bug when the player has not joined a job, milk a cow and get paid
for (com.gamingmesh.jobs.container.Job jobs : Jobs.getJobs()) {
if (jPlayer.isInJob(jobs) && Jobs.getGCManager().CowMilkingTimer > 0) {
if (cow.hasMetadata(CowMetadata)) {
long time = cow.getMetadata(CowMetadata).get(0).asLong();
if (System.currentTimeMillis() < time + Jobs.getGCManager().CowMilkingTimer) {
long timer = ((Jobs.getGCManager().CowMilkingTimer - (System.currentTimeMillis() - time)) / 1000);
jPlayer.getPlayer().sendMessage(Jobs.getLanguage().getMessage("message.cowtimer", "%time%", timer));
if (Jobs.getGCManager().CancelCowMilking)
event.setCancelled(true);
return;
}
}
}
}
Jobs.action(jPlayer, new EntityActionInfo(cow, ActionType.MILK));
Long Timer = System.currentTimeMillis();