mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Migrate (what I could find) legacy component system uses to kyori component system
Create List command Remove fionn command Remove test command Add Mojang Utils Auto add Plex Players back to cache on start if any are online
This commit is contained in:
parent
29b547fc8b
commit
8202021f07
12
build.gradle
12
build.gradle
@ -2,6 +2,7 @@ plugins {
|
||||
id 'java'
|
||||
id 'maven-publish'
|
||||
id 'net.minecrell.plugin-yml.bukkit' version '0.5.1'
|
||||
id "com.github.johnrengelman.shadow" version "7.1.2"
|
||||
}
|
||||
|
||||
repositories {
|
||||
@ -27,6 +28,7 @@ dependencies {
|
||||
library 'dev.morphia.morphia:morphia-core:2.2.3'
|
||||
library 'redis.clients:jedis:4.0.1'
|
||||
library 'org.mariadb.jdbc:mariadb-java-client:2.7.4'
|
||||
implementation 'org.apache.httpcomponents:httpclient:4.5.13'
|
||||
compileOnly 'io.papermc.paper:paper-api:1.18.1-R0.1-SNAPSHOT'
|
||||
}
|
||||
|
||||
@ -34,6 +36,10 @@ group = 'dev.plex'
|
||||
version = '1.0'
|
||||
description = 'Plex'
|
||||
|
||||
shadowJar {
|
||||
archiveClassifier.set("")
|
||||
}
|
||||
|
||||
bukkit {
|
||||
name = "Plex"
|
||||
version = rootProject.version
|
||||
@ -59,3 +65,9 @@ publishing {
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
|
||||
tasks {
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,17 @@
|
||||
package dev.plex;
|
||||
|
||||
import dev.plex.admin.Admin;
|
||||
import dev.plex.admin.AdminList;
|
||||
import dev.plex.banning.BanManager;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.MongoPlayerData;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.cache.SQLPlayerData;
|
||||
import dev.plex.config.Config;
|
||||
import dev.plex.handlers.CommandHandler;
|
||||
import dev.plex.handlers.ListenerHandler;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.player.PunishedPlayer;
|
||||
import dev.plex.punishment.PunishmentManager;
|
||||
import dev.plex.rank.RankManager;
|
||||
import dev.plex.services.ServiceManager;
|
||||
@ -19,8 +24,13 @@ import dev.plex.util.PlexUtils;
|
||||
import dev.plex.world.CustomWorld;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Plex extends JavaPlugin
|
||||
@ -80,8 +90,7 @@ public class Plex extends JavaPlugin
|
||||
{
|
||||
PlexUtils.testConnections();
|
||||
PlexLog.log("Connected to " + storageType.name().toUpperCase());
|
||||
}
|
||||
catch (Exception e)
|
||||
} catch (Exception e)
|
||||
{
|
||||
PlexLog.error("Failed to connect to " + storageType.name().toUpperCase());
|
||||
e.printStackTrace();
|
||||
@ -90,8 +99,7 @@ public class Plex extends JavaPlugin
|
||||
if (storageType == StorageType.MONGODB)
|
||||
{
|
||||
mongoPlayerData = new MongoPlayerData();
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
sqlPlayerData = new SQLPlayerData();
|
||||
}
|
||||
@ -117,6 +125,8 @@ public class Plex extends JavaPlugin
|
||||
adminList = new AdminList();
|
||||
|
||||
generateWorlds();
|
||||
|
||||
reloadPlayers();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -138,4 +148,21 @@ public class Plex extends JavaPlugin
|
||||
}
|
||||
PlexLog.log("Finished with world generation!");
|
||||
}
|
||||
|
||||
private void reloadPlayers()
|
||||
{
|
||||
Bukkit.getOnlinePlayers().forEach(player ->
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||
PlayerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache
|
||||
PlayerCache.getPunishedPlayerMap().put(player.getUniqueId(), new PunishedPlayer(player.getUniqueId()));
|
||||
if (plugin.getRankManager().isAdmin(plexPlayer))
|
||||
{
|
||||
Admin admin = new Admin(UUID.fromString(plexPlayer.getUuid()));
|
||||
admin.setRank(plexPlayer.getRankFromString());
|
||||
|
||||
plugin.getAdminList().addToCache(admin);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package dev.plex.banning;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.morphia.query.MorphiaCursor;
|
||||
import dev.morphia.query.Query;
|
||||
import dev.morphia.query.experimental.filters.Filters;
|
||||
import dev.morphia.query.experimental.updates.UpdateOperators;
|
||||
import dev.morphia.query.internal.MorphiaCursor;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.storage.StorageType;
|
||||
|
||||
@ -119,10 +119,8 @@ public class BanManager
|
||||
List<Ban> bans = Lists.newArrayList();
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
MorphiaCursor<Ban> cursor = Plex.get().getMongoConnection().getDatastore().find(Ban.class).filter(Filters.eq("active", true)).iterator();
|
||||
while (cursor.hasNext())
|
||||
for (Ban ban : Plex.get().getMongoConnection().getDatastore().find(Ban.class).filter(Filters.eq("active", true)))
|
||||
{
|
||||
Ban ban = cursor.next();
|
||||
bans.add(ban);
|
||||
}
|
||||
} else {
|
||||
|
@ -11,22 +11,25 @@ import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.exception.ConsoleMustDefinePlayerException;
|
||||
import dev.plex.command.exception.ConsoleOnlyException;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class PlexCommand extends Command implements TabExecutor, IPlexCommand
|
||||
public abstract class PlexCommand extends Command
|
||||
{
|
||||
protected static Plex plugin = Plex.get();
|
||||
|
||||
@ -34,19 +37,18 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
||||
private final CommandPermissions perms;
|
||||
|
||||
private final Rank level;
|
||||
private CommandSource sender;
|
||||
private final RequiredCommandSource commandSource;
|
||||
|
||||
public PlexCommand(String name)
|
||||
public PlexCommand()
|
||||
{
|
||||
super(name);
|
||||
super("");
|
||||
this.params = getClass().getAnnotation(CommandParameters.class);
|
||||
this.perms = getClass().getAnnotation(CommandPermissions.class);
|
||||
|
||||
setName(name);
|
||||
setLabel(name);
|
||||
setName(this.params.name());
|
||||
setLabel(this.params.name());
|
||||
setDescription(params.description());
|
||||
setUsage(params.usage().replace("<command>", name));
|
||||
setUsage(params.usage().replace("<command>", this.params.name()));
|
||||
if (params.aliases().split(",").length > 0)
|
||||
{
|
||||
setAliases(Arrays.asList(params.aliases().split(",")));
|
||||
@ -57,16 +59,11 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
||||
getMap().register("plex", this);
|
||||
}
|
||||
|
||||
protected abstract Component execute(CommandSender sender, String[] args);
|
||||
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args)
|
||||
{
|
||||
onCommand(sender, this, label, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
|
||||
public boolean execute(@NotNull CommandSender sender, @NotNull String label, String[] args)
|
||||
{
|
||||
if (!matches(label))
|
||||
{
|
||||
@ -82,77 +79,45 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
||||
{
|
||||
if (sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
sender.sendMessage(tl("noPermissionConsole"));
|
||||
send(sender, tl("noPermissionConsole"));
|
||||
return true;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
|
||||
this.sender = new CommandSource(player);
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||
{
|
||||
sender.sendMessage(tl("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMSG())));
|
||||
send(sender, tl("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMSG())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
this.sender = new CommandSource(sender);
|
||||
execute(this.sender, args);
|
||||
Component component = this.execute(sender, args);
|
||||
if (component != null)
|
||||
{
|
||||
send(sender, component);
|
||||
}
|
||||
}
|
||||
catch (CommandArgumentException ex)
|
||||
{
|
||||
send(getUsage().replace("<command>", getLabel()));
|
||||
send(sender, getUsage().replace("<command>", getLabel()));
|
||||
}
|
||||
catch (PlayerNotFoundException | CommandFailException ex)
|
||||
{
|
||||
send(ex.getMessage());
|
||||
send(sender, ex.getMessage());
|
||||
}
|
||||
catch (ConsoleMustDefinePlayerException ex)
|
||||
{
|
||||
send(tl("consoleMustDefinePlayer"));
|
||||
send(sender, tl("consoleMustDefinePlayer"));
|
||||
}
|
||||
catch (ConsoleOnlyException ex)
|
||||
{
|
||||
send(tl("consoleOnly"));
|
||||
send(sender, tl("consoleOnly"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args)
|
||||
{
|
||||
if (!matches(alias))
|
||||
{
|
||||
return ImmutableList.of();
|
||||
}
|
||||
if (sender instanceof Player player)
|
||||
{
|
||||
|
||||
this.sender = new CommandSource(player);
|
||||
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||
if (plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||
{
|
||||
return onTabComplete(this.sender, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sender = new CommandSource(sender);
|
||||
return onTabComplete(this.sender, args);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args)
|
||||
{
|
||||
return tabComplete(sender, label, args);
|
||||
}
|
||||
|
||||
private boolean matches(String label)
|
||||
{
|
||||
@ -173,49 +138,67 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void send(String s, CommandSource sender)
|
||||
protected PlexPlayer getPlexPlayer(@NotNull Player player)
|
||||
{
|
||||
sender.send(s);
|
||||
return DataUtils.getPlayer(player.getUniqueId());
|
||||
}
|
||||
|
||||
protected void send(String s, Player player)
|
||||
protected void send(Audience audience, String s)
|
||||
{
|
||||
player.sendMessage(s);
|
||||
audience.sendMessage(componentFromString(s));
|
||||
}
|
||||
|
||||
protected void send(Audience audience, Component component)
|
||||
{
|
||||
audience.sendMessage(component);
|
||||
}
|
||||
|
||||
|
||||
protected boolean isAdmin(PlexPlayer plexPlayer)
|
||||
{
|
||||
return Plex.get().getRankManager().isAdmin(plexPlayer);
|
||||
}
|
||||
|
||||
protected boolean isAdmin(CommandSender sender)
|
||||
{
|
||||
if (!(sender instanceof Player player)) return true;
|
||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||
return Plex.get().getRankManager().isAdmin(plexPlayer);
|
||||
}
|
||||
|
||||
protected boolean isAdmin(String name)
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(name);
|
||||
return Plex.get().getRankManager().isAdmin(plexPlayer);
|
||||
}
|
||||
|
||||
protected boolean isConsole()
|
||||
protected boolean isSeniorAdmin(CommandSender sender)
|
||||
{
|
||||
if (!(sender instanceof Player player)) return true;
|
||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||
return Plex.get().getRankManager().isSeniorAdmin(plexPlayer);
|
||||
}
|
||||
|
||||
protected UUID getUUID(CommandSender sender)
|
||||
{
|
||||
if (!(sender instanceof Player player)) return null;
|
||||
return player.getUniqueId();
|
||||
}
|
||||
|
||||
|
||||
protected boolean isConsole(CommandSender sender)
|
||||
{
|
||||
return !(sender instanceof Player);
|
||||
}
|
||||
|
||||
protected String tl(String s, Object... objects)
|
||||
protected Component tl(String s, Object... objects)
|
||||
{
|
||||
return PlexUtils.tl(s, objects);
|
||||
return componentFromString(PlexUtils.tl(s, objects));
|
||||
}
|
||||
|
||||
protected String usage(String s)
|
||||
protected Component usage(String s)
|
||||
{
|
||||
return ChatColor.YELLOW + "Correct Usage: " + ChatColor.GRAY + s;
|
||||
}
|
||||
|
||||
protected void send(String s)
|
||||
{
|
||||
if (sender == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
send(s, sender);
|
||||
return componentFromString(ChatColor.YELLOW + "Correct Usage: " + ChatColor.GRAY + s);
|
||||
}
|
||||
|
||||
protected Player getNonNullPlayer(String name)
|
||||
@ -254,11 +237,16 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
|
||||
World world = Bukkit.getWorld(name);
|
||||
if (world == null)
|
||||
{
|
||||
throw new CommandFailException(tl("worldNotFound"));
|
||||
throw new CommandFailException(PlexUtils.tl("worldNotFound"));
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
protected Component componentFromString(String s)
|
||||
{
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(s);
|
||||
}
|
||||
|
||||
public Rank getLevel()
|
||||
{
|
||||
return level;
|
||||
|
@ -47,7 +47,6 @@ public class AdminCMD extends PlexCommand
|
||||
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
send(sender, tl("consoleOnly"));
|
||||
throw new ConsoleOnlyException();
|
||||
}
|
||||
|
||||
@ -153,7 +152,7 @@ public class AdminCMD extends PlexCommand
|
||||
return usage("/admin list");
|
||||
}
|
||||
|
||||
return fromString("Admins: " + StringUtils.join(plugin.getAdminList().getAllAdmins(), ", "));
|
||||
return componentFromString("Admins: " + StringUtils.join(plugin.getAdminList().getAllAdmins(), ", "));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -26,18 +27,16 @@ public class AdventureCMD extends PlexCommand
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
// doesn't work
|
||||
if (sender.isConsoleSender())
|
||||
if (isConsole(sender))
|
||||
{
|
||||
throw new CommandFailException("You must define a player when using the console!");
|
||||
}
|
||||
|
||||
sender.getPlayer().setGameMode(GameMode.ADVENTURE);
|
||||
send(tl("gameModeSetTo", "adventure"));
|
||||
return;
|
||||
Player player = (Player) sender;
|
||||
player.setGameMode(GameMode.ADVENTURE);
|
||||
return tl("gameModeSetTo", "adventure");
|
||||
}
|
||||
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
if (isAdmin(sender))
|
||||
{
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
@ -45,25 +44,26 @@ public class AdventureCMD extends PlexCommand
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.ADVENTURE);
|
||||
}
|
||||
send(tl("gameModeSetTo", "adventure"));
|
||||
return;
|
||||
return tl("gameModeSetTo", "adventure");
|
||||
}
|
||||
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
send(tl("setOtherPlayerGameModeTo", player.getName(), "adventure"));
|
||||
// use send
|
||||
player.sendMessage(tl("playerSetOtherGameMode", sender.getName(), "adventure"));
|
||||
send(player, tl("playerSetOtherGameMode", sender.getName(), "adventure"));
|
||||
player.setGameMode(GameMode.ADVENTURE);
|
||||
return tl("setOtherPlayerGameModeTo", player.getName(), "adventure");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
if (isAdmin(sender))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,29 +14,29 @@ import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandParameters(usage = "/<command> <player> [reason]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
|
||||
@CommandParameters(name = "ban", usage = "/<command> <player> [reason]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
|
||||
@CommandPermissions(level = Rank.ADMIN, source = RequiredCommandSource.ANY)
|
||||
|
||||
public class BanCMD extends PlexCommand
|
||||
{
|
||||
public BanCMD() {
|
||||
super("ban");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
sender.send(usage(getUsage()));
|
||||
return;
|
||||
return usage(getUsage());
|
||||
}
|
||||
|
||||
if (args.length == 1)
|
||||
@ -51,35 +51,38 @@ public class BanCMD extends PlexCommand
|
||||
|
||||
if (isAdmin(plexPlayer))
|
||||
{
|
||||
if (!sender.isConsoleSender())
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
PlexPlayer plexPlayer1 = sender.getPlexPlayer();
|
||||
PlexPlayer plexPlayer1 = getPlexPlayer((Player) sender);
|
||||
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
|
||||
{
|
||||
sender.send(tl("higherRankThanYou"));
|
||||
return;
|
||||
return tl("higherRankThanYou");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(targetUUID) == null ? new PunishedPlayer(targetUUID) : PlayerCache.getPunishedPlayer(targetUUID);
|
||||
Punishment punishment = new Punishment(targetUUID, !sender.isConsoleSender() ? sender.getPlayer().getUniqueId() : null);
|
||||
Punishment punishment = new Punishment(targetUUID, getUUID(sender));
|
||||
punishment.setType(PunishmentType.BAN);
|
||||
punishment.setReason("");
|
||||
punishment.setPunishedUsername(plexPlayer.getName());
|
||||
//TODO: Debug End date
|
||||
punishment.setEndDate(new Date(Instant.now().plusSeconds(10/*PlexUtils.secondsToHours(24)*/).getEpochSecond()));
|
||||
punishment.setCustomTime(false);
|
||||
plugin.getPunishmentManager().doPunishment(punishedPlayer, punishment);
|
||||
Bukkit.broadcastMessage(sender.getName() + " - Banning " + plexPlayer.getName());
|
||||
Bukkit.broadcast(componentFromString(sender.getName() + " - Banning " + plexPlayer.getName()));
|
||||
if (Bukkit.getPlayer(targetUUID) != null)
|
||||
{
|
||||
Bukkit.getPlayer(targetUUID).kickPlayer("§cYou've been banned.");
|
||||
Bukkit.getPlayer(targetUUID).kick(componentFromString("&cYou've been banned."));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 && isAdmin(sender) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,38 +8,34 @@ import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(aliases = "gmc", description = "Set your own or another player's gamemode to creative mode")
|
||||
@CommandParameters(name = "creative", aliases = "gmc", description = "Set your own or another player's gamemode to creative mode")
|
||||
public class CreativeCMD extends PlexCommand
|
||||
{
|
||||
public CreativeCMD()
|
||||
{
|
||||
super("creative");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
// doesn't work
|
||||
if (sender.isConsoleSender())
|
||||
if (isConsole(sender))
|
||||
{
|
||||
throw new CommandFailException("You must define a player when using the console!");
|
||||
}
|
||||
|
||||
sender.getPlayer().setGameMode(GameMode.CREATIVE);
|
||||
send(tl("gameModeSetTo", "creative"));
|
||||
return;
|
||||
Player player = (Player) sender;
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
return tl("gameModeSetTo", "creative");
|
||||
}
|
||||
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
if (isAdmin(sender))
|
||||
{
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
@ -47,21 +43,22 @@ public class CreativeCMD extends PlexCommand
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.CREATIVE);
|
||||
}
|
||||
send(tl("gameModeSetTo", "creative"));
|
||||
return;
|
||||
return tl("gameModeSetTo", "creative");
|
||||
}
|
||||
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
send(tl("setOtherPlayerGameModeTo", player.getName(), "creative"));
|
||||
player.sendMessage(tl("playerSetOtherGameMode", sender.getName(), "creative"));
|
||||
// use send
|
||||
send(player, tl("playerSetOtherGameMode", sender.getName(), "creative"));
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
return tl("setOtherPlayerGameModeTo", player.getName(), "creative");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
if (isAdmin(sender))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
|
@ -1,142 +0,0 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.world.BlockMapChunkGenerator;
|
||||
import dev.plex.world.CustomWorld;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Enderman;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Strider;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@CommandParameters(description = "Subliminal message.")
|
||||
@CommandPermissions(source = RequiredCommandSource.IN_GAME)
|
||||
public class FionnCMD extends PlexCommand
|
||||
{
|
||||
public static boolean ENABLED = false;
|
||||
public static Map<Player, Location> LOCATION_CACHE = new HashMap<>();
|
||||
|
||||
public FionnCMD()
|
||||
{
|
||||
super("fionn");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (!sender.getPlayer().getUniqueId().equals(UUID.fromString("9aa3eda6-c271-440a-a578-a952ee9aee2f")))
|
||||
{
|
||||
throw new CommandFailException(tl("noPermission"));
|
||||
}
|
||||
if (args.length != 0)
|
||||
{
|
||||
throw new CommandArgumentException();
|
||||
}
|
||||
String name = "fionn";
|
||||
LinkedHashMap<Material, Integer> map = new LinkedHashMap<>();
|
||||
map.put(Material.CRIMSON_NYLIUM, 1);
|
||||
map.put(Material.BEDROCK, 1);
|
||||
World fionnWorld = new CustomWorld(name, new BlockMapChunkGenerator(map)).generate();
|
||||
ENABLED = true;
|
||||
fionnWorld.setTime(0);
|
||||
fionnWorld.getBlockAt(0, 5, 0).setType(Material.BARRIER);
|
||||
Strider fionn = (Strider)fionnWorld.spawnEntity(new Location(fionnWorld, 12, 6, 6, -180, -3), EntityType.STRIDER);
|
||||
fionn.setCustomNameVisible(true);
|
||||
fionn.setCustomName(ChatColor.GREEN + "fionn");
|
||||
fionn.setAI(false);
|
||||
Enderman elmon = (Enderman)fionnWorld.spawnEntity(new Location(fionnWorld, 12, 6, 0, 0, 18), EntityType.ENDERMAN);
|
||||
elmon.setCustomNameVisible(true);
|
||||
elmon.setCustomName(ChatColor.RED + "elmon");
|
||||
elmon.setInvulnerable(true);
|
||||
elmon.setAware(false);
|
||||
elmon.setGravity(true);
|
||||
// platforms in cage
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 10, 5, -2), new Location(fionnWorld, 14, 5, 2), Material.SMOOTH_STONE);
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 10, 9, -2), new Location(fionnWorld, 14, 9, 2), Material.SMOOTH_STONE_SLAB);
|
||||
// iron bars of cage
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 10, 8, -2), new Location(fionnWorld, 10, 6, 2), Material.IRON_BARS);
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 14, 8, 2), new Location(fionnWorld, 10, 6, 2), Material.IRON_BARS);
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 14, 8, 2), new Location(fionnWorld, 14, 6, -2), Material.IRON_BARS);
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 10, 8, -2), new Location(fionnWorld, 14, 6, -2), Material.IRON_BARS);
|
||||
// lava
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 10, 1, -2), new Location(fionnWorld, 14, 0, 2), Material.LAVA);
|
||||
|
||||
// iron bars of platform
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 12, 2, 6), new Location(fionnWorld, 12, 5, 6), Material.IRON_BARS);
|
||||
// platform
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 11, 6, 7), new Location(fionnWorld, 13, 6, 5), Material.SMOOTH_STONE_SLAB);
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
p.setInvisible(true);
|
||||
LOCATION_CACHE.put(p, p.getLocation());
|
||||
p.teleport(new Location(fionnWorld, 0, 5, 0, -90, 0));
|
||||
PlayerCache.getPunishedPlayer(p.getUniqueId()).setFrozen(true);
|
||||
}
|
||||
lateFakeChat("elmon", "fionn! i'm sorry for not being your sex slave...", ChatColor.RED, 20);
|
||||
lateFakeChat("fionn", "it's too late for that now...", ChatColor.GREEN, 60);
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 13, 5, -1), new Location(fionnWorld, 11, 5, 1), Material.AIR);
|
||||
}
|
||||
}.runTaskLater(plugin, 100);
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
fionn.teleport(new Location(fionnWorld, 2.5, 5.5, 0, 90, -10));
|
||||
}
|
||||
}.runTaskLater(plugin, 160);
|
||||
new BukkitRunnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
fionn.remove();
|
||||
elmon.remove();
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
p.setInvisible(false);
|
||||
Location location = LOCATION_CACHE.get(p);
|
||||
if (location != null)
|
||||
{
|
||||
p.teleport(location);
|
||||
}
|
||||
PlayerCache.getPunishedPlayer(p.getUniqueId()).setFrozen(false);
|
||||
}
|
||||
LOCATION_CACHE.clear();
|
||||
ENABLED = false;
|
||||
}
|
||||
}.runTaskLater(plugin, 200);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
public static void lateFakeChat(String name, String message, ChatColor color, int delay)
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
Bukkit.broadcastMessage(color + name + ChatColor.GRAY + ": " + ChatColor.WHITE + message);
|
||||
}
|
||||
}.runTaskLater(plugin, delay);
|
||||
}
|
||||
}
|
@ -5,20 +5,19 @@ 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 net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(description = "Teleport to the flatlands")
|
||||
@CommandParameters(name = "flatlands", description = "Teleport to the flatlands")
|
||||
public class FlatlandsCMD extends PlexCommand
|
||||
{
|
||||
public FlatlandsCMD()
|
||||
{
|
||||
super("flatlands");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
@ -26,14 +25,9 @@ public class FlatlandsCMD extends PlexCommand
|
||||
if (args.length == 0)
|
||||
{
|
||||
Location loc = new Location(Bukkit.getWorld("flatlands"), 0, 50, 0);
|
||||
sender.getPlayer().teleportAsync(loc);
|
||||
send(tl("teleportedToWorld", "flatlands"));
|
||||
((Player)sender).teleportAsync(loc);
|
||||
return tl("teleportedToWorld", "flatlands");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -11,21 +11,20 @@ import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandParameters(description = "Freeze a player on the server", usage = "/<command> <player>")
|
||||
@CommandParameters(name = "freeze", description = "Freeze a player on the server", usage = "/<command> <player>")
|
||||
@CommandPermissions(level = Rank.ADMIN)
|
||||
public class FreezeCMD extends PlexCommand
|
||||
{
|
||||
public FreezeCMD()
|
||||
{
|
||||
super("freeze");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
@ -36,7 +35,7 @@ public class FreezeCMD extends PlexCommand
|
||||
}
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());
|
||||
Punishment punishment = new Punishment(UUID.fromString(punishedPlayer.getUuid()), sender.isConsoleSender() ? null : sender.getPlayer().getUniqueId());
|
||||
Punishment punishment = new Punishment(UUID.fromString(punishedPlayer.getUuid()), getUUID(sender));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setEndDate(new Date(Instant.now().plusSeconds(10).toEpochMilli()));
|
||||
punishment.setType(PunishmentType.FREEZE);
|
||||
@ -45,11 +44,12 @@ public class FreezeCMD extends PlexCommand
|
||||
|
||||
plugin.getPunishmentManager().doPunishment(punishedPlayer, punishment);
|
||||
PlexUtils.broadcast(tl("frozePlayer", sender.getName(), player.getName()));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
return args.length == 1 && isAdmin(sender) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
45
src/main/java/dev/plex/command/impl/ListCMD.java
Normal file
45
src/main/java/dev/plex/command/impl/ListCMD.java
Normal file
@ -0,0 +1,45 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.bytebuddy.description.NamedElement;
|
||||
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.util.List;
|
||||
|
||||
@CommandParameters(name = "list", description = "Freeze a player on the server", usage = "/<command> <player>")
|
||||
@CommandPermissions(level = Rank.OP)
|
||||
public class ListCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
protected Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
List<Player> players = Lists.newArrayList(Bukkit.getOnlinePlayers());
|
||||
Component component = Component.text("There " + (players.size() > 1 ? "are" : "is") + " currently").color(NamedTextColor.GRAY)
|
||||
.append(Component.space())
|
||||
.append(Component.text(players.size()).color(NamedTextColor.YELLOW))
|
||||
.append(Component.space())
|
||||
.append(Component.text(players.size() > 1 ? "players " : "player " + "online out of").color(NamedTextColor.GRAY))
|
||||
.append(Component.space())
|
||||
.append(Component.text(Bukkit.getMaxPlayers()).color(NamedTextColor.YELLOW))
|
||||
.append(Component.newline());
|
||||
for (int i = 0; i < players.size(); i++)
|
||||
{
|
||||
Player player = players.get(i);
|
||||
component = component.append(Component.text(getPlexPlayer(player).getRankFromString().getPrefix())).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE));
|
||||
if (i != players.size() - 1)
|
||||
{
|
||||
component = component.append(Component.text(",")).append(Component.space());
|
||||
}
|
||||
}
|
||||
|
||||
return component;
|
||||
}
|
||||
}
|
@ -5,20 +5,19 @@ 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 net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(aliases = "mbw", description = "Teleport to the Master Builder world")
|
||||
@CommandParameters(name = "masterbuilderworld", aliases = "mbw", description = "Teleport to the Master Builder world")
|
||||
public class MasterbuilderworldCMD extends PlexCommand
|
||||
{
|
||||
public MasterbuilderworldCMD()
|
||||
{
|
||||
super("masterbuilderworld");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
@ -27,14 +26,9 @@ public class MasterbuilderworldCMD extends PlexCommand
|
||||
if (args.length == 0)
|
||||
{
|
||||
Location loc = new Location(Bukkit.getWorld("masterbuilderworld"), 0, 50, 0);
|
||||
sender.getPlayer().teleportAsync(loc);
|
||||
send(tl("teleportedToWorld", "Master Builder world"));
|
||||
((Player)sender).teleportAsync(loc);
|
||||
return tl("teleportedToWorld", "Master Builder World");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,34 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.MojangUtils;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Comparator;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandParameters(description = "Get the name history of a player", usage = "/<command> <player>", aliases = "nh")
|
||||
@CommandParameters(name = "namehistory", description = "Get the name history of a player", usage = "/<command> <player>", aliases = "nh")
|
||||
@CommandPermissions(level = Rank.OP)
|
||||
public class NameHistoryCMD extends PlexCommand
|
||||
{
|
||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy 'at' HH:mm:ss");
|
||||
|
||||
public NameHistoryCMD()
|
||||
{
|
||||
super("namehistory");
|
||||
}
|
||||
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("MM/dd/yyyy 'at' HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
@ -35,44 +38,52 @@ public class NameHistoryCMD extends PlexCommand
|
||||
throw new CommandArgumentException();
|
||||
}
|
||||
String username = args[0];
|
||||
JSONArray array;
|
||||
try
|
||||
|
||||
|
||||
UUID uuid;
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayerIfCached(username);
|
||||
if (offlinePlayer != null)
|
||||
{
|
||||
JSONObject profile = (JSONObject)PlexUtils.simpleGET("https://api.mojang.com/users/profiles/minecraft/" + username);
|
||||
String uuid = (String)profile.get("id");
|
||||
array = (JSONArray)PlexUtils.simpleGET("https://api.mojang.com/user/profiles/" + uuid + "/names");
|
||||
}
|
||||
catch (ParseException | IOException ex)
|
||||
uuid = offlinePlayer.getUniqueId();
|
||||
} else
|
||||
{
|
||||
send(tl("nameHistoryFail", username));
|
||||
return;
|
||||
uuid = MojangUtils.getUUID(username);
|
||||
}
|
||||
|
||||
array.sort(Comparator.reverseOrder());
|
||||
|
||||
StringBuilder result = new StringBuilder()
|
||||
.append(tl("nameHistoryTitle", username))
|
||||
.append("\n");
|
||||
for (Object o : array)
|
||||
if (uuid == null)
|
||||
{
|
||||
JSONObject object = (JSONObject)o;
|
||||
Object changedToAt = object.get("changedToAt");
|
||||
if (changedToAt == null)
|
||||
{
|
||||
changedToAt = "O";
|
||||
}
|
||||
else
|
||||
{
|
||||
changedToAt = DATE_FORMAT.format(changedToAt);
|
||||
}
|
||||
result.append(tl("nameHistoryBody", object.get("name"), changedToAt))
|
||||
.append("\n");
|
||||
return Component.text("Couldn't find this user! Please check if your spelling was correct and this player exists").color(NamedTextColor.RED);
|
||||
}
|
||||
send(result.toString());
|
||||
PlexLog.debug("NameHistory UUID: " + uuid);
|
||||
|
||||
List<Map.Entry<String, LocalDateTime>> history = MojangUtils.getNameHistory(uuid);
|
||||
PlexLog.debug("NameHistory Size: " + history.size());
|
||||
List<Component> historyList = Lists.newArrayList();
|
||||
history.forEach(entry ->
|
||||
{
|
||||
if (entry.getValue() != null)
|
||||
{
|
||||
historyList.add(
|
||||
Component.text(entry.getKey()).color(NamedTextColor.GOLD)
|
||||
.append(Component.space())
|
||||
.append(Component.text("-").color(NamedTextColor.DARK_GRAY))
|
||||
.append(Component.space())
|
||||
.append(Component.text(DATE_FORMAT.format(entry.getValue())).color(NamedTextColor.GOLD)));
|
||||
} else
|
||||
{
|
||||
historyList.add(
|
||||
Component.text(entry.getKey()).color(NamedTextColor.GOLD)
|
||||
.append(Component.space()));
|
||||
}
|
||||
});
|
||||
send(sender, Component.text("Name History (" + username + ")").color(NamedTextColor.GOLD));
|
||||
send(sender, Component.text("-----------------------------").color(NamedTextColor.GOLD).decoration(TextDecoration.STRIKETHROUGH, true));
|
||||
historyList.forEach(component -> send(sender, component));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
|
@ -6,19 +6,17 @@ import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(description = "Op everyone on the server", aliases = "opa")
|
||||
@CommandParameters(name = "opall", description = "Op everyone on the server", aliases = "opa")
|
||||
@CommandPermissions(level = Rank.ADMIN)
|
||||
public class OpAllCMD extends PlexCommand
|
||||
{
|
||||
public OpAllCMD()
|
||||
{
|
||||
super("opall");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
@ -28,11 +26,7 @@ public class OpAllCMD extends PlexCommand
|
||||
player.setOp(true);
|
||||
}
|
||||
PlexUtils.broadcast(tl("oppedAllPlayers", sender.getName()));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
@ -7,18 +7,17 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(description = "Op a player on the server", usage = "/<command> <player>")
|
||||
@CommandParameters(name = "op", description = "Op a player on the server", usage = "/<command> <player>")
|
||||
@CommandPermissions(level = Rank.OP)
|
||||
public class OpCMD extends PlexCommand
|
||||
{
|
||||
public OpCMD()
|
||||
{
|
||||
super("op");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
@ -30,10 +29,11 @@ public class OpCMD extends PlexCommand
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
player.setOp(true);
|
||||
PlexUtils.broadcast(tl("oppedPlayer", sender.getName(), player.getName()));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
@ -7,45 +8,46 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(usage = "/<command> [reload]", aliases = "plexhelp", description = "Show information about Plex or reload it")
|
||||
@CommandParameters(name = "plex", usage = "/<command> [reload]", aliases = "plexhelp", description = "Show information about Plex or reload it")
|
||||
public class PlexCMD extends PlexCommand {
|
||||
public PlexCMD() {
|
||||
super("plex");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args) {
|
||||
if (args.length == 0) {
|
||||
send(ChatColor.LIGHT_PURPLE + "Plex. The long awaited TotalFreedomMod rewrite starts here...");
|
||||
send(ChatColor.LIGHT_PURPLE + "Plugin version: " + ChatColor.GOLD + "1.0");
|
||||
return;
|
||||
send(sender, ChatColor.LIGHT_PURPLE + "Plex. The long awaited TotalFreedomMod rewrite starts here...");
|
||||
return componentFromString(ChatColor.LIGHT_PURPLE + "Plugin version: " + ChatColor.GOLD + "1.0");
|
||||
}
|
||||
if (args[0].equals("reload"))
|
||||
{
|
||||
if (!plugin.getRankManager().isSeniorAdmin(sender.getPlexPlayer()))
|
||||
if (!isSeniorAdmin(sender))
|
||||
{
|
||||
send(tl("noPermission"));
|
||||
return;
|
||||
return tl("noPermission");
|
||||
}
|
||||
Plex.get().config.load();
|
||||
send("Reloaded config file");
|
||||
send(sender, "Reloaded config file");
|
||||
Plex.get().messages.load();
|
||||
send("Reloaded messages file");
|
||||
send(sender, "Reloaded messages file");
|
||||
Plex.get().getRankManager().importDefaultRanks();
|
||||
send("Imported ranks");
|
||||
send("Plex successfully reloaded.");
|
||||
send(sender, "Imported ranks");
|
||||
send(sender, "Plex successfully reloaded.");
|
||||
} else {
|
||||
throw new CommandArgumentException();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return List.of("reload");
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return ImmutableList.of("reload");
|
||||
}
|
||||
|
||||
}
|
@ -8,28 +8,27 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.menu.PunishmentMenu;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(usage = "/<command> [player]", description = "Opens the Punishments GUI", aliases = "punishlist,punishes")
|
||||
@CommandParameters(name = "punishments", usage = "/<command> [player]", description = "Opens the Punishments GUI", aliases = "punishlist,punishes")
|
||||
@CommandPermissions(level = Rank.ADMIN, source = RequiredCommandSource.IN_GAME)
|
||||
public class PunishmentsCMD extends PlexCommand
|
||||
{
|
||||
|
||||
public PunishmentsCMD() {
|
||||
super("punishments");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
Player player = sender.getPlayer();
|
||||
new PunishmentMenu().openInv(player, 0);
|
||||
new PunishmentMenu().openInv(((Player) sender), 0);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
@ -5,25 +5,21 @@ 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 net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// TODO: See ranks of other players
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(description = "Displays your rank")
|
||||
@CommandParameters(name = "rank", description = "Displays your rank")
|
||||
public class RankCMD extends PlexCommand {
|
||||
public RankCMD() {
|
||||
super("rank");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args) {
|
||||
send(tl("yourRank", sender.getPlexPlayer().getRank()));
|
||||
return tl("yourRank", getPlexPlayer((Player) sender).getRank());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -8,57 +8,57 @@ import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(aliases = "gmsp", description = "Set your own or another player's gamemode to spectator mode")
|
||||
@CommandParameters(name = "spectator", aliases = "gmsp", description = "Set your own or another player's gamemode to spectator mode")
|
||||
public class SpectatorCMD extends PlexCommand
|
||||
{
|
||||
public SpectatorCMD()
|
||||
{
|
||||
super("spectator");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
// doesn't work
|
||||
if (sender.isConsoleSender())
|
||||
if (isConsole(sender))
|
||||
{
|
||||
throw new CommandFailException("You must define a player when using the console!");
|
||||
}
|
||||
|
||||
sender.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
send(tl("gameModeSetTo", "spectator"));
|
||||
return;
|
||||
Player player = (Player) sender;
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
return tl("gameModeSetTo", "spectator");
|
||||
}
|
||||
|
||||
if (args[0].equals("-a"))
|
||||
if (isAdmin(sender))
|
||||
{
|
||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.SPECTATOR);
|
||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
return tl("gameModeSetTo", "spectator");
|
||||
}
|
||||
send(tl("gameModeSetTo", "spectator"));
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
send(tl("setOtherPlayerGameModeTo", player.getName(), "spectator"));
|
||||
player.sendMessage(tl("playerSetOtherGameMode", sender.getName(), "spectator"));
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
// use send
|
||||
send(player, tl("playerSetOtherGameMode", sender.getName(), "spectator"));
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
return tl("setOtherPlayerGameModeTo", player.getName(), "spectator");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
if (isAdmin(sender))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
|
@ -8,38 +8,34 @@ import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(aliases = "gms", description = "Set your own or another player's gamemode to survival mode")
|
||||
@CommandParameters(name = "survival", aliases = "gms", description = "Set your own or another player's gamemode to survival mode")
|
||||
public class SurvivalCMD extends PlexCommand
|
||||
{
|
||||
public SurvivalCMD()
|
||||
{
|
||||
super("survival");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
// doesn't work
|
||||
if (sender.isConsoleSender())
|
||||
if (isConsole(sender))
|
||||
{
|
||||
throw new CommandFailException("You must define a player when using the console!");
|
||||
}
|
||||
|
||||
sender.getPlayer().setGameMode(GameMode.SURVIVAL);
|
||||
send(tl("gameModeSetTo", "survival"));
|
||||
return;
|
||||
Player player = (Player) sender;
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
return tl("gameModeSetTo", "survival");
|
||||
}
|
||||
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
if (isAdmin(sender))
|
||||
{
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
@ -47,21 +43,22 @@ public class SurvivalCMD extends PlexCommand
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.SURVIVAL);
|
||||
}
|
||||
send(tl("gameModeSetTo", "survival"));
|
||||
return;
|
||||
return tl("gameModeSetTo", "survival");
|
||||
}
|
||||
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
send(tl("setOtherPlayerGameModeTo", player.getName(), "survival"));
|
||||
player.sendMessage(tl("playerSetOtherGameMode", sender.getName(), "survival"));
|
||||
// use send
|
||||
send(player, tl("playerSetOtherGameMode", sender.getName(), "survival"));
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
return tl("setOtherPlayerGameModeTo", player.getName(), "survival");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
if (isAdmin(sender))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
|
@ -1,37 +0,0 @@
|
||||
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 java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(aliases = "tst,tast", description = "HELLO")
|
||||
public class TestCMD extends PlexCommand
|
||||
{
|
||||
public TestCMD()
|
||||
{
|
||||
super("test");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
send(tl("variableTest", sender.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return Arrays.asList("WHATTHEFAWK", "LUL");
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
@ -7,21 +7,22 @@ import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(description = "Teleport to a world.", usage = "/<command> <world>")
|
||||
@CommandParameters(name = "world", description = "Teleport to a world.", usage = "/<command> <world>")
|
||||
public class WorldCMD extends PlexCommand
|
||||
{
|
||||
public WorldCMD()
|
||||
{
|
||||
super("world");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
@ -31,21 +32,16 @@ public class WorldCMD extends PlexCommand
|
||||
throw new CommandArgumentException();
|
||||
}
|
||||
World world = getNonNullWorld(args[0]);
|
||||
sender.getPlayer().teleport(new Location(world, 0, world.getHighestBlockYAt(0, 0) + 1, 0, 0, 0));
|
||||
send(tl("playerWorldTeleport", world.getName()));
|
||||
((Player)sender).teleportAsync(new Location(world, 0, world.getHighestBlockYAt(0, 0) + 1, 0, 0, 0));
|
||||
return tl("playerWorldTeleport", world.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args)
|
||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
List<String> worlds = new ArrayList<>();
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
worlds.add(world.getName());
|
||||
}
|
||||
if (args.length == 1)
|
||||
{
|
||||
return worlds;
|
||||
return Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.toList());
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
@ -17,9 +17,9 @@ public class CommandHandler
|
||||
commands.add(new AdventureCMD());
|
||||
commands.add(new BanCMD());
|
||||
commands.add(new CreativeCMD());
|
||||
commands.add(new FionnCMD());
|
||||
commands.add(new FlatlandsCMD());
|
||||
commands.add(new FreezeCMD());
|
||||
commands.add(new ListCMD());
|
||||
commands.add(new MasterbuilderworldCMD());
|
||||
commands.add(new NameHistoryCMD());
|
||||
commands.add(new OpAllCMD());
|
||||
@ -29,7 +29,6 @@ public class CommandHandler
|
||||
commands.add(new RankCMD());
|
||||
commands.add(new SpectatorCMD());
|
||||
commands.add(new SurvivalCMD());
|
||||
commands.add(new TestCMD());
|
||||
commands.add(new WorldCMD());
|
||||
PlexLog.log(String.format("Registered %s commands!", commands.size()));
|
||||
}
|
||||
|
@ -4,28 +4,72 @@ import dev.plex.Plex;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import io.papermc.paper.chat.ChatRenderer;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ChatListener extends PlexListener
|
||||
{
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent event)
|
||||
public void onChat(AsyncChatEvent event)
|
||||
{
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(event.getPlayer().getUniqueId());
|
||||
PlexChatRenderer renderer = new PlexChatRenderer();
|
||||
|
||||
if (!plexPlayer.getPrefix().isEmpty())
|
||||
{
|
||||
event.setFormat(String.format("%s %s §7» %s", plexPlayer.getPrefix(), ChatColor.RESET + plexPlayer.displayName(), event.getMessage()));
|
||||
renderer.hasPrefix = true;
|
||||
renderer.prefix = plexPlayer.getPrefix();
|
||||
} else if (Plex.get().getRankManager().isAdmin(plexPlayer))
|
||||
{
|
||||
renderer.hasPrefix = true;
|
||||
renderer.prefix = plexPlayer.getRankFromString().getPrefix();
|
||||
}
|
||||
else if (Plex.get().getRankManager().isAdmin(plexPlayer))
|
||||
event.renderer(renderer);
|
||||
/*if (!plexPlayer.getPrefix().isEmpty())
|
||||
{
|
||||
event.setFormat(String.format("%s %s §7» %s", plexPlayer.getPrefix(), ChatColor.RESET + plexPlayer.displayName(), event.getMessage()));
|
||||
} else if (Plex.get().getRankManager().isAdmin(plexPlayer))
|
||||
{
|
||||
event.setFormat(String.format("%s %s §7» %s", plexPlayer.getRankFromString().getPrefix(), ChatColor.RESET + plexPlayer.displayName(), event.getMessage()));
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
event.setFormat(String.format("%s §7» %s", ChatColor.RESET + plexPlayer.displayName(), event.getMessage()));
|
||||
}*/
|
||||
}
|
||||
|
||||
public static class PlexChatRenderer implements ChatRenderer
|
||||
{
|
||||
public boolean hasPrefix;
|
||||
public String prefix;
|
||||
|
||||
@Override
|
||||
public @NotNull Component render(@NotNull Player source, @NotNull Component sourceDisplayName, @NotNull Component message, @NotNull Audience viewer)
|
||||
{
|
||||
if (hasPrefix)
|
||||
{
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(prefix)
|
||||
.append(Component.space())
|
||||
.append(sourceDisplayName)
|
||||
.append(Component.space())
|
||||
.append(Component.text("»").color(NamedTextColor.GRAY))
|
||||
.append(Component.space())
|
||||
.append(message);
|
||||
}
|
||||
return Component.empty()
|
||||
.append(sourceDisplayName)
|
||||
.append(Component.space())
|
||||
.append(Component.text("»").color(NamedTextColor.GRAY))
|
||||
.append(Component.space())
|
||||
.append(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,11 @@ import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.MongoPlayerData;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.cache.SQLPlayerData;
|
||||
import dev.plex.command.impl.FionnCMD;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.player.PunishedPlayer;
|
||||
import dev.plex.util.PlexLog;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -19,6 +19,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListener extends PlexListener
|
||||
@ -39,47 +40,13 @@ public class PlayerListener extends PlexListener
|
||||
PlexLog.log("A player with this name has not joined the server before, creating new entry."); // funi msg
|
||||
plexPlayer = new PlexPlayer(player.getUniqueId()); //it doesn't! okay so now create the object
|
||||
plexPlayer.setName(player.getName()); //set the name of the player
|
||||
plexPlayer.setIps(Arrays.asList(player.getAddress().getAddress().getHostAddress().trim())); //set the arraylist of ips
|
||||
plexPlayer.setIps(Collections.singletonList(player.getAddress().getAddress().getHostAddress().trim())); //set the arraylist of ips
|
||||
|
||||
DataUtils.insert(plexPlayer); // insert data in some wack db
|
||||
} else {
|
||||
plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||
}
|
||||
|
||||
/*if (mongoPlayerData != null) // Alright, check if we're saving with Mongo first
|
||||
{
|
||||
if (!mongoPlayerData.exists(player.getUniqueId())) //okay, we're saving with mongo! now check if the player's document exists
|
||||
{
|
||||
PlexLog.log("AYO THIS MAN DONT EXIST"); // funi msg
|
||||
plexPlayer = new PlexPlayer(player.getUniqueId()); //it doesn't! okay so now create the object
|
||||
plexPlayer.setName(player.getName()); //set the name of the player
|
||||
plexPlayer.setIps(Arrays.asList(player.getAddress().getAddress().getHostAddress().trim())); //set the arraylist of ips
|
||||
|
||||
mongoPlayerData.save(plexPlayer); //and put their document in mongo collection
|
||||
}
|
||||
else
|
||||
{
|
||||
plexPlayer = mongoPlayerData.getByUUID(player.getUniqueId()); //oh they do exist!
|
||||
plexPlayer.setName(plexPlayer.getName()); //set the name!
|
||||
}
|
||||
}
|
||||
else if (sqlPlayerData != null)
|
||||
{
|
||||
if (!sqlPlayerData.exists(player.getUniqueId())) //okay, we're saving with sql! now check if the player's document exists
|
||||
{
|
||||
PlexLog.log("AYO THIS MAN DONT EXIST"); // funi msg
|
||||
plexPlayer = new PlexPlayer(player.getUniqueId()); //it doesn't! okay so now create the object
|
||||
plexPlayer.setName(player.getName()); //set the name of the player
|
||||
plexPlayer.setIps(Arrays.asList(player.getAddress().getAddress().getHostAddress().trim())); //set the arraylist of ips
|
||||
sqlPlayerData.insert(plexPlayer); //and put their row into the sql table
|
||||
}
|
||||
else
|
||||
{
|
||||
plexPlayer = sqlPlayerData.getByUUID(player.getUniqueId()); //oh they do exist!
|
||||
plexPlayer.setName(plexPlayer.getName()); //set the name!
|
||||
}
|
||||
}*/
|
||||
|
||||
PlayerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache
|
||||
PlayerCache.getPunishedPlayerMap().put(player.getUniqueId(), new PunishedPlayer(player.getUniqueId()));
|
||||
|
||||
@ -94,22 +61,13 @@ public class PlayerListener extends PlexListener
|
||||
|
||||
if (!plexPlayer.getLoginMSG().isEmpty())
|
||||
{
|
||||
event.setJoinMessage(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getLoginMSG());
|
||||
event.joinMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getLoginMSG()));
|
||||
}
|
||||
else
|
||||
{
|
||||
event.setJoinMessage(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getRankFromString().getLoginMSG());
|
||||
event.joinMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getRankFromString().getLoginMSG()));
|
||||
}
|
||||
}
|
||||
|
||||
/*Punishment test = new Punishment(player.getUniqueId(), player.getUniqueId());
|
||||
test.setPunishedUsername(player.getName());
|
||||
test.setReason("hii");
|
||||
test.setType(PunishmentType.BAN);
|
||||
test.setEndDate(new Date(Instant.now().plusSeconds(10).getEpochSecond()));
|
||||
plugin.getPunishmentManager().doPunishment(PlayerCache.getPunishedPlayer(player.getUniqueId()), test);*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
// saving the player's data
|
||||
@ -132,30 +90,10 @@ public class PlayerListener extends PlexListener
|
||||
sqlPlayerData.update(plexPlayer);
|
||||
}
|
||||
|
||||
if (FionnCMD.ENABLED)
|
||||
{
|
||||
PlayerCache.getPunishedPlayer(event.getPlayer().getUniqueId()).setFrozen(false);
|
||||
}
|
||||
|
||||
PlayerCache.getPlexPlayerMap().remove(event.getPlayer().getUniqueId()); //remove them from cache
|
||||
PlayerCache.getPunishedPlayerMap().remove(event.getPlayer().getUniqueId());
|
||||
|
||||
}
|
||||
|
||||
// unrelated player quitting
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent e)
|
||||
{
|
||||
Player player = e.getPlayer();
|
||||
|
||||
if (FionnCMD.ENABLED)
|
||||
{
|
||||
player.setInvisible(false);
|
||||
Location location = FionnCMD.LOCATION_CACHE.get(player);
|
||||
if (location != null)
|
||||
{
|
||||
player.teleport(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
76
src/main/java/dev/plex/util/MojangUtils.java
Normal file
76
src/main/java/dev/plex/util/MojangUtils.java
Normal file
@ -0,0 +1,76 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MojangUtils
|
||||
{
|
||||
public static UUID getUUID(String name)
|
||||
{
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
HttpGet get = new HttpGet("https://api.mojang.com/users/profiles/minecraft/" + name);
|
||||
try
|
||||
{
|
||||
HttpResponse response = client.execute(get);
|
||||
String json = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
|
||||
JSONObject object = new JSONObject(json);
|
||||
client.close();
|
||||
return UUID.fromString(new StringBuilder(object.getString("id"))
|
||||
.insert(8, "-")
|
||||
.insert(13, "-")
|
||||
.insert(18, "-")
|
||||
.insert(23, "-").toString());
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Map.Entry<String, LocalDateTime>> getNameHistory(UUID uuid)
|
||||
{
|
||||
Map<String, LocalDateTime> names = Maps.newHashMap();
|
||||
String uuidString = uuid.toString().replace("-", "");
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpGet get = new HttpGet("https://api.mojang.com/user/profiles/" + uuidString + "/names");
|
||||
try
|
||||
{
|
||||
HttpResponse response = httpClient.execute(get);
|
||||
String json = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
|
||||
JSONArray array = new JSONArray(json);
|
||||
array.forEach(object ->
|
||||
{
|
||||
JSONObject obj = new JSONObject(object.toString());
|
||||
String name = obj.getString("name");
|
||||
if (!obj.isNull("changedToAt"))
|
||||
{
|
||||
long dateTime = obj.getLong("changedToAt");
|
||||
Instant instant = Instant.ofEpochMilli(dateTime);
|
||||
LocalDateTime time = LocalDateTime.ofInstant(instant, ZoneId.of("America/Los_Angeles"));
|
||||
names.put(name, time);
|
||||
} else
|
||||
{
|
||||
names.put(name, null);
|
||||
}
|
||||
});
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return names.entrySet().stream().sorted(Map.Entry.comparingByValue()).collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -3,6 +3,8 @@ package dev.plex.util;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.config.Config;
|
||||
import dev.plex.storage.StorageType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginCommandYamlParser;
|
||||
@ -177,7 +179,12 @@ public class PlexUtils
|
||||
|
||||
public static void broadcast(String s)
|
||||
{
|
||||
Bukkit.broadcastMessage(s);
|
||||
Bukkit.broadcast(LegacyComponentSerializer.legacyAmpersand().deserialize(s));
|
||||
}
|
||||
|
||||
public static void broadcast(Component component)
|
||||
{
|
||||
Bukkit.broadcast(component);
|
||||
}
|
||||
|
||||
public static Object simpleGET(String url) throws IOException, ParseException
|
||||
|
Loading…
Reference in New Issue
Block a user