Add a teleport blacklist, update libac and libzon

This commit is contained in:
zontreck 2023-12-18 15:21:07 -07:00
parent 009d800648
commit 67f008956d
12 changed files with 203 additions and 29 deletions

View file

@ -3,7 +3,7 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
libzontreck=1.9.121423.1700
libzontreck=1.9.121823.1318
## Environment Properties
@ -49,7 +49,7 @@ mod_name=Aria's Essentials
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GPLv3
# The mod version. See https://semver.org/
mod_version=1.1.121623.0146
mod_version=1.1.121823.0246
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View file

@ -3,13 +3,17 @@ package dev.zontreck.essentials;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import dev.zontreck.ariaslib.util.DelayedExecutorService;
import dev.zontreck.essentials.commands.teleport.TeleportActioner;
import dev.zontreck.essentials.configs.AEClientConfig;
import dev.zontreck.essentials.configs.AEServerConfig;
import dev.zontreck.essentials.events.TeleportEvent;
import dev.zontreck.essentials.gui.HeartsRenderer;
import dev.zontreck.essentials.networking.ModMessages;
import dev.zontreck.essentials.networking.S2CUpdateHearts;
@ -41,6 +45,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@Mod(AriasEssentials.MODID)
public class AriasEssentials {
public static final String MODID = "ariasessentials";
public static final Random random = new Random(Instant.now().getEpochSecond());
public static final Logger LOGGER = LogUtils.getLogger();
public static boolean ALIVE;
public static Map<UUID, Homes> player_homes = new HashMap<>();
@ -66,6 +71,15 @@ public class AriasEssentials {
MinecraftForge.EVENT_BUS.register(new ForgeEventsHandler());
}
@SubscribeEvent
public void onTeleport(TeleportEvent event)
{
if(TeleportActioner.isBlacklistedDimension(event.getContainer().Dimension))
{
event.setCanceled(true);
}
}
public void setup(FMLCommonSetupEvent ev)
{
ModMessages.register();

View file

@ -68,6 +68,7 @@ public class Messages {
public static final String HEARTS_USAGE;
public static final String HEARTS_UPDATED;
public static final String RESPAWNING;
static{
@ -143,5 +144,7 @@ public class Messages {
HEARTS_USAGE = ESSENTIALS_PREFIX + "!Dark_Green!This command allows you to toggle on and off the compressed hearts feature without editing the config file.\n\n!Gold!/hearts [true/false]";
HEARTS_UPDATED = ESSENTIALS_PREFIX + "!Dark_Red!Your hearts preferences have been updated";
RESPAWNING = ESSENTIALS_PREFIX + "!Dark_Green!Respawning at World Spawn";
}
}

View file

@ -5,12 +5,7 @@ import dev.zontreck.essentials.commands.homes.DelHomeCommand;
import dev.zontreck.essentials.commands.homes.HomeCommand;
import dev.zontreck.essentials.commands.homes.HomesCommand;
import dev.zontreck.essentials.commands.homes.SetHomeCommand;
import dev.zontreck.essentials.commands.teleport.RTPCommand;
import dev.zontreck.essentials.commands.teleport.TPACommand;
import dev.zontreck.essentials.commands.teleport.TPAHereCommand;
import dev.zontreck.essentials.commands.teleport.TPAcceptCommand;
import dev.zontreck.essentials.commands.teleport.TPCancelCommand;
import dev.zontreck.essentials.commands.teleport.TPDenyCommand;
import dev.zontreck.essentials.commands.teleport.*;
import dev.zontreck.essentials.commands.warps.DelWarpCommand;
import dev.zontreck.essentials.commands.warps.RTPWarpCommand;
import dev.zontreck.essentials.commands.warps.SetWarpCommand;
@ -43,5 +38,6 @@ public class CommandRegister {
WarpsCommand.register(ev.getDispatcher());
HeartsCommand.register(ev.getDispatcher());
SpawnCommand.register(ev.getDispatcher());
}
}

View file

@ -10,7 +10,9 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import dev.zontreck.essentials.AriasEssentials;
import dev.zontreck.essentials.Messages;
import dev.zontreck.essentials.commands.teleport.TeleportActioner;
import dev.zontreck.essentials.commands.teleport.TeleportDestination;
import dev.zontreck.essentials.configs.AEServerConfig;
import dev.zontreck.essentials.homes.Home;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.util.ChatHelpers;
@ -45,6 +47,15 @@ public class SetHomeCommand {
ServerPlayer p;
try {
p = ctx.getPlayerOrException();
if(TeleportActioner.isBlacklistedDimension(p.serverLevel()))
{
ChatHelpers.broadcastTo(p, ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + AEServerConfig.BLACKLISTED_DIMENSION_ERROR.get()), p.server);
return 0;
}
Vec3 position = p.position();
Vec2 rot = p.getRotationVector();

View file

@ -0,0 +1,69 @@
package dev.zontreck.essentials.commands.teleport;
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.essentials.AriasEssentials;
import dev.zontreck.essentials.Messages;
import dev.zontreck.essentials.commands.teleport.TeleportActioner;
import dev.zontreck.essentials.commands.teleport.TeleportContainer;
import dev.zontreck.essentials.commands.teleport.TeleportDestination;
import dev.zontreck.essentials.configs.AEServerConfig;
import dev.zontreck.essentials.util.RTPContainer;
import dev.zontreck.essentials.util.RandomPositionFactory;
import dev.zontreck.essentials.warps.NoSuchWarpException;
import dev.zontreck.essentials.warps.Warp;
import dev.zontreck.essentials.warps.WarpsProvider;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.Clickable;
import dev.zontreck.libzontreck.exceptions.InvalidSideException;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.libzontreck.vectors.Vector3;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentUtils;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
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 SpawnCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("spawn").executes(c-> respawn(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 respawn(CommandSourceStack source) {
ServerPlayer p = (ServerPlayer)source.getEntity();
ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.RESPAWNING), p.server);
BlockPos spawn = p.serverLevel().getSharedSpawnPos();
TeleportActioner.ApplyTeleportEffect(p);
TeleportContainer cont = new TeleportContainer(p, new Vec3(spawn.getX(), spawn.getY(), spawn.getZ()), Vec2.ZERO, p.serverLevel());
TeleportActioner.PerformTeleport(cont);
return 0;
}
}

View file

@ -1,9 +1,20 @@
package dev.zontreck.essentials.commands.teleport;
import dev.zontreck.ariaslib.util.DelayedExecutorService;
import dev.zontreck.essentials.AriasEssentials;
import dev.zontreck.essentials.configs.AEServerConfig;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.libzontreck.vectors.WorldPosition;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.commands.EffectCommands;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
public class TeleportActioner
{
@ -12,31 +23,36 @@ public class TeleportActioner
DelayedExecutorService.getInstance().schedule(new TeleportRunnable(contain), 2);
}
public static boolean isBlacklistedDimension(ServerLevel level)
{
WorldPosition pos = new WorldPosition(Vector3.ZERO, level);
if(AEServerConfig.DIMENSION_BLACKLIST.get().contains(pos.Dimension))
{
return true;
} else return false;
}
public static void ApplyTeleportEffect(ServerPlayer player){
if(isBlacklistedDimension(player.serverLevel())){
return;
}
// 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.DARKNESS, 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
// 05/15/2023 - Removed regen effect and replaced with feather fall.
//MobEffectInstance regen = new MobEffectInstance(MobEffects.REGENERATION, 400, 2, true, true);
// 12/18/2023 - Updated to store effects in the config, and make duration and amplifier random!
var effects = AEServerConfig.TELEPORT_EFFECTS.get();
for(int i = 0; i < effects.size(); i++) {
RegistryObject<MobEffect> effect = RegistryObject.create(new ResourceLocation(effects.get(i)), ForgeRegistries.MOB_EFFECTS);
// 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
// 12/15/2023 - Adjusted to 150 on duration to attempt to fix the levitate effect being too long
MobEffectInstance levitate = new MobEffectInstance(MobEffects.LEVITATION, 150, 1, true, true);
int duration = AriasEssentials.random.nextInt(5, 15) * 20;
int amplifier = AriasEssentials.random.nextInt(1, 4);
// 05/15/2023 - Add feather falling as a effect that lasts longer than levitate to avoid damaging the player.
MobEffectInstance feathers = new MobEffectInstance(MobEffects.SLOW_FALLING, 400, 2, true, true);
player.addEffect(inst);
player.addEffect(feathers);
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!!!)
MobEffectInstance inst = new MobEffectInstance(effect.get(), duration, amplifier, true, true);
player.addEffect(inst);
}
}
});

