Skip to content

Commit

Permalink
JSONified /alts and possible alts in /bminfo
Browse files Browse the repository at this point in the history
Clicking player name will execute /bminfo

Player names are now colour coded in this command

Green = never banned
Yellow = Banned previously
Gold = Temporarily banned
Red = Perm banned

Fixed #759
  • Loading branch information
confuser committed Apr 7, 2018
1 parent a2baae5 commit 5ec209c
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 20 deletions.
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
<pattern>javax.annotation</pattern>
<shadedPattern>me.confuser.banmanager.internal.jaxax.annotation</shadedPattern>
</relocation>
<relocation>
<pattern>me.rayzr522.jsonmessage</pattern>
<shadedPattern>me.confuser.banmanager.internal.jsonmessage</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
Expand All @@ -125,6 +129,10 @@
<id>Central</id>
<url>http://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>rayzr-repo</id>
<url>https://cdn.rawgit.com/Rayzr522/maven-repo/master/</url>
</repository>
</repositories>
<dependencies>
<dependency>
Expand Down Expand Up @@ -199,6 +207,11 @@
<artifactId>geoip2</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>me.rayzr522</groupId>
<artifactId>jsonmessage</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
34 changes: 24 additions & 10 deletions src/main/java/me/confuser/banmanager/commands/FindAltsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import me.confuser.banmanager.data.PlayerData;
import me.confuser.banmanager.util.CommandUtils;
import me.confuser.banmanager.util.IPUtils;
import me.confuser.banmanager.util.JSONCommandUtils;
import me.confuser.bukkitutil.Message;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -61,20 +63,32 @@ public void run() {
}

List<PlayerData> players = plugin.getPlayerStorage().getDuplicates(ip);
ArrayList<String> names = new ArrayList<>(players.size());

for (PlayerData player : players) {
names.add(player.getName());
}
if (sender instanceof Player) {
sender.sendMessage(Message.get("alts.header").set("ip", ipStr).toString());

if (players.isEmpty()) {
sender.sendMessage(Message.get("none").toString());
return;
}

sender.sendMessage(Message.get("alts.header").set("ip", ipStr).toString());
JSONCommandUtils.alts(players).send((Player) sender);
} else {
ArrayList<String> names = new ArrayList<>(players.size());

if (names.isEmpty()) {
sender.sendMessage(Message.get("none").toString());
return;
}
for (PlayerData player : players) {
names.add(player.getName());
}

sender.sendMessage(Message.get("alts.header").set("ip", ipStr).toString());

if (names.isEmpty()) {
sender.sendMessage(Message.get("none").toString());
return;
}

sender.sendMessage(ChatColor.GOLD + StringUtils.join(names, ", "));
sender.sendMessage(ChatColor.GOLD + StringUtils.join(names, ", "));
}
}
});

Expand Down
32 changes: 22 additions & 10 deletions src/main/java/me/confuser/banmanager/commands/InfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import me.confuser.banmanager.data.*;
import me.confuser.banmanager.util.DateUtils;
import me.confuser.banmanager.util.IPUtils;
import me.confuser.banmanager.util.JSONCommandUtils;
import me.confuser.banmanager.util.parsers.InfoCommandParser;
import me.confuser.bukkitutil.Message;
import me.rayzr522.jsonmessage.JSONMessage;
import org.apache.commons.lang.time.FastDateFormat;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -130,7 +132,7 @@ public void playerInfo(CommandSender sender, String name, Integer index, InfoCom

PlayerData player = players.get(index - 1);

ArrayList<String> messages = new ArrayList<>();
ArrayList<Object> messages = new ArrayList<>();

boolean hasFlags = parser.isBans() || parser.isKicks() || parser.isMutes() || parser.isNotes() || parser
.isWarnings() || parser.getIps() != null;
Expand Down Expand Up @@ -266,15 +268,21 @@ public void playerInfo(CommandSender sender, String name, Integer index, InfoCom
if (sender.hasPermission("bm.command.bminfo.alts")) {
messages.add(Message.getString("alts.header"));

StringBuilder duplicates = new StringBuilder();
List<PlayerData> duplicatePlayers = plugin.getPlayerStorage().getDuplicates(player.getIp());

for (PlayerData duplicatePlayer : plugin.getPlayerStorage().getDuplicates(player.getIp())) {
duplicates.append(duplicatePlayer.getName()).append(", ");
}
if (sender instanceof Player) {
messages.add(JSONCommandUtils.alts(duplicatePlayers));
} else {
StringBuilder duplicates = new StringBuilder();

for (PlayerData duplicatePlayer : duplicatePlayers) {
duplicates.append(duplicatePlayer.getName()).append(", ");
}

if (duplicates.length() >= 2) duplicates.setLength(duplicates.length() - 2);
if (duplicates.length() >= 2) duplicates.setLength(duplicates.length() - 2);

messages.add(duplicates.toString());
messages.add(duplicates.toString());
}
}

if (sender.hasPermission("bm.command.bminfo.ipstats")) {
Expand Down Expand Up @@ -364,12 +372,16 @@ public void playerInfo(CommandSender sender, String name, Integer index, InfoCom
}

// TODO Show last warning
for (String message : messages) {
sender.sendMessage(message);
for (Object message : messages) {
if (message instanceof String) {
sender.sendMessage((String) message);
} else if (message instanceof JSONMessage){
((JSONMessage) message).send((Player) sender);
}
}
}

private void handleIpHistory(ArrayList<String> messages, PlayerData player, long since, int page) {
private void handleIpHistory(ArrayList<Object> messages, PlayerData player, long since, int page) {
CloseableIterator<PlayerHistoryData> iterator = null;
try {
iterator = plugin.getPlayerHistoryStorage().getSince(player, since, page);
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/me/confuser/banmanager/util/JSONCommandUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package me.confuser.banmanager.util;

import me.confuser.banmanager.BanManager;
import me.confuser.banmanager.data.PlayerBanData;
import me.confuser.banmanager.data.PlayerData;
import me.rayzr522.jsonmessage.JSONMessage;
import org.bukkit.ChatColor;

import java.sql.SQLException;
import java.util.List;

public class JSONCommandUtils {
private static BanManager plugin = BanManager.getPlugin();

public static JSONMessage alts(List<PlayerData> players) {
JSONMessage message = JSONMessage.create();
int index = 0;

for (PlayerData player : players) {
ChatColor colour = ChatColor.GREEN;

if (plugin.getPlayerBanStorage().isBanned(player.getUUID())) {
PlayerBanData ban = plugin.getPlayerBanStorage().getBan(player.getUUID());

if (ban.getExpires() == 0) {
colour = ChatColor.RED;
} else {
colour = ChatColor.GOLD;
}
} else {
try {
if (plugin.getPlayerBanRecordStorage().getCount(player) != 0) {
colour = ChatColor.YELLOW;
}
} catch (SQLException e) {
e.printStackTrace();
}
}

message.then(player.getName()).color(colour).runCommand("/bminfo " + player.getName());

if (index != players.size() - 1) {
message.then(", ");
}

index++;
}

return message;
}
}

0 comments on commit 5ec209c

Please sign in to comment.