From d6875439104b6208d96e6fc59025c71c615db166 Mon Sep 17 00:00:00 2001 From: t00thpick1 Date: Tue, 19 Aug 2014 18:11:56 -0400 Subject: [PATCH] Prevent players from having more than one database querying command running at once. --- .../gmail/nossr50/commands/player/McrankCommand.java | 10 +++++++++- .../gmail/nossr50/commands/player/MctopCommand.java | 9 ++++++++- src/main/java/com/gmail/nossr50/mcMMO.java | 1 + .../runnables/commands/McrankCommandDisplayTask.java | 1 + .../runnables/commands/MctopCommandDisplayTask.java | 4 ++++ src/main/resources/locale/locale_en_US.properties | 1 + 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java b/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java index 5c509389f..e771c24a0 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/McrankCommand.java @@ -7,6 +7,8 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.metadata.MetadataValue; import org.bukkit.util.StringUtil; import com.gmail.nossr50.mcMMO; @@ -17,7 +19,6 @@ import com.gmail.nossr50.runnables.commands.McrankCommandAsyncTask; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; - import com.google.common.collect.ImmutableList; public class McrankCommand implements TabExecutor { @@ -88,6 +89,13 @@ public class McrankCommand implements TabExecutor { return; } + if (((Player) sender).hasMetadata(mcMMO.databaseCommandKey)) { + sender.sendMessage(LocaleLoader.getString("Commands.Database.Processing")); + return; + } else { + ((Player) sender).setMetadata(mcMMO.databaseCommandKey, new FixedMetadataValue(mcMMO.p, null)); + } + mcMMOPlayer.actualizeDatabaseATS(); } diff --git a/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java b/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java index 1b04f9c78..ba415257b 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/MctopCommand.java @@ -7,6 +7,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; import org.bukkit.entity.Player; +import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.StringUtil; import com.gmail.nossr50.mcMMO; @@ -19,7 +20,6 @@ import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; - import com.google.common.collect.ImmutableList; public class MctopCommand implements TabExecutor { @@ -91,6 +91,13 @@ public class MctopCommand implements TabExecutor { return; } + if (((Player) sender).hasMetadata(mcMMO.databaseCommandKey)) { + sender.sendMessage(LocaleLoader.getString("Commands.Database.Processing")); + return; + } else { + ((Player) sender).setMetadata(mcMMO.databaseCommandKey, new FixedMetadataValue(mcMMO.p, null)); + } + mcMMOPlayer.actualizeDatabaseATS(); } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 3a3168f6b..bf3a91276 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -116,6 +116,7 @@ public class mcMMO extends JavaPlugin { public final static String playerDataKey = "mcMMO: Player Data"; public final static String greenThumbDataKey = "mcMMO: Green Thumb"; public final static String pistonDataKey = "mcMMO: Piston State"; + public final static String databaseCommandKey = "mcMMO: Processing Database Command"; public static FixedMetadataValue metadataValue; diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java index f378f8b42..afbfea0c7 100644 --- a/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/commands/McrankCommandDisplayTask.java @@ -57,6 +57,7 @@ public class McrankCommandDisplayTask extends BukkitRunnable { rank = skills.get(null); sender.sendMessage(LocaleLoader.getString("Commands.mcrank.Overall", (rank == null ? LocaleLoader.getString("Commands.mcrank.Unranked") : rank))); + player.removeMetadata(mcMMO.databaseCommandKey, mcMMO.p); } public void displayBoard() { diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java index cbc8c4421..bdc4ba455 100644 --- a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandDisplayTask.java @@ -7,6 +7,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.database.PlayerStat; import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.locale.LocaleLoader; @@ -61,6 +62,9 @@ public class MctopCommandDisplayTask extends BukkitRunnable { sender.sendMessage(String.format("%2d. %s%s - %s%s", place, ChatColor.GREEN, stat.name, ChatColor.WHITE, stat.statVal)); place++; } + if (sender instanceof Player) { + ((Player) sender).removeMetadata(mcMMO.databaseCommandKey, mcMMO.p); + } } private void displayBoard() { diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index 7b894fa84..9c9e0674d 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -454,6 +454,7 @@ Commands.Cooldowns.Header=[[GOLD]]--= [[GREEN]]mcMMO Ability Cooldowns[[GOLD]] = Commands.Cooldowns.Row.N=\ [[RED]]{0}[[WHITE]] - [[GOLD]]{1} seconds left Commands.Cooldowns.Row.Y=\ [[AQUA]]{0}[[WHITE]] - [[DARK_GREEN]]Ready! Commands.Database.Cooldown=[[RED]]You must wait 1 second before using this command again. +Commands.Database.Processing=[[RED]]Your previous command is still being processed. Please wait. Commands.Disabled=[[RED]]This command is disabled. Commands.DoesNotExist= [[RED]]Player does not exist in the database! Commands.GodMode.Disabled=[[YELLOW]]mcMMO Godmode Disabled