Switch over various components

This commit is contained in:
Aria 2023-03-05 15:25:49 -07:00
parent 45796de812
commit 4437104c19
73 changed files with 202 additions and 2516 deletions

View file

@ -5,29 +5,14 @@ import java.util.HashMap;
import java.util.Map;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.commands.homes.DelHomeCommand;
import dev.zontreck.otemod.commands.homes.HomeCommand;
import dev.zontreck.otemod.commands.homes.HomesCommand;
import dev.zontreck.otemod.commands.homes.SetHomeCommand;
import dev.zontreck.otemod.commands.items.ShareItemInChatCommand;
import dev.zontreck.otemod.commands.profilecmds.ChatColorCommand;
import dev.zontreck.otemod.commands.profilecmds.NameColorCommand;
import dev.zontreck.otemod.commands.profilecmds.NickCommand;
import dev.zontreck.otemod.commands.profilecmds.PrefixColorCommand;
import dev.zontreck.otemod.commands.profilecmds.PrefixCommand;
import dev.zontreck.otemod.commands.teleport.RTPCommand;
import dev.zontreck.otemod.commands.teleport.TPACommand;
import dev.zontreck.otemod.commands.teleport.TPAHereCommand;
import dev.zontreck.otemod.commands.teleport.TPAcceptCommand;
import dev.zontreck.otemod.commands.teleport.TPCancelCommand;
import dev.zontreck.otemod.commands.teleport.TPDenyCommand;
import dev.zontreck.otemod.commands.vaults.TrashCommand;
import dev.zontreck.otemod.commands.vaults.VaultCommand;
import dev.zontreck.otemod.commands.warps.DelWarpCommand;
import dev.zontreck.otemod.commands.warps.RTPWarpCommand;
import dev.zontreck.otemod.commands.warps.SetWarpCommand;
import dev.zontreck.otemod.commands.warps.WarpCommand;
import dev.zontreck.otemod.commands.warps.WarpsCommand;
import dev.zontreck.otemod.commands.zschem.LoadSchem;
import dev.zontreck.otemod.commands.zschem.Place;
import dev.zontreck.otemod.commands.zschem.PlaceAsAir;
@ -99,12 +84,6 @@ public class CommandRegistry {
@SubscribeEvent
public void onRegisterCommands(final RegisterCommandsEvent ev)
{
HomesCommand.register(ev.getDispatcher());
SetHomeCommand.register(ev.getDispatcher());
HomeCommand.register(ev.getDispatcher());
DelHomeCommand.register(ev.getDispatcher());
//FlyCommand.register(ev.getDispatcher());
ChatColorCommand.register(ev.getDispatcher());
NameColorCommand.register(ev.getDispatcher());
@ -113,23 +92,10 @@ public class CommandRegistry {
NickCommand.register(ev.getDispatcher());
TPACommand.register(ev.getDispatcher());
TPCancelCommand.register(ev.getDispatcher());
TPDenyCommand.register(ev.getDispatcher());
TPAcceptCommand.register(ev.getDispatcher());
TPAHereCommand.register(ev.getDispatcher());
RTPCommand.register(ev.getDispatcher());
VaultCommand.register(ev.getDispatcher());
TrashCommand.register(ev.getDispatcher());
SetWarpCommand.register(ev.getDispatcher());
DelWarpCommand.register(ev.getDispatcher());
RTPWarpCommand.register(ev.getDispatcher());
WarpsCommand.register(ev.getDispatcher());
WarpCommand.register(ev.getDispatcher());
SetPos1.register(ev.getDispatcher());
SetPos2.register(ev.getDispatcher());
SaveSchem.register(ev.getDispatcher());

View file

@ -1,48 +0,0 @@
package dev.zontreck.otemod.commands.homes;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.implementation.profiles.Profile;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.network.chat.TextComponent;
public class DelHomeCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("rmhome").executes(c->rmHome(c.getSource(), "default")).then(Commands.argument("nickname", StringArgumentType.string()).executes(c -> rmHome(c.getSource(), StringArgumentType.getString(c, "nickname")))));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int rmHome(CommandSourceStack ctx, String homeName)
{
// Request homes
// String homeName = "";
// CommandSourceStack ctx = ctx2.getSource();
// homeName = StringArgumentType.getString(ctx2, "nickname");
// if(homeName==null)return 0;
try{
ServerPlayer p = ctx.getPlayerOrException();
Profile prof = Profile.get_profile_of(p.getStringUUID());
prof.player_homes.delete(homeName);
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors("!dark_green! Home was deleted successfully")), ctx.getServer());
}catch(Exception e)
{
e.printStackTrace();
ChatServerOverride.broadcastTo(ctx.getEntity().getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors("!dark_red! Home could not be deleted due to an unknown error")), ctx.getServer());
}
return 0;
}
}

View file

@ -1,68 +0,0 @@
package dev.zontreck.otemod.commands.homes;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.commands.teleport.TeleportActioner;
import dev.zontreck.otemod.commands.teleport.TeleportContainer;
import dev.zontreck.otemod.database.TeleportDestination;
import dev.zontreck.otemod.implementation.homes.Home;
import dev.zontreck.otemod.implementation.homes.NoSuchHomeException;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.network.chat.TextComponent;
public class HomeCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("home").executes(c-> home(c.getSource(), "default")).then(Commands.argument("nickname", StringArgumentType.string()).executes(c -> home(c.getSource(), StringArgumentType.getString(c, "nickname")))));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int home(CommandSourceStack ctx, String homeName)
{
// Request homes
// String homeName = "";
// CommandSourceStack ctx = ctx2.getSource();
// homeName = StringArgumentType.getString(ctx2, "nickname");
// if(homeName==null)return 0;
try{
ServerPlayer p = ctx.getPlayerOrException();
Profile prof = Profile.get_profile_of(p.getStringUUID());
Home home = prof.player_homes.get(homeName);
TeleportDestination dest = home.destination;
TeleportActioner.ApplyTeleportEffect(p);
TeleportContainer cont = new TeleportContainer(p, dest.Position.asMinecraftVector(), dest.Rotation.asMinecraftVector(), dest.getActualDimension());
TeleportActioner.PerformTeleport(cont);
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !dark_green!Home found! Wormhole opening now...")), ctx.getServer());
}catch(CommandSyntaxException e)
{
e.printStackTrace();
return 1;
}catch(NoSuchHomeException e)
{
ChatServerOverride.broadcastTo(ctx.getEntity().getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !dark_red!Home not found. Maybe it does not exist?")), ctx.getServer());
return 0;
} catch (UserProfileNotYetExistsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
}

View file

@ -1,65 +0,0 @@
package dev.zontreck.otemod.commands.homes;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.Clickable;
import dev.zontreck.libzontreck.chat.HoverTip;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.implementation.homes.Home;
import dev.zontreck.otemod.implementation.homes.Homes;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextComponent;
public class HomesCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("homes").executes(HomesCommand::getHomes));
}
private static int getHomes(CommandContext<CommandSourceStack> ctx)
{
// Request homes
try{
ServerPlayer player = ctx.getSource().getPlayerOrException();
Profile p = Profile.get_profile_of(player.getStringUUID());
Homes homes = p.player_homes;
ChatServerOverride.broadcastTo(player.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !Dark_Purple!There are !gold!"+String.valueOf(homes.count())+" !dark_purple!total homes.")), player.server);
for (Home string : homes.getList()) {
Style st = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(HoverTip.get(ChatColor.BOLD+ChatColor.DARK_GREEN+"Click here to go to this home")).withClickEvent(Clickable.command("/home "+string.homeName));
ChatServerOverride.broadcastTo(player.getUUID(), new TextComponent(ChatColor.BOLD + ChatColor.MINECOIN_GOLD+"["+ChatColor.resetChat()+ChatColor.UNDERLINE+ChatColor.BOLD+ChatColor.DARK_GREEN+"HOME"+ChatColor.resetChat()+ChatColor.BOLD+ChatColor.MINECOIN_GOLD+"] "+ChatColor.resetChat()+ChatColor.YELLOW+string).setStyle(st), ctx.getSource().getServer());
}
}catch(CommandSyntaxException ex)
{
ex.printStackTrace();
} catch (UserProfileNotYetExistsException e) {
e.printStackTrace();
}
return 0;
}
}

