Skip to content

Commit

Permalink
format dimension name
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkGoosik committed Jun 17, 2024
1 parent 94f9c8f commit 90362de
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/ru/pinkgoosik/dimrevive/DimensionalRevive.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import net.fabricmc.fabric.api.entity.event.v1.ServerEntityWorldChangeEvents;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.registry.RegistryKey;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameMode;
import net.minecraft.world.TeleportTarget;
import net.minecraft.world.World;
import org.apache.commons.lang3.text.WordUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.pinkgoosik.dimrevive.extension.WorldExtension;
Expand All @@ -25,19 +27,20 @@ public void onInitialize() {
ServerEntityWorldChangeEvents.AFTER_PLAYER_CHANGE_WORLD.register((player, origin, destination) -> {
var visitedDimensions = ((WorldExtension)player.getServer().getOverworld()).getVisitedDimensions().visitedDimensions;

if(!destination.getRegistryKey().equals(World.OVERWORLD) && !visitedDimensions.contains(destination.getRegistryKey().getValue().toString())) {
if(player.getServer().isHardcore() && !destination.getRegistryKey().equals(World.OVERWORLD) && !visitedDimensions.contains(destination.getRegistryKey().getValue().toString())) {


player.getServer().getPlayerManager().getPlayerList().forEach(serverPlayerEntity -> {
if(serverPlayerEntity.isSpectator()) {
FabricDimensions.teleport(serverPlayerEntity, destination, new TeleportTarget(player.getPos(), new Vec3d(0, 0, 0), player.getYaw(), player.getPitch()));
serverPlayerEntity.changeGameMode(GameMode.SURVIVAL);
serverPlayerEntity.setPortalCooldown(20 * 5);

serverPlayerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 5, 5, false, true));
serverPlayerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.SATURATION, 5, 5, false, true));
serverPlayerEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.ABSORPTION, 5, 255, false, true));
}
serverPlayerEntity.sendMessage(Text.literal("New dimension was discovered: " + destination.getRegistryKey().getValue().toString() + ". All players are revived."));
serverPlayerEntity.sendMessage(Text.literal("New dimension was discovered: §6" + formatDimensionName(destination.getRegistryKey()) + "§f. All players are revived."));
});

visitedDimensions.add(destination.getRegistryKey().getValue().toString());
Expand All @@ -49,4 +52,8 @@ public void onInitialize() {
public static Identifier id(String path) {
return new Identifier(MOD_ID, path);
}

public static String formatDimensionName(RegistryKey<World> key) {
return WordUtils.capitalize(key.getValue().getPath().replace("_", " "));
}
}

0 comments on commit 90362de

Please sign in to comment.