Finalize adding the TP commands

This commit is contained in:
Zontreck 2022-10-04 23:25:05 -07:00
parent 75c0a26183
commit b51cd270d4
14 changed files with 420 additions and 81 deletions

View file

@ -7,7 +7,7 @@ plugins {
version = '1.3.1'
version = '1.3.2'
group = 'dev.zontreck.otemod' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'otemod'
@ -156,7 +156,7 @@ jar {
attributes([
"Specification-Title" : "otemod",
"Specification-Vendor" : "Zontreck",
"Specification-Version" : "1.3.1", // We are version 1 of ourselves
"Specification-Version" : "1.3.2", // We are version 1 of ourselves
"Implementation-Title" : project.name,
"Implementation-Version" : project.jar.archiveVersion,
"Implementation-Vendor" : "Zontreck",

View file

@ -37,16 +37,7 @@ import org.slf4j.Logger;
import dev.zontreck.otemod.blocks.ModBlocks;
import dev.zontreck.otemod.chat.ChatColor;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.commands.DelHomeCommand;
import dev.zontreck.otemod.commands.FlyCommand;
import dev.zontreck.otemod.commands.HomeCommand;
import dev.zontreck.otemod.commands.HomesCommand;
import dev.zontreck.otemod.commands.SetHomeCommand;
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.CommandRegistry;
import dev.zontreck.otemod.commands.teleport.TeleportContainer;
import dev.zontreck.otemod.configs.OTEServerConfig;
import dev.zontreck.otemod.configs.Profile;
@ -72,7 +63,7 @@ public class OTEMod
public static MinecraftServer THE_SERVER;
private static boolean ALIVE;
public static boolean DEVELOPER=true;
public OTEMod()
{
@ -94,6 +85,7 @@ public class OTEMod
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(new EventHandler());
MinecraftForge.EVENT_BUS.register(new ChatServerOverride());
MinecraftForge.EVENT_BUS.register(new CommandRegistry());
ModBlocks.register(bus);
ModItems.register(bus);
@ -157,25 +149,6 @@ public class OTEMod
//LOGGER.info("DIRT BLOCK >> {}", ForgeRegistries.BLOCKS.getKey(Blocks.DIRT));
}
@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());
PrefixColorCommand.register(ev.getDispatcher());
PrefixCommand.register(ev.getDispatcher());
NickCommand.register(ev.getDispatcher());
}
// You can use SubscribeEvent and let the Event Bus discover methods to call
@SubscribeEvent
public void onServerStarting(ServerStartingEvent event)
@ -203,7 +176,7 @@ public class OTEMod
" `z` varchar(20) NOT NULL," +
" `rot_x` varchar(20) NOT NULL," +
" `rot_y` varchar(20) NOT NULL," +
" `dimension` varchar(25) NOT NULL)");
" `dimension` varchar(255) NOT NULL)"); // 10/04/2022 - fix dimension column size due to a bug where mods might have long names!
lookup.execute("CREATE TABLE IF NOT EXISTS `profiles` ("+
"`username` varchar (255) not null,"+
@ -243,6 +216,8 @@ public class OTEMod
}
}
}
OTEMod.LOGGER.info("Tearing down OTEMod teleport queue - The server is going down");
}
});
th.start();

View file

@ -0,0 +1,45 @@
package dev.zontreck.otemod.commands;
import dev.zontreck.otemod.OTEMod;
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.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 net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
@EventBusSubscriber(modid=OTEMod.MOD_ID,bus=Mod.EventBusSubscriber.Bus.FORGE)
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());
PrefixColorCommand.register(ev.getDispatcher());
PrefixCommand.register(ev.getDispatcher());
NickCommand.register(ev.getDispatcher());
TPACommand.register(ev.getDispatcher());
TPCancelCommand.register(ev.getDispatcher());
TPDenyCommand.register(ev.getDispatcher());
TPAcceptCommand.register(ev.getDispatcher());
TPAHereCommand.register(ev.getDispatcher());
}
}

View file

