Slimmer BlockState-Database

- Default logSurvival to false
 - "/lcbs cleanup" command to delete survival items, with logSurvival: false

Rename TabCompletion
This commit is contained in:
Jascha Starke 2013-10-19 16:29:40 +02:00
parent 814c848e53
commit 4498d8343f
12 changed files with 116 additions and 13 deletions

View file

@ -18,12 +18,12 @@ import de.jaschastarke.bukkit.lib.commands.MethodCommand;
import de.jaschastarke.bukkit.lib.commands.IMethodCommandContainer;
import de.jaschastarke.bukkit.lib.commands.MissingPermissionCommandException;
import de.jaschastarke.bukkit.lib.commands.NeedsPlayerArgumentCommandException;
import de.jaschastarke.bukkit.lib.commands.TabCompletionHelper;
import de.jaschastarke.bukkit.lib.commands.annotations.Alias;
import de.jaschastarke.bukkit.lib.commands.annotations.Description;
import de.jaschastarke.bukkit.lib.commands.annotations.IsCommand;
import de.jaschastarke.bukkit.lib.commands.annotations.NeedsPermission;
import de.jaschastarke.bukkit.lib.commands.annotations.Usages;
import de.jaschastarke.bukkit.lib.commands.parser.TabCompletion;
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
import de.jaschastarke.minecraft.lib.permissions.IPermission;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
@ -139,7 +139,7 @@ public class FeatureSwitchGameMode extends CoreModule<LimitedCreative> {
}
@Override
public List<TabCompletionHelper> getTabCompleter(MethodCommand cmd) {
public List<TabCompletion> getTabCompleter(MethodCommand cmd) {
return null;
}
}

View file

@ -8,10 +8,10 @@ import de.jaschastarke.bukkit.lib.commands.CommandContext;
import de.jaschastarke.bukkit.lib.commands.IHelpDescribed;
import de.jaschastarke.bukkit.lib.commands.IMethodCommandContainer;
import de.jaschastarke.bukkit.lib.commands.MethodCommand;
import de.jaschastarke.bukkit.lib.commands.TabCompletionHelper;
import de.jaschastarke.bukkit.lib.commands.annotations.Description;
import de.jaschastarke.bukkit.lib.commands.annotations.IsCommand;
import de.jaschastarke.bukkit.lib.commands.annotations.NeedsPermission;
import de.jaschastarke.bukkit.lib.commands.parser.TabCompletion;
import de.jaschastarke.maven.ArchiveDocComments;
import de.jaschastarke.maven.PluginCommand;
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
@ -95,7 +95,7 @@ public class MainCommand extends BukkitCommand implements IHelpDescribed, IMetho
}
@Override
public List<TabCompletionHelper> getTabCompleter(MethodCommand cmd) {
public List<TabCompletion> getTabCompleter(MethodCommand cmd) {
return null;
}
}

View file

@ -94,9 +94,33 @@ public class BlockStateCommand extends BukkitCommand implements IHelpDescribed {
throw new CommandException("Module " + mod.getName() + " is disabled");
return super.execute(context, args);
}
/**
* Deletes no longer used data from the BlockState-Database. Currently it only removes non-creative entries
* from the database, if you changed to "logSurvival"-config from true to false.
*/
@IsCommand("cleanup")
@Usages("")
public boolean cleanupDatabase(final CommandContext context, String... args) throws CommandException {
if (mod.getConfig().getLogSurvival()) {
context.responseFormatted(ChatFormattings.INFO, L("command.blockstate.nothing_to_cleanup"));
} else {
mod.getPlugin().getServer().getScheduler().runTaskAsynchronously(mod.getPlugin(), new BukkitRunnable() {
@Override
public void run() {
int countDeleted = mod.getModel().cleanUp(DBModel.Cleanup.SURVIVAL);
if (countDeleted < 0)
context.responseFormatted(ChatFormattings.ERROR, L("command.blockstate.cleanup_error"));
else
context.responseFormatted(ChatFormattings.SUCCESS, L("command.blockstate.cleanup_success", countDeleted));
}
});
}
return true;
}
/**
* Modifies the Block-GameMode-Database and sets all blocks in the selection to the provided gamemode. Set it
* Modifies the BlockState-Database and sets all blocks in the selection to the provided gamemode. Set it
* to "creative" to disable drop of this block on destroying. Set it to "survival" to allow it.
* WorldEdit is required, because the selection Region is used.
* gamemode can be: survival / creative / adventure / s / c / a / 0 / 1 / 2
@ -247,7 +271,13 @@ public class BlockStateCommand extends BukkitCommand implements IHelpDescribed {
mod.getModuleEntry().disable();
thread.start();
context.response(L("command.blockstate.migrate_started", source.getType(), target.getType()));
String sourceType = source.getType().toString();
if (params.getParameter("import") != null) {
if (params.getParameter("import").equals("cc")) {
sourceType = "CreativeControl-" + sourceType;
}
}
context.response(L("command.blockstate.migrate_started", sourceType, target.getType()));
return true;
}

View file

@ -130,11 +130,11 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub
* Log all Block-Places to the database. Disable to make the database more slim by not adding blocks placed in
* survival-mode.
*
* default: true
* default: false
*/
@IsConfigurationNode(order = 400)
public boolean getLogSurvival() {
return config.getBoolean("logSurvival", true);
return config.getBoolean("logSurvival", false);
}
private StringList ignoredWorlds = null;

