mirror of
https://github.com/CivMC/Civ.git
synced 2026-07-18 00:20:44 +00:00
@@ -8,7 +8,9 @@ import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import vg.civcraft.mc.namelayer.GroupManager.PlayerType;
|
||||
import vg.civcraft.mc.namelayer.NameAPI;
|
||||
@@ -28,37 +30,40 @@ public class DeleteGroup extends BaseCommandMiddle {
|
||||
Player p = (Player) sender;
|
||||
UUID uuid = NameAPI.getUUID(p.getName());
|
||||
String x = groupName;
|
||||
String confirm = "CONFIRM";
|
||||
if(x.equals(confirm))
|
||||
String confirm = "CONFIRM DELETION";
|
||||
if(x.toLowerCase().contains(confirm.toLowerCase()))
|
||||
{
|
||||
//check if they met the 15 second window
|
||||
if(confirmDeleteGroup.containsKey(uuid)){
|
||||
//user is in the hashmap
|
||||
String[] entry = confirmDeleteGroup.get(uuid);
|
||||
Group gD = gm.getGroup(entry[0]);
|
||||
//player could have lost delete permission in the mean time
|
||||
if (!NameAPI.getGroupManager().hasAccess(gD, uuid, PermissionType.getPermission("DELETE"))){
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission to run that command.");
|
||||
return;
|
||||
}
|
||||
Date now = new Date(System.currentTimeMillis() - 15000);
|
||||
//if it has been less than 15 seconds
|
||||
if(now.getTime() < Long.parseLong(entry[1]))
|
||||
{
|
||||
//good to go delete the group
|
||||
if(gm.deleteGroup(gD.getName()))
|
||||
p.sendMessage(ChatColor.GREEN + "Group was successfully deleted.");
|
||||
else
|
||||
p.sendMessage(ChatColor.GREEN + "Group is now disciplined."
|
||||
+ " Check back later to see if group is deleted.");
|
||||
|
||||
confirmDeleteGroup.remove(uuid);
|
||||
return;
|
||||
}
|
||||
else{
|
||||
p.sendMessage(ChatColor.RED + "You did not do /nldg CONFIRM fast enough, you will need to start over");
|
||||
confirmDeleteGroup.remove(uuid);
|
||||
return;
|
||||
|
||||
if(x.equalsIgnoreCase("%s %s".formatted(confirm, gD.getName()))) {
|
||||
|
||||
//player could have lost delete permission in the mean time
|
||||
if (!NameAPI.getGroupManager().hasAccess(gD, uuid, PermissionType.getPermission("DELETE"))){
|
||||
p.sendMessage(Component.text("You do not have permission to run that command.").color(NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
Date now = new Date(System.currentTimeMillis() - 15000);
|
||||
//if it has been less than 15 seconds
|
||||
if(now.getTime() < Long.parseLong(entry[1]))
|
||||
{
|
||||
//good to go delete the group
|
||||
if(gm.deleteGroup(gD.getName()))
|
||||
p.sendMessage(Component.text("Group was successfully deleted.").color(NamedTextColor.GREEN));
|
||||
else
|
||||
p.sendMessage(Component.text("Group is now disciplined. Check back later to see if group is deleted.").color(NamedTextColor.GREEN));
|
||||
|
||||
confirmDeleteGroup.remove(uuid);
|
||||
return;
|
||||
}
|
||||
else{
|
||||
p.sendMessage(Component.text("You did not do '/nldg %s %s' fast enough, you will need to start over".formatted(confirm, gD.getName())).color(NamedTextColor.RED));
|
||||
confirmDeleteGroup.remove(uuid);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,23 +74,23 @@ public class DeleteGroup extends BaseCommandMiddle {
|
||||
return;
|
||||
}
|
||||
if (!NameAPI.getGroupManager().hasAccess(g, uuid, PermissionType.getPermission("DELETE"))){
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission to run that command.");
|
||||
p.sendMessage(Component.text("You do not have permission to run that command.").color(NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
PlayerType pType = g.getPlayerType(uuid);
|
||||
if (pType == null && !p.hasPermission("namelayer.admin")){
|
||||
p.sendMessage(ChatColor.RED + "You are not on that group.");
|
||||
p.sendMessage(Component.text("You are not on that group.").color(NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (g.isDisciplined() && !p.hasPermission("namelayer.admin")){
|
||||
p.sendMessage(ChatColor.RED + "Group is disiplined.");
|
||||
p.sendMessage(Component.text("Group is disiplined.").color(NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
//set that user can confirm group in 15 seconds
|
||||
Date date = new Date();
|
||||
Long dateString = date.getTime();
|
||||
String[] groupDate = new String[] {g.getName(), dateString.toString()};
|
||||
p.sendMessage(ChatColor.GREEN + "To confirm deletion of group: " + g.getName() + "\nuse /nldg CONFIRM within 15 seconds");
|
||||
p.sendMessage(Component.text("To confirm the IRREVERSIBLE deletion of the group '%s' along with ALL reinforcements, bastions and snitches on it:\nType '/nldg %s %s' within 15 seconds.".formatted(g.getName(), confirm, g.getName())).color(NamedTextColor.RED));
|
||||
confirmDeleteGroup.put(uuid, groupDate);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user