Skip to content

Commit

Permalink
Merge pull request #623 from tWizT3ddreaMr/FullHistory
Browse files Browse the repository at this point in the history
FullHistory
  • Loading branch information
DevLeoko authored Jul 5, 2023
2 parents ea1a92b + c63e3ce commit df18f2f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,24 @@ public void discard(String name) {
* @return the punishments
*/
public List<Punishment> getPunishments(String target, PunishmentType put, boolean current) {
return getPunishmentsOfTypes(target, put == null ? Arrays.asList(PunishmentType.values()) : Arrays.asList(put), current);
}

/**
* Get all punishments which belong to the given uuid or ip.
*
* @param target the uuid or ip to search for
* @param putList a List of the basic punishment type to search for ({@link PunishmentType#BAN} would also include Tempbans).
* @param current if only active punishments should be included.
* @return the punishments
*/
public List<Punishment> getPunishmentsOfTypes(String target, List<PunishmentType> putList, boolean current) {
List<Punishment> ptList = new ArrayList<>();

if (isCached(target)) {
for (Iterator<Punishment> iterator = (current ? punishments : history).iterator(); iterator.hasNext(); ) {
Punishment pt = iterator.next();
if ((put == null || put == pt.getType().getBasic()) && pt.getUuid().equals(target)) {
if (putList.contains(pt.getType().getBasic()) && pt.getUuid().equals(target)) {
if (!current || !pt.isExpired()) {
ptList.add(pt);
} else {
Expand All @@ -144,7 +156,7 @@ public List<Punishment> getPunishments(String target, PunishmentType put, boolea
try (ResultSet rs = DatabaseManager.get().executeResultStatement(current ? SQLQuery.SELECT_USER_PUNISHMENTS : SQLQuery.SELECT_USER_PUNISHMENTS_HISTORY, target)) {
while (rs.next()) {
Punishment punishment = getPunishmentFromResultSet(rs);
if ((put == null || put == punishment.getType().getBasic()) && (!current || !punishment.isExpired())) {
if (putList.contains(punishment.getType().getBasic()) && (!current || !punishment.isExpired())) {
ptList.add(punishment);
}
}
Expand Down
17 changes: 17 additions & 0 deletions core/src/main/java/me/leoko/advancedban/manager/UpdateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ public void setup() {

if (mi.isUnitTesting()) return;

if(!mi.contains(mi.getConfig(), "FullHistory")){
try {
FileUtils.writeLines(new File(mi.getDataFolder(), "config.yml"), "UTF8", Arrays.asList(
"# These are the Punishment types that show up when running /history on a player",
"FullHistory:",
" - \"BAN\"",
" - \"IP_BAN\"",
" - \"MUTE\"",
" - \"WARNING\"",
" - \"KICK\"",
" - \"NOTE\""
), true);
} catch (IOException e) {
e.printStackTrace();
}
}

if (!mi.contains(mi.getMessages(), "UnNote.Usage")) {
try {
addMessage("Check:", " Note: \"&cNotes &8» &7%COUNT%\"", 1);
Expand Down
12 changes: 9 additions & 3 deletions core/src/main/java/me/leoko/advancedban/utils/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,15 @@ else if(args.length == 2)
else
return list();
}),
new ListProcessor(
target -> PunishmentManager.get().getPunishments(target, null, false),
"History", true, true),
input -> {
MethodInterface mi = Universal.get().getMethods();
List<PunishmentType> putList = new ArrayList<>();
mi.getStringList(mi.getConfig(),"FullHistory").forEach((typeString -> putList.add(PunishmentType.valueOf(typeString))));

new ListProcessor(
target -> PunishmentManager.get().getPunishmentsOfTypes(target, putList, false),
"History", true, true).accept(input);
},
"History.Usage",
"history"),

Expand Down
9 changes: 9 additions & 0 deletions core/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,12 @@ Friendly Register Commands: false

# If you wish to only disable tab-completion for layouts, check out the Layouts.yml file under "Use Message Layouts" and "Use Time Layouts"
Use Tab Completion: true

# These are the Punishment types that show up when running /history on a player
FullHistory:
- "BAN"
- "IP_BAN"
- "MUTE"
- "WARNING"
- "KICK"
- "NOTE"

0 comments on commit df18f2f

Please sign in to comment.