Skip to content

Commit

Permalink
Fix stargates
Browse files Browse the repository at this point in the history
  • Loading branch information
Seggan committed Mar 27, 2024
1 parent 2d3f61f commit b93d7ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack;
import io.github.thebusybiscuit.slimefun4.libraries.paperlib.PaperLib;
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
Expand Down Expand Up @@ -183,7 +182,6 @@ private void onUse(PlayerRightClickEvent event, Player p, Block b) {
gateway.setAge(GATEWAY_TICKS);
gateway.setExitLocation(b.getLocation());
gateway.update(false, false);
BlockStorage.addBlockInfo(portal, "portal", "true");
}

String destAddress = BlockStorage.getLocationInfo(b.getLocation(), "destination");
Expand Down Expand Up @@ -319,20 +317,20 @@ public void onGateBreak(BlockBreakEvent e) {

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onUsePortal(PlayerTeleportEndGatewayEvent e) {
if (!BSUtils.getStoredBoolean(e.getGateway().getLocation(), "portal")) return;
Location dest = BSUtils.getStoredLocation(e.getGateway().getExitLocation(), "dest");
Location exit = e.getGateway().getExitLocation();
if (exit == null || !(BlockStorage.check(exit) instanceof StargateController)) return;
Location dest = BSUtils.getStoredLocation(exit, "dest");
if (dest == null) return;

e.setCancelled(true);

Player p = e.getPlayer();

if (p.hasMetadata("disableStargate")) return;

Block b = dest.getBlock();
if (BlockStorage.check(b, BaseItems.STARGATE_CONTROLLER.getItemId()) &&
StargateController.getPortalBlocks(b).isEmpty()) {
e.getPlayer().sendMessage(ChatColor.RED + "The destination Stargate is not activated");
p.sendMessage(ChatColor.RED + "The destination Stargate is not activated");
return;
}

Expand All @@ -343,11 +341,11 @@ public void onUsePortal(PlayerTeleportEndGatewayEvent e) {
if (world != null) {
e.getPlayer().setMetadata("CanTpAlienWorld", new FixedMetadataValue(Galactifun.instance(), true));
}
PaperLib.teleportAsync(e.getPlayer(), destBlock.getLocation());
p.teleportAsync(destBlock.getLocation());
p.setMetadata("disableStargate", new FixedMetadataValue(Galactifun.instance(), true));
Scheduler.run(10, () -> p.removeMetadata("disableStargate", Galactifun.instance()));
} else {
e.getPlayer().sendMessage(ChatColor.RED + "The destination is blocked");
p.sendMessage(ChatColor.RED + "The destination is blocked");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.MetadataValue;

import com.destroystokyo.paper.event.player.PlayerTeleportEndGatewayEvent;
import io.github.addoncommunity.galactifun.Galactifun;
import io.github.addoncommunity.galactifun.api.items.ExclusiveGEOResource;
import io.github.addoncommunity.galactifun.api.items.spacesuit.SpaceSuitProfile;
Expand Down Expand Up @@ -210,6 +211,7 @@ private void onPlayerChangeGameMode(@Nonnull PlayerGameModeChangeEvent e) {

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerTeleport(@Nonnull PlayerTeleportEvent e) {
if (e instanceof PlayerTeleportEndGatewayEvent) return;
if (!e.getPlayer().hasPermission("galactifun.admin")) {
if (e.getTo().getWorld() != null && e.getFrom().getWorld() != e.getTo().getWorld()) {
PlanetaryWorld world = getWorld(e.getTo().getWorld());
Expand Down

0 comments on commit b93d7ac

Please sign in to comment.