Skip to content

Portal World on Folia 🎉 #3

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

Merged
merged 5 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = 'me.hsgamer'
version = '1.6.0'
version = '1.6.1'
description = 'A (temporary) world manager for Folia'

repositories {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/hsgamer/morefoworld/WorldUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ public static FeedbackWorld addWorld(WorldCreator creator) {
}

if (console.options.has("forceUpgrade")) {
net.minecraft.server.Main.convertWorldButItWorks(
actualDimension, worldSession, DataFixers.getDataFixer(), iregistrycustom_dimension, worlddimension.generator().getTypeNameForDataFixer(), console.options.has("eraseCache"), console.options.has("recreateRegionFiles")
net.minecraft.server.Main.forceUpgrade(
worldSession, DataFixers.getDataFixer(), console.options.has("eraseCache"), () -> true, iregistrycustom_dimension, console.options.has("recreateRegionFiles")
);
}

Expand Down
67 changes: 67 additions & 0 deletions src/main/java/me/hsgamer/morefoworld/listener/PortalListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.projectunified.minelib.plugin.base.BasePlugin;
import io.github.projectunified.minelib.plugin.listener.ListenerComponent;
import io.papermc.paper.event.entity.EntityInsideBlockEvent;
import io.papermc.paper.event.entity.EntityPortalReadyEvent;
import me.hsgamer.morefoworld.DebugComponent;
import me.hsgamer.morefoworld.config.PortalConfig;
Expand All @@ -15,9 +16,12 @@
import org.bukkit.event.player.PlayerTeleportEvent;

import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

public class PortalListener extends ListenerComponent {
private DebugComponent debug;
private final ConcurrentHashMap<UUID, Material> portalTeleportCache = new ConcurrentHashMap<>();

public PortalListener(BasePlugin plugin) {
super(plugin);
Expand Down Expand Up @@ -113,4 +117,67 @@ public void onEntityPortal(EntityPortalEvent event) {
}
});
}

@EventHandler
public void onEntityInsidePortal(final EntityInsideBlockEvent event) {
if (event.isCancelled()) return;
Block block = event.getBlock();
Entity entity = event.getEntity();
Material blockTypeInside = block.getType();
Location from = entity.getLocation();

if (!blockTypeInside.equals(Material.NETHER_PORTAL) && !blockTypeInside.equals(Material.END_PORTAL)) {
return;
}

debug.debug("Preparing for teleportation...");

event.setCancelled(true);

if (portalTeleportCache.get(entity.getUniqueId()) != null) {
debug.debug("The entity is being teleported");
return;
}

portalTeleportCache.put(entity.getUniqueId(), blockTypeInside);
entity.getScheduler().execute(plugin, () -> {
switch (blockTypeInside) {
case NETHER_PORTAL -> {

debug.debug("Nether portal");

Optional<World> worldOptional = plugin.get(PortalConfig.class).getWorldFromNetherPortal(from.getWorld());

worldOptional.ifPresent(world -> {
Location clone = from.clone();
clone.setWorld(world);
if (world.getEnvironment() == World.Environment.THE_END) {
teleportToEnd(event.getEntity(), clone);
debug.debug("Teleport to " + clone);
} else {
event.getEntity().teleportAsync(clone).thenRun(() -> debug.debug("Teleported to " + clone));
}
});
}
case END_PORTAL -> {

debug.debug("End portal");

Optional<World> worldOptional = plugin.get(PortalConfig.class).getWorldFromEndPortal(from.getWorld());

worldOptional.ifPresent(world -> {
Location clone = from.clone();
clone.setWorld(world);
if (world.getEnvironment() == World.Environment.THE_END) {
teleportToEnd(event.getEntity(), clone);
debug.debug("Teleport to " + clone);
} else {
event.getEntity().teleportAsync(clone).thenRun(() -> debug.debug("Teleported to " + clone));
}
});
}
}
portalTeleportCache.remove(entity.getUniqueId());
}, null, 1L);
}
}