diff --git a/bin/me/itsatacoshop247/DailyBonus/DailyBonus.class b/bin/me/itsatacoshop247/DailyBonus/DailyBonus.class deleted file mode 100644 index e5aa8e0..0000000 Binary files a/bin/me/itsatacoshop247/DailyBonus/DailyBonus.class and /dev/null differ diff --git a/bin/me/itsatacoshop247/DailyBonus/DailyBonusItemDelay.class b/bin/me/itsatacoshop247/DailyBonus/DailyBonusItemDelay.class deleted file mode 100644 index 1b8b9e6..0000000 Binary files a/bin/me/itsatacoshop247/DailyBonus/DailyBonusItemDelay.class and /dev/null differ diff --git a/bin/me/itsatacoshop247/DailyBonus/DailyBonusPlayerListener.class b/bin/me/itsatacoshop247/DailyBonus/DailyBonusPlayerListener.class deleted file mode 100644 index be3e34a..0000000 Binary files a/bin/me/itsatacoshop247/DailyBonus/DailyBonusPlayerListener.class and /dev/null differ diff --git a/dist/DailyBonus.jar b/dist/DailyBonus.jar new file mode 100644 index 0000000..d2bf263 Binary files /dev/null and b/dist/DailyBonus.jar differ diff --git a/dist/README.TXT b/dist/README.TXT new file mode 100644 index 0000000..a4b30a4 --- /dev/null +++ b/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "DailyBonus.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/dist/lib/Vault.jar b/dist/lib/Vault.jar new file mode 100644 index 0000000..e539d4b Binary files /dev/null and b/dist/lib/Vault.jar differ diff --git a/dist/lib/bukkit-1.4.6-R0.4-20130105.234759-4.jar b/dist/lib/bukkit-1.4.6-R0.4-20130105.234759-4.jar new file mode 100644 index 0000000..b0e8b75 Binary files /dev/null and b/dist/lib/bukkit-1.4.6-R0.4-20130105.234759-4.jar differ diff --git a/src/config.yml b/src/config.yml new file mode 100644 index 0000000..8f95cdc --- /dev/null +++ b/src/config.yml @@ -0,0 +1,40 @@ +Main: + Number of Tiers: 3 + Item Give Delay (In Seconds): 0 + Global Message: "&9[DailyBonus] &6!playername just got a bonus of !amount !type for logging in today!" + Global Message is Enabled: true +Tier: + 1: + Economy Amount: 5 + Message: "&6You were given &4!amount !type &6for joining today!" + Items: + - 5;5-1 + - 357;1 + Commands: + 2: + Economy Amount: 10 + Message: "&6You were given &4!amount !type &6for joining today!" + Items: + - 265;2 + - 364;5 + Commands: + - give !player 5 10 + 3: + Economy Amount: 20 + Message: "&6You were given &4!amount !type &6for joining today!" + Items: + - 266;5 + - 22;10;5 + - 372;1 + - 5;10;5-1 + Commands: + - god !player + - give !player 4 10 +Notes: +- Tiers are defined with the highest number being the highest Tier. Hence why Tier 3 give a larger amount by default than 1 or 2 do. +- To make a new Tier, copy and past one of the current Tiers below, and simply change the number to the next highest. Also make sure to change the Number of Tiers in the main. +- An amount of Economy Amount= 20;5 would give a random amount between 15 and 25. 5 in either direction. +- You can delete the Items= list to give no items, or make it one line of 0;0 to also give no items. +- In the item lists, the order is Item Id;Amount;Randomness*dash*Data Num. +- So 5;10;5*dash*1 would give Anywhere from 5 to 15 dark-wood planks. (10 to start, then randomly 0 to 5 more or less) (*dash*1 become a data of 1, the darkwood) +- Please use the Ticket system on bukkitDev for all issues with the plugin! diff --git a/src/me/itsatacoshop247/DailyBonus/DailyBonus.java b/src/me/itsatacoshop247/DailyBonus/DailyBonus.java index 2ae374e..4e03b99 100644 --- a/src/me/itsatacoshop247/DailyBonus/DailyBonus.java +++ b/src/me/itsatacoshop247/DailyBonus/DailyBonus.java @@ -5,19 +5,24 @@ //random amounts //meta data on items +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.logging.Logger; import net.milkbowl.vault.economy.Economy; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -29,14 +34,14 @@ public class DailyBonus extends JavaPlugin { public static Economy econ = null; - public List playerList = new ArrayList(); + public HashSet playerList = new HashSet(); - public HashMap numEarly = new HashMap(); + public HashMap numEarly = new HashMap(); File configFile; - File playersFile; FileConfiguration config; - FileConfiguration players; + + public Logger log = Logger.getLogger("Minecraft"); public void onDisable() { @@ -46,8 +51,29 @@ public void onDisable() { for(int x = 0; x < players.length; x++) { - this.players.set(("Players." + players[x].getName() + ".Last"), System.currentTimeMillis()); - this.savePlayers(); + File file = new File(this.getDataFolder().getAbsolutePath()+"/players/"+players[x].getName()+".yml"); + FileConfiguration pfile = new YamlConfiguration(); + try { + pfile.load(file); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvalidConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + pfile.set(("Time.Last"), System.currentTimeMillis()); + + try { + pfile.save(file); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } } } @@ -59,7 +85,6 @@ public void onEnable() setupEconomy(); this.configFile = new File(getDataFolder(), "config.yml"); - this.playersFile = new File(getDataFolder(), "players.yml"); try { firstRun(); @@ -69,10 +94,10 @@ public void onEnable() e.printStackTrace(); } this.config = new YamlConfiguration(); - this.players = new YamlConfiguration(); loadYamls(); config.options().copyDefaults(true); - players.options().copyDefaults(true); + + this.updateConfig(); } @EventHandler @@ -83,29 +108,137 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, { if(args[0].equalsIgnoreCase("Reload")) { - this.savePlayers(); - this.loadYamls(); - sender.sendMessage(ChatColor.GOLD + "DailyBonus has been reloaded."); - return true; + if(!sender.hasPermission("dailybonus.reload")) + { + sender.sendMessage(ChatColor.WHITE + "You don't have dailybonus.reload permissions!"); + } + else + { + Player[] players = this.getServer().getOnlinePlayers(); + if(players.length > 0) + { + for(int x = 0; x < players.length; x++) + { + File file = new File(this.getDataFolder().getAbsolutePath()+"/players/"+players[x].getName()+".yml"); + FileConfiguration pfile = new YamlConfiguration(); + try { + pfile.load(file); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvalidConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + pfile.set(("Time.Last"), System.currentTimeMillis()); + + try { + pfile.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + this.loadYamls(); + sender.sendMessage(ChatColor.GOLD + "DailyBonus has been reloaded."); + return true; + } } } + else + { + sender.sendMessage(ChatColor.YELLOW + this.getName() + " by " + this.getDescription().getAuthors() +". Version " + this.getDescription().getVersion() + "."); + sender.sendMessage("Use '" + ChatColor.YELLOW + "/DailyBonus reload" + ChatColor.WHITE + "' to reload the plugin."); + return true; + } } return false; } - private void firstRun() throws Exception + private void updateConfig() { - if (!this.playersFile.exists()) + HashMap items = new HashMap(); + + items = loadConfigurables(items); + + int num = 0; + for(Map.Entry item : items.entrySet()) + { + if(this.config.get(item.getKey()) == null) + { + if(item.getValue().equalsIgnoreCase("LIST")) + { + List list = Arrays.asList("LIST ITEMS GO HERE"); + this.config.addDefault(item.getKey(), list); + } + else if(item.getValue().equalsIgnoreCase("true")) + { + this.config.addDefault(item.getKey(), true); + } + else if(item.getValue().equalsIgnoreCase("false")) + { + this.config.addDefault(item.getKey(), false); + } + else if(isInteger(item.getValue())) + { + this.config.addDefault(item.getKey(), Integer.parseInt(item.getValue())); + } + else + { + this.config.addDefault(item.getKey(), item.getValue()); + } + num++; + } + } + if(num > 0) { - this.playersFile.getParentFile().mkdirs(); - copy(getResource("players.yml"), this.playersFile); - this.configFile.delete(); + this.log.info("[DailyBonus] " + num + " missing items added to config file."); } + this.saveConfig(); + } + + public boolean isInteger(String input) + { + try + { + Integer.parseInt(input); + return true; + } + catch(Exception e) + { + return false; + } + } + + private HashMap loadConfigurables(HashMap items) + { + //1.0 + items.put("Main.Number of Tiers", "1"); + items.put("Main.Item Give Delay (In Seconds)", "0"); + items.put("Main.Global Message", "&9[DailyBonus] &6!playername just got abonus of !amount !type for logging in today!"); + items.put("Main.Global Message is Enabled", "true"); + + return items; + } + + private void firstRun() throws Exception + { if (!this.configFile.exists()) { this.configFile.getParentFile().mkdirs(); copy(getResource("config.yml"), this.configFile); } + + File file = new File(this.getDataFolder().getAbsolutePath()+"/players"); + if(!file.exists()) + { + file.mkdir(); + } } private void copy(InputStream in, File file) @@ -133,7 +266,6 @@ public void loadYamls() try { this.config.load(this.configFile); - this.players.load(this.playersFile); } catch (Exception e) { @@ -153,18 +285,6 @@ public void saveConfig() } } - public void savePlayers() - { - try - { - this.players.save(this.playersFile); - } - catch (IOException e) - { - e.printStackTrace(); - } - } - private boolean setupEconomy() { if (getServer().getPluginManager().getPlugin("Vault") == null) diff --git a/src/me/itsatacoshop247/DailyBonus/DailyBonusItemDelay.java b/src/me/itsatacoshop247/DailyBonus/DailyBonusItemDelay.java index ae6ec8a..126b470 100644 --- a/src/me/itsatacoshop247/DailyBonus/DailyBonusItemDelay.java +++ b/src/me/itsatacoshop247/DailyBonus/DailyBonusItemDelay.java @@ -24,21 +24,19 @@ public DailyBonusItemDelay(DailyBonus instance, Player importPlayer, int importN @Override public void run() { - if(plugin.isEnabled()) + if(player.isOnline() && plugin.isEnabled() && !plugin.numEarly.containsKey(player.getName())) { - try + int amount = 0; + String amt = plugin.config.getString("Tier." + this.num + ".Economy Amount"); + if(amt.split(";").length > 1) { - Thread.sleep(plugin.config.getInt("Main.Item Give Delay (In Seconds)")*1000); + amount = Integer.parseInt(amt.split(";")[0]) + (int)((Math.random()*(Integer.parseInt(amt.split(";")[1])*2))-Integer.parseInt(amt.split(";")[1])); } - catch (InterruptedException e) + else { - e.printStackTrace(); + amount = plugin.config.getInt("Tier." + this.num + ".Economy Amount"); } - } - if(player.isOnline() && plugin.isEnabled() && !plugin.numEarly.containsKey(player)) - { - int amount = plugin.config.getInt("Tier." + num + ".Economy Amount"); - if(amount != 0) + if(amount > 0) { if(DailyBonus.econ != null) { @@ -51,41 +49,79 @@ public void run() } } player.sendMessage(DailyBonusPlayerListener.replaceColors(plugin.config.getString("Tier." + num + ".Message").replaceAll("!amount", "" + amount))); - List items = plugin.config.getList("Tier." + num + ".Items"); - String[] items1 = (String[]) items.toArray(new String[0]); - for(int y = 0; y < items1.length; y++) + if(plugin.config.get("Tier." + num + ".Items") != null) { - String[] line = items1[y].split(";"); - if(!line[0].equals("0")) + @SuppressWarnings("unchecked") + List items = (List) plugin.config.getList("Tier." + num + ".Items"); + for(String itemsline : items) { - ItemStack is = new ItemStack(Material.getMaterial(Integer.parseInt(line[0])), Integer.parseInt(line[1])); - if(player.getInventory().firstEmpty() < 0) - { - player.getWorld().dropItemNaturally(player.getEyeLocation(), is); - } - else + String[] line = itemsline.split(";"); + String [] data = itemsline.split("-"); + if(!line[0].equals("0")) { - player.getInventory().addItem(is); + ItemStack is = new ItemStack(Material.getMaterial(Integer.parseInt(line[0])), Integer.parseInt(line[1])); + if(data.length > 1) + { + is.setDurability(Short.parseShort(data[1])); + } + + if(line.length > 2) + { + is.setAmount(Integer.parseInt(line[1]) + (int)((Math.random()*(Integer.parseInt(line[2].split("-")[0])*2))-Integer.parseInt(line[2].split("-")[0]))); + } + + if(player.getInventory().firstEmpty() < 0) + { + player.getWorld().dropItemNaturally(player.getEyeLocation(), is); + } + else + { + player.getInventory().addItem(is); + } } } } + if(plugin.config.get("Tier." + num + ".Commands") != null) + { + @SuppressWarnings("unchecked") + List cmds = (List) plugin.config.getList("Tier." + num + ".Commands"); + + for(String cmd : cmds) + { + cmd = cmd.replaceAll("!player", player.getName()); + plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), cmd); + } + } if(plugin.config.getBoolean("Main.Global Message is Enabled")) { - plugin.getServer().broadcastMessage(DailyBonusPlayerListener.replaceColors(plugin.config.getString("Main.Global Message").replaceAll("!amount", "" + amount).replaceAll("!playername", "" + player.getDisplayName()))); + for(Player p : plugin.getServer().getOnlinePlayers()) + { + if(!p.equals(player)) + { + p.sendMessage(replaceColors(plugin.config.getString("Main.Global Message").replaceAll("!amount", "" + amount).replaceAll("!playername", "" + player.getDisplayName()).replaceAll("!type", "" + DailyBonus.econ.currencyNamePlural()))); + } + } } } - if(plugin.numEarly.containsKey(player)) + plugin.playerList.remove(player.getName()); + + if(plugin.numEarly.containsKey(player.getName())) { - int num = plugin.numEarly.get(player); + int num = plugin.numEarly.get(player.getName()); if(num <= 1) { - plugin.numEarly.remove(player); + plugin.numEarly.remove(player.getName()); } else { - plugin.numEarly.remove(player); - plugin.numEarly.put(player, (num-1)); + plugin.numEarly.remove(player.getName()); + plugin.numEarly.put(player.getName(), (num-1)); } } } -} + + static String replaceColors (String message) + { + return message.replaceAll("(?i)&([a-f0-9])", "\u00A7$1"); + } +} \ No newline at end of file diff --git a/src/me/itsatacoshop247/DailyBonus/DailyBonusPlayerListener.java b/src/me/itsatacoshop247/DailyBonus/DailyBonusPlayerListener.java index 27de920..2fabdea 100644 --- a/src/me/itsatacoshop247/DailyBonus/DailyBonusPlayerListener.java +++ b/src/me/itsatacoshop247/DailyBonus/DailyBonusPlayerListener.java @@ -1,5 +1,8 @@ package me.itsatacoshop247.DailyBonus; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; import java.util.Calendar; import java.util.List; @@ -7,6 +10,9 @@ import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -14,10 +20,8 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; - public class DailyBonusPlayerListener implements Listener //part of new method, instead of extends { - public DailyBonus plugin; public DailyBonusPlayerListener(DailyBonus instance) @@ -25,8 +29,8 @@ public DailyBonusPlayerListener(DailyBonus instance) plugin = instance; } - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) + @EventHandler(ignoreCancelled = true) + public void onPlayerJoin(PlayerJoinEvent event) throws FileNotFoundException, IOException, InvalidConfigurationException { Player player = event.getPlayer(); @@ -42,14 +46,23 @@ public void onPlayerJoin(PlayerJoinEvent event) if(plugin.config.getInt("Main.Item Give Delay (In Seconds)") > 0) { Runnable r = new DailyBonusItemDelay(plugin, player, x); - new Thread(r).start(); - plugin.playerList.add(player); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, r, 20*plugin.config.getInt("Main.Item Give Delay (In Seconds)")); + plugin.playerList.add(player.getName()); x = -666; } else { - int amount = plugin.config.getInt("Tier." + x + ".Economy Amount"); - if(amount != 0) + int amount = 0; + String amt = plugin.config.getString("Tier." + x + ".Economy Amount"); + if(amt.split(";").length > 1) + { + amount = Integer.parseInt(amt.split(";")[0]) + (int)((Math.random()*(Integer.parseInt(amt.split(";")[1])*2))-Integer.parseInt(amt.split(";")[1])); + } + else + { + amount = plugin.config.getInt("Tier." + x + ".Economy Amount"); + } + if(amount > 0) { if(DailyBonus.econ != null) { @@ -61,66 +74,115 @@ public void onPlayerJoin(PlayerJoinEvent event) player.sendMessage(ChatColor.DARK_RED + "The DailyBonus plugin would have given you economy money, but the server doesn't have Vault enabled, or it is not enabled correctly!"); } } - player.sendMessage(replaceColors(plugin.config.getString("Tier." + x + ".Message").replaceAll("!amount", "" + amount))); - List items = plugin.config.getList("Tier." + x + ".Items"); - String[] items1 = (String[]) items.toArray(new String[0]); - for(int y = 0; y < items1.length; y++) + player.sendMessage(replaceColors(plugin.config.getString("Tier." + x + ".Message").replaceAll("!amount", "" + amount).replaceAll("!type", "" + DailyBonus.econ.currencyNamePlural()))); + if(plugin.config.get("Tier." + x + ".Items") != null) { - String[] line = items1[y].split(";"); - if(!line[0].equals("0")) + @SuppressWarnings("unchecked") + List items = (List) plugin.config.getList("Tier." + x + ".Items"); + + for(String itemsline : items) { - ItemStack is = new ItemStack(Material.getMaterial(Integer.parseInt(line[0])), Integer.parseInt(line[1])); - if(player.getInventory().firstEmpty() < 0) - { - player.getWorld().dropItemNaturally(player.getEyeLocation(), is); - } - else - { - player.getInventory().addItem(is); + String[] line = itemsline.split(";"); + String [] data = itemsline.split("-"); + if(!line[0].equals("0")) + { + ItemStack is = new ItemStack(Material.getMaterial(Integer.parseInt(line[0])), Integer.parseInt(line[1])); + if(data.length > 1) + { + is.setDurability(Short.parseShort(data[1])); + } + + if(line.length > 2) + { + is.setAmount(Integer.parseInt(line[1]) + (int)((Math.random()*(Integer.parseInt(line[2].split("-")[0])*2))-Integer.parseInt(line[2].split("-")[0]))); + } + + if(player.getInventory().firstEmpty() < 0) + { + player.getWorld().dropItemNaturally(player.getEyeLocation(), is); + } + else + { + player.getInventory().addItem(is); + } } } } + if(plugin.config.get("Tier." + x + ".Commands") != null) + { + @SuppressWarnings("unchecked") + List cmds = (List) plugin.config.getList("Tier." + x + ".Commands"); + + for(String cmd : cmds) + { + cmd = cmd.replaceAll("!player", player.getName()); + plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), cmd); + } + } if(plugin.config.getBoolean("Main.Global Message is Enabled")) { - plugin.getServer().broadcastMessage(replaceColors(plugin.config.getString("Main.Global Message").replaceAll("!amount", "" + amount).replaceAll("!playername", "" + player.getDisplayName()))); + for(Player p : plugin.getServer().getOnlinePlayers()) + { + if(!p.equals(player)) + { + p.sendMessage(replaceColors(plugin.config.getString("Main.Global Message").replaceAll("!amount", "" + amount).replaceAll("!playername", "" + player.getDisplayName()).replaceAll("!type", "" + DailyBonus.econ.currencyNamePlural()))); + } + } } x = -666; } } - } + } + File file = new File(plugin.getDataFolder().getAbsolutePath()+"/players/"+player.getName()+".yml"); + FileConfiguration pfile = new YamlConfiguration(); + pfile.load(file); + + if(pfile.get("Time.Last") != null) + { + pfile.set(("Time.Last"), System.currentTimeMillis()); + pfile.save(file); + } + else + { + pfile.set("Time.Last", System.currentTimeMillis()); + pfile.save(file); + } } @EventHandler - public void onPlayerQuit(PlayerQuitEvent event) + public void onPlayerQuit(PlayerQuitEvent event) throws FileNotFoundException, IOException, InvalidConfigurationException { Player player = event.getPlayer(); - long login = plugin.players.getLong("Players." + player.getName() + ".Last"); - if(plugin.players.get("Players." + player.getName() + ".Last") != null) + File file = new File(plugin.getDataFolder().getAbsolutePath()+"/players/"+player.getName()+".yml"); + FileConfiguration pfile = new YamlConfiguration(); + pfile.load(file); + + long login = pfile.getLong("Time.Last"); + + if(pfile.get("Time.Last") != null) { - plugin.players.set(("Players." + player.getName() + ".Last"), System.currentTimeMillis()); - plugin.savePlayers(); + pfile.set(("Time.Last"), System.currentTimeMillis()); } else { - plugin.players.addDefault("Players." + player.getName() + ".Last", System.currentTimeMillis()); - plugin.savePlayers(); + pfile.set("Time.Last", System.currentTimeMillis()); } - if(plugin.playerList.contains(player)) + if(plugin.playerList.contains(player.getName())) { - plugin.players.set("Players." + player.getName() + ".Logged Early", true); - plugin.playerList.remove(player); + pfile.set("Time.Logged Early", true); + plugin.playerList.remove(player.getName()); - if(plugin.numEarly.containsKey(player)) + if(plugin.numEarly.containsKey(player.getName())) { - int already = plugin.numEarly.get(player); - plugin.numEarly.remove(player); - plugin.numEarly.put(player, (already+1)); + int already = plugin.numEarly.get(player.getName()); + plugin.numEarly.remove(player.getName()); + plugin.numEarly.put(player.getName(), (already+1)); } else { - plugin.numEarly.put(player, 1); + plugin.numEarly.put(player.getName(), 1); } } @@ -130,38 +192,49 @@ public void onPlayerQuit(PlayerQuitEvent event) if(last.get(Calendar.DATE) < current.get(Calendar.DATE) || (last.get(Calendar.MONTH) + 1) < (current.get(Calendar.MONTH) + 1) || (last.get(Calendar.YEAR)) < (current.get(Calendar.YEAR))) { - plugin.players.set("Players." + player.getName() + ".Logged Early", true); + pfile.set("Time.Logged Early", true); } - + pfile.save(file); } - private boolean CheckLastLogin(Player p) { - if(plugin.players.get("Players." + p.getName() + ".Logged Early") != null) + private boolean CheckLastLogin(Player p) throws FileNotFoundException, IOException, InvalidConfigurationException + { + File file = new File(plugin.getDataFolder().getAbsolutePath()+"/players/"+p.getName()+".yml"); + if(!file.exists()) { - if(plugin.players.getBoolean("Players." + p.getName() + ".Logged Early")) + file.createNewFile(); + FileConfiguration pfile = new YamlConfiguration(); + pfile.load(file); + pfile.set("Time.Last", System.currentTimeMillis()); + pfile.set("Time.Logged Early", false); + pfile.save(file); + + return true; + } + FileConfiguration pfile = new YamlConfiguration(); + pfile.load(file); + + if(pfile.get("Time.Logged Early") != null) + { + if(pfile.getBoolean("Time.Logged Early")) { - plugin.players.set("Players." + p.getName() + ".Logged Early", false); + pfile.set("Time.Logged Early", false); + pfile.save(file); return true; } } - if(plugin.players.get("Players." + p.getName() + ".Last") != null) + + if(pfile.get("Time.Last") != null) { Calendar current = Calendar.getInstance(); Calendar last = Calendar.getInstance(); - last.setTimeInMillis(plugin.players.getLong("Players." + p.getName() + ".Last")); + last.setTimeInMillis(pfile.getLong("Time.Last")); if(last.get(Calendar.DATE) < current.get(Calendar.DATE) || (last.get(Calendar.MONTH) + 1) < (current.get(Calendar.MONTH) + 1) || (last.get(Calendar.YEAR)) < (current.get(Calendar.YEAR))) { return true; } } - else - { - plugin.players.addDefault("Players." + p.getName() + ".Last", System.currentTimeMillis()); - plugin.players.addDefault("Players." + p.getName() + ".Logged Early", false); - plugin.savePlayers(); - return true; - } return false; } diff --git a/src/plugin.yml b/src/plugin.yml new file mode 100644 index 0000000..d473798 --- /dev/null +++ b/src/plugin.yml @@ -0,0 +1,13 @@ +name: DailyBonus +main: me.itsatacoshop247.DailyBonus.DailyBonus +version: 3.6 +author: itsatacoshop247 +description: DailyBonus +dev-url: http://dev.bukkit.org/server-mods/daily-bonus/ +commands: + DailyBonus: + description: Reload the DailyBonus config. + usage: / reload + aliases: [db, DB] + permission: dailybonus.reload + permission-message: You don't have dailybonus.reload permission.