Skip to content

Commit

Permalink
Added Tweak to fix Flight being turned off when changing world via a …
Browse files Browse the repository at this point in the history
…non portal teleport.

Temporarily disables TreeTwerking while I work out how to solve an issue with it.
  • Loading branch information
ShakeforProtein committed Aug 23, 2021
1 parent ddff5bd commit 914181f
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.ShakeforProtein</groupId>
<artifactId>TreeboTweaksSP</artifactId>
<version>0.0.6</version>
<version>0.0.8</version>
<packaging>jar</packaging>

<name>TreeboTweaksSP</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Player, Boolean> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
}
}
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -196,9 +235,12 @@ public void run() {
break;
}
}
}
}, 1L);
grew = true;
}
}
Expand All @@ -224,6 +266,8 @@ else if(!grew){
}
}
}
*/
}
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 914181f

Please sign in to comment.