diff --git a/TempFly/src/com/moneybags/tempfly/TeleportListener.java b/TempFly/src/com/moneybags/tempfly/TeleportListener.java new file mode 100644 index 0000000..f4cc3c1 --- /dev/null +++ b/TempFly/src/com/moneybags/tempfly/TeleportListener.java @@ -0,0 +1,35 @@ +package com.moneybags.tempfly; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerTeleportEvent; + +public class TeleportListener implements Listener { + + private final TempFly plugin; + + public TeleportListener(TempFly plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onTeleport(PlayerTeleportEvent event) { + Player player = event.getPlayer(); + + // Check if player is actively using TempFly + if (!plugin.getFlightManager().isTempFlying(player)) return; + + // Check if destination world allows TempFly + if (!plugin.getFlightManager().worldHasTempFly(event.getTo().getWorld())) return; + + // After teleport, stop flying but keep ability to start again + Bukkit.getScheduler().runTaskLater(plugin, () -> { + if (player.isFlying()) { + player.setFlying(false); + player.setAllowFlight(true); + } + }, 1L); + } +} diff --git a/TempFly/src/com/moneybags/tempfly/TempFly.java b/TempFly/src/com/moneybags/tempfly/TempFly.java index 9a9b098..d83454b 100644 --- a/TempFly/src/com/moneybags/tempfly/TempFly.java +++ b/TempFly/src/com/moneybags/tempfly/TempFly.java @@ -74,58 +74,62 @@ public GuiManager getGuiManager() { return gui; } - @Override - public void onEnable() { - Console.setLogger(this.getLogger()); - - Files.createFiles(this); - V.loadValues(); - - try { - this.bridge = new DataBridge(this); - } catch (IOException | SQLException e1) { - e1.printStackTrace(); - getServer().getPluginManager().disablePlugin(this); - return; - } - - tfApi = new TempFlyAPI(this); - this.flight = new FlightManager(this); - this.time = new TimeManager(this); - this.hooks = new HookManager(this); - this.commands = new CommandManager(this); - this.gui = new GuiManager(this); - - hooks.loadInternalGenres(); - initializeGui(); - initializeAesthetics(); +@Override +public void onEnable() { + Console.setLogger(this.getLogger()); + + Files.createFiles(this); + V.loadValues(); + + try { + this.bridge = new DataBridge(this); + } catch (IOException | SQLException e1) { + e1.printStackTrace(); + getServer().getPluginManager().disablePlugin(this); + return; + } + + tfApi = new TempFlyAPI(this); + this.flight = new FlightManager(this); + this.time = new TimeManager(this); + this.hooks = new HookManager(this); + this.commands = new CommandManager(this); + this.gui = new GuiManager(this); + + hooks.loadInternalGenres(); + initializeGui(); + initializeAesthetics(); + + // Register teleport listener + Bukkit.getPluginManager().registerEvents(new TeleportListener(this), this); + + try { + Metrics metrics = new Metrics(this, 8196); + metrics.addCustomChart(new Metrics.DrilldownPie("gamemode_hooks", () -> { + Map> map = new HashMap<>(); + Map entry = new HashMap<>(); + + for (TempFlyHook hook : hooks.getEnabled()) { + entry.put(hook.getHookedPlugin(), 1); + map.put(hook.getHookedPlugin(), entry); + } + if (map.size() == 0) { + entry.put("No Hooks", 1); + map.put("No Hooks", entry); + } + return map; + })); + } catch (Exception e) { + e.printStackTrace(); + } + + autosave = new AutoSave(bridge).runTaskTimerAsynchronously(this, V.save * 20 * 60, V.save * 20 * 60); + + // Support "/reload" + for (Player p : Bukkit.getOnlinePlayers()) { + flight.addUser(p); + } - - try { - Metrics metrics = new Metrics(this, 8196); - // Hooks - metrics.addCustomChart(new Metrics.DrilldownPie("gamemode_hooks", () -> { - Map> map = new HashMap<>(); - Map entry = new HashMap<>(); - - for (TempFlyHook hook: hooks.getEnabled()) { - entry.put(hook.getHookedPlugin(), 1); - map.put(hook.getHookedPlugin(), entry); - } - if (map.size() == 0) { - entry.put("No Hooks", 1); - map.put("No Hooks", entry); - } - return map; - })); - } catch (Exception e) {e.printStackTrace();} - - autosave = new AutoSave(bridge).runTaskTimerAsynchronously(this, V.save * 20 * 60, V.save * 20 * 60); - - // Support "/reload" - for (Player p: Bukkit.getOnlinePlayers()) { - flight.addUser(p); - } } private void initializeAesthetics() { @@ -193,3 +197,4 @@ public List onTabComplete(CommandSender s, Command cmd, String label, St } } +