View file

@ -64,6 +64,10 @@ public interface DBModel {
}
}
public enum Cleanup {
SURVIVAL;
}
public void onEnable() throws Exception;
public void onDisable();
public void moveState(Block from, Block to);
@ -83,4 +87,6 @@ public interface DBModel {
public void removeState(Block block);
public void finish();
}
public int cleanUp(Cleanup target);
}

View file

@ -14,6 +14,7 @@ import de.jaschastarke.bukkit.lib.database.ResultIterator;
import de.jaschastarke.database.Type;
import de.jaschastarke.database.db.Database;
import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState.Source;
import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.Cleanup;
import de.jaschastarke.utils.IDebugLogHolder;
public class DBQueries {
@ -300,6 +301,23 @@ public class DBQueries {
throw new RuntimeException("Currently only SQLite is supported.");
}
}
public int cleanup(Cleanup q) throws SQLException {
PreparedStatement delete;
if (dbg.isDebug())
dbg.getLog().debug("DBQuery: cleanup: " + q.toString());
if (q == Cleanup.SURVIVAL) {
delete = db.prepare("DELETE FROM lc_block_state WHERE gm = ?");
if (db.getType() == Type.MySQL)
delete.setString(1, GameMode.SURVIVAL.name());
else
delete.setInt(1, GameMode.SURVIVAL.getValue());
} else {
return -1;
}
return delete.executeUpdate();
}
public Database getDB() {
return db;
}

View file

@ -198,4 +198,15 @@ public class SyncronizedModel extends AbstractModel implements DBModel {
}
}
}
@Override
public int cleanUp(Cleanup target) {
try {
return q.cleanup(target);
} catch (SQLException e) {
mod.getLog().severe(e.getMessage());
mod.getLog().warn("Failed to cleanup BlockState-DB");
return -1;
}
}
}

View file

@ -18,6 +18,7 @@ import org.bukkit.metadata.Metadatable;
import de.jaschastarke.database.DatabaseConfigurationException;
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
import de.jaschastarke.minecraft.limitedcreative.blockstate.thread.CallableAction;
import de.jaschastarke.minecraft.limitedcreative.blockstate.thread.ThreadLink;
import de.jaschastarke.minecraft.limitedcreative.blockstate.thread.Transaction;
@ -259,4 +260,21 @@ public class ThreadedModel extends AbstractModel implements DBModel, Listener {
public ModBlockStates getModel() {
return mod;
}
@Override
public int cleanUp(final Cleanup target) {
return threads.call(new CallableAction<Integer>() {
@Override
public void process(ThreadLink link, DBQueries q) {
this.returnSet = true;
try {
this.returnValue = q.cleanup(target);
} catch (SQLException e) {
this.returnValue = -1;
mod.getLog().severe(e.getMessage());
mod.getLog().warn("Failed to cleanup BlockState-DB");
}
}
});
}
}

View file