View file

@ -1,77 +0,0 @@
package dev.zontreck.otemod.commands.homes;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.vectors.Vector2;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.database.TeleportDestination;
import dev.zontreck.otemod.implementation.homes.Home;
import dev.zontreck.otemod.implementation.homes.Homes;
import dev.zontreck.otemod.implementation.homes.HomesProvider;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import net.minecraft.network.chat.TextComponent;
public class SetHomeCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("sethome").executes(c->setHome(c.getSource(), "default")).then(Commands.argument("nickname", StringArgumentType.string()).executes(c -> setHome(c.getSource(), StringArgumentType.getString(c, "nickname")))));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int setHome(CommandSourceStack ctx, String homeName)
{
// Request homes
// String homeName = "";
// CommandSourceStack ctx = ctx2.getSource();
// homeName = StringArgumentType.getString(ctx2, "nickname");
// if(homeName==null)return 0;
ServerPlayer p;
try {
p = ctx.getPlayerOrException();
Vec3 position = p.position();
Vec2 rot = p.getRotationVector();
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel());
Home newhome = new Home(p, homeName, dest);
Profile profile = Profile.get_profile_of(p.getStringUUID());
Homes homes = profile.player_homes;
homes.add(newhome);
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !dark_green!Home was created or updated successfully!")), ctx.getServer());
} catch (CommandSyntaxException e) {
ChatServerOverride.broadcastTo(ctx.getEntity().getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !dark_red!Home could not be created or updated!")), ctx.getServer());
e.printStackTrace();
} catch (UserProfileNotYetExistsException e) {
ChatServerOverride.broadcastTo(ctx.getEntity().getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !dark_red!Home could not be created or updated!")), ctx.getServer());
e.printStackTrace();
}
return 0;
}
}

View file

@ -4,10 +4,10 @@ import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.HoverTip;
import dev.zontreck.libzontreck.profiles.Profile;
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.MutableComponent;
@ -54,7 +54,7 @@ public class ShareItemInChatCommand {
Style style = Style.EMPTY.withFont(Style.DEFAULT_FONT);
component = component.withStyle(style.withHoverEvent(HoverTip.getItem(is)));
ChatServerOverride.broadcast(component, OTEMod.THE_SERVER);
ChatHelpers.broadcast(component, OTEMod.THE_SERVER);
}else {
return 1;

View file

@ -2,11 +2,12 @@ package dev.zontreck.otemod.commands.profilecmds;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.LibZontreck;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.ChatColor.ColorOptions;
import dev.zontreck.libzontreck.profiles.Profile;
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
@ -51,7 +52,7 @@ public class ChatColorCommand {
}
p.chat_color = colorcoded;
p.commit();
OTEMod.PROFILES.put(play.getStringUUID(), p);
LibZontreck.PROFILES.put(play.getStringUUID(), p);
source.sendSuccess(new TextComponent(OTEMod.OTEPrefix + " "+ChatColor.DARK_PURPLE + "Your chat color has been updated"), false);

View file

@ -2,11 +2,12 @@ package dev.zontreck.otemod.commands.profilecmds;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.LibZontreck;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.ChatColor.ColorOptions;
import dev.zontreck.libzontreck.profiles.Profile;
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
@ -51,7 +52,7 @@ public class NameColorCommand {
}
p.name_color = colorcoded;
p.commit();
OTEMod.PROFILES.put(play.getStringUUID(), p);
LibZontreck.PROFILES.put(play.getStringUUID(), p);
source.sendSuccess(new TextComponent(OTEMod.OTEPrefix+ " "+ChatColor.DARK_PURPLE + "Your name color has been updated"), false);

View file

@ -3,10 +3,11 @@ package dev.zontreck.otemod.commands.profilecmds;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.libzontreck.LibZontreck;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.profiles.Profile;
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
@ -47,7 +48,7 @@ public class NickCommand {
}
p.nickname = string;
p.commit();
OTEMod.PROFILES.put(play.getStringUUID(), p);
LibZontreck.PROFILES.put(play.getStringUUID(), p);
source.sendSuccess(new TextComponent(OTEMod.OTEPrefix+ " "+ChatColor.DARK_PURPLE + "Your nickname has been updated"), false);

View file

@ -2,14 +2,14 @@ package dev.zontreck.otemod.commands.profilecmds;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.LibZontreck;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.ChatColor.ColorOptions;
import dev.zontreck.libzontreck.profiles.Profile;
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
@ -52,7 +52,7 @@ public class PrefixColorCommand {
}
p.prefix_color = colorcoded;
p.commit();
OTEMod.PROFILES.put(play.getStringUUID(), p);
LibZontreck.PROFILES.put(play.getStringUUID(), p);
source.sendSuccess(new TextComponent(OTEMod.OTEPrefix+ " "+ChatColor.DARK_PURPLE + "Your prefix color has been updated"), false);

View file

@ -3,10 +3,11 @@ package dev.zontreck.otemod.commands.profilecmds;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.libzontreck.LibZontreck;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.profiles.Profile;
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
@ -47,7 +48,7 @@ public class PrefixCommand {
}
p.prefix = string;
p.commit();
OTEMod.PROFILES.put(play.getStringUUID(), p);
LibZontreck.PROFILES.put(play.getStringUUID(), p);
source.sendSuccess(new TextComponent(OTEMod.OTEPrefix+ " "+ChatColor.DARK_PURPLE + "Your prefix has been updated"), false);

View file

@ -1,92 +0,0 @@
package dev.zontreck.otemod.commands.teleport;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3;
public class RTPCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("rtp").executes(c->rtp(c.getSource())));
//executes(c -> doCancel(c.getSource())));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int rtp(CommandSourceStack source) {
/*if(!CommandRegistry.canUse("rtp")) {
ChatServerOverride.broadcastTo(source.getPlayer().getUUID(), Component.translatable("dev.zontreck.otemod.msgs.command_cooling_down").append(Component.literal(""+CommandRegistry.getRemaining("rtp"))).append(Component.translatable("dev.zontreck.otemod.msgs.command_cooling_down_seconds")), source.getServer());
// exit
//return 0; // Removed until the player data registry is implemented
}
CommandRegistry.markUsed("rtp");*/
if(!(source.getEntity() instanceof Player)){
return 1;
}
final ServerPlayer pla = (ServerPlayer)source.getEntity();
final TeleportContainer cont = new TeleportContainer(pla, Vec3.ZERO, pla.getRotationVector(), source.getLevel());
Thread tx = new Thread(new Runnable() {
@Override
public void run(){
// We can now execute the loop to search for a safe spot!
Vector3 v = new Vector3();
// RTP is not designed to be safe really, but we at least want to check if where we are putting the player is air
Vec3 pos = pla.position();
boolean found_place= false;
RTPContainer container = RandomPositionFactory.beginRTPSearch(pla, pos, pla.getRotationVector(), pla.getLevel());
while(!container.complete)
{
if(!OTEMod.ALIVE)
{
container.aborted=true;
container.containingThread.interrupt();
return;
}
if(container.tries>30)
{
// abort!
return;
}
}
v = container.container.world_pos.Position;
ChatServerOverride.broadcastTo(pla.getUUID(), new TextComponent(ChatColor.DARK_GRAY + "["+ChatColor.DARK_GREEN + "OTEMOD" + ChatColor.DARK_GRAY + "] "+ChatColor.DARK_PURPLE+" A suitable location has been found. Wormhole opening now!"), OTEMod.THE_SERVER);
// Apply the effect
TeleportActioner.ApplyTeleportEffect(pla);
cont.Position=v.asMinecraftVector();
TeleportActioner.PerformTeleport(cont);
}
});
tx.start();
return 0;
}
}

