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:
parent
ed0eadad69
commit
e52c4fa43b
@ -841,10 +841,6 @@ public class Jobs extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// it will not run longer if it is a server error
|
|
||||||
if (!isEnabled())
|
|
||||||
return;
|
|
||||||
|
|
||||||
GUIManager.CloseInventories();
|
GUIManager.CloseInventories();
|
||||||
shopManager.CloseInventories();
|
shopManager.CloseInventories();
|
||||||
dao.saveExplore();
|
dao.saveExplore();
|
||||||
@ -854,7 +850,7 @@ public class Jobs extends JavaPlugin {
|
|||||||
|
|
||||||
shutdown();
|
shutdown();
|
||||||
consoleMsg("&e[Jobs] &2Plugin has been disabled successfully.");
|
consoleMsg("&e[Jobs] &2Plugin has been disabled successfully.");
|
||||||
this.setEnabled(false);
|
setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
@ -12,43 +12,34 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.gamingmesh.jobs.Jobs;
|
|
||||||
|
|
||||||
public class YmlMaker {
|
public class YmlMaker {
|
||||||
Jobs Plugin;
|
|
||||||
public String fileName;
|
public String fileName;
|
||||||
private JavaPlugin plugin;
|
private JavaPlugin plugin;
|
||||||
public File ConfigFile;
|
public File ConfigFile;
|
||||||
private FileConfiguration Configuration;
|
private FileConfiguration Configuration;
|
||||||
|
|
||||||
public YmlMaker(Jobs Plugin) {
|
|
||||||
this.Plugin = Plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public YmlMaker(JavaPlugin plugin, String fileName) {
|
public YmlMaker(JavaPlugin plugin, String fileName) {
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
throw new IllegalArgumentException("plugin cannot be null");
|
throw new IllegalArgumentException("plugin cannot be null");
|
||||||
}
|
}
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
|
|
||||||
File dataFolder = plugin.getDataFolder();
|
File dataFolder = plugin.getDataFolder();
|
||||||
if (dataFolder == null) {
|
if (!dataFolder.exists())
|
||||||
throw new IllegalStateException();
|
dataFolder.mkdirs();
|
||||||
}
|
ConfigFile = new File(dataFolder, fileName);
|
||||||
this.ConfigFile = new File(dataFolder.toString() + File.separatorChar + this.fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadConfig() {
|
public void reloadConfig() {
|
||||||
InputStreamReader f = null;
|
InputStreamReader f = null;
|
||||||
try {
|
try {
|
||||||
f = new InputStreamReader(new FileInputStream(this.ConfigFile), "UTF-8");
|
f = new InputStreamReader(new FileInputStream(ConfigFile), "UTF-8");
|
||||||
} catch (UnsupportedEncodingException e1) {
|
} catch (UnsupportedEncodingException | FileNotFoundException e1) {
|
||||||
e1.printStackTrace();
|
|
||||||
} catch (FileNotFoundException e1) {
|
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Configuration = YamlConfiguration.loadConfiguration(f);
|
Configuration = YamlConfiguration.loadConfiguration(f);
|
||||||
if (f != null)
|
if (f != null)
|
||||||
try {
|
try {
|
||||||
f.close();
|
f.close();
|
||||||
@ -58,31 +49,35 @@ public class YmlMaker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FileConfiguration getConfig() {
|
public FileConfiguration getConfig() {
|
||||||
if (this.Configuration == null) {
|
if (Configuration == null)
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
|
return Configuration;
|
||||||
}
|
}
|
||||||
return this.Configuration;
|
|
||||||
|
public File getConfigFile() {
|
||||||
|
if (ConfigFile == null)
|
||||||
|
ConfigFile = new File(plugin.getDataFolder(), fileName);
|
||||||
|
return ConfigFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveConfig() {
|
public void saveConfig() {
|
||||||
if ((this.Configuration == null) || (this.ConfigFile == null)) {
|
if ((Configuration == null) || (ConfigFile == null))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
getConfig().save(this.ConfigFile);
|
getConfig().save(ConfigFile);
|
||||||
} catch (IOException ex) {
|
} 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() {
|
public boolean exists() {
|
||||||
return this.ConfigFile.exists();
|
return ConfigFile != null && ConfigFile.exists() ? false : ConfigFile.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createNewFile() {
|
public void createNewFile() {
|
||||||
if (!this.ConfigFile.exists()) {
|
if (ConfigFile != null && !ConfigFile.exists()) {
|
||||||
try {
|
try {
|
||||||
this.ConfigFile.createNewFile();
|
ConfigFile.createNewFile();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -90,8 +85,7 @@ public class YmlMaker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void saveDefaultConfig() {
|
public void saveDefaultConfig() {
|
||||||
if (!this.ConfigFile.exists()) {
|
if (ConfigFile != null && !ConfigFile.exists())
|
||||||
this.plugin.saveResource(this.fileName, false);
|
plugin.saveResource(fileName, false);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,26 +222,9 @@ public class JobsPaymentListener implements Listener {
|
|||||||
if (!player.isOnline())
|
if (!player.isOnline())
|
||||||
return;
|
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);
|
ItemStack itemInHand = Jobs.getNms().getItemInMainHand(player);
|
||||||
|
|
||||||
if (itemInHand == null)
|
if (itemInHand != null && itemInHand.getType() != Material.BUCKET)
|
||||||
return;
|
|
||||||
|
|
||||||
if (itemInHand.getType() != Material.BUCKET)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// check if in creative
|
// check if in creative
|
||||||
@ -256,6 +239,23 @@ public class JobsPaymentListener implements Listener {
|
|||||||
if (jPlayer == null)
|
if (jPlayer == null)
|
||||||
return;
|
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));
|
Jobs.action(jPlayer, new EntityActionInfo(cow, ActionType.MILK));
|
||||||
|
|
||||||
Long Timer = System.currentTimeMillis();
|
Long Timer = System.currentTimeMillis();
|
||||||
|
Loading…
Reference in New Issue
Block a user