Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ build_move-BAT.bat
.project
.classpath
.idea/
*.iml
*.iml
*~
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@
</plugin>
</plugins>
</build>
<description>Bungee plugin which handles ban, mute and kick management</description>
<description>Bungee plugin which handles ban, mute, watch and kick management</description>
<version>1.4.2</version>
</project>
2 changes: 1 addition & 1 deletion src/main/java/fr/Alphart/BAT/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Configuration(){
private String language = "en";
private String prefix = "&6[&4BAT&6]&e ";

@Comment("Force players to give reason when /ban /unban /kick /mute /unmute etc.")
@Comment("Force players to give reason when /ban /unban /kick /watch /mute /unmute etc.")
private boolean mustGiveReason= false;
@Comment("Enable /bat confirm, to confirm command such as action on unknown player.")
private boolean confirmCommand = true;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/fr/Alphart/BAT/Modules/Core/CoreCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import fr.Alphart.BAT.Modules.Core.Importer.MinecraftUUIDImporter;
import fr.Alphart.BAT.Modules.Core.Importer.SQLiteMigrater;
import fr.Alphart.BAT.Modules.Kick.KickEntry;
import fr.Alphart.BAT.Modules.Watch.WatchEntry;
import fr.Alphart.BAT.Modules.Mute.MuteEntry;
import fr.Alphart.BAT.Utils.CallbackUtils.Callback;
import fr.Alphart.BAT.Utils.CallbackUtils.ProgressCallback;
Expand Down Expand Up @@ -304,6 +305,17 @@ public void onCommand(final CommandSender sender, final String[] args, final boo
: "&eThe IP &a" + entity + "&e has never been muted."));
}
break;
case "watch":
final List<WatchEntry> watches = modules.getWatchModule().getWatchData(entity);
if(!watches.isEmpty()){
message = lookupFormatter.formatWatchLookup(entity, watches, page, false);
}else{
message = new ArrayList<BaseComponent[]>();
message.add(BAT.__((!Utils.validIP(entity))
? "&eThe player &a" + entity + "&e wasn't ever watched."
: "&eThe IP &a" + entity + "&e wasn't ever watched."));
}
break;
case "kick":
final List<KickEntry> kicks = modules.getKickModule().getKickData(entity);
if(!kicks.isEmpty()){
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/fr/Alphart/BAT/Modules/Core/EntityEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import fr.Alphart.BAT.Modules.Comment.CommentEntry;
import fr.Alphart.BAT.Modules.Kick.KickEntry;
import fr.Alphart.BAT.Modules.Mute.MuteEntry;
import fr.Alphart.BAT.Modules.Watch.WatchEntry;
import fr.Alphart.BAT.Utils.UUIDNotFoundException;
import fr.Alphart.BAT.Utils.Utils;
import fr.Alphart.BAT.database.DataSourceHandler;
Expand All @@ -34,6 +35,7 @@ public class EntityEntry {

private final List<BanEntry> bans = new ArrayList<BanEntry>();
private final List<MuteEntry> mutes = new ArrayList<MuteEntry>();
private final List<WatchEntry> watches = new ArrayList<WatchEntry>();
private final List<KickEntry> kicks = new ArrayList<KickEntry>();
private final List<CommentEntry> comments = new ArrayList<CommentEntry>();

Expand Down Expand Up @@ -121,6 +123,10 @@ public EntityEntry(final String entity) {
if (modules.isLoaded("mute")) {
mutes.addAll(modules.getMuteModule().getMuteData(entity));
}

if (modules.isLoaded("watch")) {
watches.addAll(modules.getWatchModule().getWatchData(entity));
}
// No ip kick
if (modules.isLoaded("kick") && ipUsers.isEmpty()) {
kicks.addAll(modules.getKickModule().getKickData(entity));
Expand Down Expand Up @@ -148,6 +154,10 @@ public List<MuteEntry> getMutes() {
return mutes;
}

public List<WatchEntry> getWatches() {
return watches;
}

public List<KickEntry> getKicks() {
return kicks;
}
Expand Down
127 changes: 121 additions & 6 deletions src/main/java/fr/Alphart/BAT/Modules/Core/LookupFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import fr.Alphart.BAT.Modules.Comment.CommentEntry.Type;
import fr.Alphart.BAT.Modules.Kick.KickEntry;
import fr.Alphart.BAT.Modules.Mute.MuteEntry;
import fr.Alphart.BAT.Modules.Watch.WatchEntry;
import fr.Alphart.BAT.Utils.FormatUtils;
import fr.Alphart.BAT.Utils.MojangAPIProvider;
import fr.Alphart.BAT.Utils.Utils;
Expand Down Expand Up @@ -56,16 +57,25 @@ public List<BaseComponent[]> getSummaryLookupPlayer(final String pName, final bo
}

final EntityEntry ipDetails = new EntityEntry(Core.getPlayerIP(pName));

boolean isBan = false;
boolean isBanIP = false;
int bansNumber = 0;
final List<String> banServers = Lists.newArrayList();
final List<String> banIPServers = Lists.newArrayList();

boolean isMute = false;
boolean isMuteIP = false;
int mutesNumber = 0;
final List<String> muteServers = Lists.newArrayList();
final List<String> muteIPServers = Lists.newArrayList();

boolean isWatched = false;
boolean isWatchedIP = false;
int watchesNumber = 0;
final List<String> watchServers = Lists.newArrayList();
final List<String> watchIPServers = Lists.newArrayList();

int kicksNumber = 0;
// Compute player's state (as well as his ip) concerning ban and mute
for (final BanEntry banEntry : pDetails.getBans()) {
Expand All @@ -80,10 +90,10 @@ public List<BaseComponent[]> getSummaryLookupPlayer(final String pName, final bo
banIPServers.add(banEntry.getServer());
}
}
for (final MuteEntry muteEntry : pDetails.getMutes()) {
if (muteEntry.isActive()) {
isMute = true;
muteServers.add(muteEntry.getServer());
for (final WatchEntry watchEntry : pDetails.getWatches()) {
if (watchEntry.isActive()) {
isWatched = true;
watchServers.add(watchEntry.getServer());
}
}
for (final MuteEntry muteEntry : ipDetails.getMutes()) {
Expand All @@ -94,6 +104,7 @@ public List<BaseComponent[]> getSummaryLookupPlayer(final String pName, final bo
}
bansNumber = pDetails.getBans().size() + ipDetails.getBans().size();
mutesNumber = pDetails.getMutes().size() + ipDetails.getMutes().size();
watchesNumber = pDetails.getWatches().size() + ipDetails.getWatches().size();
kicksNumber = pDetails.getKicks().size();

// Load the lookup pattern
Expand Down Expand Up @@ -132,6 +143,12 @@ public List<BaseComponent[]> getSummaryLookupPlayer(final String pName, final bo
final String muteip_servers = !muteIPServers.isEmpty()
? Joiner.on(joinChar).join(muteIPServers).toLowerCase()
: _("none");
final String watch_servers = !watchServers.isEmpty()
? Joiner.on(joinChar).join(watchServers).toLowerCase()
: _("none");
final String watchip_servers = !watchIPServers.isEmpty()
? Joiner.on(joinChar).join(watchIPServers).toLowerCase()
: _("none");

final String first_login = pDetails.getFirstLogin() != EntityEntry.noDateFound
? Core.defaultDF.format(new Date(pDetails.getFirstLogin().getTime()))
Expand Down Expand Up @@ -193,8 +210,10 @@ public List<BaseComponent[]> getSummaryLookupPlayer(final String pName, final bo
.replace("{connection_state}", connection_state)
.replace("{ban_servers}", ban_servers).replace("{banip_servers}", banip_servers)
.replace("{mute_servers}", mute_servers).replace("{muteip_servers}", muteip_servers)
.replace("{watch_servers}", watch_servers).replace("{watchip_servers}", watchip_servers)
.replace("{first_login}", first_login).replace("{last_login}", last_login).replace("{last_ip}", last_ip)
.replace("{bans_number}", String.valueOf(bansNumber)).replace("{mutes_number}", String.valueOf(mutesNumber))
.replace("{watches_number}", String.valueOf(watchesNumber))
.replace("{kicks_number}", String.valueOf(kicksNumber)).replace("{comments_number}", String.valueOf(commentsNumber))
.replace("{name_history_list}", name_history_list).replaceAll("\\{last_comments:\\d\\}", last_comments)
.replace("{player}", pName).replace("{uuid}", Core.getUUID(pName))
Expand Down Expand Up @@ -433,8 +452,104 @@ public List<BaseComponent[]> formatBanLookup(final String entity, final List<Ban

return FormatUtils.formatNewLine(ChatColor.translateAlternateColorCodes('&', msg.toString()));
}


public List<BaseComponent[]> formatWatchLookup(final String entity, final List<WatchEntry> watches,
int page, final boolean staffLookup) throws InvalidModuleException {
final StringBuilder msg = new StringBuilder();

int totalPages = (int) Math.ceil((double)watches.size()/entriesPerPage);
if(watches.size() > entriesPerPage){
if(page > totalPages){
page = totalPages;
}
int beginIndex = (page - 1) * entriesPerPage;
int endIndex = (beginIndex + entriesPerPage < watches.size()) ? beginIndex + entriesPerPage : watches.size();
for(int i=watches.size() -1; i > 0; i--){
if(i >= beginIndex && i < endIndex){
continue;
}
watches.remove(i);
}
}
msg.append(lookupHeader.replace("{entity}", entity).replace("{module}", "Watch")
.replace("{page}", page + "/" + totalPages));

boolean isWatched = false;
for (final WatchEntry watchEntry : watches) {
if (watchEntry.isActive()) {
isWatched = true;
}
}

// We begin with active ban
if(isWatched){
msg.append("&6&lActive watches: &e");
final Iterator<WatchEntry> it = watches.iterator();
while(it.hasNext()){
final WatchEntry watch = it.next();
if(!watch.isActive()){
break;
}
final String begin = Core.defaultDF.format(watch.getBeginDate());
final String server = watch.getServer();
final String reason = watch.getReason();
final String end;
if(watch.getEndDate() == null){
end = "permanent watch";
}else{
end = Core.defaultDF.format(watch.getEndDate());
}

msg.append("\n");
if(staffLookup){
msg.append(_("activeStaffWatchLookupRow",
new String[] { watch.getEntity(), begin, server, reason, end}));
}else{
msg.append(_("activeWatchLookupRow",
new String[] { begin, server, reason, watch.getStaff(), end}));
}
it.remove();
}
}

if(!watches.isEmpty()){
msg.append("\n&7&lArchive watches: &e");
for(final WatchEntry watch : watches){
final String begin = Core.defaultDF.format(watch.getBeginDate());
final String server = watch.getServer();
final String reason = watch.getReason();

final String unwatchDate;
if(watch.getUnwatchDate() == null){
unwatchDate = Core.defaultDF.format(watch.getEndDate());
}else{
unwatchDate = Core.defaultDF.format(watch.getUnwatchDate());
}
final String unwatchReason = watch.getUnwatchReason();
String unwatchStaff = watch.getUnwatchStaff();
if(unwatchStaff == "null"){
unwatchStaff = "temporary watch";
}

msg.append("\n");
if(staffLookup){
msg.append(_("archiveStaffWatchLookupRow",
new String[] { watch.getEntity(), begin, server, reason, unwatchDate, unwatchReason, unwatchStaff}));
}else{
msg.append(_("archiveWatchLookupRow",
new String[] { begin, server, reason, watch.getStaff(), unwatchDate, unwatchReason, unwatchStaff}));
}
}
}

msg.append(lookupFooter.replace("{entity}", entity).replace("{module}", "Watch")
.replace("{page}", page + "/" + totalPages));

return FormatUtils.formatNewLine(ChatColor.translateAlternateColorCodes('&', msg.toString()));
}

public List<BaseComponent[]> formatMuteLookup(final String entity, final List<MuteEntry> mutes,
public List<BaseComponent[]> formatMuteLookup(final String entity, final List<MuteEntry> mutes,
int page, final boolean staffLookup) throws InvalidModuleException {
final StringBuilder msg = new StringBuilder();

Expand Down Expand Up @@ -528,7 +643,7 @@ public List<BaseComponent[]> formatMuteLookup(final String entity, final List<Mu

return FormatUtils.formatNewLine(ChatColor.translateAlternateColorCodes('&', msg.toString()));
}

public List<BaseComponent[]> formatKickLookup(final String entity, final List<KickEntry> kicks,
int page, final boolean staffLookup) throws InvalidModuleException {
final StringBuilder msg = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public static enum Action {
MUTE("mute"), MUTEIP("muteip"), TEMPMUTE("tempmute"), TEMPMUTEIP("tempmuteip"), UNMUTE("unmute"), UNMUTEIP(
"unmuteip"), MUTE_BROADCAST("mute.broadcast"),

WATCH("watch"), WATCHIP("watchip"), TEMPWATCH("tempwatch"), TEMPWATCHIP("tempwatchip"), UNWATCH("unwatch"), UNWATCHIP(
"unwatchip"), WATCH_BROADCAST("watch.broadcast"),

KICK("kick"), WARN("warn"), WARN_BROADCAST("warn.broadcast"), KICK_BROADCAST("kick.broadcast"),

LOOKUP("lookup");
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/fr/Alphart/BAT/Modules/ModulesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import fr.Alphart.BAT.Modules.Core.Core;
import fr.Alphart.BAT.Modules.Kick.Kick;
import fr.Alphart.BAT.Modules.Mute.Mute;
import fr.Alphart.BAT.Modules.Watch.Watch;

public class ModulesManager {
private final Logger log;
Expand Down Expand Up @@ -67,6 +68,7 @@ public void loadModules() {
modules.put(new Core(), IModule.OFF_STATE);
modules.put(new Ban(), IModule.OFF_STATE);
modules.put(new Mute(), IModule.OFF_STATE);
modules.put(new Watch(), IModule.OFF_STATE);
modules.put(new Kick(), IModule.OFF_STATE);
modules.put(new Comment(), IModule.OFF_STATE);
cmdsModules = new HashMap<String, IModule>();
Expand Down Expand Up @@ -165,6 +167,14 @@ public Mute getMuteModule() throws InvalidModuleException {
return null;
}

public Watch getWatchModule() throws InvalidModuleException {
final IModule module = getModule("watch");
if (module != null) {
return (Watch) module;
}
return null;
}

public Kick getKickModule() throws InvalidModuleException {
final IModule module = getModule("kick");
if (module != null) {
Expand Down
Loading