View file

@ -1,154 +0,0 @@
package dev.zontreck.otemod.commands.teleport;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Stream;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
public class RTPContainer {
public TeleportContainer container;
public int tries = -1;
public boolean complete = false;
public boolean aborted=false;
public Thread containingThread;
private Types heightMapType;
private int SearchDirection;
public static final List<Block> BLACKLIST;
static {
List<Block> tmp = new ArrayList<>();
tmp.add(Blocks.LAVA);
tmp.add(Blocks.BEDROCK);
tmp.add(Blocks.WATER);
BLACKLIST = tmp;
}
public void moveDown() {
container.world_pos.Position = container.world_pos.Position.moveDown();
container.Position = container.world_pos.Position.asMinecraftVector();
}
public void moveUp() {
container.world_pos.Position = container.world_pos.Position.moveUp();
container.Position = container.world_pos.Position.asMinecraftVector();
}
public void move()
{
if(SearchDirection==1){
moveUp();
}else if(SearchDirection==0)
{
moveDown();
}
}
public void moveOpposite()
{
if(SearchDirection==1){
moveDown();
}else if(SearchDirection==0)
{
moveUp();
}
}
public void newPosition() {
if(!OTEMod.ALIVE)return;
containingThread=Thread.currentThread();
Random rng = new Random(Instant.now().getEpochSecond());
Vector3 pos = new Vector3(rng.nextDouble(0xFFFF), 0, rng.nextDouble(0xFFFF));
BlockPos bpos = pos.asBlockPos();
container.Dimension.getChunk(bpos.getX() >> 4, bpos.getZ() >> 4, ChunkStatus.HEIGHTMAPS);
pos = new Vector3(
container.Dimension.getHeightmapPos(heightMapType, pos.asBlockPos()));
while (!container.Dimension.getWorldBorder().isWithinBounds(pos.asBlockPos())) {
pos = new Vector3(rng.nextDouble(0xffff), 0, rng.nextDouble(0xffff));
bpos = pos.asBlockPos();
container.Dimension.getChunk(bpos.getX() >> 4, bpos.getZ() >> 4, ChunkStatus.HEIGHTMAPS);
pos = new Vector3(
container.Dimension.getHeightmapPos(heightMapType, pos.asBlockPos()));
}
container.world_pos.Position = pos;
container.Position = container.world_pos.Position.asMinecraftVector();
if (pos.y < -60) {
newPosition();
return;
}
if (pos.y >= container.Dimension.getLogicalHeight()) {
spiralPositions(pos);
}
tries++;
}
private void spiralPositions(Vector3 position)
{
for(BlockPos pos : BlockPos.spiralAround(new BlockPos(position.x, container.Dimension.getSeaLevel(), position.z), 16, Direction.WEST, Direction.NORTH)){
if(isSafe(pos)){
// Set the new position
container.world_pos.Position = new Vector3(pos);
container.Position = container.world_pos.Position.asMinecraftVector();
return;
}
}
}
protected RTPContainer(ServerPlayer player, Vec3 pos, Vec2 rot, ServerLevel level) {
container = new TeleportContainer(player, pos, rot, level);
if(container.Dimension.dimensionType().hasCeiling())
{
heightMapType = Heightmap.Types.MOTION_BLOCKING_NO_LEAVES;
SearchDirection=-1;
}else {
heightMapType = Types.MOTION_BLOCKING_NO_LEAVES;
SearchDirection=1;
}
newPosition();
}
public boolean isSafe(BlockPos blockPos) {
containingThread=Thread.currentThread();
BlockState b = container.Dimension.getBlockState(blockPos);
BlockState b2 = container.Dimension.getBlockState(blockPos.above());
BlockState b3 = container.Dimension.getBlockState(blockPos.below());
if (b.isAir() && b2.isAir()) {
if (!b3.isAir()) {
if (BLACKLIST.contains(b3.getBlock())) {
return false;
} else
return true;
} else
return false;
} else
return false;
}
}

View file

@ -1,23 +0,0 @@
package dev.zontreck.otemod.commands.teleport;
import dev.zontreck.otemod.implementation.DelayedExecutorService;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
/**
* The factory system used to start searching for a random teleport position
*/
public class RandomPositionFactory {
public static RTPContainer beginRTPSearch(ServerPlayer player, Vec3 pos, Vec2 rot, ServerLevel level)
{
RTPContainer contain= new RTPContainer(player, pos, rot, level);
Thread tx = new Thread(new RandomPositionLocator(contain));
tx.setName("RTPTask-"+String.valueOf(DelayedExecutorService.getNext()));
tx.start();
return contain;
}
}

View file

