mirror of
https://github.com/plexusorg/Plex.git
synced 2025-07-01 07:36:42 +00:00
Add smite command and a few other fixes
This commit is contained in:
@ -27,9 +27,9 @@ public class CommandSpyCMD extends PlexCommand
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(playerSender.getUniqueId());
|
||||
plexPlayer.setCommandSpy(!plexPlayer.isCommandSpy());
|
||||
DataUtils.update(plexPlayer);
|
||||
return Component.text(PlexUtils.messageString("toggleCommandSpy")).color(NamedTextColor.GRAY)
|
||||
send(sender, messageComponent("toggleCommandSpy")
|
||||
.append(Component.space())
|
||||
.append(Component.text(plexPlayer.isCommandSpy() ? PlexUtils.messageString("enabled") : PlexUtils.messageString("disabled")).color(NamedTextColor.GRAY));
|
||||
.append(plexPlayer.isCommandSpy() ? messageComponent("enabled") : messageComponent("disabled")));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -34,7 +37,8 @@ public class EntityWipeCMD extends PlexCommand
|
||||
List<String> entityWhitelist = new LinkedList<>(Arrays.asList(args));
|
||||
|
||||
EntityType[] entityTypes = EntityType.values();
|
||||
entityWhitelist.removeIf(name -> {
|
||||
entityWhitelist.removeIf(name ->
|
||||
{
|
||||
boolean res = Arrays.stream(entityTypes).noneMatch(entityType -> name.equalsIgnoreCase(entityType.name()));
|
||||
if (res)
|
||||
{
|
||||
@ -53,18 +57,13 @@ public class EntityWipeCMD extends PlexCommand
|
||||
{
|
||||
if (entity.getType() != EntityType.PLAYER)
|
||||
{
|
||||
String type = entity.getType().name();
|
||||
String type = entity.getName();
|
||||
|
||||
if (useBlacklist ? entityBlacklist.stream().noneMatch(entityName -> entityName.equalsIgnoreCase(type)) : entityWhitelist.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(type)))
|
||||
{
|
||||
/*
|
||||
Location loc = entity.getLocation();
|
||||
loc.setY(-500);
|
||||
entity.teleportAsync(loc);
|
||||
*/
|
||||
entity.remove();
|
||||
|
||||
entityCounts.put(type,entityCounts.getOrDefault(type, 0) + 1);
|
||||
entityCounts.put(type, entityCounts.getOrDefault(type, 0) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -88,9 +87,25 @@ public class EntityWipeCMD extends PlexCommand
|
||||
PlexUtils.broadcast(messageComponent("removedEntitiesOfTypes", sender.getName(), entityCount, list));
|
||||
}
|
||||
|
||||
entityCounts.forEach((entityName, numRemoved) -> {
|
||||
/*entityCounts.forEach((entityName, numRemoved) -> {
|
||||
sender.sendMessage(messageComponent("removedEntitiesOfType", sender.getName(), numRemoved, entityName));
|
||||
});
|
||||
});*/
|
||||
return null;
|
||||
}
|
||||
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
List<String> entities = new ArrayList<>();
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
for (Entity entity : world.getEntities())
|
||||
{
|
||||
if (entity.getType() != EntityType.PLAYER)
|
||||
{
|
||||
entities.add(entity.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return entities.stream().toList();
|
||||
}
|
||||
}
|
@ -33,15 +33,9 @@ public class MobPurgeCMD extends PlexCommand
|
||||
if (entity instanceof Mob)
|
||||
{
|
||||
String type = entity.getType().name();
|
||||
|
||||
/*
|
||||
Location loc = entity.getLocation();
|
||||
loc.setY(-500);
|
||||
entity.teleportAsync(loc);
|
||||
*/
|
||||
entity.remove();
|
||||
|
||||
entityCounts.put(type,entityCounts.getOrDefault(type, 0) + 1);
|
||||
entityCounts.put(type, entityCounts.getOrDefault(type, 0) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -50,9 +44,9 @@ public class MobPurgeCMD extends PlexCommand
|
||||
|
||||
PlexUtils.broadcast(messageComponent("removedMobs", sender.getName(), entityCount));
|
||||
|
||||
entityCounts.forEach((entityName, numRemoved) -> {
|
||||
/*entityCounts.forEach((entityName, numRemoved) -> {
|
||||
sender.sendMessage(messageComponent("removedEntitiesOfType", sender.getName(), numRemoved, entityName));
|
||||
});
|
||||
});*/
|
||||
return null;
|
||||
}
|
||||
}
|
@ -56,32 +56,17 @@ public class NotesCMD extends PlexCommand
|
||||
send(sender, mmString("<red>This player has no notes!"));
|
||||
return;
|
||||
}
|
||||
AtomicReference<Component> noteList = new AtomicReference<>(Component.text("Player notes for: " + plexPlayer.getName()).color(NamedTextColor.GREEN));
|
||||
for (Note note : notes)
|
||||
{
|
||||
Component noteLine = Component.text(note.getId() + " - Written by: " + DataUtils.getPlayer(note.getWrittenBy()).getName() + " on " + DATE_FORMAT.format(note.getTimestamp())).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false);
|
||||
noteLine = noteLine.append(Component.text(note.getNote())).color(NamedTextColor.GOLD).decoration(TextDecoration.ITALIC, true);
|
||||
noteList.set(noteList.get().append(Component.newline()));
|
||||
noteList.set(noteList.get().append(noteLine));
|
||||
}
|
||||
send(sender, noteList.get());
|
||||
readNotes(sender, plexPlayer, notes);
|
||||
});
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
List<Note> notes = plexPlayer.getNotes();
|
||||
if (notes.size() == 0)
|
||||
{
|
||||
return mmString("<red>This player has no notes!");
|
||||
}
|
||||
AtomicReference<Component> noteList = new AtomicReference<>(Component.text("Player notes for: " + plexPlayer.getName()).color(NamedTextColor.GREEN));
|
||||
for (Note note : notes)
|
||||
{
|
||||
Component noteLine = Component.text(note.getId() + " - Written by: " + DataUtils.getPlayer(note.getWrittenBy()).getName() + " on " + DATE_FORMAT.format(note.getTimestamp())).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false);
|
||||
noteLine = noteLine.append(Component.text(note.getNote())).color(NamedTextColor.GOLD).decoration(TextDecoration.ITALIC, true);
|
||||
noteList.set(noteList.get().append(Component.newline()));
|
||||
noteList.set(noteList.get().append(noteLine));
|
||||
}
|
||||
send(sender, noteList.get());
|
||||
readNotes(sender, plexPlayer, notes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -99,7 +84,8 @@ public class NotesCMD extends PlexCommand
|
||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
||||
{
|
||||
plugin.getSqlNotes().addNote(note);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
DataUtils.update(plexPlayer);
|
||||
}
|
||||
@ -112,7 +98,8 @@ public class NotesCMD extends PlexCommand
|
||||
try
|
||||
{
|
||||
id = Integer.parseInt(args[2]);
|
||||
} catch (NumberFormatException ignored)
|
||||
}
|
||||
catch (NumberFormatException ignored)
|
||||
{
|
||||
return Component.text("Invalid number: " + args[2]).color(NamedTextColor.RED);
|
||||
}
|
||||
@ -126,14 +113,16 @@ public class NotesCMD extends PlexCommand
|
||||
{
|
||||
plugin.getSqlNotes().deleteNote(id, plexPlayer.getUuid()).whenComplete((notes1, ex1) ->
|
||||
send(sender, Component.text("Removed note with ID: " + id).color(NamedTextColor.GREEN)));
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
send(sender, mmString("<red>A note with this ID could not be found"));
|
||||
}
|
||||
}
|
||||
plexPlayer.getNotes().removeIf(note -> note.getId() == id);
|
||||
});
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
if (plexPlayer.getNotes().removeIf(note -> note.getId() == id))
|
||||
{
|
||||
@ -155,7 +144,9 @@ public class NotesCMD extends PlexCommand
|
||||
plexPlayer.getNotes().clear();
|
||||
send(sender, Component.text("Cleared " + notes.size() + " note(s).").color(NamedTextColor.GREEN));
|
||||
});
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
int count = plexPlayer.getNotes().size();
|
||||
plexPlayer.getNotes().clear();
|
||||
DataUtils.update(plexPlayer);
|
||||
@ -170,6 +161,19 @@ public class NotesCMD extends PlexCommand
|
||||
}
|
||||
}
|
||||
|
||||
private void readNotes(@NotNull CommandSender sender, PlexPlayer plexPlayer, List<Note> notes)
|
||||
{
|
||||
AtomicReference<Component> noteList = new AtomicReference<>(Component.text("Player notes for: " + plexPlayer.getName()).color(NamedTextColor.GREEN));
|
||||
for (Note note : notes)
|
||||
{
|
||||
Component noteLine = Component.text(note.getId() + " - Written by: " + DataUtils.getPlayer(note.getWrittenBy()).getName() + " on " + DATE_FORMAT.format(note.getTimestamp())).color(NamedTextColor.YELLOW).decoration(TextDecoration.ITALIC, false);
|
||||
noteLine = noteLine.append(Component.text(note.getNote())).color(NamedTextColor.GOLD).decoration(TextDecoration.ITALIC, true);
|
||||
noteList.set(noteList.get().append(Component.newline()));
|
||||
noteList.set(noteList.get().append(noteLine));
|
||||
}
|
||||
send(sender, noteList.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
|
@ -7,6 +7,9 @@ import dev.plex.command.annotation.System;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -41,4 +44,14 @@ public class RankCMD extends PlexCommand
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
150
src/main/java/dev/plex/command/impl/SmiteCMD.java
Normal file
150
src/main/java/dev/plex/command/impl/SmiteCMD.java
Normal file
@ -0,0 +1,150 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.smite", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "smite", usage = "/<command> <player> [reason] [-ci | -q]", description = "Someone being a little bitch? Smite them down...")
|
||||
public class SmiteCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
return usage();
|
||||
}
|
||||
|
||||
String reason = null;
|
||||
boolean silent = false;
|
||||
boolean clearinv = false;
|
||||
|
||||
if (args.length >= 2)
|
||||
{
|
||||
if (args[args.length - 1].equalsIgnoreCase("-q"))
|
||||
{
|
||||
if (args[args.length - 1].equalsIgnoreCase("-q"))
|
||||
{
|
||||
silent = true;
|
||||
}
|
||||
|
||||
if (args.length >= 3)
|
||||
{
|
||||
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " ");
|
||||
}
|
||||
}
|
||||
else if (args[args.length - 1].equalsIgnoreCase("-ci"))
|
||||
{
|
||||
if (args[args.length - 1].equalsIgnoreCase("-ci"))
|
||||
{
|
||||
clearinv = true;
|
||||
}
|
||||
|
||||
if (args.length >= 3)
|
||||
{
|
||||
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " ");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
|
||||
}
|
||||
}
|
||||
|
||||
final Player player = getNonNullPlayer(args[0]);
|
||||
final PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||
|
||||
Title title = Title.title(Component.text("You've been smitten.").color(NamedTextColor.RED), Component.text("Be sure to follow the rules!").color(NamedTextColor.YELLOW));
|
||||
player.showTitle(title);
|
||||
|
||||
if (!silent)
|
||||
{
|
||||
PlexUtils.broadcast(mmString("<red>" + player.getName() + " has been a naughty, naughty boy."));
|
||||
if (reason != null)
|
||||
{
|
||||
PlexUtils.broadcast(mmString(" <red>Reason: " + "<yellow>" + reason));
|
||||
}
|
||||
PlexUtils.broadcast(mmString(" <red>Smitten by: " + "<yellow>" + sender.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
send(sender, "Smitten " + player.getName() + " quietly.");
|
||||
}
|
||||
|
||||
// Deop
|
||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
||||
{
|
||||
player.setOp(false);
|
||||
}
|
||||
|
||||
// Set gamemode to survival
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
|
||||
// Clear inventory
|
||||
if (clearinv)
|
||||
{
|
||||
player.getInventory().clear();
|
||||
}
|
||||
|
||||
// Strike with lightning effect
|
||||
final Location targetPos = player.getLocation();
|
||||
final World world = player.getWorld();
|
||||
for (int x = -1; x <= 1; x++)
|
||||
{
|
||||
for (int z = -1; z <= 1; z++)
|
||||
{
|
||||
final Location strike_pos = new Location(world, targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z);
|
||||
world.strikeLightning(strike_pos);
|
||||
}
|
||||
}
|
||||
|
||||
// Kill
|
||||
player.setHealth(0.0);
|
||||
|
||||
Punishment punishment = new Punishment(plexPlayer.getUuid(), getUUID(sender));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setEndDate(LocalDateTime.now());
|
||||
punishment.setType(PunishmentType.SMITE);
|
||||
punishment.setPunishedUsername(player.getName());
|
||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||
|
||||
if (reason != null)
|
||||
{
|
||||
punishment.setReason(reason);
|
||||
send(player, mmString("<red>You've been smitten. Reason: <yellow>" + reason));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (checkTab(sender, Rank.ADMIN, "plex.smite") && args.length == 1)
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user