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 4 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
47 changes: 47 additions & 0 deletions src/me/StevenLawson/TotalFreedomMod/Commands/Command_rc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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>")
public class Command_rc extends TFM_Command
Copy link
Member

Choose a reason for hiding this comment

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

Probably should be the full command name, and /rc as an alias.

{
@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);
Copy link
Member

Choose a reason for hiding this comment

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

Formatting here. PLease use braces

}
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.

Trailing full stop here, should also start with a capital.

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;
}
}