-
Notifications
You must be signed in to change notification settings - Fork 222
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
Closed
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b0d807b
Remove Chunks command
ChargedCreeper 3a2a038
Fixed console error
ChargedCreeper 00af651
Rename Command_rc to Command_rc.java
ChargedCreeper 289280b
Update formatting
ChargedCreeper 66fa35a
Update Command_rc.java
ChargedCreeper 11f0c75
Renamed to unloadchunk, and add rc alias
ChargedCreeper d755c9c
Update Command_unloadchunks.java
ChargedCreeper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/me/StevenLawson/TotalFreedomMod/Commands/Command_rc.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
@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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.