@ -1,92 +0,0 @@
package dev.zontreck.otemod.commands.teleport;
import java.util.Iterator;
import java.util.concurrent.ScheduledExecutorService;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.events.RTPEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraftforge.common.MinecraftForge;
/**
* This class aims to serve as the Random Position Locate system
* It aims to be as non-thread blocking as possible to avoid server lag
*
* To utilize, initialize a RTPContainer from the RandomPositionFactory and execute from there.
*/
public class RandomPositionLocator implements Runnable
{
private final RTPContainer contain;
public RandomPositionLocator(RTPContainer rtp)
{
contain=rtp;
}
@Override
public void run() {
if(!OTEMod.ALIVE)return;
ChatServerOverride.broadcastTo(contain.container.PlayerInst.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !Dark_Purple!Searching... Attempt "+String.valueOf(contain.tries)+"/30")), OTEMod.THE_SERVER);
ServerLevel levl = contain.container.Dimension;
ChunkAccess chunk = levl.getChunk(contain.container.world_pos.Position.asBlockPos());
ChunkPos cpos = chunk.getPos();
boolean needsLoading = false;
needsLoading = !(levl.getForcedChunks().contains(cpos.toLong()));
if(needsLoading)
levl.setChunkForced(cpos.x, cpos.z, true);
int curChecks=0;
while(curChecks<30)
{
if(contain.isSafe(contain.container.world_pos.Position.asBlockPos()))
{
contain.complete=true;
if(needsLoading)
levl.setChunkForced(cpos.x, cpos.z, false);
if(MinecraftForge.EVENT_BUS.post(new RTPEvent(contain.container.PlayerInst, contain.container.world_pos)))
{
contain.complete=false;
ChatServerOverride.broadcastTo(contain.container.PlayerInst.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !Dark_Red!Last position checked was probably claimed. Another mod has asked us not to send you to that location, continuing the search")), OTEMod.THE_SERVER);
break;
}
return;
}else {
curChecks++;
contain.move();
OTEMod.LOGGER.info("[DEBUG] "+ChatColor.doColors("!Dark_Red!Checking position: "+contain.container.world_pos.Position.toString()+"; "+contain.container.Dimension.getBlockState(contain.container.world_pos.Position.asBlockPos()).getBlock().toString()+"; "+contain.container.Dimension.getBlockState(contain.container.world_pos.Position.asBlockPos().below()).getBlock().toString()));
}
}
if(needsLoading)
levl.setChunkForced(cpos.x, cpos.z, false);
contain.newPosition();
if(contain.tries > 30)
{
// Abort
ChatServerOverride.broadcastTo(contain.container.PlayerInst.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !Dark_Red!Could not find a suitable location in 30 attempts")), OTEMod.THE_SERVER);
contain.aborted=true;
return;
}else {
// Schedule the task to execute
//run();
RandomPositionLocator next = new RandomPositionLocator(contain);
OTEMod.delayedExecutor.schedule(next, 2);
}
}
}

View file

@ -1,98 +0,0 @@
package dev.zontreck.otemod.commands.teleport;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.Clickable;
import dev.zontreck.libzontreck.chat.HoverTip;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerPlayer;
public class TPACommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("tpa").executes(c->usage(c.getSource())).then(Commands.argument("player", EntityArgument.player()).executes(c -> tpa(c.getSource(), EntityArgument.getPlayer(c, "player")))));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int tpa(CommandSourceStack source, ServerPlayer serverPlayer) {
// Send the request to player
if(serverPlayer == null){
source.sendFailure(new TextComponent(ChatColor.DARK_RED+"Error: Player not found"));
return 1;
}
ServerPlayer play = (ServerPlayer)source.getEntity();
if(!OTEMod.DEVELOPER){
if(play.getUUID() == serverPlayer.getUUID()){
source.sendFailure(new TextComponent(ChatColor.DARK_RED+"You cannot teleport to yourself!"));
return 1;
}
}
TeleportContainer cont = new TeleportContainer(play.getUUID(), serverPlayer.getUUID());
for(TeleportContainer cont2 : OTEMod.TeleportRegistry){
if(cont2.compareTo(cont)==0){
ChatServerOverride.broadcastTo(cont.FromPlayer, new TextComponent(ChatColor.DARK_RED+ "You already have a TPA Request active, wait for it to expire, or use the cancel button/command"), source.getServer());
return 0;
}else {
if(cont2.FromPlayer == cont.FromPlayer){
ChatServerOverride.broadcastTo(cont.FromPlayer, new TextComponent(ChatColor.DARK_RED+ "You already have a TPA Request active, wait for it to expire, or use the cancel button/command"), source.getServer());
return 0;
}
}
}
ClickEvent ce = Clickable.command("/tpcancel "+cont.TeleportID.toString());
HoverEvent he = HoverTip.get(ChatColor.DARK_GREEN+"Cancel this teleport request (Not yet implemented)");
Style s = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(he).withClickEvent(ce);
// Send the alerts
ChatServerOverride.broadcastTo(cont.FromPlayer, new TextComponent(ChatColor.BOLD + ChatColor.DARK_GREEN +"TPA Request Sent! ").append(new TextComponent(ChatColor.BOLD+ChatColor.DARK_GRAY+"["+ChatColor.DARK_RED+"X"+ChatColor.DARK_GRAY+"]").setStyle(s)), serverPlayer.server);
ce = Clickable.command("/tpaccept "+cont.TeleportID.toString());
he = HoverTip.get(ChatColor.DARK_GREEN + "Accept tp request");
ClickEvent ce2 = Clickable.command("/tpdeny "+cont.TeleportID.toString());
HoverEvent he2 = HoverTip.get(ChatColor.DARK_RED+"Deny this request");
s = Style.EMPTY.withFont(Style.DEFAULT_FONT).withClickEvent(ce).withHoverEvent(he);
Style s2 = Style.EMPTY.withFont(Style.DEFAULT_FONT).withClickEvent(ce2).withHoverEvent(he2);
Profile p;
try {
p = Profile.get_profile_of(cont.FromPlayer.toString());
} catch (UserProfileNotYetExistsException e) {
return 1;
}
ChatServerOverride.broadcastTo(cont.ToPlayer, new TextComponent(p.name_color+p.nickname + ChatColor.BOLD + ChatColor.DARK_PURPLE+" is requesting to teleport to you\n \n").
append(new TextComponent(ChatColor.DARK_GRAY+"["+ChatColor.DARK_GREEN+"ACCEPT" + ChatColor.DARK_GRAY+"] ").setStyle(s)).
append(new TextComponent(ChatColor.DARK_GRAY + "["+ChatColor.DARK_RED+"DENY"+ChatColor.DARK_GRAY+"]").setStyle(s2)), serverPlayer.server);
OTEMod.TeleportRegistry.add(cont);
return 0;
}
private static int usage(CommandSourceStack source) {
source.sendSuccess(new TextComponent("/tpa USAGE\n\n "+ChatColor.BOLD + ChatColor.DARK_GRAY+"/tpa "+ChatColor.DARK_RED+"target_player\n"), false);
return 0;
}
}

View file

@ -1,98 +0,0 @@
package dev.zontreck.otemod.commands.teleport;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.Clickable;
import dev.zontreck.libzontreck.chat.HoverTip;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerPlayer;
public class TPAHereCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("tpahere").executes(c->usage(c.getSource())).then(Commands.argument("player", EntityArgument.player()).executes(c -> tpa(c.getSource(), EntityArgument.getPlayer(c, "player")))));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int tpa(CommandSourceStack source, ServerPlayer serverPlayer) {
// Send the request to player
ServerPlayer play = (ServerPlayer)source.getEntity();
if(serverPlayer == null){
source.sendFailure(new TextComponent(ChatColor.DARK_RED+"Error: Player not found"));
return 1;
}
if(!OTEMod.DEVELOPER){
if(play.getUUID() == serverPlayer.getUUID()){
source.sendFailure(new TextComponent(ChatColor.DARK_RED+"You cannot teleport to yourself!"));
return 1;
}
}
TeleportContainer cont = new TeleportContainer(serverPlayer.getUUID(), play.getUUID());
for(TeleportContainer cont2 : OTEMod.TeleportRegistry){
if(cont2.compareTo(cont)==0){
ChatServerOverride.broadcastTo(cont.ToPlayer, new TextComponent(ChatColor.DARK_RED+ "You already have a TPA Request active, wait for it to expire, or use the cancel button/command"), source.getServer());
return 0;
}else {
if(cont2.ToPlayer.equals(cont.ToPlayer)){
ChatServerOverride.broadcastTo(cont.FromPlayer, new TextComponent(ChatColor.DARK_RED+ "You already have a TPA Request active, wait for it to expire, or use the cancel button/command"), source.getServer());
return 0;
}
}
}
ClickEvent ce = Clickable.command("/tpcancel "+cont.TeleportID.toString());
HoverEvent he = HoverTip.get(ChatColor.DARK_GREEN+"Cancel this teleport request (Not yet implemented)");
Style s = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(he).withClickEvent(ce);
// Send the alerts
ChatServerOverride.broadcastTo(cont.ToPlayer, new TextComponent(ChatColor.BOLD + ChatColor.DARK_GREEN +"TPA Request Sent! ").append(new TextComponent(ChatColor.BOLD+ChatColor.DARK_GRAY+"["+ChatColor.DARK_RED+"X"+ChatColor.DARK_GRAY+"]").setStyle(s)), serverPlayer.server);
ce = Clickable.command("/tpaccept "+cont.TeleportID.toString());
he = HoverTip.get(ChatColor.DARK_GREEN + "Accept tp request");
ClickEvent ce2 = Clickable.command("/tpdeny "+cont.TeleportID.toString());
HoverEvent he2 = HoverTip.get(ChatColor.DARK_RED+"Deny this request");
s = Style.EMPTY.withFont(Style.DEFAULT_FONT).withClickEvent(ce).withHoverEvent(he);
Style s2 = Style.EMPTY.withFont(Style.DEFAULT_FONT).withClickEvent(ce2).withHoverEvent(he2);
Profile p;
try {
p = Profile.get_profile_of(cont.ToPlayer.toString());
} catch (UserProfileNotYetExistsException e) {
return 1;
}
ChatServerOverride.broadcastTo(cont.FromPlayer, new TextComponent(p.name_color+p.nickname + ChatColor.BOLD + ChatColor.DARK_PURPLE+" is requesting you to teleport to them\n \n").
append(new TextComponent(ChatColor.DARK_GRAY+"["+ChatColor.DARK_GREEN+"ACCEPT" + ChatColor.DARK_GRAY+"] ").setStyle(s)).
append(new TextComponent(ChatColor.DARK_GRAY + "["+ChatColor.DARK_RED+"DENY"+ChatColor.DARK_GRAY+"]").setStyle(s2)), serverPlayer.server);
OTEMod.TeleportRegistry.add(cont);
return 0;
}
private static int usage(CommandSourceStack source) {
source.sendSuccess(new TextComponent("/tpa USAGE\n\n "+ChatColor.BOLD + ChatColor.DARK_GRAY+"/tpa "+ChatColor.DARK_RED+"target_player\n"), false);
return 0;
}
}

