Restructures events, and adds some missing protections
All checks were successful
EpicKnarvik97/Stargate/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Stargate/pipeline/head This commit looks good
This commit is contained in:
@@ -7,23 +7,19 @@ import net.knarcraft.knarlib.util.ConfigHelper;
|
||||
import net.knarcraft.knarlib.util.UpdateChecker;
|
||||
import net.knarcraft.stargate.command.CommandStarGate;
|
||||
import net.knarcraft.stargate.command.StarGateTabCompleter;
|
||||
import net.knarcraft.stargate.config.EconomyConfig;
|
||||
import net.knarcraft.stargate.config.Message;
|
||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.config.StargateConfig;
|
||||
import net.knarcraft.stargate.config.StargateGateConfig;
|
||||
import net.knarcraft.stargate.config.addons.EconomyConfig;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||
import net.knarcraft.stargate.container.ChunkUnloadRequest;
|
||||
import net.knarcraft.stargate.container.ControlBlockUpdateRequest;
|
||||
import net.knarcraft.stargate.listener.BlockEventListener;
|
||||
import net.knarcraft.stargate.listener.EntityEventListener;
|
||||
import net.knarcraft.stargate.listener.EntitySpawnListener;
|
||||
import net.knarcraft.stargate.listener.EnvironmentChangeListener;
|
||||
import net.knarcraft.stargate.listener.PlayerEventListener;
|
||||
import net.knarcraft.stargate.listener.PluginEventListener;
|
||||
import net.knarcraft.stargate.listener.PortalEventListener;
|
||||
import net.knarcraft.stargate.listener.TeleportEventListener;
|
||||
import net.knarcraft.stargate.listener.VehicleEventListener;
|
||||
import net.knarcraft.stargate.listener.WorldEventListener;
|
||||
import net.knarcraft.stargate.listener.StargateBreakListener;
|
||||
import net.knarcraft.stargate.listener.StargateCreateDestroyListener;
|
||||
import net.knarcraft.stargate.listener.StargateTeleportListener;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.thread.BlockChangeThread;
|
||||
@@ -407,15 +403,10 @@ public class Stargate extends ConfigCommentPlugin {
|
||||
*/
|
||||
private void registerEventListeners() {
|
||||
pluginManager.registerEvents(new PlayerEventListener(), this);
|
||||
pluginManager.registerEvents(new BlockEventListener(), this);
|
||||
|
||||
pluginManager.registerEvents(new VehicleEventListener(), this);
|
||||
pluginManager.registerEvents(new EntityEventListener(), this);
|
||||
pluginManager.registerEvents(new PortalEventListener(), this);
|
||||
pluginManager.registerEvents(new WorldEventListener(), this);
|
||||
pluginManager.registerEvents(new PluginEventListener(this), this);
|
||||
pluginManager.registerEvents(new TeleportEventListener(), this);
|
||||
pluginManager.registerEvents(new EntitySpawnListener(), this);
|
||||
pluginManager.registerEvents(new StargateCreateDestroyListener(), this);
|
||||
pluginManager.registerEvents(new StargateTeleportListener(), this);
|
||||
pluginManager.registerEvents(new EnvironmentChangeListener(this), this);
|
||||
pluginManager.registerEvents(new StargateBreakListener(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -3,7 +3,7 @@ package net.knarcraft.stargate.command;
|
||||
import de.themoep.minedown.MineDown;
|
||||
import net.knarcraft.knarlib.util.FileHelper;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.Message;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import org.bukkit.command.Command;
|
||||
|
@@ -3,10 +3,10 @@ package net.knarcraft.stargate.command;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.ConfigOption;
|
||||
import net.knarcraft.stargate.config.ConfigTag;
|
||||
import net.knarcraft.stargate.config.DynmapManager;
|
||||
import net.knarcraft.stargate.config.Message;
|
||||
import net.knarcraft.stargate.config.OptionDataType;
|
||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.config.addons.DynmapManager;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.portal.PortalSignDrawer;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package net.knarcraft.stargate.command;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@@ -5,13 +5,18 @@ import net.knarcraft.knarlib.formatting.Translator;
|
||||
import net.knarcraft.knarlib.property.ColorConversion;
|
||||
import net.knarcraft.knarlib.util.ConfigHelper;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.addons.DynmapManager;
|
||||
import net.knarcraft.stargate.config.addons.EconomyConfig;
|
||||
import net.knarcraft.stargate.config.formatting.LanguageLoader;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||
import net.knarcraft.stargate.listener.BungeeCordListener;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.portal.property.gate.GateHandler;
|
||||
import net.knarcraft.stargate.thread.BlockChangeThread;
|
||||
import net.knarcraft.stargate.utility.BungeeHelper;
|
||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
@@ -358,7 +363,21 @@ public final class StargateConfig {
|
||||
|
||||
if (start) {
|
||||
messenger.registerOutgoingPluginChannel(Stargate.getInstance(), bungeeChannel);
|
||||
messenger.registerIncomingPluginChannel(Stargate.getInstance(), bungeeChannel, new BungeeCordListener());
|
||||
messenger.registerIncomingPluginChannel(Stargate.getInstance(), bungeeChannel, (channel, unused, message) -> {
|
||||
//Ignore plugin messages if some other plugin message is received
|
||||
if (!channel.equals(BungeeHelper.getBungeeChannel())) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Try to read the plugin message
|
||||
String receivedMessage = BungeeHelper.readPluginMessage(message);
|
||||
if (receivedMessage == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Use the message to initiate teleportation
|
||||
BungeeHelper.handleTeleportMessage(receivedMessage);
|
||||
});
|
||||
} else {
|
||||
messenger.unregisterIncomingPluginChannel(Stargate.getInstance(), bungeeChannel);
|
||||
messenger.unregisterOutgoingPluginChannel(Stargate.getInstance(), bungeeChannel);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package net.knarcraft.stargate.config;
|
||||
package net.knarcraft.stargate.config.addons;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
@@ -1,6 +1,9 @@
|
||||
package net.knarcraft.stargate.config;
|
||||
package net.knarcraft.stargate.config.addons;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.ConfigOption;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.portal.PortalSignDrawer;
|
||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
@@ -1,4 +1,4 @@
|
||||
package net.knarcraft.stargate.config;
|
||||
package net.knarcraft.stargate.config.formatting;
|
||||
|
||||
import net.knarcraft.knarlib.property.ColorConversion;
|
||||
import net.knarcraft.knarlib.util.FileHelper;
|
@@ -1,4 +1,4 @@
|
||||
package net.knarcraft.stargate.config;
|
||||
package net.knarcraft.stargate.config.formatting;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
@@ -1,4 +1,4 @@
|
||||
package net.knarcraft.stargate.config;
|
||||
package net.knarcraft.stargate.config.formatting;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.knarcraft.stargate.Stargate;
|
@@ -1,42 +0,0 @@
|
||||
package net.knarcraft.stargate.listener;
|
||||
|
||||
import net.knarcraft.stargate.utility.BungeeHelper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This listener teleports a user if a valid message is received from BungeeCord
|
||||
*
|
||||
* <p>Specifically, if a string starts with SGBungee encoded to be readable by readUTF followed by
|
||||
* [PlayerUUID]delimiter[DestinationPortal] is received on the BungeeCord channel, this listener will teleport the
|
||||
* player to the destination portal.</p>
|
||||
*/
|
||||
public class BungeeCordListener implements PluginMessageListener {
|
||||
|
||||
/**
|
||||
* Receives plugin messages
|
||||
*
|
||||
* @param channel <p>The channel the message was received on</p>
|
||||
* @param unused <p>Unused.</p>
|
||||
* @param message <p>The message received from the plugin</p>
|
||||
*/
|
||||
@Override
|
||||
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player unused, byte[] message) {
|
||||
//Ignore plugin messages if some other plugin message is received
|
||||
if (!channel.equals(BungeeHelper.getBungeeChannel())) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Try to read the plugin message
|
||||
String receivedMessage = BungeeHelper.readPluginMessage(message);
|
||||
if (receivedMessage == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Use the message to initiate teleportation
|
||||
BungeeHelper.handleTeleportMessage(receivedMessage);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,68 +0,0 @@
|
||||
package net.knarcraft.stargate.listener;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.utility.EntityHelper;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityPortalEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This listener listens for any relevant events on portal entities
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class EntityEventListener implements Listener {
|
||||
|
||||
/**
|
||||
* This event handler prevents sending entities to the normal nether instead of the stargate target
|
||||
*
|
||||
* @param event <p>The event to check and possibly cancel</p>
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPortalEvent(@NotNull EntityPortalEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = event.getEntity();
|
||||
//Cancel normal portal event is near a stargate
|
||||
if (PortalHandler.getByAdjacentEntrance(event.getFrom(), EntityHelper.getEntityMaxSizeInt(entity)) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method catches any explosion events
|
||||
*
|
||||
* <p>If destroyed by explosions is enabled, any portals destroyed by the explosion will be unregistered. If not,
|
||||
* the explosion will be cancelled.</p>
|
||||
*
|
||||
* @param event <p>The triggered explosion event</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onEntityExplode(@NotNull EntityExplodeEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
for (Block block : event.blockList()) {
|
||||
Portal portal = PortalHandler.getByBlock(block);
|
||||
if (portal == null) {
|
||||
continue;
|
||||
}
|
||||
if (Stargate.getGateConfig().destroyedByExplosion()) {
|
||||
PortalRegistry.unregisterPortal(portal, true);
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
package net.knarcraft.stargate.listener;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A listener that listens for any relevant events causing entities to spawn
|
||||
*/
|
||||
public class EntitySpawnListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onCreatureSpawn(@NotNull CreatureSpawnEvent event) {
|
||||
//Prevent Zombified Piglins and other creatures form spawning at stargates
|
||||
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NETHER_PORTAL &&
|
||||
PortalHandler.getByEntrance(event.getLocation()) != null) {
|
||||
event.setCancelled(true);
|
||||
Stargate.debug("EntitySpawnListener", "Prevented creature from spawning at Stargate");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,96 @@
|
||||
package net.knarcraft.stargate.listener;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.StargateConfig;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.event.world.WorldUnloadEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This listener listens for any plugins/worlds being enabled or disabled
|
||||
*/
|
||||
public class EnvironmentChangeListener implements Listener {
|
||||
|
||||
private final Stargate stargate;
|
||||
|
||||
/**
|
||||
* Instantiates a new plugin event listener
|
||||
*
|
||||
* @param stargate <p>A reference to the stargate plugin to </p>
|
||||
*/
|
||||
public EnvironmentChangeListener(@NotNull Stargate stargate) {
|
||||
this.stargate = stargate;
|
||||
}
|
||||
|
||||
/**
|
||||
* This event listens for and announces that the vault plugin was detected and enabled
|
||||
*
|
||||
* <p>Each time this event is called, the economy handler will try to enable vault</p>
|
||||
*
|
||||
* @param ignored <p>The actual event called. This is currently not used</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPluginEnable(@NotNull PluginEnableEvent ignored) {
|
||||
if (Stargate.getEconomyConfig().setupEconomy(stargate.getServer().getPluginManager())) {
|
||||
Plugin vault = Stargate.getEconomyConfig().getVault();
|
||||
if (vault != null) {
|
||||
String vaultVersion = vault.getDescription().getVersion();
|
||||
Stargate.logInfo(new SGFormatBuilder(Message.VAULT_LOADED).replace("%version%", vaultVersion).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This event listens for the vault plugin being disabled and notifies the console
|
||||
*
|
||||
* @param event <p>The event caused by disabling a plugin</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPluginDisable(@NotNull PluginDisableEvent event) {
|
||||
if (event.getPlugin().equals(Stargate.getEconomyConfig().getVault())) {
|
||||
Stargate.logInfo("Vault plugin lost.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This listener listens for the loading of a world and loads all gates from the world if not already loaded
|
||||
*
|
||||
* @param event <p>The triggered world load event</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onWorldLoad(@NotNull WorldLoadEvent event) {
|
||||
StargateConfig config = Stargate.getStargateConfig();
|
||||
if (!config.getManagedWorlds().contains(event.getWorld().getName()) &&
|
||||
PortalFileHelper.loadAllPortals(event.getWorld())) {
|
||||
config.addManagedWorld(event.getWorld().getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This listener listens for the unloading of a world
|
||||
*
|
||||
* @param event <p>The triggered world unload event</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onWorldUnload(@NotNull WorldUnloadEvent event) {
|
||||
Stargate.debug("onWorldUnload", "Reloading all Stargates");
|
||||
World world = event.getWorld();
|
||||
String worldName = world.getName();
|
||||
StargateConfig config = Stargate.getStargateConfig();
|
||||
if (config.getManagedWorlds().contains(worldName)) {
|
||||
config.removeManagedWorld(worldName);
|
||||
PortalRegistry.clearPortals(world);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -3,59 +3,41 @@ package net.knarcraft.stargate.listener;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.knarcraft.knarlib.util.UpdateChecker;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.Message;
|
||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalActivator;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||
import net.knarcraft.stargate.portal.teleporter.VehicleTeleporter;
|
||||
import net.knarcraft.stargate.utility.BungeeHelper;
|
||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import net.knarcraft.stargate.utility.TeleportHelper;
|
||||
import net.knarcraft.stargate.utility.UUIDMigrationHelper;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
import org.geysermc.geyser.api.GeyserApi;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This listener listens to any player-related events related to stargates
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class PlayerEventListener implements Listener {
|
||||
|
||||
private static final Map<Player, Long> previousEventTimes = new HashMap<>();
|
||||
private boolean hasGeyser = true;
|
||||
private boolean hasFloodgate = true;
|
||||
|
||||
/**
|
||||
* This event handler handles detection of any player teleporting through a bungee gate
|
||||
@@ -96,198 +78,6 @@ public class PlayerEventListener implements Listener {
|
||||
new PlayerTeleporter(portal, player).teleport(portal, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* This event handler detects if a player moves into a portal
|
||||
*
|
||||
* @param event <p>The player move event which was triggered</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerMove(@NotNull PlayerMoveEvent event) {
|
||||
if (event.isCancelled() || event.getTo() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockLocation fromLocation = new BlockLocation(event.getFrom().getBlock());
|
||||
BlockLocation toLocation = new BlockLocation(event.getTo().getBlock());
|
||||
Player player = event.getPlayer();
|
||||
|
||||
//Check whether the event needs to be considered
|
||||
if (!isRelevantMoveEvent(event, player, fromLocation, toLocation)) {
|
||||
return;
|
||||
}
|
||||
Portal entrancePortal = PortalHandler.getByEntrance(toLocation);
|
||||
//Check an additional block away in case the portal is a bungee portal using END_PORTAL
|
||||
if (entrancePortal == null) {
|
||||
entrancePortal = PortalHandler.getByAdjacentEntrance(toLocation);
|
||||
// This should never realistically be null
|
||||
if (entrancePortal == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Portal destination = entrancePortal.getPortalActivator().getDestination(player);
|
||||
if (destination == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity playerVehicle = player.getVehicle();
|
||||
//If the player is in a vehicle, but vehicle handling is disabled, just ignore the player
|
||||
if (playerVehicle == null || (playerVehicle instanceof LivingEntity &&
|
||||
Stargate.getGateConfig().handleVehicles())) {
|
||||
teleportPlayer(playerVehicle, player, entrancePortal, destination, event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports a player, also teleports the player's vehicle if it's a living entity
|
||||
*
|
||||
* @param playerVehicle <p>The vehicle the player is currently sitting in</p>
|
||||
* @param player <p>The player which moved</p>
|
||||
* @param entrancePortal <p>The entrance the player entered</p>
|
||||
* @param destination <p>The destination of the entrance portal</p>
|
||||
* @param event <p>The move event causing the teleportation to trigger</p>
|
||||
*/
|
||||
private void teleportPlayer(@Nullable Entity playerVehicle, @NotNull Player player, @NotNull Portal entrancePortal,
|
||||
@NotNull Portal destination, @NotNull PlayerMoveEvent event) {
|
||||
if (playerVehicle instanceof LivingEntity) {
|
||||
//Make sure any horses are properly tamed
|
||||
if (playerVehicle instanceof AbstractHorse horse && !horse.isTamed()) {
|
||||
horse.setTamed(true);
|
||||
horse.setOwner(player);
|
||||
}
|
||||
//Teleport the player's vehicle
|
||||
player.setVelocity(new Vector());
|
||||
new VehicleTeleporter(destination, (Vehicle) playerVehicle).teleportEntity(entrancePortal);
|
||||
} else {
|
||||
//Just teleport the player like normal
|
||||
new PlayerTeleporter(destination, player).teleportPlayer(entrancePortal, event);
|
||||
}
|
||||
if (!entrancePortal.getOptions().isQuiet()) {
|
||||
new SGFormatBuilder(Message.TELEPORTED).success(player);
|
||||
}
|
||||
entrancePortal.getPortalOpener().closePortal(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a player move event is relevant for this plugin
|
||||
*
|
||||
* @param event <p>The player move event to check</p>
|
||||
* @param player <p>The player which moved</p>
|
||||
* @param fromLocation <p>The location the player is moving from</p>
|
||||
* @param toLocation <p>The location the player is moving to</p>
|
||||
* @return <p>True if the event is relevant</p>
|
||||
*/
|
||||
private boolean isRelevantMoveEvent(@NotNull PlayerMoveEvent event, Player player,
|
||||
@NotNull BlockLocation fromLocation, @NotNull BlockLocation toLocation) {
|
||||
//Check to see if the player moved to another block
|
||||
if (fromLocation.equals(toLocation)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Get the portal the player entered, if any
|
||||
Portal entrancePortal = getEnteredPortal(toLocation, player);
|
||||
if (entrancePortal == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Portal destination = entrancePortal.getPortalActivator().getDestination(player);
|
||||
|
||||
//Catch always open portals without a valid destination to prevent the user for being teleported and denied
|
||||
if (!entrancePortal.getOptions().isBungee() && destination == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Decide if the anything stops the player from teleport
|
||||
if (PermissionHelper.playerCannotTeleport(entrancePortal, destination, player, event)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Decide if the user should be teleported to another bungee server
|
||||
if (entrancePortal.getOptions().isBungee()) {
|
||||
if (BungeeHelper.bungeeTeleport(player, entrancePortal, event) && !entrancePortal.getOptions().isQuiet()) {
|
||||
new SGFormatBuilder(Message.TELEPORTED).success(player);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//Make sure to check if the player has any leashed creatures, even though leashed teleportation is disabled
|
||||
return TeleportHelper.noLeashedCreaturesPreventTeleportation(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the portal a player entered
|
||||
*
|
||||
* @param toLocation <p>The location the player moved to</p>
|
||||
* @param player <p>The player that moved</p>
|
||||
* @return <p>The portal the player entered, or null if no portal was entered</p>
|
||||
*/
|
||||
private Portal getEnteredPortal(@NotNull BlockLocation toLocation, @NotNull Player player) {
|
||||
Portal entrancePortal = PortalHandler.getByEntrance(toLocation);
|
||||
// Return if in an entrance
|
||||
if (entrancePortal != null) {
|
||||
return entrancePortal;
|
||||
}
|
||||
|
||||
//Check an additional block away for special cases like BungeeCord portals using END_PORTAL as its material
|
||||
entrancePortal = PortalHandler.getByAdjacentEntrance(toLocation);
|
||||
if (entrancePortal == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// If END_GATEWAY and END_PORTAL cannot appear, skip further checks
|
||||
Set<Material> entranceMaterials = MaterialHelper.specifiersToMaterials(entrancePortal.getGate().getPortalOpenMaterials());
|
||||
if (!entranceMaterials.contains(Material.END_GATEWAY) && !entranceMaterials.contains(Material.END_PORTAL)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get the real materials in the entrance, as END_GATEWAY or END_PORTAL may be available, but not chosen
|
||||
Set<Material> materialsInEntrance = new HashSet<>();
|
||||
for (BlockLocation location : entrancePortal.getStructure().getEntrances()) {
|
||||
materialsInEntrance.add(location.getType());
|
||||
}
|
||||
|
||||
// Abort if not a special case
|
||||
if ((!materialsInEntrance.contains(Material.END_GATEWAY) || !isGeyserPlayer(player)) &&
|
||||
(!entrancePortal.getOptions().isBungee() || !materialsInEntrance.contains(Material.END_PORTAL))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return entrancePortal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given player is connected through Geyser
|
||||
*
|
||||
* @param player <p>The player to check</p>
|
||||
* @return <p>True if the player is connected through Geyser</p>
|
||||
*/
|
||||
private boolean isGeyserPlayer(@NotNull Player player) {
|
||||
// Prevent unnecessary checking for non-geyser and floodgate servers
|
||||
if (!hasGeyser && !hasFloodgate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use Geyser API to get connection status
|
||||
if (hasGeyser) {
|
||||
try {
|
||||
return GeyserApi.api().connectionByUuid(player.getUniqueId()) != null;
|
||||
} catch (NoClassDefFoundError error1) {
|
||||
hasGeyser = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Use Floodgate API to get connection status
|
||||
if (hasFloodgate) {
|
||||
try {
|
||||
return FloodgateApi.getInstance().isFloodgatePlayer(player.getUniqueId());
|
||||
} catch (NoClassDefFoundError error2) {
|
||||
hasFloodgate = false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This event handler detects if a player clicks a button or a sign
|
||||
*
|
||||
|
@@ -1,60 +0,0 @@
|
||||
package net.knarcraft.stargate.listener;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.Message;
|
||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This listener listens for any plugins being enabled or disabled to catch the loading of vault
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class PluginEventListener implements Listener {
|
||||
|
||||
private final Stargate stargate;
|
||||
|
||||
/**
|
||||
* Instantiates a new plugin event listener
|
||||
*
|
||||
* @param stargate <p>A reference to the stargate plugin to </p>
|
||||
*/
|
||||
public PluginEventListener(@NotNull Stargate stargate) {
|
||||
this.stargate = stargate;
|
||||
}
|
||||
|
||||
/**
|
||||
* This event listens for and announces that the vault plugin was detected and enabled
|
||||
*
|
||||
* <p>Each time this event is called, the economy handler will try to enable vault</p>
|
||||
*
|
||||
* @param ignored <p>The actual event called. This is currently not used</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPluginEnable(@NotNull PluginEnableEvent ignored) {
|
||||
if (Stargate.getEconomyConfig().setupEconomy(stargate.getServer().getPluginManager())) {
|
||||
Plugin vault = Stargate.getEconomyConfig().getVault();
|
||||
if (vault != null) {
|
||||
String vaultVersion = vault.getDescription().getVersion();
|
||||
Stargate.logInfo(new SGFormatBuilder(Message.VAULT_LOADED).replace("%version%", vaultVersion).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This event listens for the vault plugin being disabled and notifies the console
|
||||
*
|
||||
* @param event <p>The event caused by disabling a plugin</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPluginDisable(@NotNull PluginDisableEvent event) {
|
||||
if (event.getPlugin().equals(Stargate.getEconomyConfig().getVault())) {
|
||||
Stargate.logInfo("Vault plugin lost.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,126 +0,0 @@
|
||||
package net.knarcraft.stargate.listener;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.container.FromTheEndTeleportation;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityPortalEnterEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.world.PortalCreateEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Listens for and cancels relevant portal events
|
||||
*/
|
||||
public class PortalEventListener implements Listener {
|
||||
|
||||
private static final Map<Player, FromTheEndTeleportation> playersFromTheEnd = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Listens for and aborts vanilla portal creation caused by stargate creation
|
||||
*
|
||||
* @param event <p>The triggered event</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPortalCreation(@NotNull PortalCreateEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
//Unnecessary nether portal creation is only triggered by nether pairing
|
||||
if (event.getReason() == PortalCreateEvent.CreateReason.NETHER_PAIR) {
|
||||
//If an entity is standing in a Stargate entrance, it can be assumed that the creation is a mistake
|
||||
Entity entity = event.getEntity();
|
||||
if (entity != null && PortalHandler.getByAdjacentEntrance(entity.getLocation()) != null) {
|
||||
Stargate.debug("PortalEventListener::onPortalCreation",
|
||||
"Cancelled nether portal create event");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen for entities entering an artificial end portal
|
||||
*
|
||||
* @param event <p>The triggered event</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onEntityPortalEnter(@NotNull EntityPortalEnterEvent event) {
|
||||
Location location = event.getLocation();
|
||||
World world = location.getWorld();
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
//Hijack normal portal teleportation if teleporting from a stargate, and teleporting from an end portal in the
|
||||
// end
|
||||
if (!(entity instanceof Player player) || location.getBlock().getType() != Material.END_PORTAL ||
|
||||
world == null || world.getEnvironment() != World.Environment.THE_END) {
|
||||
return;
|
||||
}
|
||||
|
||||
Portal portal = PortalHandler.getByAdjacentEntrance(location);
|
||||
if (portal == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Stargate.debug("PortalEventListener::onEntityPortalEnter",
|
||||
"Found player " + player + " entering END_PORTAL " + portal);
|
||||
|
||||
//Decide if the anything stops the player from teleporting
|
||||
if (PermissionHelper.playerCannotTeleport(portal, portal.getPortalActivator().getDestination(),
|
||||
player, null) || portal.getOptions().isBungee()) {
|
||||
//Teleport the player back to the portal they came in, just in case
|
||||
playersFromTheEnd.put(player, new FromTheEndTeleportation(portal));
|
||||
Stargate.debug("PortalEventListener::onEntityPortalEnter",
|
||||
"Sending player back to the entrance");
|
||||
} else {
|
||||
Portal destination = portal.getPortalActivator().getDestination();
|
||||
if (destination != null) {
|
||||
playersFromTheEnd.put(player, new FromTheEndTeleportation(destination));
|
||||
Stargate.debug("PortalEventListener::onEntityPortalEnter",
|
||||
"Sending player to destination");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen for the respawn event to catch players teleporting from the end in an artificial end portal
|
||||
*
|
||||
* @param event <p>The triggered event</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onRespawn(@NotNull PlayerRespawnEvent event) {
|
||||
Player respawningPlayer = event.getPlayer();
|
||||
FromTheEndTeleportation teleportation = playersFromTheEnd.remove(respawningPlayer);
|
||||
if (teleportation == null) {
|
||||
return;
|
||||
}
|
||||
Portal exitPortal = teleportation.exitPortal();
|
||||
|
||||
//Overwrite respawn location to respawn in front of the portal
|
||||
PlayerTeleporter teleporter = new PlayerTeleporter(exitPortal, respawningPlayer);
|
||||
Location respawnLocation = teleporter.getExit();
|
||||
event.setRespawnLocation(respawnLocation);
|
||||
//Try and force the player if for some reason the changing of respawn location isn't properly handled
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Stargate.getInstance(), () ->
|
||||
respawningPlayer.teleport(respawnLocation), 1);
|
||||
|
||||
//Properly close the portal to prevent it from staying in a locked state until it times out
|
||||
exitPortal.getPortalOpener().closePortal(false);
|
||||
|
||||
Stargate.debug("PortalEventListener::onRespawn", "Overwriting respawn for " + respawningPlayer +
|
||||
" to " + respawnLocation.getWorld() + ":" + respawnLocation);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,267 @@
|
||||
package net.knarcraft.stargate.listener;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockDispenseEvent;
|
||||
import org.bukkit.event.block.BlockExplodeEvent;
|
||||
import org.bukkit.event.block.BlockFadeEvent;
|
||||
import org.bukkit.event.block.BlockFertilizeEvent;
|
||||
import org.bukkit.event.block.BlockFormEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockMultiPlaceEvent;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.EntityBlockFormEvent;
|
||||
import org.bukkit.event.block.LeavesDecayEvent;
|
||||
import org.bukkit.event.block.SpongeAbsorbEvent;
|
||||
import org.bukkit.event.block.TNTPrimeEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityBreakDoorEvent;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
import org.bukkit.event.world.PortalCreateEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A listener for any events that might cause a Stargate to be altered or break
|
||||
*/
|
||||
public class StargateBreakListener implements Listener {
|
||||
|
||||
/**
|
||||
* Cancels blocks from being placed in the Stargate's entrance
|
||||
*
|
||||
* @param event <p>The event to check and possibly cancel</p>
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onBlockPlace(@NotNull BlockPlaceEvent event) {
|
||||
if (!Stargate.getGateConfig().protectEntrance()) {
|
||||
return;
|
||||
}
|
||||
Block block = event.getBlock();
|
||||
Portal portal = PortalHandler.getByEntrance(block);
|
||||
if (portal != null) {
|
||||
//Prevent blocks from being placed in the entrance, if protectEntrance is enabled, as breaking the block
|
||||
// would destroy the portal
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method catches any explosion events
|
||||
*
|
||||
* <p>If destroyed by explosions is enabled, any portals destroyed by the explosion will be unregistered. If not,
|
||||
* the explosion will be cancelled.</p>
|
||||
*
|
||||
* @param event <p>The triggered explosion event</p>
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onEntityExplode(@NotNull EntityExplodeEvent event) {
|
||||
for (Block block : event.blockList()) {
|
||||
Portal portal = PortalHandler.getByBlock(block);
|
||||
if (portal == null) {
|
||||
continue;
|
||||
}
|
||||
if (Stargate.getGateConfig().destroyedByExplosion()) {
|
||||
PortalRegistry.unregisterPortal(portal, true);
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onCreatureSpawn(@NotNull CreatureSpawnEvent event) {
|
||||
//Prevent Zombified Piglins and other creatures form spawning at stargates
|
||||
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NETHER_PORTAL &&
|
||||
PortalHandler.getByEntrance(event.getLocation()) != null) {
|
||||
event.setCancelled(true);
|
||||
Stargate.debug("EntitySpawnListener", "Prevented creature from spawning at Stargate");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPistonExtend(BlockPistonExtendEvent event) {
|
||||
cancelPistonIfNeeded(event.getBlocks(), event.getDirection(), event);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPistonRetract(@NotNull BlockPistonRetractEvent event) {
|
||||
cancelPistonIfNeeded(event.getBlocks(), event.getDirection(), event);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockExplode(@NotNull BlockExplodeEvent event) {
|
||||
cancelIfAtEntrance(event, event.blockList());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockFromTo(@NotNull BlockFromToEvent event) {
|
||||
cancelIfAtEntrance(event, event.getToBlock());
|
||||
cancelIfAtEntrance(event, event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockFormEvent(@NotNull BlockFormEvent event) {
|
||||
cancelIfAtEntrance(event, event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPhysics(@NotNull BlockPhysicsEvent event) {
|
||||
cancelIfAtEntrance(event, event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBurn(@NotNull BlockBurnEvent event) {
|
||||
cancelIfAtEntrance(event, event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockIgnite(@NotNull BlockIgniteEvent event) {
|
||||
cancelIfAtEntrance(event, event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockFade(@NotNull BlockFadeEvent event) {
|
||||
cancelIfAtEntrance(event, event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockFertilize(@NotNull BlockFertilizeEvent event) {
|
||||
cancelIfAtEntrance(event, event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockMultiPlace(@NotNull BlockMultiPlaceEvent event) {
|
||||
cancelIfAtEntrance(event, getBlocksFromBlockStates(event.getReplacedBlockStates()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityBlockForm(@NotNull EntityBlockFormEvent event) {
|
||||
cancelIfAtEntrance(event, event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onLeavesDecay(@NotNull LeavesDecayEvent event) {
|
||||
cancelIfAtEntrance(event, event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onSpongeAbsorb(@NotNull SpongeAbsorbEvent event) {
|
||||
cancelIfAtEntrance(event, getBlocksFromBlockStates(event.getBlocks()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityChangeBlock(@NotNull EntityChangeBlockEvent event) {
|
||||
cancelIfAtEntrance(event, event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityBreakDoor(@NotNull EntityBreakDoorEvent event) {
|
||||
cancelIfAtEntrance(event, event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPortalCreate(@NotNull PortalCreateEvent event) {
|
||||
cancelIfAtEntrance(event, getBlocksFromBlockStates(event.getBlocks()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityPlace(@NotNull EntityPlaceEvent event) {
|
||||
cancelIfAtEntrance(event, event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerBucketEmpty(@NotNull PlayerBucketEmptyEvent event) {
|
||||
cancelIfAtEntrance(event, event.getBlock());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockDispense(@NotNull BlockDispenseEvent event) {
|
||||
if (event.getBlock().getBlockData() instanceof Directional dispenser) {
|
||||
cancelIfAtEntrance(event, event.getBlock().getRelative(dispenser.getFacing()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onTNTPrime(@NotNull TNTPrimeEvent tntPrimeEvent) {
|
||||
cancelIfAtEntrance(tntPrimeEvent, tntPrimeEvent.getBlock());
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the given event if it involves a Stargate's entrance
|
||||
*
|
||||
* @param event <p>The event to cancel</p>
|
||||
* @param block <p>The block in question</p>
|
||||
*/
|
||||
private boolean cancelIfAtEntrance(@NotNull Cancellable event, @NotNull Block block) {
|
||||
if (PortalHandler.getByEntrance(block) != null || PortalHandler.getByControl(block) != null ||
|
||||
PortalHandler.getByBlock(block) != null) {
|
||||
event.setCancelled(true);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the given event if it involves a Stargate's entrance
|
||||
*
|
||||
* @param event <p>The event to cancel</p>
|
||||
* @param blocks <p>The blocks in question</p>
|
||||
*/
|
||||
private void cancelIfAtEntrance(@NotNull Cancellable event, @NotNull List<Block> blocks) {
|
||||
for (Block block : blocks) {
|
||||
if (cancelIfAtEntrance(event, block)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of blocks from a list of block states
|
||||
*
|
||||
* @param blockStates <p>The block states to convert into blocks</p>
|
||||
* @return <p>The corresponding blocks</p>
|
||||
*/
|
||||
@NotNull
|
||||
private List<Block> getBlocksFromBlockStates(@NotNull List<BlockState> blockStates) {
|
||||
return blockStates.stream().map(BlockState::getBlock).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the movement of a piston if it would interfere with a Stargate
|
||||
*
|
||||
* @param blocks <p>The blocks involved in the move</p>
|
||||
* @param blockFace <p>The block face of the piston</p>
|
||||
* @param event <p>The event to possibly cancel</p>
|
||||
*/
|
||||
private void cancelPistonIfNeeded(@NotNull List<Block> blocks, @NotNull BlockFace blockFace,
|
||||
@NotNull Cancellable event) {
|
||||
cancelIfAtEntrance(event, blocks);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
List<Block> movedBlocks = blocks.stream().map(block -> block.getRelative(blockFace)).toList();
|
||||
cancelIfAtEntrance(event, movedBlocks);
|
||||
}
|
||||
|
||||
}
|
@@ -1,8 +1,8 @@
|
||||
package net.knarcraft.stargate.listener;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.Message;
|
||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.container.BlockChangeRequest;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.event.StargateDestroyEvent;
|
||||
@@ -11,58 +11,23 @@ import net.knarcraft.stargate.portal.PortalCreator;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.utility.EconomyHelper;
|
||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Snowman;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.block.BlockPistonEvent;
|
||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.EntityBlockFormEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class is responsible for listening to relevant block events related to creating and breaking portals
|
||||
*/
|
||||
public class BlockEventListener implements Listener {
|
||||
|
||||
/**
|
||||
* Detects snowmen ruining portals
|
||||
*
|
||||
* <p>If entrance protection or portal verification is enabled, the snowman will be prevented from placing snow in
|
||||
* the portal entrance.</p>
|
||||
*
|
||||
* @param event <p>The triggered event</p>
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockFormedByEntity(@NotNull EntityBlockFormEvent event) {
|
||||
if ((!Stargate.getGateConfig().protectEntrance() &&
|
||||
!Stargate.getGateConfig().verifyPortals())) {
|
||||
return;
|
||||
}
|
||||
//We are only interested in snowman events
|
||||
if (!(event.getEntity() instanceof Snowman)) {
|
||||
return;
|
||||
}
|
||||
//Cancel the event if a snowman is trying to place snow in the portal's entrance
|
||||
if (PortalHandler.getByEntrance(event.getBlock()) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
public class StargateCreateDestroyListener implements Listener {
|
||||
|
||||
/**
|
||||
* Detects sign changes to detect if the user is creating a new gate
|
||||
@@ -97,20 +62,6 @@ public class BlockEventListener implements Listener {
|
||||
portal::drawSign, 1);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onBlockPlace(@NotNull BlockPlaceEvent event) {
|
||||
if (!Stargate.getGateConfig().protectEntrance()) {
|
||||
return;
|
||||
}
|
||||
Block block = event.getBlock();
|
||||
Portal portal = PortalHandler.getByEntrance(block);
|
||||
if (portal != null) {
|
||||
//Prevent blocks from being placed in the entrance, if protectEntrance is enabled, as breaking the block
|
||||
// would destroy the portal
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects block breaking to detect if the user is destroying a gate
|
||||
*
|
||||
@@ -206,77 +157,4 @@ public class BlockEventListener implements Listener {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents any block physics events which may damage parts of the portal
|
||||
*
|
||||
* @param event <p>The event to check and possibly cancel</p>
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockPhysics(@NotNull BlockPhysicsEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Portal portal = null;
|
||||
|
||||
if (block.getType() == Material.NETHER_PORTAL) {
|
||||
portal = PortalHandler.getByEntrance(block);
|
||||
} else if (MaterialHelper.isButtonCompatible(block.getType())) {
|
||||
portal = PortalHandler.getByControl(block);
|
||||
}
|
||||
if (portal != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels any block move events which may cause a block to enter the opening of a portal
|
||||
*
|
||||
* @param event <p>The event to check and possibly cancel</p>
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockFromTo(@NotNull BlockFromToEvent event) {
|
||||
Portal portal = PortalHandler.getByEntrance(event.getBlock());
|
||||
|
||||
if (portal != null && event.getBlock().getY() == event.getToBlock().getY()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels any piston extend events if the target block is part of a portal
|
||||
*
|
||||
* @param event <p>The event to check and possibly cancel</p>
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPistonExtend(@NotNull BlockPistonExtendEvent event) {
|
||||
cancelPistonEvent(event, event.getBlocks());
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels any piston retract events if the target block is part of a portal
|
||||
*
|
||||
* @param event <p>The event to check and possibly cancel</p>
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPistonRetract(@NotNull BlockPistonRetractEvent event) {
|
||||
if (!event.isSticky()) {
|
||||
return;
|
||||
}
|
||||
cancelPistonEvent(event, event.getBlocks());
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels a piston event if it would destroy a portal
|
||||
*
|
||||
* @param event <p>The event to cancel</p>
|
||||
* @param blocks <p>The blocks included in the event</p>
|
||||
*/
|
||||
private void cancelPistonEvent(@NotNull BlockPistonEvent event, @NotNull List<Block> blocks) {
|
||||
for (Block block : blocks) {
|
||||
Portal portal = PortalHandler.getByBlock(block);
|
||||
if (portal != null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,530 @@
|
||||
package net.knarcraft.stargate.listener;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.container.FromTheEndTeleportation;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||
import net.knarcraft.stargate.portal.teleporter.VehicleTeleporter;
|
||||
import net.knarcraft.stargate.utility.BungeeHelper;
|
||||
import net.knarcraft.stargate.utility.EconomyHelper;
|
||||
import net.knarcraft.stargate.utility.EntityHelper;
|
||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
import net.knarcraft.stargate.utility.TeleportHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityPortalEnterEvent;
|
||||
import org.bukkit.event.entity.EntityPortalEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.vehicle.VehicleMoveEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
import org.geysermc.geyser.api.GeyserApi;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This listener listens for the vehicle move event to teleport vehicles through portals
|
||||
*/
|
||||
public class StargateTeleportListener implements Listener {
|
||||
|
||||
private static final Map<Player, FromTheEndTeleportation> playersFromTheEnd = new HashMap<>();
|
||||
private boolean hasGeyser = true;
|
||||
private boolean hasFloodgate = true;
|
||||
|
||||
/**
|
||||
* This event handler handles some special teleportation events
|
||||
*
|
||||
* <p>This event cancels nether portal, end gateway and end portal teleportation if the user teleported from a
|
||||
* stargate entrance. This prevents the user from just teleporting to the nether or the end with portals using
|
||||
* the special teleportation blocks.</p>
|
||||
*
|
||||
* @param event <p>The event to check and possibly cancel</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerTeleport(@NotNull PlayerTeleportEvent event) {
|
||||
PlayerTeleportEvent.TeleportCause cause = event.getCause();
|
||||
|
||||
//Block normal portal teleportation if teleporting from a stargate
|
||||
if (!event.isCancelled() && (cause == PlayerTeleportEvent.TeleportCause.NETHER_PORTAL ||
|
||||
cause == PlayerTeleportEvent.TeleportCause.END_GATEWAY ||
|
||||
cause == PlayerTeleportEvent.TeleportCause.END_PORTAL)
|
||||
&& PortalHandler.getByAdjacentEntrance(event.getFrom()) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This event handler prevents sending entities to the normal nether instead of the stargate target
|
||||
*
|
||||
* @param event <p>The event to check and possibly cancel</p>
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPortalEvent(@NotNull EntityPortalEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = event.getEntity();
|
||||
//Cancel normal portal event is near a stargate
|
||||
if (PortalHandler.getByAdjacentEntrance(event.getFrom(), EntityHelper.getEntityMaxSizeInt(entity)) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for a vehicle moving through a portal
|
||||
*
|
||||
* @param event <p>The triggered move event</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onVehicleMove(@NotNull VehicleMoveEvent event) {
|
||||
if (!Stargate.getGateConfig().handleVehicles()) {
|
||||
return;
|
||||
}
|
||||
List<Entity> passengers = event.getVehicle().getPassengers();
|
||||
Vehicle vehicle = event.getVehicle();
|
||||
|
||||
Portal entrancePortal;
|
||||
int entitySize = EntityHelper.getEntityMaxSizeInt(vehicle);
|
||||
if (EntityHelper.getEntityMaxSize(vehicle) > 1) {
|
||||
entrancePortal = PortalHandler.getByAdjacentEntrance(event.getTo(), entitySize - 1);
|
||||
} else {
|
||||
entrancePortal = PortalHandler.getByEntrance(event.getTo());
|
||||
}
|
||||
|
||||
//Return if the portal cannot be teleported through
|
||||
if (entrancePortal == null || !entrancePortal.isOpen() || entrancePortal.getOptions().isBungee()) {
|
||||
return;
|
||||
}
|
||||
|
||||
teleportVehicle(passengers, entrancePortal, vehicle);
|
||||
}
|
||||
|
||||
/**
|
||||
* This event handler detects if a player moves into a portal
|
||||
*
|
||||
* @param event <p>The player move event which was triggered</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerMove(@NotNull PlayerMoveEvent event) {
|
||||
if (event.isCancelled() || event.getTo() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockLocation fromLocation = new BlockLocation(event.getFrom().getBlock());
|
||||
BlockLocation toLocation = new BlockLocation(event.getTo().getBlock());
|
||||
Player player = event.getPlayer();
|
||||
|
||||
//Check whether the event needs to be considered
|
||||
if (!isRelevantMoveEvent(event, player, fromLocation, toLocation)) {
|
||||
return;
|
||||
}
|
||||
Portal entrancePortal = PortalHandler.getByEntrance(toLocation);
|
||||
//Check an additional block away in case the portal is a bungee portal using END_PORTAL
|
||||
if (entrancePortal == null) {
|
||||
entrancePortal = PortalHandler.getByAdjacentEntrance(toLocation);
|
||||
// This should never realistically be null
|
||||
if (entrancePortal == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Portal destination = entrancePortal.getPortalActivator().getDestination(player);
|
||||
if (destination == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity playerVehicle = player.getVehicle();
|
||||
//If the player is in a vehicle, but vehicle handling is disabled, just ignore the player
|
||||
if (playerVehicle == null || (playerVehicle instanceof LivingEntity &&
|
||||
Stargate.getGateConfig().handleVehicles())) {
|
||||
teleportPlayer(playerVehicle, player, entrancePortal, destination, event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen for entities entering an artificial end portal
|
||||
*
|
||||
* @param event <p>The triggered event</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onEntityPortalEnter(@NotNull EntityPortalEnterEvent event) {
|
||||
Location location = event.getLocation();
|
||||
World world = location.getWorld();
|
||||
Entity entity = event.getEntity();
|
||||
|
||||
//Hijack normal portal teleportation if teleporting from a stargate, and teleporting from an end portal in the
|
||||
// end
|
||||
if (!(entity instanceof Player player) || location.getBlock().getType() != Material.END_PORTAL ||
|
||||
world == null || world.getEnvironment() != World.Environment.THE_END) {
|
||||
return;
|
||||
}
|
||||
|
||||
Portal portal = PortalHandler.getByAdjacentEntrance(location);
|
||||
if (portal == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Stargate.debug("PortalEventListener::onEntityPortalEnter",
|
||||
"Found player " + player + " entering END_PORTAL " + portal);
|
||||
|
||||
//Decide if the anything stops the player from teleporting
|
||||
if (PermissionHelper.playerCannotTeleport(portal, portal.getPortalActivator().getDestination(),
|
||||
player, null) || portal.getOptions().isBungee()) {
|
||||
//Teleport the player back to the portal they came in, just in case
|
||||
playersFromTheEnd.put(player, new FromTheEndTeleportation(portal));
|
||||
Stargate.debug("PortalEventListener::onEntityPortalEnter",
|
||||
"Sending player back to the entrance");
|
||||
} else {
|
||||
Portal destination = portal.getPortalActivator().getDestination();
|
||||
if (destination != null) {
|
||||
playersFromTheEnd.put(player, new FromTheEndTeleportation(destination));
|
||||
Stargate.debug("PortalEventListener::onEntityPortalEnter",
|
||||
"Sending player to destination");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen for the respawn event to catch players teleporting from the end in an artificial end portal
|
||||
*
|
||||
* @param event <p>The triggered event</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onRespawn(@NotNull PlayerRespawnEvent event) {
|
||||
Player respawningPlayer = event.getPlayer();
|
||||
FromTheEndTeleportation teleportation = playersFromTheEnd.remove(respawningPlayer);
|
||||
if (teleportation == null) {
|
||||
return;
|
||||
}
|
||||
Portal exitPortal = teleportation.exitPortal();
|
||||
|
||||
//Overwrite respawn location to respawn in front of the portal
|
||||
PlayerTeleporter teleporter = new PlayerTeleporter(exitPortal, respawningPlayer);
|
||||
Location respawnLocation = teleporter.getExit();
|
||||
event.setRespawnLocation(respawnLocation);
|
||||
//Try and force the player if for some reason the changing of respawn location isn't properly handled
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Stargate.getInstance(), () ->
|
||||
respawningPlayer.teleport(respawnLocation), 1);
|
||||
|
||||
//Properly close the portal to prevent it from staying in a locked state until it times out
|
||||
exitPortal.getPortalOpener().closePortal(false);
|
||||
|
||||
Stargate.debug("PortalEventListener::onRespawn", "Overwriting respawn for " + respawningPlayer +
|
||||
" to " + respawnLocation.getWorld() + ":" + respawnLocation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports a vehicle through a stargate
|
||||
*
|
||||
* @param passengers <p>The passengers inside the vehicle</p>
|
||||
* @param entrancePortal <p>The portal the vehicle is entering</p>
|
||||
* @param vehicle <p>The vehicle passing through</p>
|
||||
*/
|
||||
private static void teleportVehicle(@NotNull List<Entity> passengers, @NotNull Portal entrancePortal,
|
||||
@NotNull Vehicle vehicle) {
|
||||
String route = "VehicleEventListener::teleportVehicle";
|
||||
|
||||
if (!passengers.isEmpty() && TeleportHelper.containsPlayer(passengers)) {
|
||||
Stargate.debug(route, "Found passenger vehicle");
|
||||
teleportPlayerAndVehicle(entrancePortal, vehicle);
|
||||
} else {
|
||||
Stargate.debug(route, "Found vehicle without players");
|
||||
Portal destinationPortal = entrancePortal.getPortalActivator().getDestination();
|
||||
if (destinationPortal == null) {
|
||||
Stargate.debug(route, "Unable to find portal destination");
|
||||
return;
|
||||
}
|
||||
Stargate.debug("vehicleTeleport", destinationPortal.getWorld() + " " +
|
||||
destinationPortal.getSignLocation());
|
||||
new VehicleTeleporter(destinationPortal, vehicle).teleportEntity(entrancePortal);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports a player and the vehicle the player sits in
|
||||
*
|
||||
* @param entrancePortal <p>The portal the minecart entered</p>
|
||||
* @param vehicle <p>The vehicle to teleport</p>
|
||||
*/
|
||||
private static void teleportPlayerAndVehicle(@NotNull Portal entrancePortal, @NotNull Vehicle vehicle) {
|
||||
Entity rootEntity = vehicle;
|
||||
while (rootEntity.getVehicle() != null) {
|
||||
rootEntity = rootEntity.getVehicle();
|
||||
}
|
||||
List<Player> players = TeleportHelper.getPlayers(rootEntity.getPassengers());
|
||||
Portal destinationPortal = getDestinationPortal(players, entrancePortal);
|
||||
|
||||
//Cancel the teleport if no players activated the portal, or if any players are denied access
|
||||
boolean cancelTeleportation = false;
|
||||
for (Player player : players) {
|
||||
if (destinationPortal == null) {
|
||||
cancelTeleportation = true;
|
||||
if (!entrancePortal.getOptions().isQuiet()) {
|
||||
new SGFormatBuilder(Message.INVALID_DESTINATION).error(player);
|
||||
}
|
||||
} else if (!TeleportHelper.playerCanTeleport(player, entrancePortal, destinationPortal)) {
|
||||
cancelTeleportation = true;
|
||||
}
|
||||
}
|
||||
if (cancelTeleportation || destinationPortal == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Take payment from all players
|
||||
if (!takePayment(players, entrancePortal, destinationPortal)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Perform the teleportation
|
||||
teleportPlayerAndVehicle(players, vehicle, entrancePortal, destinationPortal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the teleportation of one or more players in a vehicle
|
||||
*
|
||||
* @param players <p>The players to be teleported</p>
|
||||
* @param vehicle <p>The vehicle that triggered the teleportation</p>
|
||||
* @param entrancePortal <p>The portal the player(s) and vehicle entered from</p>
|
||||
* @param destinationPortal <p>The portal the player(s) and vehicle are teleporting to</p>
|
||||
*/
|
||||
private static void teleportPlayerAndVehicle(@NotNull List<Player> players, @NotNull Vehicle vehicle,
|
||||
@NotNull Portal entrancePortal, @NotNull Portal destinationPortal) {
|
||||
//Teleport the vehicle and inform the user if the vehicle was teleported
|
||||
boolean teleported = new VehicleTeleporter(destinationPortal, vehicle).teleportEntity(entrancePortal);
|
||||
if (!teleported) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entrancePortal.getOptions().isQuiet()) {
|
||||
for (Player player : players) {
|
||||
new SGFormatBuilder(Message.TELEPORTED).success(player);
|
||||
}
|
||||
}
|
||||
entrancePortal.getPortalOpener().closePortal(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to get the destination portal selected by one of the players included in the teleportation
|
||||
*
|
||||
* @param players <p>The players to be teleported</p>
|
||||
* @param entrancePortal <p>The portal the players are entering</p>
|
||||
* @return <p>The destination portal, or null if not found</p>
|
||||
*/
|
||||
@Nullable
|
||||
private static Portal getDestinationPortal(@NotNull List<Player> players, @NotNull Portal entrancePortal) {
|
||||
for (Player player : players) {
|
||||
//The entrance portal must be open for one player for the teleportation to happen
|
||||
if (!entrancePortal.getPortalOpener().isOpenFor(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Check if any of the players has selected the destination
|
||||
Portal possibleDestinationPortal = entrancePortal.getPortalActivator().getDestination(player);
|
||||
if (possibleDestinationPortal != null) {
|
||||
return possibleDestinationPortal;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes payment for the given players
|
||||
*
|
||||
* @param players <p>The players to take payment from</p>
|
||||
* @param entrancePortal <p>The portal the players are travelling from</p>
|
||||
* @param destinationPortal <p>The portal the players are travelling to</p>
|
||||
* @return <p>True if payment was successfully taken, false otherwise</p>
|
||||
*/
|
||||
private static boolean takePayment(@NotNull List<Player> players, @NotNull Portal entrancePortal,
|
||||
@NotNull Portal destinationPortal) {
|
||||
for (Player player : players) {
|
||||
//To prevent the case where the first passenger pays and then the second passenger is denied, this has to be
|
||||
// run after it has been confirmed that all passengers are able to pay. Also note that some players might
|
||||
// not have to pay, and thus the cost check has to be in the loop,
|
||||
int cost = EconomyHelper.getUseCost(player, entrancePortal, destinationPortal);
|
||||
if (cost > 0) {
|
||||
if (EconomyHelper.cannotPayTeleportFee(entrancePortal, player, cost)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports a player, also teleports the player's vehicle if it's a living entity
|
||||
*
|
||||
* @param playerVehicle <p>The vehicle the player is currently sitting in</p>
|
||||
* @param player <p>The player which moved</p>
|
||||
* @param entrancePortal <p>The entrance the player entered</p>
|
||||
* @param destination <p>The destination of the entrance portal</p>
|
||||
* @param event <p>The move event causing the teleportation to trigger</p>
|
||||
*/
|
||||
private void teleportPlayer(@Nullable Entity playerVehicle, @NotNull Player player, @NotNull Portal entrancePortal,
|
||||
@NotNull Portal destination, @NotNull PlayerMoveEvent event) {
|
||||
if (playerVehicle instanceof LivingEntity) {
|
||||
//Make sure any horses are properly tamed
|
||||
if (playerVehicle instanceof AbstractHorse horse && !horse.isTamed()) {
|
||||
horse.setTamed(true);
|
||||
horse.setOwner(player);
|
||||
}
|
||||
//Teleport the player's vehicle
|
||||
player.setVelocity(new Vector());
|
||||
new VehicleTeleporter(destination, (Vehicle) playerVehicle).teleportEntity(entrancePortal);
|
||||
} else {
|
||||
//Just teleport the player like normal
|
||||
new PlayerTeleporter(destination, player).teleportPlayer(entrancePortal, event);
|
||||
}
|
||||
if (!entrancePortal.getOptions().isQuiet()) {
|
||||
new SGFormatBuilder(Message.TELEPORTED).success(player);
|
||||
}
|
||||
entrancePortal.getPortalOpener().closePortal(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a player move event is relevant for this plugin
|
||||
*
|
||||
* @param event <p>The player move event to check</p>
|
||||
* @param player <p>The player which moved</p>
|
||||
* @param fromLocation <p>The location the player is moving from</p>
|
||||
* @param toLocation <p>The location the player is moving to</p>
|
||||
* @return <p>True if the event is relevant</p>
|
||||
*/
|
||||
private boolean isRelevantMoveEvent(@NotNull PlayerMoveEvent event, Player player,
|
||||
@NotNull BlockLocation fromLocation, @NotNull BlockLocation toLocation) {
|
||||
//Check to see if the player moved to another block
|
||||
if (fromLocation.equals(toLocation)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Get the portal the player entered, if any
|
||||
Portal entrancePortal = getEnteredPortal(toLocation, player);
|
||||
if (entrancePortal == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Portal destination = entrancePortal.getPortalActivator().getDestination(player);
|
||||
|
||||
//Catch always open portals without a valid destination to prevent the user for being teleported and denied
|
||||
if (!entrancePortal.getOptions().isBungee() && destination == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Decide if the anything stops the player from teleport
|
||||
if (PermissionHelper.playerCannotTeleport(entrancePortal, destination, player, event)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Decide if the user should be teleported to another bungee server
|
||||
if (entrancePortal.getOptions().isBungee()) {
|
||||
if (BungeeHelper.bungeeTeleport(player, entrancePortal, event) && !entrancePortal.getOptions().isQuiet()) {
|
||||
new SGFormatBuilder(Message.TELEPORTED).success(player);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//Make sure to check if the player has any leashed creatures, even though leashed teleportation is disabled
|
||||
return TeleportHelper.noLeashedCreaturesPreventTeleportation(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the portal a player entered
|
||||
*
|
||||
* @param toLocation <p>The location the player moved to</p>
|
||||
* @param player <p>The player that moved</p>
|
||||
* @return <p>The portal the player entered, or null if no portal was entered</p>
|
||||
*/
|
||||
private Portal getEnteredPortal(@NotNull BlockLocation toLocation, @NotNull Player player) {
|
||||
Portal entrancePortal = PortalHandler.getByEntrance(toLocation);
|
||||
// Return if in an entrance
|
||||
if (entrancePortal != null) {
|
||||
return entrancePortal;
|
||||
}
|
||||
|
||||
//Check an additional block away for special cases like BungeeCord portals using END_PORTAL as its material
|
||||
entrancePortal = PortalHandler.getByAdjacentEntrance(toLocation);
|
||||
if (entrancePortal == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// If END_GATEWAY and END_PORTAL cannot appear, skip further checks
|
||||
Set<Material> entranceMaterials = MaterialHelper.specifiersToMaterials(entrancePortal.getGate().getPortalOpenMaterials());
|
||||
if (!entranceMaterials.contains(Material.END_GATEWAY) && !entranceMaterials.contains(Material.END_PORTAL)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get the real materials in the entrance, as END_GATEWAY or END_PORTAL may be available, but not chosen
|
||||
Set<Material> materialsInEntrance = new HashSet<>();
|
||||
for (BlockLocation location : entrancePortal.getStructure().getEntrances()) {
|
||||
materialsInEntrance.add(location.getType());
|
||||
}
|
||||
|
||||
// Abort if not a special case
|
||||
if ((!materialsInEntrance.contains(Material.END_GATEWAY) || !isGeyserPlayer(player)) &&
|
||||
(!entrancePortal.getOptions().isBungee() || !materialsInEntrance.contains(Material.END_PORTAL))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return entrancePortal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given player is connected through Geyser
|
||||
*
|
||||
* @param player <p>The player to check</p>
|
||||
* @return <p>True if the player is connected through Geyser</p>
|
||||
*/
|
||||
private boolean isGeyserPlayer(@NotNull Player player) {
|
||||
// Prevent unnecessary checking for non-geyser and floodgate servers
|
||||
if (!hasGeyser && !hasFloodgate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use Geyser API to get connection status
|
||||
if (hasGeyser) {
|
||||
try {
|
||||
return GeyserApi.api().connectionByUuid(player.getUniqueId()) != null;
|
||||
} catch (NoClassDefFoundError error1) {
|
||||
hasGeyser = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Use Floodgate API to get connection status
|
||||
if (hasFloodgate) {
|
||||
try {
|
||||
return FloodgateApi.getInstance().isFloodgatePlayer(player.getUniqueId());
|
||||
} catch (NoClassDefFoundError error2) {
|
||||
hasFloodgate = false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
package net.knarcraft.stargate.listener;
|
||||
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This listener listens to teleportation-related events
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class TeleportEventListener implements Listener {
|
||||
|
||||
/**
|
||||
* This event handler handles some special teleportation events
|
||||
*
|
||||
* <p>This event cancels nether portal, end gateway and end portal teleportation if the user teleported from a
|
||||
* stargate entrance. This prevents the user from just teleporting to the nether or the end with portals using
|
||||
* the special teleportation blocks.</p>
|
||||
*
|
||||
* @param event <p>The event to check and possibly cancel</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerTeleport(@NotNull PlayerTeleportEvent event) {
|
||||
PlayerTeleportEvent.TeleportCause cause = event.getCause();
|
||||
|
||||
//Block normal portal teleportation if teleporting from a stargate
|
||||
if (!event.isCancelled() && (cause == PlayerTeleportEvent.TeleportCause.NETHER_PORTAL ||
|
||||
cause == PlayerTeleportEvent.TeleportCause.END_GATEWAY ||
|
||||
cause == PlayerTeleportEvent.TeleportCause.END_PORTAL)
|
||||
&& PortalHandler.getByAdjacentEntrance(event.getFrom()) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,198 +0,0 @@
|
||||
package net.knarcraft.stargate.listener;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.Message;
|
||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.teleporter.VehicleTeleporter;
|
||||
import net.knarcraft.stargate.utility.EconomyHelper;
|
||||
import net.knarcraft.stargate.utility.EntityHelper;
|
||||
import net.knarcraft.stargate.utility.TeleportHelper;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.vehicle.VehicleMoveEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This listener listens for the vehicle move event to teleport vehicles through portals
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class VehicleEventListener implements Listener {
|
||||
|
||||
/**
|
||||
* Check for a vehicle moving through a portal
|
||||
*
|
||||
* @param event <p>The triggered move event</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onVehicleMove(@NotNull VehicleMoveEvent event) {
|
||||
if (!Stargate.getGateConfig().handleVehicles()) {
|
||||
return;
|
||||
}
|
||||
List<Entity> passengers = event.getVehicle().getPassengers();
|
||||
Vehicle vehicle = event.getVehicle();
|
||||
|
||||
Portal entrancePortal;
|
||||
int entitySize = EntityHelper.getEntityMaxSizeInt(vehicle);
|
||||
if (EntityHelper.getEntityMaxSize(vehicle) > 1) {
|
||||
entrancePortal = PortalHandler.getByAdjacentEntrance(event.getTo(), entitySize - 1);
|
||||
} else {
|
||||
entrancePortal = PortalHandler.getByEntrance(event.getTo());
|
||||
}
|
||||
|
||||
//Return if the portal cannot be teleported through
|
||||
if (entrancePortal == null || !entrancePortal.isOpen() || entrancePortal.getOptions().isBungee()) {
|
||||
return;
|
||||
}
|
||||
|
||||
teleportVehicle(passengers, entrancePortal, vehicle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports a vehicle through a stargate
|
||||
*
|
||||
* @param passengers <p>The passengers inside the vehicle</p>
|
||||
* @param entrancePortal <p>The portal the vehicle is entering</p>
|
||||
* @param vehicle <p>The vehicle passing through</p>
|
||||
*/
|
||||
private static void teleportVehicle(@NotNull List<Entity> passengers, @NotNull Portal entrancePortal,
|
||||
@NotNull Vehicle vehicle) {
|
||||
String route = "VehicleEventListener::teleportVehicle";
|
||||
|
||||
if (!passengers.isEmpty() && TeleportHelper.containsPlayer(passengers)) {
|
||||
Stargate.debug(route, "Found passenger vehicle");
|
||||
teleportPlayerAndVehicle(entrancePortal, vehicle);
|
||||
} else {
|
||||
Stargate.debug(route, "Found vehicle without players");
|
||||
Portal destinationPortal = entrancePortal.getPortalActivator().getDestination();
|
||||
if (destinationPortal == null) {
|
||||
Stargate.debug(route, "Unable to find portal destination");
|
||||
return;
|
||||
}
|
||||
Stargate.debug("vehicleTeleport", destinationPortal.getWorld() + " " +
|
||||
destinationPortal.getSignLocation());
|
||||
new VehicleTeleporter(destinationPortal, vehicle).teleportEntity(entrancePortal);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleports a player and the vehicle the player sits in
|
||||
*
|
||||
* @param entrancePortal <p>The portal the minecart entered</p>
|
||||
* @param vehicle <p>The vehicle to teleport</p>
|
||||
*/
|
||||
private static void teleportPlayerAndVehicle(@NotNull Portal entrancePortal, @NotNull Vehicle vehicle) {
|
||||
Entity rootEntity = vehicle;
|
||||
while (rootEntity.getVehicle() != null) {
|
||||
rootEntity = rootEntity.getVehicle();
|
||||
}
|
||||
List<Player> players = TeleportHelper.getPlayers(rootEntity.getPassengers());
|
||||
Portal destinationPortal = getDestinationPortal(players, entrancePortal);
|
||||
|
||||
//Cancel the teleport if no players activated the portal, or if any players are denied access
|
||||
boolean cancelTeleportation = false;
|
||||
for (Player player : players) {
|
||||
if (destinationPortal == null) {
|
||||
cancelTeleportation = true;
|
||||
if (!entrancePortal.getOptions().isQuiet()) {
|
||||
new SGFormatBuilder(Message.INVALID_DESTINATION).error(player);
|
||||
}
|
||||
} else if (!TeleportHelper.playerCanTeleport(player, entrancePortal, destinationPortal)) {
|
||||
cancelTeleportation = true;
|
||||
}
|
||||
}
|
||||
if (cancelTeleportation || destinationPortal == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Take payment from all players
|
||||
if (!takePayment(players, entrancePortal, destinationPortal)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Perform the teleportation
|
||||
teleportPlayerAndVehicle(players, vehicle, entrancePortal, destinationPortal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the teleportation of one or more players in a vehicle
|
||||
*
|
||||
* @param players <p>The players to be teleported</p>
|
||||
* @param vehicle <p>The vehicle that triggered the teleportation</p>
|
||||
* @param entrancePortal <p>The portal the player(s) and vehicle entered from</p>
|
||||
* @param destinationPortal <p>The portal the player(s) and vehicle are teleporting to</p>
|
||||
*/
|
||||
private static void teleportPlayerAndVehicle(@NotNull List<Player> players, @NotNull Vehicle vehicle,
|
||||
@NotNull Portal entrancePortal, @NotNull Portal destinationPortal) {
|
||||
//Teleport the vehicle and inform the user if the vehicle was teleported
|
||||
boolean teleported = new VehicleTeleporter(destinationPortal, vehicle).teleportEntity(entrancePortal);
|
||||
if (!teleported) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entrancePortal.getOptions().isQuiet()) {
|
||||
for (Player player : players) {
|
||||
new SGFormatBuilder(Message.TELEPORTED).success(player);
|
||||
}
|
||||
}
|
||||
entrancePortal.getPortalOpener().closePortal(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to get the destination portal selected by one of the players included in the teleportation
|
||||
*
|
||||
* @param players <p>The players to be teleported</p>
|
||||
* @param entrancePortal <p>The portal the players are entering</p>
|
||||
* @return <p>The destination portal, or null if not found</p>
|
||||
*/
|
||||
@Nullable
|
||||
private static Portal getDestinationPortal(@NotNull List<Player> players, @NotNull Portal entrancePortal) {
|
||||
for (Player player : players) {
|
||||
//The entrance portal must be open for one player for the teleportation to happen
|
||||
if (!entrancePortal.getPortalOpener().isOpenFor(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Check if any of the players has selected the destination
|
||||
Portal possibleDestinationPortal = entrancePortal.getPortalActivator().getDestination(player);
|
||||
if (possibleDestinationPortal != null) {
|
||||
return possibleDestinationPortal;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes payment for the given players
|
||||
*
|
||||
* @param players <p>The players to take payment from</p>
|
||||
* @param entrancePortal <p>The portal the players are travelling from</p>
|
||||
* @param destinationPortal <p>The portal the players are travelling to</p>
|
||||
* @return <p>True if payment was successfully taken, false otherwise</p>
|
||||
*/
|
||||
private static boolean takePayment(@NotNull List<Player> players, @NotNull Portal entrancePortal,
|
||||
@NotNull Portal destinationPortal) {
|
||||
for (Player player : players) {
|
||||
//To prevent the case where the first passenger pays and then the second passenger is denied, this has to be
|
||||
// run after it has been confirmed that all passengers are able to pay. Also note that some players might
|
||||
// not have to pay, and thus the cost check has to be in the loop,
|
||||
int cost = EconomyHelper.getUseCost(player, entrancePortal, destinationPortal);
|
||||
if (cost > 0) {
|
||||
if (EconomyHelper.cannotPayTeleportFee(entrancePortal, player, cost)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@@ -1,51 +0,0 @@
|
||||
package net.knarcraft.stargate.listener;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.StargateConfig;
|
||||
import net.knarcraft.stargate.portal.PortalRegistry;
|
||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.event.world.WorldUnloadEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This listener listens for the loading and unloading of worlds to load and unload stargates
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class WorldEventListener implements Listener {
|
||||
|
||||
/**
|
||||
* This listener listens for the loading of a world and loads all gates from the world if not already loaded
|
||||
*
|
||||
* @param event <p>The triggered world load event</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onWorldLoad(@NotNull WorldLoadEvent event) {
|
||||
StargateConfig config = Stargate.getStargateConfig();
|
||||
if (!config.getManagedWorlds().contains(event.getWorld().getName()) &&
|
||||
PortalFileHelper.loadAllPortals(event.getWorld())) {
|
||||
config.addManagedWorld(event.getWorld().getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This listener listens for the unloading of a world
|
||||
*
|
||||
* @param event <p>The triggered world unload event</p>
|
||||
*/
|
||||
@EventHandler
|
||||
public void onWorldUnload(@NotNull WorldUnloadEvent event) {
|
||||
Stargate.debug("onWorldUnload", "Reloading all Stargates");
|
||||
World world = event.getWorld();
|
||||
String worldName = world.getName();
|
||||
StargateConfig config = Stargate.getStargateConfig();
|
||||
if (config.getManagedWorlds().contains(worldName)) {
|
||||
config.removeManagedWorld(worldName);
|
||||
PortalRegistry.clearPortals(world);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,6 +1,5 @@
|
||||
package net.knarcraft.stargate.portal;
|
||||
|
||||
import net.knarcraft.stargate.transformation.SimpleVectorOperation;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
||||
import net.knarcraft.stargate.portal.property.PortalLocation;
|
||||
@@ -10,6 +9,7 @@ import net.knarcraft.stargate.portal.property.PortalOwner;
|
||||
import net.knarcraft.stargate.portal.property.PortalStrings;
|
||||
import net.knarcraft.stargate.portal.property.PortalStructure;
|
||||
import net.knarcraft.stargate.portal.property.gate.Gate;
|
||||
import net.knarcraft.stargate.transformation.SimpleVectorOperation;
|
||||
import net.knarcraft.stargate.utility.DirectionHelper;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.World;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package net.knarcraft.stargate.portal;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.Message;
|
||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.event.StargateActivateEvent;
|
||||
import net.knarcraft.stargate.event.StargateDeactivateEvent;
|
||||
import net.knarcraft.stargate.utility.ListHelper;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package net.knarcraft.stargate.portal;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.Message;
|
||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
||||
import net.knarcraft.stargate.event.StargateCreateEvent;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package net.knarcraft.stargate.portal;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.Message;
|
||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.config.material.BukkitTagSpecifier;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.container.RelativeBlockVector;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package net.knarcraft.stargate.portal;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.DynmapManager;
|
||||
import net.knarcraft.stargate.config.addons.DynmapManager;
|
||||
import net.knarcraft.stargate.config.material.BukkitTagSpecifier;
|
||||
import net.knarcraft.stargate.container.BlockLocation;
|
||||
import net.knarcraft.stargate.utility.PortalFileHelper;
|
||||
|
@@ -3,8 +3,8 @@ package net.knarcraft.stargate.portal;
|
||||
import net.knarcraft.knarlib.property.ColorConversion;
|
||||
import net.knarcraft.knarlib.util.ColorHelper;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.Message;
|
||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.container.SignData;
|
||||
import net.knarcraft.stargate.portal.property.PortalLocation;
|
||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.Message;
|
||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.PortalHandler;
|
||||
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||
|
@@ -2,9 +2,9 @@ package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.EconomyConfig;
|
||||
import net.knarcraft.stargate.config.Message;
|
||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.config.addons.EconomyConfig;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.property.PortalOwner;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.Message;
|
||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.event.StargateAccessEvent;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.property.PortalOption;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package net.knarcraft.stargate.utility;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.Message;
|
||||
import net.knarcraft.stargate.config.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.config.formatting.Message;
|
||||
import net.knarcraft.stargate.config.formatting.SGFormatBuilder;
|
||||
import net.knarcraft.stargate.portal.Portal;
|
||||
import net.knarcraft.stargate.portal.teleporter.EntityTeleporter;
|
||||
import org.bukkit.Bukkit;
|
||||
|
Reference in New Issue
Block a user