diff --git a/.gitignore b/.gitignore
index 49f8f06..5a62623 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,5 @@
.classpath
.settings/
.project
+.idea
+target/
diff --git a/pom.xml b/pom.xml
index 9ff4bfa..27c642d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
4.0.0
svenwiltink.com.github
- test
+ modreq
1.0-SNAPSHOT
diff --git a/src/main/java/modreq/Metrics.java b/src/main/java/modreq/Metrics.java
index 7e56d40..14262a5 100644
--- a/src/main/java/modreq/Metrics.java
+++ b/src/main/java/modreq/Metrics.java
@@ -376,7 +376,7 @@ private void postPlugin(final boolean isPing) throws IOException {
// is enabled
String pluginVersion = description.getVersion();
String serverVersion = Bukkit.getVersion();
- int playersOnline = Bukkit.getServer().getOnlinePlayers().length;
+ int playersOnline = Bukkit.getServer().getOnlinePlayers().size();
// END server software specific section -- all code below does not use
// any code outside of this class / Java
diff --git a/src/main/java/modreq/ModReq.java b/src/main/java/modreq/ModReq.java
index dd84e15..dff33b7 100644
--- a/src/main/java/modreq/ModReq.java
+++ b/src/main/java/modreq/ModReq.java
@@ -96,27 +96,28 @@ private void startMetrics() {
}
}
+
public void checkConfigFile() {
configFile = new File(getDataFolder().getAbsolutePath() + "/config.yml");
if (!configFile.exists()) {
firstrun();
}
- YamlConfiguration pluginYML = YamlConfiguration.loadConfiguration(this
- .getResource("plugin.yml"));
+ YamlConfiguration pluginYML = YamlConfiguration.loadConfiguration(getTextResource("plugin.yml"));
if (!pluginYML.getString("config-version").equals(
getConfig().getString("version"))) {
logger.info("[ModReq] Your plugin version does not match the config version. Please visit the bukkitdev page for more information");
}
}
+
public void reload() {
messages = new File(getDataFolder().getAbsolutePath() + "/messages.yml");
configFile = new File(getDataFolder().getAbsolutePath() + "/config.yml");
if (!configFile.exists()) {
firstrun();
}
- YamlConfiguration pluginYML = YamlConfiguration.loadConfiguration(this
- .getResource("plugin.yml"));
+
+ YamlConfiguration pluginYML = YamlConfiguration.loadConfiguration(getTextResource("plugin.yml"));
if (!pluginYML.getString("config-version").equals(
getConfig().getString("version"))) {
logger.info("[ModReq] Your plugin version does not match the config version. Please visit the bukkitdev page for more information");
@@ -184,14 +185,17 @@ private void loadMessages() {
Messages = getDefaultMessages();
}
}
+
private void saveDefaultMessages() {
plugin.saveResource("messages.yml", true);
}
+
public YamlConfiguration getDefaultMessages() {
- YamlConfiguration pluginYML = YamlConfiguration.loadConfiguration(this
- .getResource("messages.yml"));
+ File messagesYaml = new File(getDataFolder().getAbsolutePath() + "/messages.yml");
+ YamlConfiguration pluginYML = YamlConfiguration.loadConfiguration(messagesYaml);
return pluginYML;
}
+
private void startNotify() {
if (this.getConfig().getBoolean("notify-on-time")) {
logger.info("[ModReq] Notifying on time enabled");
@@ -203,7 +207,7 @@ public void run() {
TicketHandler th = getTicketHandler();
int opentickets = th.getOpenTicketsAmount();
if (opentickets > 0) {
- Player[] online = Bukkit.getOnlinePlayers();
+ Player[] online = Bukkit.getOnlinePlayers().toArray(new Player[Bukkit.getOnlinePlayers().size()]);
for (int i = 0; i < online.length; i++) {
if (online[i].hasPermission("modreq.check")) {
online[i].sendMessage(ChatColor.GOLD
diff --git a/src/main/java/modreq/Ticket.java b/src/main/java/modreq/Ticket.java
index 7396962..c65fccf 100644
--- a/src/main/java/modreq/Ticket.java
+++ b/src/main/java/modreq/Ticket.java
@@ -19,6 +19,7 @@
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Collection;
import modreq.managers.TicketHandler;
@@ -137,17 +138,13 @@ public Location getLocation() {
*/
public void sendSummarytoPlayer(Player p) {
ChatColor namecolor = ChatColor.RED;
- Player[] list = Bukkit.getServer().getOnlinePlayers();
- int l = list.length;
- int n = 0;
- while (n < l) {
- Player op = list[n];
+ Collection extends Player> list = Bukkit.getServer().getOnlinePlayers();
+ for (Player op : list) {
if (op.getName().equals(submitter)) {
if (op.isOnline()) {
namecolor = ChatColor.GREEN;
}
}
- n++;
}
String summessage = message;
if (summessage.length() > 15) {
@@ -295,11 +292,11 @@ public void sendMessageToSubmitter(String message) {// sends a message to
// the submitter of a
// ticket if he is
// online
- Player[] op = Bukkit.getOnlinePlayers();
- for (int i = 0; i < op.length; i++) {
- if (op[i].getName().equals(submitter)) {
- if (op[i].isOnline()) {
- op[i].sendMessage(message);
+ Collection extends Player> list = Bukkit.getOnlinePlayers();
+ for (Player op : list) {
+ if (op.getName().equals(submitter)) {
+ if (op.isOnline()) {
+ op.sendMessage(message);
return;
}
}
@@ -337,16 +334,15 @@ public void deleteComment(int i) {
}
}
- public void addDefaultComment(Player p, CommentType c) {
+ public void addDefaultComment(@org.jetbrains.annotations.NotNull Player p, CommentType c) {
Comment comment = new Comment(p.getName(), c.getDefaultComment(), c);
addComment(comment);
}
public void notifyStaff(String notification) {
- Player[] op = Bukkit.getOnlinePlayers();
- for (int i = 0; i < op.length; i++) {
- if (op[i].getName().equals(staff)) {
- op[i].sendMessage(notification);
+ for (Player p : Bukkit.getOnlinePlayers()) {
+ if (p.getName().equals(staff)) {
+ p.sendMessage(notification);
return;
}
}
diff --git a/src/main/java/modreq/commands/ModreqCommand.java b/src/main/java/modreq/commands/ModreqCommand.java
index 5321e69..c0778a5 100644
--- a/src/main/java/modreq/commands/ModreqCommand.java
+++ b/src/main/java/modreq/commands/ModreqCommand.java
@@ -78,17 +78,11 @@ public boolean onCommand(CommandSender sender, Command cmd, String label,
public void sendMessageToAdmins(String message) {// sends a message to all
// online players with the
// modreq.check permission
- Player[] list = Bukkit.getServer().getOnlinePlayers();
- int l = list.length;
- int n = 0;
- while (n < l) {
- Player op = list[n];
+ for (Player op : Bukkit.getOnlinePlayers()) {
if (op.hasPermission("modreq.check")) {
op.sendMessage(message);
}
- n++;
}
-
}
private int savereq(String message, CommandSender sender, Location loc) {// save
diff --git a/src/main/java/modreq/commands/ModsCommand.java b/src/main/java/modreq/commands/ModsCommand.java
index 8b2b8bb..2b53fbf 100644
--- a/src/main/java/modreq/commands/ModsCommand.java
+++ b/src/main/java/modreq/commands/ModsCommand.java
@@ -27,40 +27,42 @@
public class ModsCommand extends SubCommandExecutor {
-
public ModsCommand(ModReq instance) {
}
@command
public void Null(CommandSender sender, String[] args) {
if (sender.hasPermission("modreq.mods")) {
- sender.sendMessage(ModReq.format(ModReq.getInstance().Messages.getString("headers-footers.mods.header"), "", "",""));
- Player[] op = Bukkit.getOnlinePlayers();
- String online = "";
- for (int i = 0; i < op.length; i++) {
- if (op[i].hasPermission("modreq.check")) {
+ sender.sendMessage(ModReq.format(ModReq.getInstance().Messages.getString("headers-footers.mods.header"), "", "", ""));
+ boolean first = true;
+ StringBuilder online = new StringBuilder();
+ for (Player op : Bukkit.getOnlinePlayers()) {
+ if (op.hasPermission("modreq.check")) {
if (sender instanceof Player) {
- if (((Player) sender).canSee(op[i])) {
- if (i == 0) {
- online = op[i].getDisplayName();
+ if (((Player) sender).canSee(op)) {
+ if (first) {
+ online = new StringBuilder(op.getDisplayName());
+ first = false;
} else {
- online = online + " " + op[i].getDisplayName();
+ online.append(" ").append(op.getDisplayName());
}
}
} else {
- if (i == 0) {
- online = op[i].getDisplayName();
+ if (first) {
+ online = new StringBuilder(op.getDisplayName());
+ first = false;
} else {
- online = online + " " + op[i].getDisplayName();
+ online.append(" ").append(op.getDisplayName());
}
}
}
}
- if (online.equals("")) {
- sender.sendMessage(ModReq.format(ModReq.getInstance().Messages.getString("error.nomods"), "", "",""));
+ String onlineString = online.toString();
+ if (onlineString.equals("")) {
+ sender.sendMessage(ModReq.format(ModReq.getInstance().Messages.getString("error.nomods"), "", "", ""));
return;
}
- sender.sendMessage(online);
+ sender.sendMessage(onlineString);
}
}
}