View file

@ -1,67 +0,0 @@
package dev.zontreck.otemod.commands.teleport;
import java.util.UUID;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerPlayer;
public class TPAcceptCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("tpaccept").then(Commands.argument("TeleportUUID", StringArgumentType.string()).executes(c->doCancel(c.getSource(), StringArgumentType.getString(c, "TeleportUUID")))));
//executes(c -> doCancel(c.getSource())));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int doCancel(CommandSourceStack source, String TPID) {
UUID teleporter = UUID.fromString(TPID);
ServerPlayer play = (ServerPlayer)source.getEntity();
for(TeleportContainer cont : OTEMod.TeleportRegistry){
if(cont.TeleportID.equals(teleporter)){
// Accepting!
ServerPlayer from = source.getServer().getPlayerList().getPlayer(cont.FromPlayer);
ServerPlayer to = source.getServer().getPlayerList().getPlayer(cont.ToPlayer);
Component comp = new TextComponent(OTEMod.OTEPrefix + " " + ChatColor.DARK_PURPLE+"Teleport request was accepted. Opening wormhole!");
ChatServerOverride.broadcastTo(cont.FromPlayer, comp, source.getServer());
ChatServerOverride.broadcastTo(cont.ToPlayer, comp, source.getServer());
OTEMod.TeleportRegistry.remove(cont);
cont.PlayerInst = from;
cont.Position = to.position();
cont.Rotation = to.getRotationVector();
cont.Dimension = to.getLevel();
TeleportActioner.ApplyTeleportEffect(from);
TeleportActioner.PerformTeleport(cont);
return 0;
}
}
Component comp = new TextComponent(ChatColor.DARK_RED+"The teleport was not found, perhaps the request expired or was already cancelled/denied");
ChatServerOverride.broadcastTo(play.getUUID(), comp, source.getServer());
return 0;
}
}

View file

@ -1,54 +0,0 @@
package dev.zontreck.otemod.commands.teleport;
import java.util.UUID;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerPlayer;
public class TPCancelCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("tpcancel").then(Commands.argument("TeleportUUID", StringArgumentType.string()).executes(c->doCancel(c.getSource(), StringArgumentType.getString(c, "TeleportUUID")))));
//executes(c -> doCancel(c.getSource())));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int doCancel(CommandSourceStack source, String TPID) {
UUID teleporter = UUID.fromString(TPID);
ServerPlayer play = (ServerPlayer)source.getEntity();
for(TeleportContainer cont : OTEMod.TeleportRegistry){
if(cont.TeleportID.equals(teleporter)){
// Canceling!
Component comp = new TextComponent(OTEMod.OTEPrefix + " " + ChatColor.DARK_PURPLE+"Teleport request was cancelled");
ChatServerOverride.broadcastTo(cont.FromPlayer, comp, source.getServer());
ChatServerOverride.broadcastTo(cont.ToPlayer, comp, source.getServer());
OTEMod.TeleportRegistry.remove(cont);
return 0;
}
}
Component comp = new TextComponent(ChatColor.DARK_RED+"The teleport was not found, perhaps the request expired or was already cancelled");
ChatServerOverride.broadcastTo(play.getUUID(), comp, source.getServer());
return 0;
}
}

View file

