Fix tp commands

This commit is contained in:
Aria 2023-02-27 16:23:29 -07:00
parent 603952e185
commit 8b013b7baa
9 changed files with 76 additions and 70 deletions

View file

@ -1,7 +1,13 @@
package dev.zontreck.essentials.commands.teleport;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.essentials.AriasEssentials;
import dev.zontreck.essentials.Messages;
import dev.zontreck.essentials.util.RTPContainer;
import dev.zontreck.essentials.util.RandomPositionFactory;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.libzontreck.vectors.Vector3;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
@ -55,7 +61,7 @@ public class RTPCommand {
RTPContainer container = RandomPositionFactory.beginRTPSearch(pla, pos, pla.getRotationVector(), pla.getLevel());
while(!container.complete)
{
if(!OTEMod.ALIVE)
if(!AriasEssentials.ALIVE)
{
container.aborted=true;
container.containingThread.interrupt();
@ -70,7 +76,7 @@ public class RTPCommand {
}
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);
ChatHelpers.broadcastTo(pla.getUUID(), new TextComponent(Messages.ESSENTIALS_PREFIX + ChatColor.DARK_PURPLE+" A suitable location has been found. Wormhole opening now!"), pla.server);
// Apply the effect
TeleportActioner.ApplyTeleportEffect(pla);

View file

@ -5,6 +5,9 @@ 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.libzontreck.profiles.Profile;
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
import dev.zontreck.libzontreck.util.ChatHelpers;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
@ -35,21 +38,22 @@ public class TPACommand {
}
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;
}
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){
for(TeleportContainer cont2 : TeleportRegistry.get()){
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());
ChatHelpers.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());
ChatHelpers.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;
}
}
@ -62,7 +66,7 @@ public class TPACommand {
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);
ChatHelpers.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());
@ -79,11 +83,11 @@ public class TPACommand {
} 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").
ChatHelpers.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);
TeleportRegistry.get().add(cont);
return 0;
}

View file

@ -5,10 +5,9 @@ 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.libzontreck.profiles.Profile;
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
import dev.zontreck.libzontreck.util.ChatHelpers;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
@ -39,21 +38,20 @@ public class TPAHereCommand {
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;
}
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){
for(TeleportContainer cont2 : TeleportRegistry.get()){
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());
ChatHelpers.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());
ChatHelpers.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;
}
}
@ -66,7 +64,7 @@ public class TPAHereCommand {
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);
ChatHelpers.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());
@ -83,11 +81,11 @@ public class TPAHereCommand {
} 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").
ChatHelpers.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);
TeleportRegistry.get().add(cont);
return 0;
}

View file

@ -5,7 +5,9 @@ import java.util.UUID;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.essentials.Messages;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.util.ChatHelpers;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
@ -37,12 +39,12 @@ public class TPAcceptCommand {
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!");
Component comp = new TextComponent(Messages.ESSENTIALS_PREFIX + ChatColor.DARK_PURPLE+"Teleport request was accepted. Opening wormhole!");
ChatServerOverride.broadcastTo(cont.FromPlayer, comp, source.getServer());
ChatServerOverride.broadcastTo(cont.ToPlayer, comp, source.getServer());
ChatHelpers.broadcastTo(cont.FromPlayer, comp, source.getServer());
ChatHelpers.broadcastTo(cont.ToPlayer, comp, source.getServer());
OTEMod.TeleportRegistry.remove(cont);
TeleportRegistry.get().remove(cont);
cont.PlayerInst = from;
@ -58,7 +60,7 @@ public class TPAcceptCommand {
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());
ChatHelpers.broadcastTo(play.getUUID(), comp, source.getServer());
return 0;
}

View file

