use of net.minecraft.server.WhitelistEntry in project KahzerxMod by otakucraft.
the class ServerConfigMixin method onWhitelistAdd.
@Inject(method = "add", at = @At("RETURN"))
public void onWhitelistAdd(V entry, CallbackInfo ci) {
if (OpOnWhitelistExtension.isExtensionEnabled && OpOnWhitelistExtension.server != null && entry instanceof WhitelistEntry) {
try {
JSONParser parser = new JSONParser();
JSONObject obj = (JSONObject) parser.parse(new Gson().toJson(entry));
Optional<GameProfile> profile = OpOnWhitelistExtension.server.getUserCache().getByUuid(UUID.fromString((String) ((JSONObject) obj.get("key")).get("id")));
if (profile.isEmpty()) {
return;
}
GameProfile gameProfile = profile.get();
if (!OpOnWhitelistExtension.server.getPlayerManager().isOperator(gameProfile)) {
OpOnWhitelistExtension.server.getPlayerManager().addToOperators(gameProfile);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of net.minecraft.server.WhitelistEntry in project KahzerxMod by otakucraft.
the class ExremoveCommand method execute.
@Override
public void execute(MessageReceivedEvent event, MinecraftServer server, String serverPrefix, DiscordWhitelistExtension extension) {
boolean feedback = extension.getDiscordExtension().extensionSettings().isShouldFeedback();
String[] req = event.getMessage().getContentRaw().split(" ");
String playerName = req[1];
if (req.length != 2) {
event.getMessage().delete().queueAfter(2, TimeUnit.SECONDS);
this.sendHelpCommand(serverPrefix, event.getChannel(), feedback);
return;
}
Optional<GameProfile> profile = server.getUserCache().findByName(playerName);
if (profile.isEmpty()) {
EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**Not premium.**" }, serverPrefix, true, Color.RED, true, feedback);
if (embed != null) {
event.getChannel().sendMessageEmbeds(embed.build()).queue();
}
return;
}
if (!extension.canRemove(69420L, profile.get().getId().toString())) {
EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**You can't remove " + profile.get().getName() + ".**" }, serverPrefix, true, Color.RED, true, feedback);
if (embed != null) {
event.getChannel().sendMessageEmbeds(embed.build()).queue();
}
return;
}
Whitelist whitelist = server.getPlayerManager().getWhitelist();
if (!whitelist.isAllowed(profile.get())) {
EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**" + playerName + " is not whitelisted.**" }, serverPrefix, true, Color.YELLOW, true, feedback);
if (embed != null) {
event.getChannel().sendMessageEmbeds(embed.build()).queue();
}
return;
}
WhitelistEntry whitelistEntry = new WhitelistEntry(profile.get());
extension.deletePlayer(69420L, profile.get().getId().toString());
whitelist.remove(whitelistEntry);
ServerPlayerEntity player = server.getPlayerManager().getPlayer(profile.get().getId());
if (player != null) {
player.networkHandler.disconnect(new LiteralText("Byee~"));
}
EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**" + profile.get().getName() + " removed D:**" }, serverPrefix, true, Color.GREEN, true, feedback);
if (embed != null) {
event.getChannel().sendMessageEmbeds(embed.build()).queue();
}
}
use of net.minecraft.server.WhitelistEntry in project KahzerxMod by otakucraft.
the class ExaddCommand method execute.
@Override
public void execute(MessageReceivedEvent event, MinecraftServer server, String serverPrefix, DiscordWhitelistExtension extension) {
boolean feedback = extension.getDiscordExtension().extensionSettings().isShouldFeedback();
String[] req = event.getMessage().getContentRaw().split(" ");
String playerName = req[1];
if (req.length != 2) {
event.getMessage().delete().queueAfter(2, TimeUnit.SECONDS);
this.sendHelpCommand(serverPrefix, event.getChannel(), feedback);
return;
}
Optional<GameProfile> profile = server.getUserCache().findByName(playerName);
if (profile.isEmpty()) {
EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**Not premium.**" }, serverPrefix, true, Color.RED, true, feedback);
if (embed != null) {
event.getChannel().sendMessageEmbeds(embed.build()).queue();
}
return;
}
Whitelist whitelist = server.getPlayerManager().getWhitelist();
if (whitelist.isAllowed(profile.get())) {
EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**" + playerName + " already whitelisted.**" }, serverPrefix, true, Color.YELLOW, true, feedback);
if (embed != null) {
event.getChannel().sendMessageEmbeds(embed.build()).queue();
}
return;
}
WhitelistEntry whitelistEntry = new WhitelistEntry(profile.get());
if (extension.isPlayerBanned(profile.get().getId().toString())) {
EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**Looks like that player is banned.**" }, serverPrefix, true, Color.RED, true, feedback);
if (embed != null) {
event.getChannel().sendMessageEmbeds(embed.build()).queue();
}
return;
}
if (extension.alreadyAddedBySomeone(profile.get().getId().toString())) {
EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**Already whitelisted by someone else.**" }, serverPrefix, true, Color.RED, true, feedback);
if (embed != null) {
event.getChannel().sendMessageEmbeds(embed.build()).queue();
}
return;
}
extension.addPlayer(69420L, profile.get().getId().toString(), profile.get().getName());
whitelist.add(whitelistEntry);
EmbedBuilder embed = DiscordChatUtils.generateEmbed(new String[] { "**" + profile.get().getName() + " added :D**" }, serverPrefix, true, Color.GREEN, true, feedback);
if (embed != null) {
event.getChannel().sendMessageEmbeds(embed.build()).queue();
}
}
use of net.minecraft.server.WhitelistEntry in project mc-discord-bridge by Selicre.
the class DiscordBotImpl method handleNormalDiscordCommand.
private boolean handleNormalDiscordCommand(Message message) {
if (message.getMember() != null && message.getContentRaw().startsWith("!mcname")) {
String[] args = message.getContentRaw().split(" ");
if (args.length == 2) {
Optional<GameProfile> lookupResult = server.getUserCache().findByName(args[1]);
if (lookupResult.isEmpty()) {
message.reply("I couldn't find a Minecraft user called `" + args[1] + "` - are you sure that it's correct?").queue();
} else {
GameProfile profile = lookupResult.get();
UUID old = playerLookup.updatePlayerProfile(message.getMember(), profile);
server.getPlayerManager().getWhitelist().add(new WhitelistEntry(profile));
if (old == null) {
message.reply("Welcome, " + profile.getName() + "! You're all set up and have been added to the whitelist.").queue();
} else if (old.equals(profile.getId())) {
message.reply("I already know who you are <3").queue();
} else {
message.reply("I will remember that your new player profile is " + profile.getName() + ", but your old account has been forgotten.").queue();
server.getPlayerManager().getWhitelist().remove(new GameProfile(old, null));
}
try {
server.getPlayerManager().getWhitelist().save();
} catch (IOException ex) {
LOGGER.warn("Couldn't save whitelist", ex);
}
}
} else {
message.reply("Usage: !mcname MyMinecraftUsername").queue();
}
return true;
}
return false;
}
use of net.minecraft.server.WhitelistEntry in project MC-Server-Protection by GStefanowich.
the class ClaimCommand method invitedList.
private static int invitedList(@NotNull ServerCommandSource source, @NotNull GameProfile player) throws CommandSyntaxException {
// Get information about the server
MinecraftServer server = source.getServer();
ClaimCache claimCache = ((ClaimsAccessor) server).getClaimManager();
UserCache cache = server.getUserCache();
Whitelist whitelist = server.getPlayerManager().getWhitelist();
// Store information about invites
GameProfile invitedBy = null;
List<WhitelistEntry> invited = new ArrayList<>();
ClaimantPlayer claim = claimCache.getPlayerClaim(player.getId());
// Loop the whitelist
for (WhitelistEntry entry : whitelist.values()) {
if (entry == null)
continue;
UUID invitedById = ((WhitelistedPlayer) entry).getInvitedBy();
if (invitedById != null) {
if (player.getId().equals(((WhitelistedPlayer) entry).getUUID()))
invitedBy = cache.getByUuid(invitedById).orElse(null);
else if (player.getId().equals(invitedById))
invited.add(entry);
}
}
Entity entity = source.getEntity();
boolean isPlayer = (entity instanceof PlayerEntity && player.getId().equals(entity.getUuid()));
// Output as text
MutableText out = null;
if (invitedBy != null)
out = new LiteralText("").append(new LiteralText(isPlayer ? "You" : player.getName()).formatted(Formatting.GRAY)).append(" " + (isPlayer ? "were" : "was") + " invited to the server by ").formatted(Formatting.WHITE).append(ClaimCommand.inviteeFormattedName(source, claim, invitedBy.getName(), invitedBy.getId()));
MutableText inv = new LiteralText("").formatted(Formatting.WHITE).append(new LiteralText(isPlayer ? "You" : player.getName()).formatted(Formatting.GRAY)).append(" invited the following players [").append(MessageUtils.formatNumber(invited.size())).append("]: ").append(MessageUtils.listToTextComponent(invited, (entry) -> ClaimCommand.inviteeFormattedName(source, claim, ((WhitelistedPlayer) entry).getName(), ((WhitelistedPlayer) entry).getUUID())));
if (out == null)
out = inv;
else
out.append("\n").append(inv);
source.sendFeedback(out, false);
return Command.SINGLE_SUCCESS;
}
Aggregations