@ -1,54 +0,0 @@
package dev.zontreck.otemod.commands.teleport;
import java.util.UUID;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerPlayer;
public class TPDenyCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("tpdeny").then(Commands.argument("TeleportUUID", StringArgumentType.string()).executes(c->doCancel(c.getSource(), StringArgumentType.getString(c, "TeleportUUID")))));
//executes(c -> doCancel(c.getSource())));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int doCancel(CommandSourceStack source, String TPID) {
UUID teleporter = UUID.fromString(TPID);
ServerPlayer play = (ServerPlayer)source.getEntity();
for(TeleportContainer cont : OTEMod.TeleportRegistry){
if(cont.TeleportID.equals(teleporter)){
// Canceling!
Component comp = new TextComponent(OTEMod.OTEPrefix + " " + ChatColor.DARK_PURPLE+"Teleport request was denied");
ChatServerOverride.broadcastTo(cont.FromPlayer, comp, source.getServer());
ChatServerOverride.broadcastTo(cont.ToPlayer, comp, source.getServer());
OTEMod.TeleportRegistry.remove(cont);
return 0;
}
}
Component comp = new TextComponent(ChatColor.DARK_RED+"The teleport was not found, perhaps the request expired or was already cancelled/denied");
ChatServerOverride.broadcastTo(play.getUUID(), comp, source.getServer());
return 0;
}
}

View file

@ -1,39 +0,0 @@
package dev.zontreck.otemod.commands.teleport;
import dev.zontreck.otemod.OTEMod;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
public class TeleportActioner
{
public static void PerformTeleport(TeleportContainer contain){
//sub_runnable run = new sub_runnable(contain);
OTEMod.delayedExecutor.schedule(new TeleportRunnable(contain), 2);
}
public static void ApplyTeleportEffect(ServerPlayer player){
// 10/05/2022 - Thinking ahead here to future proof it so i can do things in threads safely
// By adding this task onto the main server thread, any thread can call the TeleportActioner and it will be actioned on the main thread without needing to repeat the process of sending this to the server thread.
player.server.execute(new Runnable(){
public void run(){
MobEffectInstance inst = new MobEffectInstance(MobEffects.BLINDNESS, 250, 1, true, true);
// 02/26/2023 - Adjusted to 400 due to 1.18.2, the teleport is slightly more delayed, and thus a regen is needed incase levitation runs out too soon
MobEffectInstance regen = new MobEffectInstance(MobEffects.REGENERATION, 400, 2, true, true);
// 10-05-2022 - Adjusted to 100 on duration due to a small issue where it would sometimes stop levitation prior to the teleport taking effect.
// 02/26/2023 - Adjusted to 200 on duration due to 1.18.2 causing levitation to run out too quickly before teleport
// Small tradeoff is the player now levitates slightly longer at the destination. This is acceptable. Compensated by increasing regen strength by 1
MobEffectInstance levitate = new MobEffectInstance(MobEffects.LEVITATION, 200, 1, true, true);
player.addEffect(inst);
player.addEffect(regen);
player.addEffect(levitate); // ensure the player can't fall into lava in the short time we are not in control (if the player was silly enough to make a home above lava!!!)
}
});
}
}

View file

@ -1,71 +0,0 @@
package dev.zontreck.otemod.commands.teleport;
import java.time.Instant;
import java.util.UUID;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.libzontreck.vectors.WorldPosition;
import dev.zontreck.otemod.OTEMod;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
public class TeleportContainer implements Comparable{
public UUID FromPlayer;
public UUID ToPlayer;
public long StartedAt;
public UUID TeleportID;
public WorldPosition world_pos;
/*
* The following variables are only used when actioning the teleport itself, and should only be initialized once the teleport is about to engage
*/
public ServerPlayer PlayerInst;
public Vec3 Position;
public Vec2 Rotation;
public ServerLevel Dimension;
public boolean has_expired(){
if(Instant.now().getEpochSecond() > (StartedAt + (60)))
{
return true;
}else return false;
}
public TeleportContainer (UUID From, UUID To)
{
FromPlayer = From;
ToPlayer=To;
TeleportID = UUID.randomUUID();
StartedAt = Instant.now().getEpochSecond();
}
public TeleportContainer(ServerPlayer f_p, Vec3 f_pos, Vec2 f_rot, ServerLevel f_dim) {
SetTeleportDestination(f_p, f_pos, f_rot, f_dim);
world_pos = new WorldPosition(new Vector3(f_pos), f_dim);
}
private void SetTeleportDestination(ServerPlayer f_p, Vec3 f_pos, Vec2 f_rot, ServerLevel f_dim) {
PlayerInst = f_p;
Position = f_pos;
Rotation = f_rot;
Dimension = f_dim;
world_pos = new WorldPosition(new Vector3(f_pos), f_dim);
}
@Override
public int compareTo(Object o) {
if(o instanceof TeleportContainer){
TeleportContainer cont = (TeleportContainer)o;
if(cont.FromPlayer != FromPlayer){
return -1;
}else {
if(cont.ToPlayer != ToPlayer)return 1;
else return 0;
}
}else return -1;
}
}

View file

@ -1,32 +0,0 @@
package dev.zontreck.otemod.commands.teleport;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.PlayerFlyCache;
import dev.zontreck.otemod.implementation.DelayedExecutorService;
public class TeleportRunnable implements Runnable
{
public final TeleportContainer Action;
public TeleportRunnable(TeleportContainer cont){
Action = cont;
}
@Override
public void run() {
final PlayerFlyCache c = PlayerFlyCache.cachePlayer(Action.PlayerInst);
Action.PlayerInst.teleportTo(Action.Dimension, Action.Position.x, Action.Position.y, Action.Position.z, Action.Rotation.y, Action.Rotation.x);
OTEMod.delayedExecutor.schedule(new Runnable(){
public PlayerFlyCache cached = c;
public TeleportContainer container=Action;
@Override
public void run()
{
c.Assert(container.PlayerInst);
container.PlayerInst.setPos(container.Position);
container.PlayerInst.giveExperiencePoints(1);
}
}, 1);
}
}

View file

