Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public void onDisable() {
@Override
public void postModulesEnable() {
ticketManager.postStartup();
discordStaffLog.postStartup();
}

public AdminConfig getAdminConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public ProfanityFilter(AdminModule adminModule) {
highlyOffensiveWords.add(Pattern.compile(expandPattern(offensiveWord), Pattern.CASE_INSENSITIVE));
}
Bukkit.getPluginManager().registerEvents(this, adminModule.getPlugin());
adminModule.getTicketManager().registerTicketType("profanity", (ticket, subject) -> Component
.text("Player ")
.append(subject.displayName())
.append(Component.text(" - Highly offensive language"))
);
}

public Component filter(Component component) {
Expand All @@ -63,6 +68,8 @@ private void onPlayerChat(AsyncChatEvent event) {
);
adminModule.getTicketManager().createSystemTicket(
event.getPlayer().getLocation(),
event.getPlayer().getUniqueId(),
"profanity",
String.format("Player %s was automatically muted for highly offensive language. Message was \"%s\".", event.getPlayer().getName(), plainTextMessage)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.context.CommandContext;
import com.froobworld.nabsuite.command.NabCommand;
import com.froobworld.nabsuite.command.argument.predicate.ArgumentPredicate;
import com.froobworld.nabsuite.modules.admin.AdminModule;
import com.froobworld.nabsuite.modules.admin.command.argument.TicketArgument;
import com.froobworld.nabsuite.modules.admin.ticket.Ticket;
Expand All @@ -30,6 +31,7 @@ public void execute(CommandContext<CommandSender> context) {
Ticket ticket = context.get("ticket");
String message = context.get("message");
ticket.addNote(ConsoleUtils.getSenderUUID(context.getSender()), message);
adminModule.getDiscordStaffLog().updateTicketNotification(ticket);
context.getSender().sendMessage(Component.text("Note added.", NamedTextColor.YELLOW));
}

Expand All @@ -39,7 +41,12 @@ public Command.Builder<CommandSender> populateBuilder(Command.Builder<CommandSen
.argument(new TicketArgument<>(
true,
"ticket",
adminModule.getTicketManager()
adminModule.getTicketManager(),
new ArgumentPredicate<>(
true,
(context, ticket) -> context.getSender().hasPermission(ticket.getPermission()),
"You don't have permission for that ticket"
)
))
.argument(StringArgument.<CommandSender>newBuilder("message").greedy());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public Command.Builder<CommandSender> populateBuilder(Command.Builder<CommandSen
true,
"ticket",
adminModule.getTicketManager(),
new ArgumentPredicate<>(
true,
(context, ticket) -> context.getSender().hasPermission(ticket.getPermission()),
"You don't have permission for that ticket"
),
new ArgumentPredicate<>(
true,
(context, ticket) -> ticket.isOpen(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public TicketCommand(AdminModule adminModule) {
new TicketReadCommand(adminModule),
new TicketTeleportCommand(adminModule),
new TicketAddNoteCommand(adminModule),
new TicketCloseCommand(adminModule)
new TicketCloseCommand(adminModule),
new TicketDelegateCommand(adminModule),
new TicketEscalateCommand(adminModule)
));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.froobworld.nabsuite.modules.admin.command;

import cloud.commandframework.Command;
import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.context.CommandContext;
import com.froobworld.nabsuite.command.NabCommand;
import com.froobworld.nabsuite.command.argument.predicate.ArgumentPredicate;
import com.froobworld.nabsuite.modules.admin.AdminModule;
import com.froobworld.nabsuite.modules.admin.command.argument.TicketArgument;
import com.froobworld.nabsuite.modules.admin.ticket.Ticket;
import com.froobworld.nabsuite.util.ConsoleUtils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.CommandSender;

import java.util.Optional;

public class TicketDelegateCommand extends NabCommand {
private final AdminModule adminModule;

public TicketDelegateCommand(AdminModule adminModule) {
super(
"delegate",
"Delegate a ticket with an optional note.",
"nabsuite.command.ticket.delegate",
CommandSender.class
);
this.adminModule = adminModule;
}

@Override
public void execute(CommandContext<CommandSender> context) {
Ticket ticket = context.get("ticket");
Optional<String> note = context.getOptional("note");

String currentLevel = ticket.getLevel();
int currentIndex = adminModule.getAdminConfig().ticketLevels.get().indexOf(currentLevel);
if (currentIndex > 0) {
ticket.setLevel(adminModule.getAdminConfig().ticketLevels.get().get(currentIndex - 1));
ticket.addNote(ConsoleUtils.getSenderUUID(context.getSender()), "(Delegated ticket" + note.map(s -> " with note: '" + s + "'").orElse("") + ")");
context.getSender().sendMessage(Component.text("Ticket delegated.", NamedTextColor.YELLOW));
adminModule.getDiscordStaffLog().updateTicketNotification(ticket);
adminModule.getStaffTaskManager().notifyNewTask(
ticket.getPermission(),
// Only notify players that haven't seen the ticket before
player -> !player.hasPermission("nabsuite.ticket." + currentLevel)
);
} else {
context.getSender().sendMessage(Component.text("Unable to determine level to delegate to.", NamedTextColor.RED));
}
}

@Override
public Command.Builder<CommandSender> populateBuilder(Command.Builder<CommandSender> builder) {
return builder
.argument(new TicketArgument<>(
true,
"ticket",
adminModule.getTicketManager(),
new ArgumentPredicate<>(
true,
(context, ticket) -> context.getSender().hasPermission(ticket.getPermission()),
"You don't have permission for that ticket"
),
new ArgumentPredicate<>(
true,
(context, ticket) -> ticket.canDelegate(),
"Ticket cannot be delegated"
),
new ArgumentPredicate<>(
true,
(context, ticket) -> ticket.isOpen(),
"That ticket is closed"
)
))
.argument(StringArgument.<CommandSender>newBuilder("note").greedy().asOptional());
}

@Override
public String getUsage() {
return "/ticket delegate <id> [note]";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.froobworld.nabsuite.modules.admin.command;

import cloud.commandframework.Command;
import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.context.CommandContext;
import com.froobworld.nabsuite.command.NabCommand;
import com.froobworld.nabsuite.command.argument.predicate.ArgumentPredicate;
import com.froobworld.nabsuite.modules.admin.AdminModule;
import com.froobworld.nabsuite.modules.admin.command.argument.TicketArgument;
import com.froobworld.nabsuite.modules.admin.ticket.Ticket;
import com.froobworld.nabsuite.util.ConsoleUtils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.command.CommandSender;

import java.util.Optional;

public class TicketEscalateCommand extends NabCommand {
private final AdminModule adminModule;

public TicketEscalateCommand(AdminModule adminModule) {
super(
"escalate",
"Escalate a ticket with an optional note.",
"nabsuite.command.ticket.escalate",
CommandSender.class
);
this.adminModule = adminModule;
}

@Override
public void execute(CommandContext<CommandSender> context) {
Ticket ticket = context.get("ticket");
Optional<String> note = context.getOptional("note");

String currentLevel = ticket.getLevel();
int currentIndex = adminModule.getAdminConfig().ticketLevels.get().indexOf(currentLevel);
if (currentIndex >= 0 && currentIndex < adminModule.getAdminConfig().ticketLevels.get().size() - 1) {
ticket.setLevel(adminModule.getAdminConfig().ticketLevels.get().get(currentIndex + 1));
ticket.addNote(ConsoleUtils.getSenderUUID(context.getSender()), "(Escalated ticket" + note.map(s -> " with note: '" + s + "'").orElse("") + ")");
context.getSender().sendMessage(Component.text("Ticket escalated.", NamedTextColor.YELLOW));
adminModule.getDiscordStaffLog().updateTicketNotification(ticket);
adminModule.getStaffTaskManager().notifyNewTask(ticket.getPermission());
} else {
context.getSender().sendMessage(Component.text("Unable to determine level to escalate to.", NamedTextColor.RED));
}
}

@Override
public Command.Builder<CommandSender> populateBuilder(Command.Builder<CommandSender> builder) {
return builder
.argument(new TicketArgument<>(
true,
"ticket",
adminModule.getTicketManager(),
new ArgumentPredicate<>(
true,
(context, ticket) -> context.getSender().hasPermission(ticket.getPermission()),
"You don't have permission for that ticket"
),
new ArgumentPredicate<>(
true,
(context, ticket) -> ticket.canEscalate(),
"Ticket cannot be escalated"
),
new ArgumentPredicate<>(
true,
(context, ticket) -> ticket.isOpen(),
"That ticket is closed"
)
))
.argument(StringArgument.<CommandSender>newBuilder("note").greedy().asOptional());
}

@Override
public String getUsage() {
return "/ticket escalate <id> [note]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cloud.commandframework.Command;
import cloud.commandframework.context.CommandContext;
import com.froobworld.nabsuite.command.NabCommand;
import com.froobworld.nabsuite.command.argument.predicate.ArgumentPredicate;
import com.froobworld.nabsuite.modules.admin.AdminModule;
import com.froobworld.nabsuite.modules.admin.command.argument.TicketArgument;
import com.froobworld.nabsuite.modules.admin.ticket.Ticket;
Expand Down Expand Up @@ -73,7 +74,12 @@ public Command.Builder<CommandSender> populateBuilder(Command.Builder<CommandSen
.argument(new TicketArgument<>(
true,
"ticket",
adminModule.getTicketManager()
adminModule.getTicketManager(),
new ArgumentPredicate<>(
true,
(context, ticket) -> context.getSender().hasPermission(ticket.getPermission()),
"You don't have permission for that ticket"
)
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@
import com.froobworld.nabsuite.modules.admin.command.argument.TicketArgument;
import com.froobworld.nabsuite.modules.admin.ticket.Ticket;
import com.froobworld.nabsuite.modules.basics.BasicsModule;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.time.Duration;
import java.util.UUID;

public class TicketTeleportCommand extends NabCommand {
private final AdminModule adminModule;
private final Cache<Integer, UUID> recentTeleports = CacheBuilder.newBuilder().expireAfterAccess(Duration.ofMinutes(5)).build();

public TicketTeleportCommand(AdminModule adminModule) {
super(
Expand All @@ -30,8 +37,19 @@ public TicketTeleportCommand(AdminModule adminModule) {
public void execute(CommandContext<CommandSender> context) {
Player player = (Player) context.getSender();
Ticket ticket = context.get("ticket");
UUID recentTeleport = recentTeleports.getIfPresent(ticket.getId());
boolean coordinateWarning = ticket.isOpen() && recentTeleport != null && recentTeleport != player.getUniqueId();
if (recentTeleport == null) {
recentTeleports.put(ticket.getId(), player.getUniqueId());
}

adminModule.getPlugin().getModule(BasicsModule.class).getPlayerTeleporter().teleportAsync(player, ticket.getLocation()).thenRun(() -> {
player.sendMessage(Component.text("Whoosh!", NamedTextColor.YELLOW));

if (coordinateWarning && Bukkit.getPlayer(recentTeleport) instanceof Player other) {
player.sendMessage(other.displayName()
.append(Component.text(" recently teleported to this ticket, please coordinate review.").color(NamedTextColor.YELLOW)));
}
});
}

Expand All @@ -42,6 +60,11 @@ public Command.Builder<CommandSender> populateBuilder(Command.Builder<CommandSen
true,
"ticket",
adminModule.getTicketManager(),
new ArgumentPredicate<>(
true,
(context, ticket) -> context.getSender().hasPermission(ticket.getPermission()),
"You don't have permission for that ticket"
),
new ArgumentPredicate<>(
true,
(sender, ticket) -> ticket.getLocation() != null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.List;

public class AdminConfig extends NabConfiguration {
private static final int CONFIG_VERSION = 4;
private static final int CONFIG_VERSION = 5;

public AdminConfig(AdminModule adminModule) {
super(
Expand Down Expand Up @@ -76,5 +76,19 @@ public static class DeputySettings extends ConfigSection {
public final ConfigEntry<Long> expiryNotificationTime = new ConfigEntry<>(duration -> DurationParser.fromString(duration.toString()));
}

@Entry(key = "ticket-levels")
public final ConfigEntry<List<String>> ticketLevels = ConfigEntries.stringListEntry();

@SectionMap(key = "ticket-types", defaultKey = "default")
public ConfigSectionMap<String, TicketType> ticketTypes = new ConfigSectionMap<>(s -> s, TicketType.class, true);

public static class TicketType extends ConfigSection {

@Entry(key = "level")
public final ConfigEntry<String> level = new ConfigEntry<>();

@Entry(key = "allow-delegate")
public final ConfigEntry<Boolean> allowDelegate = new ConfigEntry<>();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.froobworld.nabsuite.modules.admin.AdminModule;
import com.froobworld.nabsuite.modules.basics.BasicsModule;
import com.froobworld.nabsuite.util.DurationDisplayer;
import net.kyori.adventure.text.Component;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.cacheddata.Result;
import net.luckperms.api.event.node.NodeMutateEvent;
Expand Down Expand Up @@ -46,6 +47,13 @@ public DeputyManager(AdminModule adminModule) {
updateAllDeputies();
Bukkit.getScheduler().scheduleSyncRepeatingTask(adminModule.getPlugin(), this::runExpiryCheckTask, 200, 600);
}
levels.forEach(level -> adminModule.getTicketManager().registerTicketType(
"deputy-expiry-"+level.getName(),
(ticket,subject) -> Component
.text("Player ")
.append(subject.displayName())
.append(Component.text(" - "+level.getName()+" deputy expiry"))
));
}

private void sendDeputyAddNotification(CommandSender sender, DeputyPlayer previous, DeputyPlayer current, long duration) {
Expand Down Expand Up @@ -76,6 +84,8 @@ private void sendDeputyExpiryWarning(DeputyPlayer deputyPlayer) {
long expiryTime = Math.ceilDiv(deputyPlayer.getExpiry() - System.currentTimeMillis(), 3600000) * 3600000;
String duration = DurationDisplayer.asDurationString(expiryTime);
adminModule.getTicketManager().createSystemTicket(
deputyPlayer.getUuid(),
"deputy-expiry-"+deputyPlayer.getDeputyLevel().getName(),
"Appointment of " + deputyPlayer.getPlayerIdentity().getLastName() + " as " + deputyPlayer.getDeputyLevel().getName() + " deputy expires in less than " + duration + ". Please determine if it should be renewed, if another deputy should be appointed, or if no action is needed."
);
basicsModule.getMailCentre().sendSystemMail(deputyPlayer.getUuid(), "Your appointment as " + deputyPlayer.getDeputyLevel().getName() + " deputy will expire in less than " + duration + ".");
Expand Down
Loading