View file

@ -3,6 +3,8 @@ package dev.zontreck.essentials.commands.teleport;
import dev.zontreck.ariaslib.terminal.Task;
import dev.zontreck.ariaslib.util.DelayedExecutorService;
import dev.zontreck.essentials.events.TeleportEvent;
import net.minecraftforge.common.MinecraftForge;
public class TeleportRunnable extends Task
{
@ -15,6 +17,12 @@ public class TeleportRunnable extends Task
@Override
public void run() {
if(MinecraftForge.EVENT_BUS.post(new TeleportEvent(Action)))
{
return;
}
Action.PlayerInst.teleportTo(Action.Dimension, Action.Position.x, Action.Position.y, Action.Position.z, Action.Rotation.y, Action.Rotation.x);
DelayedExecutorService.getInstance().schedule(new Task("tp_action",true){

View file

@ -13,7 +13,7 @@ public class AEClientConfig
static {
BUILDER.push("overlay");
ENABLE_HEARTS_RENDER = BUILDER.comment("Enable compressed hearts? This puts all the hearts in a single row").define("enable_hearts", false);
ENABLE_HEARTS_RENDER = BUILDER.comment("Enable compressed hearts? This puts all the hearts in a single row").define("enable_hearts", true);
BUILDER.pop();
SPEC = BUILDER.build();

View file

@ -1,7 +1,11 @@
package dev.zontreck.essentials.configs;
import dev.zontreck.ariaslib.util.Lists;
import net.minecraftforge.common.ForgeConfigSpec;
import java.util.ArrayList;
import java.util.List;
public class AEServerConfig {
// TODO:
/*
@ -21,7 +25,10 @@ public class AEServerConfig {
public static final ForgeConfigSpec.ConfigValue<Integer> COST_TO_MAKE_WARP;
public static final ForgeConfigSpec.ConfigValue<Integer> MAX_HOMES;
public static final ForgeConfigSpec.ConfigValue<List<String>> DIMENSION_BLACKLIST;
public static final ForgeConfigSpec.ConfigValue<String> BLACKLISTED_DIMENSION_ERROR;
public static final ForgeConfigSpec.ConfigValue<List<String>> TELEPORT_EFFECTS;
static{
@ -35,12 +42,43 @@ public class AEServerConfig {
BUILDER.push("permissions").comment("This section defines permissions, such as total number of homes, and who can make warps");
MAX_HOMES = BUILDER.comment("Maximum number of homes that are allowed per player (-1 disables the limit entirely)").define("max_homes", -1);
BUILDER.pop();
BUILDER.push("teleport");
BUILDER.push("blacklist");
DIMENSION_BLACKLIST = BUILDER.comment("Blacklist the use of teleportation commands from any of the listed dimensions.").define("blacklist", Lists.of("dimdoors:dungeon_pockets", "dimdoors:limbo", "dimdoors:personal_pockets", "dimdoors:public_pockets"));
BLACKLISTED_DIMENSION_ERROR = BUILDER.comment("The error to say if the user tries to teleport out of a blacklisted dimension").define("error", "!Dark_Red!You appear to be in a place where we cannot find you.");
BUILDER.pop();
TELEPORT_EFFECTS = BUILDER.comment("Teleportation effects that get applied when the user attempts a teleport. Teleport effects will always have a random duration between 5 seconds and 15 seconds. The amplifier will also be random, between Lv1 and Lv4").define("effects", Lists.of(
"minecraft:darkness",
"minecraft:levitation",
"minecraft:slow_falling",
"minecraft:hunger"
));
BUILDER.pop();
SPEC=BUILDER.build();
}
static class TeleportEffect
{
String Effect;
int Duration;
int Amplifier;
boolean Ambient;
public TeleportEffect(String name, int Duration, int Amplifier, boolean Ambient)
{
this.Effect = name;
this.Duration = Duration;
this.Amplifier = Amplifier;
this.Ambient = Ambient;
}
}
}

View file

@ -0,0 +1,19 @@
package dev.zontreck.essentials.events;
import dev.zontreck.essentials.commands.teleport.TeleportContainer;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
@Cancelable
public class TeleportEvent extends Event
{
private TeleportContainer container;
public TeleportEvent(TeleportContainer container)
{
this.container=container;
}
public TeleportContainer getContainer() {
return container;
}
}

View file

@ -65,7 +65,7 @@ description='''${mod_description}'''
[[dependencies.${mod_id}]]
modId="libzontreck"
mandatory=true
versionRange="[1.9,1.10)"
versionRange="[1.9.121823,1.10)"
ordering="NONE"
side="BOTH"