@ -3,13 +3,12 @@ package dev.zontreck.otemod.commands.vaults;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.implementation.vault.NoMoreVaultException;
import dev.zontreck.otemod.implementation.vault.VaultContainer;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.SimpleMenuProvider;
@ -36,7 +35,7 @@ public class TrashCommand {
try {
container = new VaultContainer(play, -1);
} catch (NoMoreVaultException e) {
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You cannot open anymore vaults. Craft a new vault!")), play.server);
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You cannot open anymore vaults. Craft a new vault!")), play.server);
return 0;
}

View file

@ -4,20 +4,15 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.vault.NoMoreVaultException;
import dev.zontreck.otemod.implementation.vault.Vault;
import dev.zontreck.otemod.implementation.vault.VaultContainer;
import dev.zontreck.otemod.implementation.vault.VaultProvider;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.SimpleMenuProvider;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.network.NetworkHooks;
public class VaultCommand {
@ -39,7 +34,7 @@ public class VaultCommand {
ServerPlayer play = (ServerPlayer)source.getEntity();
if(i <0)
{
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(ChatColor.doColors(OTEMod.OTEPrefix+" !Dark_Red!You can only specify a vault number in the positive range")), source.getServer());
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(ChatColor.doColors(OTEMod.OTEPrefix+" !Dark_Red!You can only specify a vault number in the positive range")), source.getServer());
return 0;
}
doOpen(play, i);
@ -54,7 +49,7 @@ public class VaultCommand {
try {
container = new VaultContainer(p, i);
} catch (NoMoreVaultException e) {
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You cannot open anymore vaults. Craft a new vault!")), p.server);
ChatHelpers.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You cannot open anymore vaults. Craft a new vault!")), p.server);
return;
}

View file

@ -1,69 +0,0 @@
package dev.zontreck.otemod.commands.warps;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.vectors.Vector2;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.database.TeleportDestination;
import dev.zontreck.otemod.implementation.warps.NoSuchWarpException;
import dev.zontreck.otemod.implementation.warps.Warp;
import dev.zontreck.otemod.implementation.warps.WarpsProvider;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
public class DelWarpCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("delwarp").then(Commands.argument("nickname", StringArgumentType.string()).executes(c -> setWarp(c.getSource(), StringArgumentType.getString(c, "nickname")))));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int setWarp(CommandSourceStack source, String string) {
ServerPlayer p = (ServerPlayer)source.getEntity();
Warp warp;
try {
warp = WarpsProvider.WARPS_INSTANCE.getNamedWarp(string);
} catch (NoSuchWarpException e) {
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!That warp does not exist")), p.server);
return 0;
}
if(p.getUUID().equals(warp.owner) || p.hasPermissions(5))
{
try {
WarpsProvider.WARPS_INSTANCE.delete(WarpsProvider.WARPS_INSTANCE.getNamedWarp(string));
} catch (NoSuchWarpException e) {
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!That warp does not exist")), p.server);
return 0;
}
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Warp deleted successfully")), p.server);
}else {
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!Warp could not be deleted, because you do not own the warp.")), p.server);
}
return 0;
}
}

View file

@ -1,55 +0,0 @@
package dev.zontreck.otemod.commands.warps;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.vectors.Vector2;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.database.TeleportDestination;
import dev.zontreck.otemod.implementation.warps.Warp;
import dev.zontreck.otemod.implementation.warps.WarpsProvider;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
public class RTPWarpCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("rtpwarp").then(Commands.argument("nickname", StringArgumentType.string()).executes(c -> setWarp(c.getSource(), StringArgumentType.getString(c, "nickname")))));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int setWarp(CommandSourceStack source, String string) {
ServerPlayer p = (ServerPlayer)source.getEntity();
Vec3 position = p.position();
Vec2 rot = p.getRotationVector();
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel());
Warp warp = new Warp(p.getUUID(), string, true, true, dest);
WarpsProvider.WARPS_INSTANCE.add(warp);
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Random Position Teleport (RTP) Warp created successfully")), p.server);
return 0;
}
}

View file

@ -1,55 +0,0 @@
package dev.zontreck.otemod.commands.warps;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.vectors.Vector2;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.database.TeleportDestination;
import dev.zontreck.otemod.implementation.warps.Warp;
import dev.zontreck.otemod.implementation.warps.WarpsProvider;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
public class SetWarpCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("setwarp").then(Commands.argument("nickname", StringArgumentType.string()).executes(c -> setWarp(c.getSource(), StringArgumentType.getString(c, "nickname")))));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int setWarp(CommandSourceStack source, String string) {
ServerPlayer p = (ServerPlayer)source.getEntity();
Vec3 position = p.position();
Vec2 rot = p.getRotationVector();
TeleportDestination dest = new TeleportDestination(new Vector3(position), new Vector2(rot), p.getLevel());
Warp w = new Warp(p.getUUID(), string, false, true, dest);
WarpsProvider.WARPS_INSTANCE.add(w);
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Warp created successfully")), p.server);
return 0;
}
}

View file

@ -1,124 +0,0 @@
package dev.zontreck.otemod.commands.warps;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Iterator;
import java.util.List;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.Clickable;
import dev.zontreck.libzontreck.exceptions.InvalidSideException;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.commands.teleport.RTPCommand;
import dev.zontreck.otemod.commands.teleport.RTPContainer;
import dev.zontreck.otemod.commands.teleport.RandomPositionFactory;
import dev.zontreck.otemod.commands.teleport.TeleportActioner;
import dev.zontreck.otemod.commands.teleport.TeleportContainer;
import dev.zontreck.otemod.database.TeleportDestination;
import dev.zontreck.otemod.implementation.warps.NoSuchWarpException;
import dev.zontreck.otemod.implementation.warps.Warp;
import dev.zontreck.otemod.implementation.warps.WarpsProvider;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
public class WarpCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("warp").executes(c-> nowarp(c.getSource())).then(Commands.argument("name", StringArgumentType.string()).executes(c->warp(c.getSource(), StringArgumentType.getString(c, "name")))));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int warp(CommandSourceStack source, String string) {
final ServerPlayer p;
try{
p=source.getPlayerOrException();
Warp warp = WarpsProvider.WARPS_INSTANCE.getNamedWarp(string);
TeleportDestination dest = warp.destination;
ServerLevel dimL=(ServerLevel) dest.getActualDimension();
final int type = warp.RTP ? 1 : 0;
final ServerLevel f_dim = dimL;
if(type == 1)
{
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ ChatColor.doColors(" !Dark_Green!Attempting to locate a safe location. This may take a minute or two")), p.server);
}else{
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ ChatColor.doColors(" !Dark_Purple!Warping!")), p.server);
}
Thread tx = new Thread(new Runnable(){
public void run(){
if(type==1){
try {
dest.Position = Vector3.ZERO;
RTPContainer cont = RandomPositionFactory.beginRTPSearch(p, Vec3.ZERO, Vec2.ZERO, f_dim);
while(!cont.complete)
{
if(!OTEMod.ALIVE)
{
cont.aborted=true;
cont.containingThread.interrupt();
return;
}
if(cont.tries>30)
{
return;
}
}
dest.Position = cont.container.world_pos.Position;
//RTPCommand.findPosition(source.getLevel(), false, p.getUUID());
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Location found, warping!")), p.server);
} catch (Exception e) {
e.printStackTrace();
return;
}
}
TeleportActioner.ApplyTeleportEffect(p);
TeleportContainer tc = new TeleportContainer(p, dest.Position.asMinecraftVector(), dest.Rotation.asMinecraftVector(), f_dim);
TeleportActioner.PerformTeleport(tc);
}
});
tx.start();
}catch(NoSuchWarpException e)
{
ChatServerOverride.broadcastTo(source.getEntity().getUUID(), new TextComponent(ChatColor.DARK_RED+"No such warp"), source.getServer());
} catch (CommandSyntaxException e) {
e.printStackTrace();
}
return 0;
}
private static int nowarp(CommandSourceStack source) {
ServerPlayer p = (ServerPlayer)source.getEntity();
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(ChatColor.DARK_RED + "You must supply the warp name. If you need to know what warps are available, please use the warps command, or click this message.").withStyle(Style.EMPTY.withFont(Style.DEFAULT_FONT).withClickEvent(Clickable.command("/warps"))), source.getServer());
return 0;
}
}

View file

