Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/main/java/de/blazemcworld/fireflow/code/CodeEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import de.blazemcworld.fireflow.code.node.impl.function.FunctionOutputsNode;
import de.blazemcworld.fireflow.code.type.AllTypes;
import de.blazemcworld.fireflow.code.widget.*;
import de.blazemcworld.fireflow.messages.Messages;
import de.blazemcworld.fireflow.space.Space;
import me.xdrop.fuzzywuzzy.FuzzySearch;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -727,17 +728,20 @@ public void webBroadcast(JsonElement json) {
public void authorizeWeb(String webId, ServerPlayerEntity approver) {
for (EditOrigin origin : webUsers) {
if (origin.tryAuth(webId)) {
approver.sendMessage(Text.literal("Authorized web to edit code!").formatted(Formatting.GREEN), false);
Messages.sendMessage("Authorized the web editor to edit code!", Messages.SUCCESS, approver);
for (ServerPlayerEntity player : space.getPlayers()) {
if (!space.info.isOwnerOrDeveloper(player.getUuid())) continue;
if (player == approver) continue;
player.sendMessage(Text.literal(approver.getGameProfile().getName() + " authorized a web editor request!").formatted(Formatting.YELLOW), false);
Messages.sendMessage(
"<white>" + approver.getGameProfile().getName() + "<default> authorized a web editor request!",
Messages.INFO, player
);
}
return;
}
}

approver.sendMessage(Text.literal("Could not find web editor with matching id!").formatted(Formatting.RED), false);
Messages.sendMessage("Could not find the web editor with the matching id!", Messages.ERROR, approver);
}

public void close() {
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/de/blazemcworld/fireflow/code/web/WebEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import de.blazemcworld.fireflow.code.EditOrigin;
import de.blazemcworld.fireflow.code.widget.Widget;
import de.blazemcworld.fireflow.code.widget.WidgetVec;
import de.blazemcworld.fireflow.messages.Messages;
import de.blazemcworld.fireflow.space.Space;
import de.blazemcworld.fireflow.space.SpaceInfo;
import de.blazemcworld.fireflow.space.SpaceManager;
Expand Down Expand Up @@ -154,13 +155,16 @@ private void handleAuth(JsonObject json) {
editor.enterCode(origin);
for (ServerPlayerEntity player : space.getPlayers()) {
if (!space.info.isOwnerOrDeveloper(player.getUuid())) continue;
player.sendMessage(Text.literal("Someone opened the web editor for this space.").formatted(Formatting.YELLOW));
player.sendMessage(Text.literal("Click this to allow access, otherwise ignore it.").setStyle(
Style.EMPTY.withClickEvent(new ClickEvent.RunCommand("/authorize-web " + id))
.withHoverEvent(new HoverEvent.ShowText(Text.literal("Warning: Only do this if you know and trust the person who opened the web editor!")
.formatted(Formatting.RED)))
.withFormatting(Formatting.GOLD)
));
Messages.sendMessage(
"Someone opened the web editor for this space.",
Messages.NOTIFY, player
);
Messages.sendMessage(
"<click:run_command:\"/authorize-web "+id+"\">" +
"<hover:show_text:\"<default>Warning: Only do this if you know and trust the person who opened the web editor!\">" +
"Click this message to allow access, otherwise ignore it.",
Messages.FOLLOWUP, player
);
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import de.blazemcworld.fireflow.code.EditOrigin;
import de.blazemcworld.fireflow.messages.Messages;
import de.blazemcworld.fireflow.space.Space;
import de.blazemcworld.fireflow.util.ModeManager;
import net.minecraft.server.command.CommandManager;
Expand All @@ -28,7 +29,7 @@ private static void register(CommandDispatcher<ServerCommandSource> cd, String i
if (space == null) return Command.SINGLE_SUCCESS;

if (ModeManager.getFor(player) != ModeManager.Mode.CODE) {
player.sendMessage(Text.literal("You must be in code mode to do that!").formatted(Formatting.RED));
Messages.sendMessage("You must be in code mode to do that!", Messages.ERROR, player);
return Command.SINGLE_SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import de.blazemcworld.fireflow.messages.Messages;
import de.blazemcworld.fireflow.space.Space;
import de.blazemcworld.fireflow.space.SpaceInfo;
import de.blazemcworld.fireflow.space.SpaceManager;
Expand All @@ -23,7 +24,7 @@ public static void register(CommandDispatcher<ServerCommandSource> cd) {
if (space == null) return Command.SINGLE_SUCCESS;

if (!space.info.isOwnerOrBuilder(player.getUuid())) {
player.sendMessage(Text.literal("You are not allowed to do that!").formatted(Formatting.RED));
Messages.sendMessage("You are not allowed to do that!", Messages.ERROR, player);
return Command.SINGLE_SUCCESS;
}

Expand All @@ -38,12 +39,12 @@ public static void register(CommandDispatcher<ServerCommandSource> cd) {
int id = IntegerArgumentType.getInteger(ctx, "id");
SpaceInfo info = SpaceManager.getInfo(id);
if (info == null) {
player.sendMessage(Text.literal("Could not find space with id " + id + "!").formatted(Formatting.RED));
Messages.sendMessage("Could not find space with id " + id + "!", Messages.ERROR, player);
return Command.SINGLE_SUCCESS;
}

if (!info.isOwnerOrBuilder(player.getUuid())) {
player.sendMessage(Text.literal("You are not allowed to do that!").formatted(Formatting.RED));
Messages.sendMessage("You are not allowed to do that!", Messages.ERROR, player);
return Command.SINGLE_SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import de.blazemcworld.fireflow.messages.Messages;
import de.blazemcworld.fireflow.space.Space;
import de.blazemcworld.fireflow.space.SpaceInfo;
import de.blazemcworld.fireflow.space.SpaceManager;
Expand Down Expand Up @@ -38,12 +39,12 @@ private static void register(CommandDispatcher<ServerCommandSource> cd, String a
int id = IntegerArgumentType.getInteger(ctx, "id");
SpaceInfo info = SpaceManager.getInfo(id);
if (info == null) {
player.sendMessage(Text.literal("Could not find space with id " + id + "!").formatted(Formatting.RED));
Messages.sendMessage("Could not find space with id " + id + "!", Messages.ERROR, player);
return Command.SINGLE_SUCCESS;
}

if (!info.isOwnerOrDeveloper(player.getUuid())) {
player.sendMessage(Text.literal("You are not allowed to do that!").formatted(Formatting.RED));
Messages.sendMessage("You are not allowed to do that!", Messages.ERROR, player);
return Command.SINGLE_SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.blazemcworld.fireflow.command;

import de.blazemcworld.fireflow.messages.Messages;
import de.blazemcworld.fireflow.space.Space;
import de.blazemcworld.fireflow.space.SpaceManager;
import de.blazemcworld.fireflow.util.ModeManager;
Expand All @@ -12,7 +13,7 @@ public class CommandHelper {

public static ServerPlayerEntity getPlayer(ServerCommandSource src) {
if (!src.isExecutedByPlayer()) {
src.sendError(Text.literal("You must be a player for this!"));
Messages.sendMessage("You must be a player for this!", Messages.ERROR, src);
return null;
}
return src.getPlayer();
Expand All @@ -22,7 +23,7 @@ public static Space getSpace(ServerPlayerEntity player) {
if (player == null) return null;
Space space = SpaceManager.getSpaceForPlayer(player);
if (space == null) {
player.sendMessage(Text.literal("You must be on a space for this!").formatted(Formatting.RED));
Messages.sendMessage("You must be on a space for this!", Messages.ERROR, player);
return null;
}
return space;
Expand All @@ -31,7 +32,7 @@ public static Space getSpace(ServerPlayerEntity player) {
public static boolean isOwner(ServerPlayerEntity player, Space space) {
if (space == null || player == null) return false;
if (!space.info.owner.equals(player.getUuid())) {
player.sendMessage(Text.literal("You are not allowed to do that!").formatted(Formatting.RED));
Messages.sendMessage("You are not allowed to do that!", Messages.ERROR, player);
return false;
}
return true;
Expand All @@ -40,7 +41,7 @@ public static boolean isOwner(ServerPlayerEntity player, Space space) {
public static boolean isDeveloperOrOwner(ServerPlayerEntity player, Space space) {
if (space == null || player == null) return false;
if (!space.info.isOwnerOrDeveloper(player.getUuid())) {
player.sendMessage(Text.literal("You are not allowed to do that!").formatted(Formatting.RED));
Messages.sendMessage("You are not allowed to do that!", Messages.ERROR, player);
return false;
}
return true;
Expand All @@ -49,7 +50,7 @@ public static boolean isDeveloperOrOwner(ServerPlayerEntity player, Space space)
public static boolean isInCode(ServerPlayerEntity player, Space space) {
if (space == null || player == null) return false;
if (ModeManager.getFor(player) != ModeManager.Mode.CODE) {
player.sendMessage(Text.literal("You must be in code mode for this!").formatted(Formatting.RED));
Messages.sendMessage("You must be in code mode for this!", Messages.ERROR, player);
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import de.blazemcworld.fireflow.FireFlow;
import de.blazemcworld.fireflow.messages.Messages;
import de.blazemcworld.fireflow.space.PlayWorld;
import de.blazemcworld.fireflow.space.Space;
import de.blazemcworld.fireflow.space.SpaceInfo;
Expand Down Expand Up @@ -42,13 +43,14 @@ private static void attach(LiteralArgumentBuilder<ServerCommandSource> node, Str
Set<UUID> contributors = getMap.apply(space.info);

if (contributors.isEmpty()) {
player.sendMessage(Text.literal("There are no " + id + "s!").formatted(Formatting.RED));
Messages.sendMessage("There are no "+ id + "s!", Messages.INFO, player);
return Command.SINGLE_SUCCESS;
}

player.sendMessage(Text.literal("Space " + id + (contributors.size() == 1 ? "" : "s") + " (" + contributors.size() + "):").formatted(Formatting.AQUA));
Messages.sendMessage("Space " + id + (contributors.size() == 1 ? "" : "s") + " (" + contributors.size() + "):", Messages.INFO, player);
for (UUID uuid : contributors) {
resolveName(player.getServerWorld(), uuid, name -> player.sendMessage(Text.literal("- " + name).formatted(Formatting.DARK_AQUA)));
resolveName(player.getServerWorld(), uuid, name -> Messages.sendMessage(
"<hover:show_text:\"<default>" + uuid.toString() + "\">" + name, Messages.FOLLOWUP, player));
}

return Command.SINGLE_SUCCESS;
Expand All @@ -70,23 +72,23 @@ private static void attach(LiteralArgumentBuilder<ServerCommandSource> node, Str
String name = ctx.getArgument("name", String.class);

if (player.getGameProfile().getName().equalsIgnoreCase(name)) {
player.sendMessage(Text.literal("You are always a " + id + "!").formatted(Formatting.RED));
Messages.sendMessage("You are always a " + id + "!", Messages.ERROR, player);
return Command.SINGLE_SUCCESS;
}

resolveUUID(player.getServerWorld(), name, uuid -> {
if (uuid == null) {
player.sendMessage(Text.literal("Could not find player with name " + name).formatted(Formatting.RED));
Messages.sendMessage("Could not find player with name "+ name, Messages.ERROR, player);
return;
}

Set<UUID> contributors = getMap.apply(space.info);
if (contributors.contains(uuid)) {
player.sendMessage(Text.literal("Player " + name + " is already a " + id).formatted(Formatting.RED));
Messages.sendMessage("Player " + name + " is already a " + id, Messages.ERROR, player);
return;
}
contributors.add(uuid);
player.sendMessage(Text.literal("Added " + name + " as " + id).formatted(Formatting.AQUA));
Messages.sendMessage("Added " + name + " as " + id, Messages.SUCCESS, player);
});

return Command.SINGLE_SUCCESS;
Expand All @@ -109,19 +111,19 @@ private static void attach(LiteralArgumentBuilder<ServerCommandSource> node, Str
String name = ctx.getArgument("name", String.class);

if (player.getGameProfile().getName().equalsIgnoreCase(name)) {
player.sendMessage(Text.literal("You cannot remove yourself!").formatted(Formatting.RED));
Messages.sendMessage("You cannot remove yourself!", Messages.ERROR, player);
return Command.SINGLE_SUCCESS;
}

resolveUUID(player.getServerWorld(), name, uuid -> {
if (uuid == null) {
player.sendMessage(Text.literal("Could not find player with name " + name).formatted(Formatting.RED));
Messages.sendMessage("Could not find player with name " + name, Messages.ERROR, player);
return;
}

Set<UUID> contributors = getMap.apply(space.info);
if (!contributors.contains(uuid)) {
player.sendMessage(Text.literal("Player " + name + " is not a " + id).formatted(Formatting.RED));
Messages.sendMessage("Player " + name + " is not a " + id, Messages.ERROR, player);
return;
}
contributors.remove(uuid);
Expand All @@ -137,7 +139,7 @@ private static void attach(LiteralArgumentBuilder<ServerCommandSource> node, Str
}
}

player.sendMessage(Text.literal("Removed " + name + " as " + id).formatted(Formatting.AQUA));
Messages.sendMessage("Removed " + name + " as " + id, Messages.SUCCESS, player);
});

return Command.SINGLE_SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import de.blazemcworld.fireflow.messages.Messages;
import de.blazemcworld.fireflow.space.Space;
import de.blazemcworld.fireflow.util.DummyPlayer;
import net.minecraft.server.command.CommandManager;
Expand All @@ -24,7 +25,7 @@ public static void register(CommandDispatcher<ServerCommandSource> cd) {
if (!CommandHelper.isDeveloperOrOwner(player, space)) return Command.SINGLE_SUCCESS;

if (space.dummyManager.getDummy(id) != null) {
player.sendMessage(Text.literal("That dummy has already been spawned!").formatted(Formatting.RED));
Messages.sendMessage("That dummy has already been spawned!", Messages.ERROR, player);
return Command.SINGLE_SUCCESS;
}

Expand All @@ -43,7 +44,7 @@ public static void register(CommandDispatcher<ServerCommandSource> cd) {

DummyPlayer dummy = space.dummyManager.getDummy(id);
if (dummy == null) {
player.sendMessage(Text.literal("That dummy has not been spawned!").formatted(Formatting.RED));
Messages.sendMessage("That dummy has not been spawned!", Messages.ERROR, player);
return Command.SINGLE_SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import de.blazemcworld.fireflow.messages.Messages;
import de.blazemcworld.fireflow.space.Lobby;
import de.blazemcworld.fireflow.util.ModeManager;
import net.minecraft.server.command.CommandManager;
Expand All @@ -24,7 +25,7 @@ private static void register(CommandDispatcher<ServerCommandSource> cd, String a
if (player == null) return Command.SINGLE_SUCCESS;

if (player.getServerWorld() == Lobby.world) {
player.sendMessage(Text.literal("You are already in the lobby!").formatted(Formatting.RED));
Messages.sendMessage("You are already in the lobby!", Messages.ERROR, player);
return Command.SINGLE_SUCCESS;
}

Expand Down
Loading