Push 1.3.2.2

Fix rtp so it no longer blocks the server
This commit is contained in:
Zontreck 2022-10-05 16:07:04 -07:00
parent 30f4f3deff
commit 098de9f9d4
12 changed files with 269 additions and 84 deletions

View file

@ -7,7 +7,7 @@ plugins {
version = '1.3.2.1'
version = "${my_version}"
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.2.1", // We are version 1 of ourselves
"Specification-Version" : "${my_version}", // We are version 1 of ourselves
"Implementation-Title" : project.name,
"Implementation-Version" : project.jar.archiveVersion,
"Implementation-Vendor" : "Zontreck",

View file

@ -3,6 +3,8 @@
org.gradle.jvmargs=-Xmx8G
org.gradle.daemon=false
my_version=1.3.2.2
mc_version=1.19.2
forge_version=43.1.32
jei_version=11.3.0.262

View file

@ -118,9 +118,7 @@ public class ChatServerOverride {
}
String msg = ev.getMessage().getString();
for(ChatColor.ColorOptions color : ChatColor.ColorOptions.values()){
msg = msg.replace("!"+color.toString()+"!", ChatColor.from(color));
}
msg=doColors(msg);
String nameStr = ChatColor.resetChat() + "< "+ XD.name_color + XD.nickname + ChatColor.resetChat() + " >";
String message = ": "+XD.chat_color + msg;
@ -131,15 +129,27 @@ public class ChatServerOverride {
ChatServerOverride.broadcast(Component.literal(prefixStr+nameStr+message).setStyle(hover), ev.getPlayer().server);
}
public static void broadcastAboveToolBar(Component message, MinecraftServer s)
public static String doColors(String msg)
{
// This will broadcast to all players
for(ServerPlayer play : s.getPlayerList().getPlayers())
{
play.displayClientMessage(message, true); // Send the message!
for(ChatColor.ColorOptions color : ChatColor.ColorOptions.values()){
msg = msg.replace("!"+color.toString()+"!", ChatColor.from(color));
}
LogToConsole(Component.literal("[all] ").append(message));
return msg;
}
public static void broadcastAbove(Component message, MinecraftServer s)
{
s.execute(new Runnable() {
public void run(){
// This will broadcast to all players
for(ServerPlayer play : s.getPlayerList().getPlayers())
{
play.displayClientMessage(message, true); // Send the message!
}
LogToConsole(Component.literal("[all] ").append(message));
}
});
}
public static void LogToConsole(Component Message)
{
@ -147,25 +157,40 @@ public class ChatServerOverride {
}
public static void broadcast(Component message, MinecraftServer s)
{
// This will broadcast to all players
for(ServerPlayer play : s.getPlayerList().getPlayers())
{
play.displayClientMessage(message, false); // Send the message!
}
LogToConsole(Component.literal("[all] ").append(message));
s.execute(new Runnable() {
public void run(){
// This will broadcast to all players
for(ServerPlayer play : s.getPlayerList().getPlayers())
{
play.displayClientMessage(message, false); // Send the message!
}
LogToConsole(Component.literal("[all] ").append(message));
}
});
}
public static void broadcastTo(UUID ID, Component message, MinecraftServer s)
{
ServerPlayer play = s.getPlayerList().getPlayer(ID);
play.displayClientMessage(message, false); // Send the message!
LogToConsole(Component.literal("[server] -> ["+play.getName().toString()+"] ").append(message));
s.execute(new Runnable() {
public void run(){
ServerPlayer play = s.getPlayerList().getPlayer(ID);
play.displayClientMessage(message, false); // Send the message!
LogToConsole(Component.literal("[server] -> ["+play.getName().toString()+"] ").append(message));
}
});
}
public static void broadcastToAbove(UUID ID, Component message, MinecraftServer s)
{
ServerPlayer play = s.getPlayerList().getPlayer(ID);
play.displayClientMessage(message, true); // Send the message!
LogToConsole(Component.literal("[server] -> ["+play.getName().toString()+"] ").append(message));
s.execute(new Runnable() {
public void run(){
ServerPlayer play = s.getPlayerList().getPlayer(ID);
play.displayClientMessage(message, true); // Send the message!
LogToConsole(Component.literal("[server] -> ["+play.getName().toString()+"] ").append(message));
}
});
}
}

View file

@ -1,5 +1,9 @@
package dev.zontreck.otemod.commands;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.commands.profilecmds.ChatColorCommand;
import dev.zontreck.otemod.commands.profilecmds.NameColorCommand;
@ -13,6 +17,7 @@ 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.VaultCommand;
import dev.zontreck.otemod.configs.OTEServerConfig;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@ -20,6 +25,59 @@ import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
@EventBusSubscriber(modid=OTEMod.MOD_ID,bus=Mod.EventBusSubscriber.Bus.FORGE)
public class CommandRegistry {
public static Map<String,Long> CommandCooldownRegistry = new HashMap<>();
public static void markUsed(String cmd)
{
// Command was used, mark the current time
CommandCooldownRegistry.put(cmd, Instant.now().getEpochSecond());
}
public static boolean canUse(String cmd)
{
if(!CommandCooldownRegistry.containsKey(cmd)) return true;
long lastUse = CommandCooldownRegistry.get(cmd);
switch(cmd)
{
case "rtp":
{
if(Instant.now().getEpochSecond() > lastUse+Long.parseLong(String.valueOf(OTEServerConfig.RTP_COOLDOWN))){
CommandCooldownRegistry.remove(cmd);
return true;
}else return false;
}
default:
{
CommandCooldownRegistry.remove(cmd);
return true; // cooldown not yet made
}
}
}
public static String getRemaining(String string) {
long now = Instant.now().getEpochSecond();
if(!CommandCooldownRegistry.containsKey(string))return "0";
long used = CommandCooldownRegistry.get(string);
long cmd_time = 0L;
switch(string)
{
case "rtp":
{
cmd_time = Long.parseLong(String.valueOf(OTEServerConfig.RTP_COOLDOWN));
break;
}
default:
{
cmd_time = 0L;
break;
}
}
used+=cmd_time;
long diff = used-now;
if(diff<0)diff=0L;
return String.valueOf(diff);
}
@SubscribeEvent
public void onRegisterCommands(final RegisterCommandsEvent ev)
@ -47,5 +105,6 @@ public class CommandRegistry {
VaultCommand.register(ev.getDispatcher());
}
}

View file

@ -1,14 +1,18 @@
package dev.zontreck.otemod.commands.teleport;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType;
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.commands.CommandRegistry;
import dev.zontreck.otemod.containers.Vector3;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
@ -16,6 +20,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.DoubleBlockCombiner.BlockType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
@ -23,7 +28,7 @@ public class RTPCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("rtp").executes(c->rtp(c.getSource())));
dispatcher.register(Commands.literal("rtp").executes(c->rtp(c.getSource(), false)).then(Commands.argument("ignorewater", BoolArgumentType.bool()).executes(c->rtp(c.getSource(), BoolArgumentType.getBool(c, "ignorewater")))));
//executes(c -> doCancel(c.getSource())));
@ -33,63 +38,126 @@ public class RTPCommand {
//}));
}
private static int rtp(CommandSourceStack source) {
private static int rtp(CommandSourceStack source, boolean allowWater) {
/*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");*/
ServerPlayer pla = source.getPlayer();
TeleportContainer cont = new TeleportContainer(pla, null, source.getPlayer().getRotationVector(), source.getLevel());
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;
int tries=0;
while(!found_place){
// Take our current position, and send us in a random direction
Random rng = new Random((long) (pos.x+pos.y+pos.z));
v.y = 500;
v.x = rng.nextDouble(0xffff);
v.z = rng.nextDouble(0xffff);
// Begin to scan for ground
while(v.y != 0)
{
// check block above and below
BlockState b = source.getLevel().getBlockState(new BlockPos(v.asMinecraftVector()));
BlockState b2 = source.getLevel().getBlockState(new BlockPos(v.moveUp().asMinecraftVector()));
BlockState b3 = source.getLevel().getBlockState(new BlockPos(v.moveDown().asMinecraftVector()));
Block bx = b.getBlock();
Thread tx = new Thread(new Runnable() {
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
if(b.isAir()){
if(b2.isAir()){
if(!b3.isAir()){
found_place = true;
break;
Vec3 pos = pla.position();
boolean found_place= false;
int tries=0;
ChatServerOverride.broadcastTo(pla.getUUID(), Component.literal(ChatColor.DARK_GRAY + "["+ChatColor.DARK_GREEN+"OTEMOD"+ChatColor.DARK_GRAY+"] "+ChatColor.GREEN+"Searching for a suitable landing location..."), source.getServer());
while(!found_place){
// Take our current position, and send us in a random direction
Random rng = new Random((long) (pos.x+pos.y+pos.z));
v.y = 500;
v.x = rng.nextDouble(0xffff);
v.z = rng.nextDouble(0xffff);
boolean is_invalid_location = false;
String block_place="";
// Begin to scan for ground
while(v.y != 0)
{
// check block above and below
BlockState b = source.getLevel().getBlockState(new BlockPos(v.asMinecraftVector()));
BlockState b2 = source.getLevel().getBlockState(new BlockPos(v.moveUp().asMinecraftVector()));
BlockState b3 = source.getLevel().getBlockState(new BlockPos(v.moveDown().asMinecraftVector()));
//Block bx = b.getBlock();
// Check that none of the blocks are water or lava
if(b.isAir()){
if(b2.isAir()){
if(!b3.isAir()){
// Check names
boolean valid=true;
List<String> blackList = new ArrayList<>();
if(!allowWater)
blackList.add("Water");
blackList.add("Lava");
block_place = b3.getBlock().getName().getString();
OTEMod.LOGGER.info(b3.getBlock().getName().getString());
if(blackList.contains(b.getBlock().getName().getString())){
valid=false;
is_invalid_location=true;
}
if(blackList.contains(b2.getBlock().getName().getString())){
valid=false;
is_invalid_location=true;
}
if(blackList.contains(b3.getBlock().getName().getString())){
valid=false;
is_invalid_location=true;
}
if(valid){
found_place = true;
break;
}
}
}
}
v =v.moveDown();
}
if(tries>=30)
{
// Aborting RTP
ChatServerOverride.broadcastTo(pla.getUUID(), Component.literal(ChatColor.DARK_RED+"Could not find a suitable location after 30 tries. Giving up on RTP"), source.getServer());
return;
}
tries++;
String sAppend = "";
if(is_invalid_location){
sAppend = block_place + " is not valid";
}
ChatServerOverride.broadcastToAbove(pla.getUUID(), Component.literal(ChatColor.DARK_PURPLE+"Still searching.... Try ["+String.valueOf(tries)+"/30] "+sAppend), source.getServer());
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
v =v.moveDown();
ChatServerOverride.broadcastTo(pla.getUUID(), Component.literal(ChatColor.DARK_GRAY + "["+ChatColor.DARK_GREEN + "OTEMOD" + ChatColor.DARK_GRAY + "] "+ChatColor.DARK_PURPLE+" A suitable location has been found. Wormhole opening now!"), source.getServer());
// Apply the effect
TeleportActioner.ApplyTeleportEffect(pla);
cont.Position=v.asMinecraftVector();
TeleportActioner.PerformTeleport(cont);
}
if(tries>=5)
{
// Aborting RTP
ChatServerOverride.broadcastTo(pla.getUUID(), Component.literal(ChatColor.DARK_RED+"Could not find a suitable location after 5 tries. Giving up on RTP"), source.getServer());
return 0;
}
tries++;
}
});
ChatServerOverride.broadcastTo(pla.getUUID(), Component.literal(ChatColor.DARK_GRAY + "["+ChatColor.DARK_GREEN + "OTEMOD" + ChatColor.DARK_GRAY + "] "+ChatColor.DARK_PURPLE+" A suitable location has been found. Wormhole opening now!"), source.getServer());
// Apply the effect
TeleportActioner.ApplyTeleportEffect(pla);
cont.Position=v.asMinecraftVector();
TeleportActioner.PerformTeleport(cont);
tx.start();
return 0;

View file

@ -14,15 +14,21 @@ public class TeleportActioner
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.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!!!)
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

@ -21,6 +21,7 @@ public class OTEServerConfig {
public static final ForgeConfigSpec.ConfigValue<String> PASSWORD;
public static final ForgeConfigSpec.ConfigValue<String> DATABASE;
public static final ForgeConfigSpec.ConfigValue<Integer> ITEM_DESPAWN_TIMER;
public static final ForgeConfigSpec.ConfigValue<Integer> RTP_COOLDOWN;
static {
List<ItemStack> defaults = new ArrayList<ItemStack>();
@ -33,6 +34,10 @@ public class OTEServerConfig {
PASSWORD = BUILDER.comment("Database Password (MySQL)").define("password", "password");
DATABASE = BUILDER.comment("Database Name (MySQL)").define("database", "otemod");
ITEM_DESPAWN_TIMER = BUILDER.comment("How many times should the item's expire be cancelled. The vanilla expire time is 5 minutes, so this would be ticked down once every 5 minutes.").define("item_extra_lives", (60/5));
BUILDER.pop();
BUILDER.push("COMMANDS");
RTP_COOLDOWN = BUILDER.comment("How many seconds between RTP uses? This can be quite laggy on the server due to the potential that new chunks are getting generated").define("rtp.cooldown", 30); // Default of 30 should be enough
BUILDER.pop();

View file

@ -50,4 +50,10 @@ public class Vector3
Vector3 n = new Vector3(x, y, z);
return n;
}
@Override
public String toString()
{
return "<"+String.valueOf(x)+", "+String.valueOf(y)+", "+String.valueOf(z)+">";
}
}

View file

@ -0,0 +1,6 @@
package dev.zontreck.otemod.registry;
public class PerPlayerDataRegistry {
// The idea here is to make a registry unique to a player for mod data
// This will allow separating handling of functions, like cooldowns
}

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.2.1" #mandatory
version="1.3.2.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/

View file

@ -26,6 +26,10 @@
"dev.zontreck.otemod.msgs.homes.goto.success": "§2Home found, warping home now",
"dev.zontreck.otemod.msgs.homes.del.success": "§2Home was deleted successfully",
"dev.zontreck.otemod.msgs.homes.del.fail": "§cHome could not be deleted due to an error",
"dev.zontreck.otemod.msgs.command_cooling_down": "This command is currently on cooldown. You must wait for ",
"dev.zontreck.otemod.msgs.command_cooling_down_seconds": "seconds.",
"minecraft.player.joined": "",
"minecraft.player.joined.renamed": "",
"minecraft.player.quit": ""

View file

@ -1,7 +1,11 @@
{
"type": "mekanism:enriching",
"input": "otemod:eternium_ore",
"output": "otemod:eternium_dust",
"input": {
"ingredient": "otemod:eternium_ore"
},
"output": {
"item": "otemod:eternium_dust"
},
"experience": 25,
"cookingtime": 60
}