Skip to content

Commit

Permalink
Made ModReq compatible with spigot >= 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
svenwiltink committed Sep 6, 2019
1 parent 74b31b8 commit e503fa6
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.classpath
.settings/
.project
.idea
target/
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>svenwiltink.com.github</groupId>
<artifactId>test</artifactId>
<artifactId>modreq</artifactId>
<version>1.0-SNAPSHOT</version>


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/modreq/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/modreq/ModReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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
Expand Down
28 changes: 12 additions & 16 deletions src/main/java/modreq/Ticket.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import modreq.managers.TicketHandler;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/modreq/commands/ModreqCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 18 additions & 16 deletions src/main/java/modreq/commands/ModsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit e503fa6

Please sign in to comment.