This command probably works

This commit is contained in:
t00thpick1 2016-04-23 00:24:05 -04:00
parent 8822b4edae
commit dcd79e87e1
5 changed files with 134 additions and 0 deletions

View File

@ -0,0 +1,46 @@
package com.gmail.nossr50.commands;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.FlatfileDatabaseManager;
import com.gmail.nossr50.database.SQLDatabaseManager;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList;
public class MHDCommand implements TabExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (mcMMO.getDatabaseManager() instanceof SQLDatabaseManager) {
SQLDatabaseManager m = (SQLDatabaseManager) mcMMO.getDatabaseManager();
m.resetMobHealthSettings();
for (McMMOPlayer player : UserManager.getPlayers()) {
player.getProfile().setMobHealthbarType(Config.getInstance().getMobHealthbarDefault());
}
sender.sendMessage("Mob health reset");
return true;
}
if (mcMMO.getDatabaseManager() instanceof FlatfileDatabaseManager) {
FlatfileDatabaseManager m = (FlatfileDatabaseManager) mcMMO.getDatabaseManager();
m.resetMobHealthSettings();
for (McMMOPlayer player : UserManager.getPlayers()) {
player.getProfile().setMobHealthbarType(Config.getInstance().getMobHealthbarDefault());
}
sender.sendMessage("Mob health reset");
return true;
}
return false;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return ImmutableList.of();
}
}

View File

@ -1289,4 +1289,57 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
public static int EXP_ALCHEMY = 40; public static int EXP_ALCHEMY = 40;
public static int UUID_INDEX = 41; public static int UUID_INDEX = 41;
public static int SCOREBOARD_TIPS = 42; public static int SCOREBOARD_TIPS = 42;
public void resetMobHealthSettings() {
BufferedReader in = null;
FileWriter out = null;
String usersFilePath = mcMMO.getUsersFilePath();
synchronized (fileWritingLock) {
try {
in = new BufferedReader(new FileReader(usersFilePath));
StringBuilder writer = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
// Remove empty lines from the file
if (line.isEmpty()) {
continue;
}
String[] character = line.split(":");
character[HEALTHBAR] = Config.getInstance().getMobHealthbarDefault().toString();
line = new StringBuilder(org.apache.commons.lang.StringUtils.join(character, ":")).append(":").toString();
writer.append(line).append("\r\n");
}
// Write the new file
out = new FileWriter(usersFilePath);
out.write(writer.toString());
}
catch (IOException e) {
mcMMO.p.getLogger().severe("Exception while reading " + usersFilePath + " (Are you sure you formatted it correctly?)" + e.toString());
}
finally {
if (in != null) {
try {
in.close();
}
catch (IOException e) {
// Ignore
}
}
if (out != null) {
try {
out.close();
}
catch (IOException e) {
// Ignore
}
}
}
}
}
} }

View File

@ -1417,4 +1417,23 @@ public final class SQLDatabaseManager implements DatabaseManager {
LOAD, LOAD,
SAVE; SAVE;
} }
public void resetMobHealthSettings() {
PreparedStatement statement = null;
Connection connection = null;
try {
connection = getConnection(PoolIdentifier.MISC);
statement = connection.prepareStatement("UPDATE " + tablePrefix + "huds SET mobhealthbar = ?");
statement.setString(1, Config.getInstance().getMobHealthbarDefault().toString());
statement.executeUpdate();
}
catch (SQLException ex) {
printErrors(ex);
}
finally {
tryClose(statement);
tryClose(connection);
}
}
} }

View File

@ -7,6 +7,7 @@ import org.bukkit.command.PluginCommand;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.KrakenCommand; import com.gmail.nossr50.commands.KrakenCommand;
import com.gmail.nossr50.commands.MHDCommand;
import com.gmail.nossr50.commands.McImportCommand; import com.gmail.nossr50.commands.McImportCommand;
import com.gmail.nossr50.commands.McabilityCommand; import com.gmail.nossr50.commands.McabilityCommand;
import com.gmail.nossr50.commands.McconvertCommand; import com.gmail.nossr50.commands.McconvertCommand;
@ -390,6 +391,15 @@ public final class CommandRegistrationManager {
command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mobhealth", "<DISABLED | HEARTS | BAR>")); command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mobhealth", "<DISABLED | HEARTS | BAR>"));
command.setExecutor(new MobhealthCommand()); command.setExecutor(new MobhealthCommand());
} }
private static void registerMHDCommand() {
PluginCommand command = mcMMO.p.getCommand("mhd");
command.setDescription("Resets all mob health bar settings for all players to the default"); //TODO: Localize
command.setPermission("mcmmo.commands.mhd");
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.0", "mhd"));
command.setExecutor(new MHDCommand());
}
private static void registerMcscoreboardCommand() { private static void registerMcscoreboardCommand() {
PluginCommand command = mcMMO.p.getCommand("mcscoreboard"); PluginCommand command = mcMMO.p.getCommand("mcscoreboard");
@ -430,6 +440,7 @@ public final class CommandRegistrationManager {
registerMcrefreshCommand(); registerMcrefreshCommand();
registerMcscoreboardCommand(); registerMcscoreboardCommand();
registerMobhealthCommand(); registerMobhealthCommand();
registerMHDCommand();
registerXprateCommand(); registerXprateCommand();
// Chat Commands // Chat Commands

View File

@ -111,6 +111,8 @@ commands:
mobhealth: mobhealth:
aliases: [mcmobhealth] aliases: [mcmobhealth]
description: Change the style of the mob healthbar description: Change the style of the mob healthbar
mhd:
description: Sets all players mob health settings to default
mcscoreboard: mcscoreboard:
aliases: [mcsb] aliases: [mcsb]
description: Manage your mcMMO Scoreboard description: Manage your mcMMO Scoreboard
@ -947,6 +949,9 @@ permissions:
description: Allows access to the mmoshowdb command description: Allows access to the mmoshowdb command
mcmmo.commands.mobhealth: mcmmo.commands.mobhealth:
description: Allows access to the mobhealth command description: Allows access to the mobhealth command
mcmmo.commands.mhd:
default: false
description: Allows access to the mhd command
mcmmo.commands.party.*: mcmmo.commands.party.*:
default: false default: false
description: Implies access to all mcmmo.commands.party permissions. description: Implies access to all mcmmo.commands.party permissions.