Skip to content

Commit

Permalink
DragonEggDrop:
Browse files Browse the repository at this point in the history
+ Scheduled a BukkitRunnable to constantly do update checks every 30 minutes to assure that a new version is being accounted for
+ Overrided the #onDisable() method to clear any extraneous data that was left behind upon shutdown

DragonEggDropCmd:
+ Added a notification in the main command that shows that a new version is available if the player is op

LootManager:
+ Added a #getLoot() method to get the loot collection

RandomCollection:
+ Added a #clear() method to clear existing data from the collection and set the total to 0

plugin.yml:
* Updated the plugin.yml ready for new release
  • Loading branch information
2008Choco committed Jan 31, 2017
1 parent 3deb5db commit 28ccdc2
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: DragonEggDrop
main: com.ninjaguild.dragoneggdrop.DragonEggDrop
version: 1.2.1
version: 1.2.2
author: NinjaStix

commands:
Expand Down
28 changes: 27 additions & 1 deletion src/com/ninjaguild/dragoneggdrop/DragonEggDrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
Expand Down Expand Up @@ -71,6 +73,8 @@ public class DragonEggDrop extends JavaPlugin {

private DEDManager dedManager;
private NMSAbstract nmsAbstract;

private BukkitTask updateTask;

@Override
public void onEnable() {
Expand Down Expand Up @@ -107,7 +111,29 @@ public void onEnable() {
this.getCommand("dragoneggdrop").setExecutor(new DragonEggDropCmd(this));

// Update check
this.doVersionCheck();
this.updateTask = new BukkitRunnable() {
@Override
public void run() {
boolean previousState = newVersionAvailable;
doVersionCheck();

// New version found
if (previousState != newVersionAvailable) {
Bukkit.getOnlinePlayers().forEach(p -> {
if (p.isOp()) sendMessage(p, ChatColor.GRAY + "A new version is available for download (Version " + newVersion + "). ");
});
}
}
}.runTaskTimerAsynchronously(this, 0, 36000);
}

@Override
public void onDisable() {
if (this.updateTask != null)
this.updateTask.cancel();

this.dedManager.getDragonNames().clear();
this.dedManager.getLootManager().getLoot().clear();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
sender.sendMessage(ChatColor.GOLD + "Author: " + plugin.getDescription().getAuthors().get(0));
sender.sendMessage(ChatColor.GOLD + "Maintainer: 2008Choco");
sender.sendMessage(ChatColor.GOLD + "Version: " + plugin.getDescription().getVersion());
if (sender.isOp() && plugin.isNewVersionAvailable())
sender.sendMessage(ChatColor.AQUA + "NEW VERSION AVAILABLE!: " + plugin.getNewVersion());
sender.sendMessage(ChatColor.YELLOW + "/dragoneggdrop help");
sender.sendMessage(ChatColor.GOLD + "-----------------------");

Expand Down
10 changes: 9 additions & 1 deletion src/com/ninjaguild/dragoneggdrop/loot/LootManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,15 @@ private void loadLootItems() {
}
}

// FIXME: NMS-Dependent
/**
* Get all loot loaded into the loot manager
*
* @return all loaded loot
*/
public RandomCollection<ItemStack> getLoot() {
return loot;
}

/**
* Place a chest with randomized loot at a specific location
*
Expand Down
10 changes: 9 additions & 1 deletion src/com/ninjaguild/dragoneggdrop/utils/RandomCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,12 @@ public E next() {
return map.ceilingEntry(value).getValue();
}

}
/**
* Clear all data from the random collection
*/
public void clear() {
this.map.clear();
this.total = 0;
}

}

0 comments on commit 28ccdc2

Please sign in to comment.