@ -134,6 +134,20 @@ public class ThreadLink {
return action.getValue();
}
public void queue(Action act) {
synchronized (updateQueue) {
updateQueue.add(act);
updateQueue.notify();
}
}
public <T> T call(CallableAction<T> act) {
synchronized (updateQueue) {
updateQueue.push(act);
updateQueue.notify();
}
return act.getValue();
}
public List<BlockState> callUpdate(Cuboid c) {
FetchCuboidAction action = new FetchCuboidAction(c);
synchronized (updateQueue) {

View file

@ -26,12 +26,12 @@ import de.jaschastarke.bukkit.lib.commands.ICommand;
import de.jaschastarke.bukkit.lib.commands.IHelpDescribed;
import de.jaschastarke.bukkit.lib.commands.MethodCommand;
import de.jaschastarke.bukkit.lib.commands.MissingPermissionCommandException;
import de.jaschastarke.bukkit.lib.commands.TabCompletionHelper;
import de.jaschastarke.bukkit.lib.commands.TabCompletionHelper.Completer;
import de.jaschastarke.bukkit.lib.commands.TabCompletionHelper.Context;
import de.jaschastarke.bukkit.lib.commands.annotations.IsCommand;
import de.jaschastarke.bukkit.lib.commands.annotations.Usages;
import de.jaschastarke.bukkit.lib.commands.parser.DefinedParameterParser;
import de.jaschastarke.bukkit.lib.commands.parser.TabCompletion;
import de.jaschastarke.bukkit.lib.commands.parser.TabCompletion.Completer;
import de.jaschastarke.bukkit.lib.commands.parser.TabCompletion.Context;
import de.jaschastarke.maven.ArchiveDocComments;
import de.jaschastarke.maven.PluginCommand;
import de.jaschastarke.minecraft.lib.permissions.IAbstractPermission;
@ -114,9 +114,9 @@ public class RegionsCommand extends BukkitCommand implements IHelpDescribed {
for (ICommand cmd : handler.getCommands()) {
if (cmd instanceof MethodCommand) {
if (cmd.getName().equals("info")) {
((MethodCommand) cmd).getCompleter().add(TabCompletionHelper.forUsageLine("[region]"));
((MethodCommand) cmd).getCompleter().add(TabCompletion.forUsageLine("[region]"));
}
for (TabCompletionHelper c : ((MethodCommand) cmd).getCompleter()) {
for (TabCompletion c : ((MethodCommand) cmd).getCompleter()) {
c.setCompleter("region", new RegionCompleter());
}
}

View file

@ -38,6 +38,9 @@ command.blockstate.migration_finished_restart: A Server-Restart is required!
command.blockstate.migration_error: Migration failed with error: {0}
command.blockstate.migrate_useronline_error: There are players on the Server. The migration shouldn't be run with active players.
command.blockstate.migrate_confirm: Are you sure you want to start the migration? It may take a very long time and much CPU. To confirm execution run the command with the following added: {0}
command.blockstate.nothing_to_cleanup: Nothing to cleanup
command.blockstate.cleanup_success: Successfully removed {0} entries from database
command.blockstate.cleanup_error: Error while cleaning database. Check server.log
cmdblock.blocked: This command is blocked while in creative mode.
cmdblock.blocked.requires_worldedit: WorlEdit is required to use this command

View file

@ -38,6 +38,9 @@ command.blockstate.migration_finished_restart: Server-Neustart notwendig!
command.blockstate.migration_error: Migration mit folgendem Fehler fehlgeschlagen: {0}
command.blockstate.migrate_useronline_error: Es sind Spieler auf dem Server. Die Migration sollte nicht mit aktiven Spielern ausgeführt werden.
command.blockstate.migrate_confirm: Bist du sicher. dass du die Migration starten willst? Dies dauert vermutlich sehr lange und benötigt viel Prozessor-Leistung. Um die Ausführung zu bestätigen führe den Befehl erneut mit folgendem Parameter aus: {0}
command.blockstate.nothing_to_cleanup: Nichts aufzuräumen
command.blockstate.cleanup_success: Erfolgreich {0} Datensätze aus der Datenbank gelöscht
command.blockstate.cleanup_error: Fehler beim Aufräumen der Datenbank. server.log prüfen
cmdblock.blocked: Dieses Kommando ist im Kreativ-Modus blockiert
cmdblock.blocked.requires_worldedit: WorldEdit wird für diesen Befehl benötigt