Add smite command and a few other fixes

This commit is contained in:
Telesphoreo 2022-04-07 18:23:38 -05:00
parent 6f7fcc5b51
commit fb17c4c858
13 changed files with 263 additions and 76 deletions

View File

@ -109,7 +109,7 @@ public class Plex extends JavaPlugin
system = config.getString("system");
PlexLog.log("Attempting to connect to DB: {0}", plugin.config.getString("data.central.storage"));
PlexLog.log("Attempting to connect to DB: {0}", plugin.config.getString("data.central.db"));
try
{
PlexUtils.testConnections();

View File

@ -44,7 +44,6 @@ public class DataUtils
return PlayerCache.getPlexPlayerMap().get(uuid);
}
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
return Plex.get().getMongoPlayerData().getByUUID(uuid);

View File

@ -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;
}

View File

@ -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,15 +57,10 @@ 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);
@ -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();
}
}

View File

@ -33,12 +33,6 @@ 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);
@ -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;
}
}

View File

@ -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
{

View File

@ -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();
}
}

View 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();
}
}

View File

@ -33,7 +33,8 @@ public class PlayerListener extends PlexListener
{
player.setOp(true);
PlexLog.debug("Automatically opped " + player.getName() + " since ranks are enabled.");
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
player.setOp(false);
PlexLog.debug("Automatically deopped " + player.getName() + " since ranks are disabled.");
@ -46,7 +47,8 @@ public class PlayerListener extends PlexListener
plexPlayer.setName(player.getName()); // set the name of the player
plexPlayer.setIps(Arrays.asList(player.getAddress().getAddress().getHostAddress().trim())); // set the arraylist of ips
DataUtils.insert(plexPlayer); // insert data in some wack db
} else
}
else
{
plexPlayer = DataUtils.getPlayer(player.getUniqueId());
List<String> ips = plexPlayer.getIps();

View File

@ -135,6 +135,10 @@ public class PunishmentManager extends PlexBase
public boolean isBanned(UUID uuid)
{
/*if (!DataUtils.hasPlayedBefore(uuid))
{
return false;
}*/
return DataUtils.getPlayer(uuid).getPunishments().stream().anyMatch(punishment -> punishment.getType() == PunishmentType.BAN && punishment.isActive());
}

View File

@ -2,5 +2,5 @@ package dev.plex.punishment;
public enum PunishmentType
{
MUTE, FREEZE, BAN, KICK
MUTE, FREEZE, BAN, KICK, SMITE
}

View File

@ -97,18 +97,21 @@ public class PlexUtils extends PlexBase
if (Plex.get().getStorageType() == StorageType.MARIADB)
{
PlexLog.log("Successfully enabled MySQL!");
} else if (Plex.get().getStorageType() == StorageType.SQLITE)
}
else if (Plex.get().getStorageType() == StorageType.SQLITE)
{
PlexLog.log("Successfully enabled SQLite!");
}
} catch (SQLException e)
}
catch (SQLException e)
{
if (Plex.get().getMongoConnection().getDatastore() != null)
{
PlexLog.log("Successfully enabled MongoDB!");
}
}
} else
}
else
{
if (Plex.get().getMongoConnection().getDatastore() != null)
{
@ -154,13 +157,9 @@ public class PlexUtils extends PlexBase
{
throw new NullPointerException();
}
/*for (Object object : objects)
{
f = f.replaceFirst("<v>", String.valueOf(object));
}*/
for (int i = 0; i < objects.length; i++)
{
f = f.replace("{" + i + "}", PlainTextComponentSerializer.plainText().serialize(MiniMessage.miniMessage().deserialize(String.valueOf(objects[i]))));
f = f.replace("{" + i + "}", String.valueOf(objects[i]));
}
return f;
}
@ -219,10 +218,12 @@ public class PlexUtils extends PlexBase
if (config.getString(path) == null)
{
color = def;
} else if (ChatColor.getByChar(config.getString(path)) == null)
}
else if (ChatColor.getByChar(config.getString(path)) == null)
{
color = def;
} else
}
else
{
color = ChatColor.getByChar(config.getString(path));
}
@ -274,7 +275,8 @@ public class PlexUtils extends PlexBase
{
world.setGameRule(rule, value);
PlexLog.debug("Setting game rule " + gameRule + " for world " + world.getName() + " with value " + value);
} else
}
else
{
PlexLog.error(String.format("Failed to set game rule %s for world %s with value %s!", gameRule, world.getName().toLowerCase(Locale.ROOT), value));
}
@ -326,7 +328,8 @@ public class PlexUtils extends PlexBase
in.close();
connection.disconnect();
return new JSONParser().parse(content.toString());
} catch (IOException | ParseException ex)
}
catch (IOException | ParseException ex)
{
return null;
}
@ -359,12 +362,14 @@ public class PlexUtils extends PlexBase
{
Class<?> clazz = Class.forName(info.getName());
classes.add(clazz);
} catch (ClassNotFoundException ex)
}
catch (ClassNotFoundException ex)
{
PlexLog.error("Unable to find class " + info.getName() + " in " + packageName);
}
});
} catch (IOException ex)
}
catch (IOException ex)
{
PlexLog.error("Something went wrong while fetching classes from " + packageName);
throw new RuntimeException(ex);

View File

@ -78,6 +78,7 @@ consoleMustDefinePlayer: "<red>You must define a player since you are running th
newAdminAdded: "<aqua>{0} - Adding {1} to the admin list"
# 0 - The command sender
# 1 - The player
# 2 - The rank name
adminReadded: "<aqua>{0} - Re-adding {1} to the admin list as rank: {2}"
# 0 - The command sender
# 1 - The player