@ -1,90 +0,0 @@
package dev.zontreck.otemod.commands.warps;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.Clickable;
import dev.zontreck.libzontreck.chat.HoverTip;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.implementation.profiles.Profile;
import dev.zontreck.otemod.implementation.profiles.UserProfileNotYetExistsException;
import dev.zontreck.otemod.implementation.warps.Warp;
import dev.zontreck.otemod.implementation.warps.WarpsProvider;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.level.ServerPlayer;
public class WarpsCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("warps").executes(c-> warps(c.getSource())));
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
//String arg = StringArgumentType.getString(command, "nickname");
//return setHome(command.getSource(), arg);
//}));
}
private static int warps(CommandSourceStack source) {
ServerPlayer p = (ServerPlayer)source.getEntity();
Map<String, Warp> warps = WarpsProvider.WARPS_INSTANCE.get();
ChatServerOverride.broadcastTo(p.getUUID(), new TextComponent(OTEMod.OTEPrefix + " "+ChatColor.resetChat() + "There are "+warps.size()+" warps available"), source.getServer());
Iterator<Entry<String, Warp>> it = warps.entrySet().iterator();
while(it.hasNext())
{
// TODO: Implement public and private. Private requires an ACL be implemented. New GUI
Warp warp = it.next().getValue();
// Pull the owner profile
Profile prof=null;
try {
prof = Profile.get_profile_of(warp.owner.toString());
} catch (UserProfileNotYetExistsException e) {
e.printStackTrace();
return 1;
}
String warpName = warp.WarpName;
int warpType = 0;
if(warp.RTP) warpType=1;
String appendType = (warpType == 0) ? "standard warp." : "RTP Warp. This has a position randomizer.";
HoverEvent hover = HoverTip.get(ChatColor.BOLD + ChatColor.DARK_PURPLE + "This warp is a "+appendType);
ClickEvent click = Clickable.command("/warp "+warpName);
Style S = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(hover).withClickEvent(click);
Component warpMsg = new TextComponent(ChatColor.GREEN + warpName + ChatColor.resetChat()).withStyle(S);
// Now, display the warp name, along with the warp's owner information
HoverEvent h2 = HoverTip.get(prof.name_color+prof.nickname+ChatColor.resetChat()+ChatColor.AQUA+" is the owner of this warp");
S = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(h2);
Component ownerInfo = new TextComponent(ChatColor.GOLD+ " [Hover to see the warp's info]").withStyle(S);
// Combine the two
warpMsg = new TextComponent("").append(warpMsg).append(ownerInfo);
ChatServerOverride.broadcastTo(p.getUUID(), warpMsg, source.getServer());
}
return 0;
}
}

View file

@ -11,10 +11,10 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.libzontreck.vectors.WorldPosition;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.integrations.LuckPermsHelper;
import dev.zontreck.otemod.permissions.Permissions;
import dev.zontreck.otemod.zschem.MemoryHolder;
@ -115,17 +115,17 @@ public class LoadSchem {
MemoryHolder.setBlocks(play, blocks);
}else {
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !Dark_Red!No such ZSchem exists!")), source.getServer());
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix + ChatColor.doColors(" !Dark_Red!No such ZSchem exists!")), source.getServer());
return 0;
}
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!ZSchem loaded from disk!")), OTEMod.THE_SERVER);
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!ZSchem loaded from disk!")), OTEMod.THE_SERVER);
return 0;
}
}
}
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(ChatColor.doColors("!Dark_Red! You must set the first position")), OTEMod.THE_SERVER);
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(ChatColor.doColors("!Dark_Red! You must set the first position")), OTEMod.THE_SERVER);
return 0;
}
@ -136,7 +136,7 @@ public class LoadSchem {
usage += ChatColor.doColors("!gold! /loadzschem [string:name]");
ServerPlayer play=(ServerPlayer)source.getEntity();
if(play==null)return 1;
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(usage), OTEMod.THE_SERVER);
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(usage), OTEMod.THE_SERVER);
return 0;
}
}

View file

@ -6,6 +6,7 @@ import java.util.List;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.integrations.LuckPermsHelper;
@ -45,7 +46,7 @@ public class Place {
if(!MemoryHolder.hasPlayerCached(play)){
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You must first load the zschem!")), OTEMod.THE_SERVER);
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You must first load the zschem!")), OTEMod.THE_SERVER);
return 1;
}
@ -66,13 +67,13 @@ public class Place {
}else {
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You must first load the zschem!")), OTEMod.THE_SERVER);
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You must first load the zschem!")), OTEMod.THE_SERVER);
return 1;
}
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Enqueued!")), OTEMod.THE_SERVER);
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Enqueued!")), OTEMod.THE_SERVER);
return 0;
}

View file

@ -7,6 +7,7 @@ import java.util.List;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
@ -48,7 +49,7 @@ public class PlaceAsAir {
if(!MemoryHolder.hasPlayerCached(play)){
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You must first set the positions!")), OTEMod.THE_SERVER);
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You must first set the positions!")), OTEMod.THE_SERVER);
return 1;
}
@ -73,13 +74,13 @@ public class PlaceAsAir {
}else {
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You must first set the positions!")), OTEMod.THE_SERVER);
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Red!You must first set the positions!")), OTEMod.THE_SERVER);
return 1;
}
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Enqueued!")), OTEMod.THE_SERVER);
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Enqueued!")), OTEMod.THE_SERVER);
return 0;
}

View file

@ -10,6 +10,7 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
@ -107,12 +108,12 @@ public class SaveSchem {
} catch (IOException e) {
e.printStackTrace();
}
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!ZSchem saved to disk!")), OTEMod.THE_SERVER);
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!ZSchem saved to disk!")), OTEMod.THE_SERVER);
return 0;
}
}
}
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(ChatColor.doColors("!Dark_Red! You must first set the positions")), OTEMod.THE_SERVER);
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(ChatColor.doColors("!Dark_Red! You must first set the positions")), OTEMod.THE_SERVER);
return 0;
}
@ -123,7 +124,7 @@ public class SaveSchem {
usage += ChatColor.doColors("!gold! /savezschem [string:name]");
ServerPlayer play=(ServerPlayer)source.getEntity();
if(play==null)return 1;
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(usage), OTEMod.THE_SERVER);
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(usage), OTEMod.THE_SERVER);
return 0;
}
}

View file

@ -3,6 +3,7 @@ package dev.zontreck.otemod.commands.zschem;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
@ -39,7 +40,7 @@ public class SetPos1 {
MemoryHolder.setPos1(play, new Vector3(source.getPosition()));
MemoryHolder.setLevel(play, source.getLevel());
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Position 1 set!")), OTEMod.THE_SERVER);
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Position 1 set!")), OTEMod.THE_SERVER);
return 0;
}

View file

@ -3,6 +3,7 @@ package dev.zontreck.otemod.commands.zschem;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
@ -39,7 +40,7 @@ public class SetPos2 {
MemoryHolder.setPos2(play, new Vector3(source.getPosition()));
MemoryHolder.setLevel(play, source.getLevel());
ChatServerOverride.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Position 2 set!")), OTEMod.THE_SERVER);
ChatHelpers.broadcastTo(play.getUUID(), new TextComponent(OTEMod.OTEPrefix+ChatColor.doColors(" !Dark_Green!Position 2 set!")), OTEMod.THE_SERVER);
return 0;
}