Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unload chunks command #674

Closed
wants to merge 7 commits into from
Closed
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package me.StevenLawson.TotalFreedomMod.Commands;

import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.entity.Player;

@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
@CommandParameters(description = "Unloads chunks not currently in use.", usage = "/<command>", aliases="rc")
public class Command_unloadchunks extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
int numChunks = 0;
for (World world : server.getWorlds())
{
numChunks += unloadUnusedChunks(world);
}
TFM_Util.adminAction(sender.getName(), "Unloading unused chunks", true);
Copy link
Member

Choose a reason for hiding this comment

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

Message should probably be sent before actually unloading chunks. :)


if (!senderIsConsole)
{
sender_p.sendMessage(numChunks + " chunks unloaded.");
}
TFM_Log.info(numChunks + " chunks unloaded.");
return true;
}

private int unloadUnusedChunks(World world)
{
int numChunks = 0;
for (Chunk loadedChunk : world.getLoadedChunks())
{
if (!world.isChunkInUse(loadedChunk.getX(), loadedChunk.getZ()))
{
if (world.unloadChunk(loadedChunk))
{
numChunks++;
}
}
}
return numChunks;
}
}