@ -1,13 +1,13 @@
package dev.zontreck.otemod.commands.teleport;
package dev.zontreck.essentials.commands.teleport;
import java.util.UUID;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.essentials.Messages;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.libzontreck.util.ChatHelpers;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
@ -32,22 +32,22 @@ public class TPCancelCommand {
UUID teleporter = UUID.fromString(TPID);
ServerPlayer play = (ServerPlayer)source.getEntity();
for(TeleportContainer cont : OTEMod.TeleportRegistry){
for(TeleportContainer cont : TeleportRegistry.get()){
if(cont.TeleportID.equals(teleporter)){
// Canceling!
Component comp = new TextComponent(OTEMod.OTEPrefix + " " + ChatColor.DARK_PURPLE+"Teleport request was cancelled");
Component comp = new TextComponent(Messages.ESSENTIALS_PREFIX + ChatColor.DARK_PURPLE+"Teleport request was cancelled");
ChatServerOverride.broadcastTo(cont.FromPlayer, comp, source.getServer());
ChatServerOverride.broadcastTo(cont.ToPlayer, comp, source.getServer());
ChatHelpers.broadcastTo(cont.FromPlayer, comp, source.getServer());
ChatHelpers.broadcastTo(cont.ToPlayer, comp, source.getServer());
OTEMod.TeleportRegistry.remove(cont);
TeleportRegistry.get().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());
ChatHelpers.broadcastTo(play.getUUID(), comp, source.getServer());
return 0;
}

View file

@ -1,13 +1,13 @@
package dev.zontreck.otemod.commands.teleport;
package dev.zontreck.essentials.commands.teleport;
import java.util.UUID;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.essentials.Messages;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.libzontreck.util.ChatHelpers;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
@ -32,22 +32,22 @@ public class TPDenyCommand {
UUID teleporter = UUID.fromString(TPID);
ServerPlayer play = (ServerPlayer)source.getEntity();
for(TeleportContainer cont : OTEMod.TeleportRegistry){
for(TeleportContainer cont : TeleportRegistry.get()){
if(cont.TeleportID.equals(teleporter)){
// Canceling!
Component comp = new TextComponent(OTEMod.OTEPrefix + " " + ChatColor.DARK_PURPLE+"Teleport request was denied");
Component comp = new TextComponent(Messages.ESSENTIALS_PREFIX + ChatColor.DARK_PURPLE+"Teleport request was denied");
ChatServerOverride.broadcastTo(cont.FromPlayer, comp, source.getServer());
ChatServerOverride.broadcastTo(cont.ToPlayer, comp, source.getServer());
ChatHelpers.broadcastTo(cont.FromPlayer, comp, source.getServer());
ChatHelpers.broadcastTo(cont.ToPlayer, comp, source.getServer());
OTEMod.TeleportRegistry.remove(cont);
TeleportRegistry.get().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());
ChatHelpers.broadcastTo(play.getUUID(), comp, source.getServer());
return 0;
}

View file

@ -10,6 +10,7 @@ import java.util.Random;
import java.util.stream.Stream;
import dev.zontreck.essentials.AriasEssentials;
import dev.zontreck.essentials.commands.teleport.TeleportContainer;
import dev.zontreck.libzontreck.vectors.Vector3;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;

View file

@ -1,6 +1,6 @@
package dev.zontreck.essentials.commands.teleport;
package dev.zontreck.essentials.util;
import dev.zontreck.essentials.implementation.DelayedExecutorService;
import dev.zontreck.libzontreck.util.DelayedExecutorService;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.phys.Vec2;

View file

@ -1,20 +1,15 @@
package dev.zontreck.otemod.commands.teleport;
import java.util.Iterator;
import java.util.concurrent.ScheduledExecutorService;
package dev.zontreck.essentials.util;
import dev.zontreck.essentials.AriasEssentials;
import dev.zontreck.essentials.Messages;
import dev.zontreck.essentials.events.RTPEvent;
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 dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.libzontreck.util.DelayedExecutorService;
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;
/**
@ -34,8 +29,8 @@ public class RandomPositionLocator implements Runnable
@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);
if(!AriasEssentials.ALIVE)return;
ChatHelpers.broadcastTo(contain.container.PlayerInst.getUUID(), new TextComponent(Messages.ESSENTIALS_PREFIX + ChatColor.doColors(" !Dark_Purple!Searching... Attempt "+String.valueOf(contain.tries)+"/30")), contain.container.PlayerInst.server);
ServerLevel levl = contain.container.Dimension;
ChunkAccess chunk = levl.getChunk(contain.container.world_pos.Position.asBlockPos());
@ -59,7 +54,7 @@ public class RandomPositionLocator implements Runnable
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);
ChatHelpers.broadcastTo(contain.container.PlayerInst.getUUID(), new TextComponent(Messages.ESSENTIALS_PREFIX + 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")), contain.container.PlayerInst.server);
break;
}
@ -67,7 +62,7 @@ public class RandomPositionLocator implements Runnable
}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()));
//AriasEssentials.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)
@ -78,14 +73,14 @@ public class RandomPositionLocator implements Runnable
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);
ChatHelpers.broadcastTo(contain.container.PlayerInst.getUUID(), new TextComponent(Messages.ESSENTIALS_PREFIX + ChatColor.doColors(" !Dark_Red!Could not find a suitable location in 30 attempts")), contain.container.PlayerInst.server);
contain.aborted=true;
return;
}else {
// Schedule the task to execute
//run();
RandomPositionLocator next = new RandomPositionLocator(contain);
OTEMod.delayedExecutor.schedule(next, 2);
DelayedExecutorService.getInstance().schedule(next, 2);
}
}