From 914181f0046b9f992811a60f477e071fa875510e Mon Sep 17 00:00:00 2001 From: ShakeforProtein Date: Mon, 23 Aug 2021 13:53:44 +1000 Subject: [PATCH] Added Tweak to fix Flight being turned off when changing world via a non portal teleport. Temporarily disables TreeTwerking while I work out how to solve an issue with it. --- pom.xml | 2 +- .../treebotweakssp/TreeboTweaksSP.java | 4 ++ .../MaintainFlightBetweenWorlds.java | 42 +++++++++++++++ .../Listeners/TwerkingListener.java | 52 +++++++++++++++++-- src/main/resources/config.yml | 2 + 5 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 src/main/java/me/shakeforprotein/treebotweakssp/Tweaks/MaintainFlightBetweenWorlds/MaintainFlightBetweenWorlds.java diff --git a/pom.xml b/pom.xml index 238f0bc..51fed0a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.ShakeforProtein TreeboTweaksSP - 0.0.6 + 0.0.8 jar TreeboTweaksSP diff --git a/src/main/java/me/shakeforprotein/treebotweakssp/TreeboTweaksSP.java b/src/main/java/me/shakeforprotein/treebotweakssp/TreeboTweaksSP.java index 6b4ef6a..6d09837 100644 --- a/src/main/java/me/shakeforprotein/treebotweakssp/TreeboTweaksSP.java +++ b/src/main/java/me/shakeforprotein/treebotweakssp/TreeboTweaksSP.java @@ -15,6 +15,7 @@ import me.shakeforprotein.treebotweakssp.Tweaks.DynMapToInGameMap.CommandMakeMap; import me.shakeforprotein.treebotweakssp.Tweaks.DynMapToInGameMap.InternalMapRenderer; import me.shakeforprotein.treebotweakssp.Tweaks.DynMapToInGameMap.MapRenderListener; +import me.shakeforprotein.treebotweakssp.Tweaks.MaintainFlightBetweenWorlds.MaintainFlightBetweenWorlds; import me.shakeforprotein.treebotweakssp.Tweaks.MarkHomesOnDynMap.MarkHomesOnDynMap; import me.shakeforprotein.treebotweakssp.Tweaks.NerfMobDropsWhenNotKilledByPlayer.NerfDrops; import me.shakeforprotein.treebotweakssp.Tweaks.NetherWater.AllowWaterInNether; @@ -188,6 +189,9 @@ public void run() { markHomesOnDynMap.enable(); } } + if(getConfig().getBoolean("Tweaks.MaintainFlightBetweenWorlds")){ + Bukkit.getPluginManager().registerEvents(new MaintainFlightBetweenWorlds(this), this); + } } public void runCommandSynchronouslyLater(CommandSender sender, String command, long delay) { diff --git a/src/main/java/me/shakeforprotein/treebotweakssp/Tweaks/MaintainFlightBetweenWorlds/MaintainFlightBetweenWorlds.java b/src/main/java/me/shakeforprotein/treebotweakssp/Tweaks/MaintainFlightBetweenWorlds/MaintainFlightBetweenWorlds.java new file mode 100644 index 0000000..0452127 --- /dev/null +++ b/src/main/java/me/shakeforprotein/treebotweakssp/Tweaks/MaintainFlightBetweenWorlds/MaintainFlightBetweenWorlds.java @@ -0,0 +1,42 @@ +package me.shakeforprotein.treebotweakssp.Tweaks.MaintainFlightBetweenWorlds; + +import me.shakeforprotein.treebotweakssp.TreeboTweaksSP; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerChangedWorldEvent; + +import java.util.HashMap; + +public class MaintainFlightBetweenWorlds implements Listener { + + + private TreeboTweaksSP pl; + private HashMap flyingPlayers = new HashMap<>(); + + public MaintainFlightBetweenWorlds(TreeboTweaksSP main){ + this.pl = main; + + Bukkit.getScheduler().runTaskTimer(pl, ()->{ + flyingPlayers.clear(); + for(Player player : Bukkit.getOnlinePlayers()){ + if(player.isFlying() && player.getAllowFlight()){ + flyingPlayers.put(player, true); + } else { + flyingPlayers.put(player, false); + } + } + }, 60L, 5L); + } + + @EventHandler + public void maintainFlight(PlayerChangedWorldEvent e){ + if(flyingPlayers.containsKey(e.getPlayer()) && e.getPlayer().hasPermission("essentials.fly")){ + Bukkit.getScheduler().runTaskLater(pl, ()->{ + e.getPlayer().setAllowFlight(true); + e.getPlayer().setFlying(true); + }, 2L); + } + } +} diff --git a/src/main/java/me/shakeforprotein/treebotweakssp/Tweaks/TreeTwerking/Listeners/TwerkingListener.java b/src/main/java/me/shakeforprotein/treebotweakssp/Tweaks/TreeTwerking/Listeners/TwerkingListener.java index f5e9dfc..4c27d8c 100644 --- a/src/main/java/me/shakeforprotein/treebotweakssp/Tweaks/TreeTwerking/Listeners/TwerkingListener.java +++ b/src/main/java/me/shakeforprotein/treebotweakssp/Tweaks/TreeTwerking/Listeners/TwerkingListener.java @@ -7,7 +7,10 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockGrowEvent; +import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerToggleSneakEvent; +import org.bukkit.event.world.StructureGrowEvent; +import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.List; @@ -47,17 +50,54 @@ public void PlayerTwerk(PlayerToggleSneakEvent e) { for (int y = -2; y < 2; y++) { for (int z = -5; z < 5; z++) { Block block = new Location(loc.getWorld(), loc.getBlockX() + x + 0.5, loc.getY() + y + 0.5, loc.getZ() + z + 0.5).getBlock(); + /* */ + + if(block.getState().getBlockData() instanceof Sapling){ + Sapling sapling = (Sapling) block.getState().getBlockData(); + Material saplingType = block.getType(); + if(sapling.getStage() < sapling.getMaximumStage() && ThreadLocalRandom.current().nextInt(100) < 10){ + sapling.setStage(sapling.getStage() +1); + block.getLocation().getWorld().spawnParticle(Particle.REDSTONE, block.getLocation().add(block.getX() + 0.5,block.getY() + 0.8,block.getZ() + 0.5), 3, new Particle.DustOptions(Color.GREEN, 3f)); + block.setBlockData(sapling); + } else if(sapling.getStage() == sapling.getMaximumStage()){ + + block.getLocation().getWorld().spawnParticle(Particle.REDSTONE, block.getLocation().add(block.getX() + 0.5,block.getY() + 0.8,block.getZ() + 0.5), 3, new Particle.DustOptions(Color.ORANGE, 5f)); + } else { + + block.getLocation().getWorld().spawnParticle(Particle.REDSTONE, block.getLocation().add(block.getX() + 0.5,block.getY() + 0.8,block.getZ() + 0.5), 3, new Particle.DustOptions(Color.WHITE, 1f)); + } + } + } + } + } + } + } + + /* for (Material mat : saplings) { if (!block.getType().isAir() && block.getType() != Material.VOID_AIR && block.getType() == mat) { if (Math.floor(ThreadLocalRandom.current().nextInt(5)) == 4) { Sapling sapling = (Sapling) block.getBlockData(); - if (sapling.getStage() <= sapling.getMaximumStage()) { + + if (sapling.getStage() <= sapling.getMaximumStage() ) { if (ThreadLocalRandom.current().nextInt(20) > 15) { sapling.setStage(sapling.getMaximumStage()); block.setBlockData(sapling); block.getState().update(); makeTree(block); - new BlockGrowEvent(block, block.getState()); + BlockGrowEvent blockGrowEvent = new BlockGrowEvent(block, block.getState()); + + if(block.getType() == Material.AIR){ + block.setType(mat); + for(double a = -0.5; a < 0.5; a = a + 0.1){ + for(double b = 0.1; b < 0.5; b = b + 0.1){ + for(double c = -0.5; c < 0.5; c = c + 0.1){ + block.getLocation().getWorld().spawnParticle(Particle.REDSTONE, block.getLocation().add(a + 0.5,b + 0.8,c + 0.5), 3, new Particle.DustOptions(Color.RED, 5.5f)); + block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(mat, 1)); + } + } + } + } } } @@ -128,7 +168,6 @@ && new Location(l.getWorld(), l.getBlockX(), l.getBlockY(), l.getBlockZ() - 1).g new Location(l.getWorld(), l.getBlockX()+1, l.getBlockY(), l.getBlockZ()).getBlock().setType(Material.AIR); new Location(l.getWorld(), l.getBlockX()+1, l.getBlockY(), l.getBlockZ()+1).getBlock().setType(Material.AIR); new Location(l.getWorld(), l.getBlockX(), l.getBlockY(), l.getBlockZ()+1).getBlock().setType(Material.AIR); - break; case "SOUTHWEST": l.getBlock().setType(Material.AIR); @@ -161,7 +200,7 @@ && new Location(l.getWorld(), l.getBlockX(), l.getBlockY(), l.getBlockZ() - 1).g @Override public void run() { if(l.getBlock().getType() == Material.AIR) { - switch (direction) { + switch (direction) { case "SOUTHEAST": l.getBlock().setType(saplingType); @@ -196,9 +235,12 @@ public void run() { break; } + } } }, 1L); + + grew = true; } } @@ -224,6 +266,8 @@ else if(!grew){ } } + } + */ } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b830377..8a59ab6 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -37,6 +37,8 @@ Tweaks: Description_AutoBalancePvP: Applies Buff/Debuff to PvP based on win loss ratio between combatants. MarkHomesOnDynMap: false Description_MarkHomesOnDynMap: Loads homes data from TreeboTeleport and makes markers available to DynMap + MaintainFlightBetweenWorlds: true + Description_MaintainFlightBetweenWorlds: Ensures flight status is toggled on during world change if it was toggled on prior to world change. DynmapToInGameMapDetails: World: 'Survival'