Skip to content

Commit

Permalink
Added all messages to config (Fixes #18)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankHeijden authored and Phoenix616 committed Oct 20, 2017
1 parent 032b834 commit 88ca2e0
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 97 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.wfector</groupId>
<artifactId>chestshopnotifier</artifactId>
<version>1.2.1-SNAPSHOT</version>
<version>1.3.0-SNAPSHOT</version>
<name>ChestShopNotifier</name>
<description>Bukkit plugin to shows all transactions made in your ChestShops throughout history.</description>

Expand Down Expand Up @@ -131,4 +131,4 @@
</build>


</project>
</project>
5 changes: 2 additions & 3 deletions src/main/java/com/wfector/command/CleanDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.wfector.notifier.ChestShopNotifier;
import com.wfector.util.Time;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;

Expand Down Expand Up @@ -50,9 +49,9 @@ public void run() {
}
statement.executeUpdate("DELETE FROM csnUUID" + whereStr + ";");

sender.sendMessage(ChatColor.RED + "Cleaned database from " + (readOnly ? "read" : "all") + " entries!");
sender.sendMessage(plugin.getMessage("database-cleaned", "amount", (readOnly ? "read" : "all")));
} catch (SQLException e) {
sender.sendMessage(ChatColor.RED + "Database error while executing this command!");
sender.sendMessage(plugin.getMessage("database-error-oncommand"));
e.printStackTrace();
} finally {
ChestShopNotifier.close(c);
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/wfector/command/Clear.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import com.wfector.notifier.ChestShopNotifier;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
Expand All @@ -31,9 +30,9 @@ public void run() {
Statement statement = c.createStatement();
statement.executeUpdate("DELETE FROM csnUUID WHERE `Unread`='1' AND `ShopOwnerId`='" + senderId.toString() + "'");

if(plugin.getMessage("history-clear") != null) sender.sendMessage(plugin.getMessage("history-clear"));
sender.sendMessage(plugin.getMessage("history-clear"));
} catch (SQLException e) {
sender.sendMessage(ChatColor.RED + "Database error while executing this command!");
sender.sendMessage(plugin.getMessage("database-error-oncommand"));
e.printStackTrace();
} finally {
ChestShopNotifier.close(c);
Expand Down
37 changes: 18 additions & 19 deletions src/main/java/com/wfector/command/CommandRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.UUIDs.NameManager;
import com.wfector.notifier.BatchRunner;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand All @@ -24,40 +23,40 @@ public CommandRunner(ChestShopNotifier plugin) {

public boolean onCommand(final CommandSender sender, Command cmd, String label, String[] args) {
if(args.length == 0) {
Help.SendDialog(sender);
new Help(plugin).SendDialog(sender);
return true;
} else {
if(args[0].equalsIgnoreCase("reload") && (sender.hasPermission("csn.command.reload"))) {
sender.sendMessage(ChatColor.LIGHT_PURPLE + "ChestShop Notifier // " + ChatColor.GRAY + "Reloading, please wait...");

plugin.updateConfiguration(sender);
sender.sendMessage(plugin.getMessage("reload-cmd"));
return true;

} else if(args[0].equalsIgnoreCase("convert") && sender.hasPermission("csn.admin")) {

if(!plugin.isPluginEnabled()) {
sender.sendMessage(ChatColor.RED + "Invalid database connection. Please edit config and /csn reload.");
sender.sendMessage(plugin.getMessage("database-error"));
return true;
}

sender.sendMessage(ChatColor.RED + "Attempting to convert database...");
sender.sendMessage(plugin.getMessage("database-convert"));
plugin.getLogger().log(Level.INFO, "Attempting to convert database...");

new Converter(plugin, sender).runTaskAsynchronously(plugin);
return true;

} else if(args[0].equalsIgnoreCase("upload") && sender.hasPermission("csn.command.upload")) {
if(!plugin.isPluginEnabled()) {
sender.sendMessage(ChatColor.RED + "Invalid database connection. Please edit config and /csn reload.");
sender.sendMessage(plugin.getMessage("database-error"));
return true;
}

new BatchRunner(plugin).runTaskAsynchronously(plugin);

sender.sendMessage(ChatColor.RED + "Batch executed!");
sender.sendMessage(plugin.getMessage("database-upload"));

} else if(args[0].equalsIgnoreCase("cleandatabase") && sender.hasPermission("csn.command.cleandatabase")) {
if(!plugin.isPluginEnabled()) {
sender.sendMessage(ChatColor.RED + "Invalid database connection. Please edit config and /csn reload.");
sender.sendMessage(plugin.getMessage("database-error"));
return true;
}

Expand All @@ -68,7 +67,7 @@ public boolean onCommand(final CommandSender sender, Command cmd, String label,
CleanDatabase.Parameter param = CleanDatabase.Parameter.getFromInput(args[i]);
if (param != null) {
if (i + 1 + param.getArgs().length > args.length) {
sender.sendMessage(ChatColor.RED + "Missing parameter arguments: " + param.getUsage());
sender.sendMessage(plugin.getMessage("missing-arguments", "usage", param.getUsage()));
return true;
}
switch (param) {
Expand All @@ -77,7 +76,7 @@ public boolean onCommand(final CommandSender sender, Command cmd, String label,
int days = Integer.parseInt(args[i + 1]);
cleaner.cleanBefore(days);
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.RED + args[i + 1] + " is not a valid number input for " + param.getUsage() + "!");
sender.sendMessage(plugin.getMessage("invalid-number", "typo", args[i + 1]).replace("{usage}", param.getUsage()));
return true;
}
break;
Expand All @@ -91,7 +90,7 @@ public boolean onCommand(final CommandSender sender, Command cmd, String label,
if (userId != null) {
cleaner.cleanUser(userId);
} else {
sender.sendMessage(ChatColor.RED + args[i + 1] + " is not a valid username/uuid input for " + param.getUsage() + "!");
sender.sendMessage(plugin.getMessage("invalid-username", "typo", args[i + 1]).replace("{usage}", param.getUsage())); //should work?
}
break;
case READ_ONLY:
Expand All @@ -111,13 +110,13 @@ public boolean onCommand(final CommandSender sender, Command cmd, String label,
return true;

} else if(args[0].equalsIgnoreCase("help") && sender.hasPermission("csn.command")) {
Help.SendDialog(sender);
new Help(plugin).SendDialog(sender);
return true;

} else if(args[0].equalsIgnoreCase("history") && sender.hasPermission("csn.command.history")) {

if(!plugin.isPluginEnabled()) {
sender.sendMessage(ChatColor.RED + "Invalid database connection. Please edit config and /csn reload.");
sender.sendMessage(plugin.getMessage("database-error"));
return true;
}

Expand All @@ -139,20 +138,20 @@ public boolean onCommand(final CommandSender sender, Command cmd, String label,
if (target != null) {
userId = target.getUniqueId();
} else {
sender.sendMessage(ChatColor.RED + "The user '" + args[1] + "' was not found.");
sender.sendMessage(plugin.getMessage("user-not-found", "player", args[1]));
return true;
}
}
if (args.length > 2) {
try {
page = Integer.parseInt(args[2]);
} catch (NumberFormatException e2) {
sender.sendMessage(ChatColor.YELLOW + args[2] + ChatColor.RED + " is not a valid page number input for /csn history <user> <page>!");
sender.sendMessage(plugin.getMessage("page-not-found-other", "page", args[2]));
return true;
}
}
} else {
sender.sendMessage(ChatColor.YELLOW + args[1] + ChatColor.RED + " is not a valid page number input for /csn history <page>!");
sender.sendMessage(plugin.getMessage("page-not-found", "page", args[1]));
return true;
}
}
Expand All @@ -168,7 +167,7 @@ public boolean onCommand(final CommandSender sender, Command cmd, String label,

} else if(args[0].equalsIgnoreCase("clear") && sender.hasPermission("csn.command.clear")) {
if(!plugin.isPluginEnabled()) {
sender.sendMessage(ChatColor.RED + "Invalid database connection. Please edit config and /csn reload.");
sender.sendMessage(plugin.getMessage("database-error"));
return true;
}

Expand All @@ -178,7 +177,7 @@ public boolean onCommand(final CommandSender sender, Command cmd, String label,
}
}

sender.sendMessage(ChatColor.RED + "Command not recognized. Type /csn help for help.");
sender.sendMessage(plugin.getMessage("unrecognized-command"));
return true;
}
}
5 changes: 2 additions & 3 deletions src/main/java/com/wfector/command/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.logging.Level;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;

import com.wfector.notifier.ChestShopNotifier;
Expand All @@ -31,10 +30,10 @@ public Converter(ChestShopNotifier plugin, CommandSender sender) {

public void run() {
if (convertDatabase()) {
sender.sendMessage(ChatColor.RED + "Database converted!");
sender.sendMessage(plugin.getMessage("database-converted"));
plugin.getLogger().log(Level.INFO, "Database converted!");
} else {
sender.sendMessage(ChatColor.RED + "Error while trying to convert! Maybe you don't have a 'csn' table?");
sender.sendMessage(plugin.getMessage("database-convert-fail"));
plugin.getLogger().log(Level.SEVERE, "Error while trying to convert! Maybe you don't have a 'csn' table?");
}
}
Expand Down
62 changes: 30 additions & 32 deletions src/main/java/com/wfector/command/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,52 @@

import java.util.ArrayList;

import org.bukkit.ChatColor;
import com.wfector.notifier.ChestShopNotifier;
import org.bukkit.command.CommandSender;

public class Help {
private final ChestShopNotifier plugin;

public static void SendDialog(CommandSender sender) {
public Help(ChestShopNotifier main) {
plugin = main;
}

ArrayList<String> helpItems = new ArrayList<String>();
public void SendDialog(CommandSender sender) {

helpItems.add("&dChestShop Notifier // &7Commands");
helpItems.add("&c ");
helpItems.add("&7 /csn &dhelp &f- Plugin usage & commands");
if (sender.hasPermission("csn.command.history")) {
helpItems.add("&7 /csn &dhistory [<page>]&f- View sales");
ArrayList<String> helpItems = new ArrayList<String>();
helpItems.add(plugin.getMessage("help.header"));
helpItems.add(plugin.getMessage("help.help"));
if(sender.hasPermission("csn.command.history")) {
helpItems.add(plugin.getMessage("help.history"));
}
if (sender.hasPermission("csn.command.read")) {
helpItems.add("&7 /csn &dread &f- Mark all sales as read");
if(sender.hasPermission("csn.command.read")) {
helpItems.add(plugin.getMessage("help.read"));
}
if (sender.hasPermission("csn.command.clear")) {
helpItems.add("&7 /csn &dclear &f- Remove read sales");
if(sender.hasPermission("csn.command.clear")) {
helpItems.add(plugin.getMessage("help.clear"));
}
helpItems.add("&c ");

if (sender.hasPermission("csn.command.history.others")) {
helpItems.add("&7 /csn &dhistory <username> [<page>]&f- View sales of another player");
if(sender.hasPermission("csn.command.history.others")) {
helpItems.add(plugin.getMessage("help.history-others"));
}
if (sender.hasPermission("csn.command.cleandatabase")) {
helpItems.add("&7 /csn &ccleandatabase &f- Remove database entries. Parameters:");
helpItems.add("&c --older-than, -o <days> &f- Removes entries older than <days>");
helpItems.add("&c --user, -user <username/uuid> &f- Removes entries from a single user only");
helpItems.add("&c --read-only, -r &f- Removes only read entries, default behaviour");
helpItems.add("&c --all, -a &f- Removes all entries");
if(sender.hasPermission("csn.command.cleandatabase")) {
helpItems.add(plugin.getMessage("help.cleandatabase"));
helpItems.add(plugin.getMessage("help.cleandatabase-older-than"));
helpItems.add(plugin.getMessage("help.cleandatabase-user"));
helpItems.add(plugin.getMessage("help.cleandatabase-read-only"));
helpItems.add(plugin.getMessage("help.cleandatabase-all"));
}
if (sender.hasPermission("csn.command.upload")) {
helpItems.add("&7 /csn &cupload &f- Force update databases");
if(sender.hasPermission("csn.command.upload")) {
helpItems.add(plugin.getMessage("help.upload"));
}
if (sender.hasPermission("csn.command.convert")) {
helpItems.add("&7 /csn &cconvert &f- Convert database to UUIDs");
if(sender.hasPermission("csn.command.convert")) {
helpItems.add(plugin.getMessage("help.convert"));
}

if (sender.hasPermission("csn.command.reload")) {
helpItems.add("&7 /csn &creload &f- Reload configuration");
if(sender.hasPermission("csn.command.reload")) {
helpItems.add(plugin.getMessage("help.reload"));
}

for(String item : helpItems) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', item));
sender.sendMessage(item);
}

}

}
23 changes: 10 additions & 13 deletions src/main/java/com/wfector/command/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ private void gatherResults() {
if (markRead) {
Statement readStatement = c.createStatement();
int rowsUpdated = readStatement.executeUpdate("UPDATE csnUUID SET `Unread`='1' WHERE `ShopOwnerId`='" + userId.toString() + "'");

if (rowsUpdated > 0 && plugin.getMessage("history-marked-read") != null)
sender.sendMessage(plugin.getMessage("history-marked-read"));
if (rowsUpdated > 0)
sender.sendMessage(plugin.getMessage("history-marked-read"));
}

} catch (SQLException e) {
Expand All @@ -97,18 +96,16 @@ public void addEntry(HistoryEntry addEntry) {

private void showResults() {
boolean other = !(sender instanceof Player) || !((Player) sender).getUniqueId().equals(userId);
if(plugin.getMessage("history-caption") != null) {
String message = plugin.getMessage("history-caption");
if (other) {
String userName = NameManager.getUsername(userId);
message += ChatColor.GRAY + " (" + (userName != null ? userName : userId) + ")";
}
sender.sendMessage(message);
String message = plugin.getMessage("history-caption");
if (other) {
String userName = NameManager.getUsername(userId);
message += ChatColor.GRAY + " (" + (userName != null ? userName : userId) + ")";
}
sender.sendMessage(message);
sender.sendMessage("");

if(historyEntries.isEmpty()) {
if(plugin.getMessage("history-empty") != null) sender.sendMessage(plugin.getMessage("history-empty"));
sender.sendMessage(plugin.getMessage("history-empty"));
return;
}

Expand All @@ -133,14 +130,14 @@ private void showResults() {
}

sender.sendMessage(" ");
if (maxPages > 1 && plugin.getMessage("history-footer-page") != null) {
if (maxPages > 1) {
sender.sendMessage(
plugin.getMessage("history-footer-page")
.replace("{current}", String.valueOf(page))
.replace("{pages}", String.valueOf(maxPages))
);
}
if (!other && sender.hasPermission("csn.command.clear") && plugin.getMessage("history-footer-clear") != null) {
if (!other && sender.hasPermission("csn.command.clear")) {
sender.sendMessage(plugin.getMessage("history-footer-clear"));
}

Expand Down
Loading

0 comments on commit 88ca2e0

Please sign in to comment.