Skip to content

Commit

Permalink
Removed Saving top ten list message
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Apr 4, 2018
1 parent de04058 commit 8f751fd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/com/wasteofplastic/askyblock/AsyncBackup.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public AsyncBackup(final ASkyBlock plugin) {
public void run() {
plugin.getGrid().saveGrid();
plugin.getTinyDB().asyncSaveDB();
if (plugin.getTopTen() != null) {
plugin.getTopTen().topTenSave();
}
}}, Settings.backupDuration, Settings.backupDuration);
}

Expand Down
11 changes: 4 additions & 7 deletions src/com/wasteofplastic/askyblock/TopTen.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class TopTen implements Listener, Requester {

public TopTen(ASkyBlock plugin) {
this.plugin = plugin;
topTenLoad();
}

/**
Expand Down Expand Up @@ -99,8 +100,7 @@ public void topTenAddEntry(UUID ownerUUID, long l) {
}
}
topTenList.put(ownerUUID, l);
topTenList = topTenList.entrySet().stream()
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).limit(10)
topTenList = topTenList.entrySet().stream().sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).limit(10)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
// Add head to cache
if (topTenList.containsKey(ownerUUID) && !topTenHeads.containsKey(ownerUUID)) {
Expand Down Expand Up @@ -203,13 +203,12 @@ public void topTenSave() {
if (topTenList == null) {
return;
}
plugin.getLogger().info("Saving top ten list");
//plugin.getLogger().info("Saving top ten list");
// Make file
File topTenFile = new File(plugin.getDataFolder(), "topten.yml");
// Make configuration
YamlConfiguration config = new YamlConfiguration();
// Save config

int rank = 0;
for (Map.Entry<UUID, Long> m : topTenList.entrySet()) {
if (rank++ == 10) {
Expand All @@ -231,6 +230,7 @@ public void topTenSave() {
* then the top ten is created
*/
public void topTenLoad() {
plugin.getLogger().info("Loading Top Ten");
topTenList.clear();
// Check to see if the top ten list exists
File topTenFile = new File(plugin.getDataFolder(), "topten.yml");
Expand All @@ -243,12 +243,9 @@ public void topTenLoad() {
// Load the values
if (topTenConfig.isSet("topten")) {
for (String playerUUID : topTenConfig.getConfigurationSection("topten").getKeys(false)) {
// getLogger().info(playerUUID);
try {
UUID uuid = UUID.fromString(playerUUID);
// getLogger().info(uuid.toString());
int level = topTenConfig.getInt("topten." + playerUUID);
// getLogger().info("Level = " + level);
topTenAddEntry(uuid, level);
} catch (Exception e) {
e.printStackTrace();
Expand Down
56 changes: 56 additions & 0 deletions src/com/wasteofplastic/askyblock/commands/AdminCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -49,6 +52,7 @@
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
Expand Down Expand Up @@ -1361,6 +1365,11 @@ else if (split[0].equalsIgnoreCase("deleteisland")) {
countUnowned(sender);
return true;
}

if (split[1].equalsIgnoreCase("players")) {
purgePlayers(sender);
return true;
}
// Set the flag
purgeFlag = true;
// See if this purge unowned
Expand Down Expand Up @@ -2131,6 +2140,53 @@ else if (split[0].equalsIgnoreCase("purge")) {
}
}

private void purgePlayers(CommandSender sender) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
// This map is a list of owner and island level
YamlConfiguration player = new YamlConfiguration();
File oldPlayers = new File(plugin.getPlayersFolder(), "oldplayers");
if (!oldPlayers.exists()) {
oldPlayers.mkdirs();
}
Path targetPath = oldPlayers.toPath();
int index = 0;
for (final File f : plugin.getPlayersFolder().listFiles()) {
// Need to remove the .yml suffix
String fileName = f.getName();
if (fileName.endsWith(".yml")) {
try {
player.load(f);
index++;
if (index % 1000 == 0) {
plugin.getLogger().info("Processed " + index + " players");
}
if (!player.getBoolean("hasIsland") && !player.getBoolean("hasTeam")) {
Path fileToMovePath = f.toPath();
Files.move(fileToMovePath, targetPath.resolve(fileToMovePath.getFileName()));
}
} catch (Exception e) {
plugin.getLogger().severe("Error when moving player file. File is " + fileName);
plugin.getLogger().severe("Look at the stack trace and edit the file - it probably has broken YAML in it for some reason.");
e.printStackTrace();
}
}
}
plugin.getLogger().info("Processed " + index + " players for top ten");

plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
if (sender != null) {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().generalSuccess);
} else {
plugin.getLogger().warning("Completed player purge.");
}

}});
});

}

/**
* Deletes the overworld and nether islands together
* @param island
Expand Down

3 comments on commit 8f751fd

@tastybento
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also adds purge players admin command.

Includes top ten saving in the regular database saving.

@ygtdmn
Copy link
Contributor

@ygtdmn ygtdmn commented on 8f751fd Apr 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tastybento hi. This player purge command will not remove players with islands right?

@tastybento
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uniodex No.

Please sign in to comment.