Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #76

Merged
merged 4 commits into from
Jan 4, 2025
Merged

Dev #76

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2101.1.3]

### Added
* Now fires an `EntityTeleportEvent.TeleportCommand` event on NeoForge when any teleportation is done
* Note: There isn't a Fabric API equivalent for this event

### Fixed
* Fixed problem on SMP where player data (e.g. home location) wasn't always written for the player
* In particular if player disconnected before the server ran a scheduled level save

## [2101.1.2]

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private static void playerLoggedIn(ServerPlayer serverPlayer) {
private static void playerLoggedOut(ServerPlayer serverPlayer) {
FTBEPlayerData.getOrCreate(serverPlayer).ifPresent(data -> {
data.setLastSeenPos(new TeleportPos(serverPlayer));
data.markDirty();
data.saveIfChanged();
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.ftb.mods.ftbessentials.util;

import dev.architectury.event.CompoundEventResult;
import dev.architectury.injectables.annotations.ExpectPlatform;
import dev.ftb.mods.ftbessentials.api.event.TeleportEvent;
import dev.ftb.mods.ftbessentials.config.FTBEConfig;
import dev.ftb.mods.ftbessentials.util.TeleportPos.TeleportResult;
Expand Down Expand Up @@ -49,15 +50,25 @@ public TeleportResult checkCooldown(ServerPlayer player) {
return TeleportResult.SUCCESS;
}

@ExpectPlatform
private static boolean firePlatformTeleportEvent(ServerPlayer player, Vec3 pos) {
throw new AssertionError();
}

public TeleportResult teleport(ServerPlayer player, Function<ServerPlayer, TeleportPos> positionGetter) {
TeleportResult cooldownResult = checkCooldown(player);
if (!cooldownResult.isSuccess()) {
return cooldownResult;
}

CompoundEventResult<Component> result = TeleportEvent.TELEPORT.invoker().teleport(player);
if (result.isFalse()) {
return TeleportResult.failed(result.object());
}

TeleportResult cooldownResult = checkCooldown(player);
if (!cooldownResult.isSuccess()) {
return cooldownResult;
TeleportPos pos = positionGetter.apply(player);
if (!firePlatformTeleportEvent(player, Vec3.atBottomCenterOf(pos.getPos()))) {
return TeleportResult.failed(Component.translatable("ftbessentials.teleport_prevented"));
}

int warmupTime = warmupConfig.applyAsInt(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"ftbessentials.chat.status.stop_stream": "is no longer streaming!",
"ftbessentials.messages.kick_self": "You kicked yourself!",
"ftbessentials.feedback.limit_radius": "Limiting radius to %s",
"ftbessentials.feedback.players_within": "%s player(s) within %sm"
"ftbessentials.feedback.players_within": "%s player(s) within %sm",
"ftbessentials.teleport_prevented": "Teleportation was prevented!"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.ftb.mods.ftbessentials.util.fabric;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.phys.Vec3;

public class WarmupCooldownTeleporterImpl {
public static boolean firePlatformTeleportEvent(ServerPlayer player, Vec3 pos) {
// TODO don't think there's a FAPI event for this; update here if one gets added
return true;
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ archives_base_name=ftb-essentials
maven_group=dev.ftb.mods

minecraft_version=1.21.1
mod_version=2101.1.2
mod_version=2101.1.3
mod_author=FTB Team

# Deps
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.ftb.mods.ftbessentials.util.neoforge;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.entity.EntityTeleportEvent;

public class WarmupCooldownTeleporterImpl {
public static boolean firePlatformTeleportEvent(ServerPlayer player, Vec3 pos) {
EntityTeleportEvent.TeleportCommand event = new EntityTeleportEvent.TeleportCommand(player, pos.x, pos.y, pos.z);
NeoForge.EVENT_BUS.post(event);
return !event.isCanceled();
}
}
Loading