@ -16,6 +16,8 @@ import com.mojang.math.Vector3d;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatColor;
import dev.zontreck.otemod.commands.teleport.TeleportActioner;
import dev.zontreck.otemod.commands.teleport.TeleportContainer;
import dev.zontreck.otemod.configs.PlayerFlyCache;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
@ -123,51 +125,15 @@ public class HomeCommand {
return 1;
}
MobEffectInstance inst = new MobEffectInstance(MobEffects.DARKNESS, 200, 1, true, true);
MobEffectInstance regen = new MobEffectInstance(MobEffects.REGENERATION, 200, 1, true, true);
MobEffectInstance invul = new MobEffectInstance(MobEffects.LEVITATION, 75, 1, true, true);
p.addEffect(inst);
p.addEffect(regen);
p.addEffect(invul); // 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!!!)
// Send boss bar
TeleportActioner.ApplyTeleportEffect(p);
// Instantiate a Teleport Runner
final ServerPlayer f_p = p;
final Vec3 f_pos = position;
final Vec2 f_rot = rot;
final ServerLevel f_dim = dimL;
Thread t = new Thread(new Runnable() {
public void run()
{
try {
Thread.sleep(3000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
PlayerFlyCache c = PlayerFlyCache.cachePlayer(f_p);
f_p.teleportTo(f_dim, f_pos.x, f_pos.y, f_pos.z, f_rot.y, f_rot.x);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
c.Assert(f_p);
f_p.setPos(f_pos);
}
});
t.start();
TeleportContainer cont = new TeleportContainer(f_p, f_pos, f_rot, f_dim);
TeleportActioner.PerformTeleport(cont);
}
if(!has_home)throw new SQLException("NO HOME");

View file

@ -13,6 +13,7 @@ import com.mojang.brigadier.context.CommandContext;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatColor;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.chat.Clickable;
import dev.zontreck.otemod.chat.HoverTip;
import net.minecraft.ChatFormatting;
@ -63,7 +64,7 @@ public class HomesCommand {
for (String string : homes) {
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));
ctx.getSource().sendSystemMessage(Component.literal(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));
ChatServerOverride.broadcastTo(ctx.getSource().getPlayer().getUUID(), Component.literal(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 (SQLException e) {

View file

@ -1,4 +1,4 @@
package dev.zontreck.otemod.commands;
package dev.zontreck.otemod.commands.teleport;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.ArgumentType;
@ -9,7 +9,6 @@ import dev.zontreck.otemod.chat.ChatColor;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.chat.Clickable;
import dev.zontreck.otemod.chat.HoverTip;
import dev.zontreck.otemod.commands.teleport.TeleportContainer;
import dev.zontreck.otemod.configs.Profile;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
@ -38,6 +37,12 @@ public class TPACommand {
source.sendFailure(Component.literal(ChatColor.DARK_RED+"Error: Player not found"));
return 1;
}
if(!OTEMod.DEVELOPER){
if(source.getPlayer().getUUID() == serverPlayer.getUUID()){
source.sendFailure(Component.literal(ChatColor.DARK_RED+"You cannot teleport to yourself!"));
return 1;
}
}
TeleportContainer cont = new TeleportContainer(source.getPlayer().getUUID(), serverPlayer.getUUID());
for(TeleportContainer cont2 : OTEMod.TeleportRegistry){
@ -53,7 +58,7 @@ public class TPACommand {
}
ClickEvent ce = Clickable.command("tpcancel");
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);
@ -62,9 +67,9 @@ public class TPACommand {
ChatServerOverride.broadcastTo(cont.FromPlayer, Component.literal(ChatColor.BOLD + ChatColor.DARK_GREEN +"TPA Request Sent! ").append(Component.literal(ChatColor.BOLD+ChatColor.DARK_GRAY+"["+ChatColor.DARK_RED+"X"+ChatColor.DARK_GRAY+"]").setStyle(s)), serverPlayer.server);
ce = Clickable.command("tpaccept");
ce = Clickable.command("/tpaccept "+cont.TeleportID.toString());
he = HoverTip.get(ChatColor.DARK_GREEN + "Accept tp request");
ClickEvent ce2 = Clickable.command("tpdeny");
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);
@ -75,11 +80,12 @@ public class TPACommand {
append(Component.literal(ChatColor.DARK_GRAY+"["+ChatColor.DARK_GREEN+"ACCEPT" + ChatColor.DARK_GRAY+"] ").setStyle(s)).
append(Component.literal(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(Component.literal("/tpa USAGE\n\n\t"+ChatColor.BOLD + ChatColor.DARK_GRAY+"/tpa "+ChatColor.DARK_RED+"target_player\n"), false);
source.sendSuccess(Component.literal("/tpa USAGE\n\n "+ChatColor.BOLD + ChatColor.DARK_GRAY+"/tpa "+ChatColor.DARK_RED+"target_player\n"), false);
return 0;
}
}

View file

@ -0,0 +1,91 @@
package dev.zontreck.otemod.commands.teleport;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatColor;
import dev.zontreck.otemod.chat.ChatServerOverride;
import dev.zontreck.otemod.chat.Clickable;
import dev.zontreck.otemod.chat.HoverTip;
import dev.zontreck.otemod.configs.Profile;
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.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
if(serverPlayer == null){
source.sendFailure(Component.literal(ChatColor.DARK_RED+"Error: Player not found"));
return 1;
}
if(!OTEMod.DEVELOPER){
if(source.getPlayer().getUUID() == serverPlayer.getUUID()){
source.sendFailure(Component.literal(ChatColor.DARK_RED+"You cannot teleport to yourself!"));
return 1;
}
}
TeleportContainer cont = new TeleportContainer(serverPlayer.getUUID(), source.getPlayer().getUUID());
for(TeleportContainer cont2 : OTEMod.TeleportRegistry){
if(cont2.compareTo(cont)==0){
ChatServerOverride.broadcastTo(cont.ToPlayer, Component.literal(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, Component.literal(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, Component.literal(ChatColor.BOLD + ChatColor.DARK_GREEN +"TPA Request Sent! ").append(Component.literal(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 = Profile.get_profile_of(cont.ToPlayer.toString());
ChatServerOverride.broadcastTo(cont.FromPlayer, Component.literal(p.name_color+p.nickname + ChatColor.BOLD + ChatColor.DARK_PURPLE+" is requesting you to teleport to them\n \n").
append(Component.literal(ChatColor.DARK_GRAY+"["+ChatColor.DARK_GREEN+"ACCEPT" + ChatColor.DARK_GRAY+"] ").setStyle(s)).
append(Component.literal(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(Component.literal("/tpa USAGE\n\n "+ChatColor.BOLD + ChatColor.DARK_GRAY+"/tpa "+ChatColor.DARK_RED+"target_player\n"), false);
return 0;
}
}

View file

@ -0,0 +1,64 @@
package dev.zontreck.otemod.commands.teleport;
import java.util.UUID;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatColor;
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.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);
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 = Component.literal(ChatColor.DARK_GRAY + "["+ ChatColor.DARK_GREEN+ "OTEMOD" + ChatColor.DARK_GRAY+"] " + 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 = Component.literal(ChatColor.DARK_RED+"The teleport was not found, perhaps the request expired or was already cancelled/denied");
ChatServerOverride.broadcastTo(source.getPlayer().getUUID(), comp, source.getServer());
return 0;
}
}

View file

@ -0,0 +1,50 @@
package dev.zontreck.otemod.commands.teleport;
import java.util.UUID;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatColor;
import dev.zontreck.otemod.chat.ChatServerOverride;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
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);
for(TeleportContainer cont : OTEMod.TeleportRegistry){
if(cont.TeleportID.equals(teleporter)){
// Canceling!
Component comp = Component.literal(ChatColor.DARK_GRAY + "["+ ChatColor.DARK_GREEN+ "OTEMOD" + ChatColor.DARK_GRAY+"] " + 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 = Component.literal(ChatColor.DARK_RED+"The teleport was not found, perhaps the request expired or was already cancelled");
ChatServerOverride.broadcastTo(source.getPlayer().getUUID(), comp, source.getServer());
return 0;
}
}

View file

@ -0,0 +1,50 @@
package dev.zontreck.otemod.commands.teleport;
import java.util.UUID;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.chat.ChatColor;
import dev.zontreck.otemod.chat.ChatServerOverride;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
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);
for(TeleportContainer cont : OTEMod.TeleportRegistry){
if(cont.TeleportID.equals(teleporter)){
// Canceling!
Component comp = Component.literal(ChatColor.DARK_GRAY + "["+ ChatColor.DARK_GREEN+ "OTEMOD" + ChatColor.DARK_GRAY+"] " + 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 = Component.literal(ChatColor.DARK_RED+"The teleport was not found, perhaps the request expired or was already cancelled/denied");
ChatServerOverride.broadcastTo(source.getPlayer().getUUID(), comp, source.getServer());
return 0;
}
}

View file

@ -0,0 +1,28 @@
package dev.zontreck.otemod.commands.teleport;
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);
Thread t = new Thread(new TeleportRunnable(contain));
t.start();
}
public static void ApplyTeleportEffect(ServerPlayer player){
MobEffectInstance inst = new MobEffectInstance(MobEffects.DARKNESS, 200, 1, true, true);
MobEffectInstance regen = new MobEffectInstance(MobEffects.REGENERATION, 200, 1, true, true);
MobEffectInstance invul = new MobEffectInstance(MobEffects.LEVITATION, 75, 1, true, true);
player.addEffect(inst);
player.addEffect(regen);
player.addEffect(invul); // 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

@ -3,10 +3,25 @@ package dev.zontreck.otemod.commands.teleport;
import java.time.Instant;
import java.util.UUID;
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;
/*
* 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)))
@ -19,10 +34,22 @@ public class TeleportContainer implements Comparable{
{
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);
}
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;
}
@Override
public int compareTo(Object o) {
if(o instanceof TeleportContainer){

View file

@ -0,0 +1,36 @@
package dev.zontreck.otemod.commands.teleport;
import dev.zontreck.otemod.configs.PlayerFlyCache;
public class TeleportRunnable implements Runnable
{
public final TeleportContainer Action;
public TeleportRunnable(TeleportContainer cont){
Action = cont;
}
@Override
public void run() {
try {
Thread.sleep(3000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
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);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
c.Assert(Action.PlayerInst);
Action.PlayerInst.setPos(Action.Position);
}
}

View file

@ -19,7 +19,7 @@ modId="otemod" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
# see the associated build.gradle script for how to populate this completely automatically during a build
version="1.3.1" #mandatory
version="1.3.2" #mandatory
# A display name for the mod
displayName="OTEMod Resources" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/