Fix speed and jump boost upgrades for real

This commit is contained in:
Esophose 2019-02-24 16:52:59 -07:00
parent e2bb8c6896
commit 73f7530941
4 changed files with 86 additions and 72 deletions

View File

@ -1,8 +1,35 @@
package me.goodandevil.skyblock.island;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.IllegalPluginAccessException;
import com.google.common.base.Preconditions;
import me.goodandevil.skyblock.SkyBlock;
import me.goodandevil.skyblock.api.event.island.*;
import me.goodandevil.skyblock.api.event.island.IslandCreateEvent;
import me.goodandevil.skyblock.api.event.island.IslandDeleteEvent;
import me.goodandevil.skyblock.api.event.island.IslandLoadEvent;
import me.goodandevil.skyblock.api.event.island.IslandOwnershipTransferEvent;
import me.goodandevil.skyblock.api.event.island.IslandUnloadEvent;
import me.goodandevil.skyblock.ban.BanManager;
import me.goodandevil.skyblock.config.FileManager;
import me.goodandevil.skyblock.config.FileManager.Config;
@ -30,23 +57,6 @@ import me.goodandevil.skyblock.utils.world.WorldBorder;
import me.goodandevil.skyblock.utils.world.block.BlockDegreesType;
import me.goodandevil.skyblock.visit.VisitManager;
import me.goodandevil.skyblock.world.WorldManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.IllegalPluginAccessException;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.io.File;
import java.io.IOException;
import java.util.*;
public class IslandManager {
@ -1102,35 +1112,8 @@ public class IslandManager {
public void giveUpgrades(Player player, Island island) {
UpgradeManager upgradeManager = skyblock.getUpgradeManager();
List<Upgrade> upgrades = upgradeManager.getUpgrades(Upgrade.Type.Speed);
if (upgrades != null && upgrades.size() > 0 && upgrades.get(0).isEnabled()
&& island.isUpgrade(Upgrade.Type.Speed)) {
Bukkit.getServer().getScheduler().runTask(skyblock, new Runnable() {
@Override
public void run() {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1));
}
});
}
upgrades = upgradeManager.getUpgrades(Upgrade.Type.Jump);
if (upgrades != null && upgrades.size() > 0 && upgrades.get(0).isEnabled()
&& island.isUpgrade(Upgrade.Type.Jump)) {
Bukkit.getServer().getScheduler().runTask(skyblock, new Runnable() {
@Override
public void run() {
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 1));
}
});
}
upgrades = upgradeManager.getUpgrades(Upgrade.Type.Fly);
if (upgrades != null && upgrades.size() > 0 && upgrades.get(0).isEnabled()
&& island.isUpgrade(Upgrade.Type.Fly)) {
List<Upgrade> flyUpgrades = upgradeManager.getUpgrades(Upgrade.Type.Fly);
if (flyUpgrades != null && flyUpgrades.size() > 0 && flyUpgrades.get(0).isEnabled() && island.isUpgrade(Upgrade.Type.Fly)) {
Bukkit.getServer().getScheduler().runTask(skyblock, new Runnable() {
@Override
public void run() {
@ -1181,9 +1164,6 @@ public class IslandManager {
}
}
player.removePotionEffect(PotionEffectType.SPEED);
player.removePotionEffect(PotionEffectType.JUMP);
if (player.getGameMode() != GameMode.CREATIVE) {
player.setFlying(false);
player.setAllowFlight(false);

View File

@ -401,8 +401,8 @@ public class Block implements Listener {
if (type != Material.COBBLESTONE && type != Material.STONE)
return;
if (generatorManager != null && generatorManager.getGenerators().size() > 0) {
Island island = islandManager.getIslandAtLocation(event.getBlock().getLocation());
Island island = islandManager.getIslandAtLocation(event.getBlock().getLocation());
if (generatorManager != null && generatorManager.getGenerators().size() > 0 && island != null) {
IslandWorld world = worldManager.getIslandWorld(event.getBlock().getWorld());
List<Generator> generators = new ArrayList<>(generatorManager.getGenerators());

View File

@ -111,11 +111,6 @@ public class Upgrade {
} else {
island.setUpgrade(player, me.goodandevil.skyblock.upgrade.Upgrade.Type.Speed,
true);
for (Player all : islandManager.getPlayersAtIsland(island)) {
all.addPotionEffect(
new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1));
}
}
soundManager.playSound(player, Sounds.WOOD_CLICK.bukkitSound(), 1.0F, 1.0F);
@ -144,11 +139,6 @@ public class Upgrade {
island.setUpgrade(player,
me.goodandevil.skyblock.upgrade.Upgrade.Type.Speed, true);
for (Player all : islandManager.getPlayersAtIsland(island)) {
all.addPotionEffect(
new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1));
}
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(skyblock,
new Runnable() {
@Override
@ -186,11 +176,6 @@ public class Upgrade {
} else {
island.setUpgrade(player, me.goodandevil.skyblock.upgrade.Upgrade.Type.Jump,
true);
for (Player all : islandManager.getPlayersAtIsland(island)) {
all.addPotionEffect(
new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 1));
}
}
soundManager.playSound(player, Sounds.WOOD_CLICK.bukkitSound(), 1.0F, 1.0F);
@ -219,11 +204,6 @@ public class Upgrade {
island.setUpgrade(player, me.goodandevil.skyblock.upgrade.Upgrade.Type.Jump,
true);
for (Player all : islandManager.getPlayersAtIsland(island)) {
all.addPotionEffect(
new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 1));
}
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(skyblock,
new Runnable() {
@Override

View File

@ -3,14 +3,21 @@ package me.goodandevil.skyblock.upgrade;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import me.goodandevil.skyblock.SkyBlock;
import me.goodandevil.skyblock.config.FileManager.Config;
import me.goodandevil.skyblock.island.Island;
import me.goodandevil.skyblock.island.IslandManager;
public class UpgradeManager {
@ -55,6 +62,9 @@ public class UpgradeManager {
upgradeStorage.put(Upgrade.Type.Size, upgrades);
}
// Task for applying the speed & jump boost upgrades if the player is on an island that has them
Bukkit.getScheduler().scheduleSyncRepeatingTask(SkyBlock.getInstance(), this::applyUpgrades, 5L, 20L);
}
public List<Upgrade> getUpgrades(Upgrade.Type type) {
@ -139,4 +149,48 @@ public class UpgradeManager {
return false;
}
private void applyUpgrades() {
IslandManager islandManager = skyblock.getIslandManager();
UpgradeManager upgradeManager = skyblock.getUpgradeManager();
for (Player player : Bukkit.getOnlinePlayers()) {
Island island = islandManager.getIslandAtLocation(player.getLocation());
if (island == null) continue;
// Apply potion effect upgrades
Collection<PotionEffect> potionEffects = player.getActivePotionEffects();
PotionEffect speed = null, jump = null;
for (PotionEffect potionEffect : potionEffects) {
if (potionEffect.getType().equals(PotionEffectType.SPEED)) {
speed = potionEffect;
} else if (potionEffect.getType().equals(PotionEffectType.JUMP)) {
jump = potionEffect;
}
if (speed != null && jump != null) break;
}
// Speed
List<Upgrade> speedUpgrades = upgradeManager.getUpgrades(Upgrade.Type.Speed);
if (speedUpgrades != null && speedUpgrades.size() > 0 && speedUpgrades.get(0).isEnabled() && island.isUpgrade(Upgrade.Type.Speed)) {
if (speed == null) {
speed = new PotionEffect(PotionEffectType.SPEED, 60, 1);
} else if (speed.getAmplifier() == 1 && speed.getDuration() < 60) {
speed = new PotionEffect(PotionEffectType.SPEED, speed.getDuration() + 21, 1);
}
player.addPotionEffect(speed, true);
}
// Jump boost
List<Upgrade> jumpUpgrades = upgradeManager.getUpgrades(Upgrade.Type.Jump);
if (jumpUpgrades != null && jumpUpgrades.size() > 0 && jumpUpgrades.get(0).isEnabled() && island.isUpgrade(Upgrade.Type.Jump)) {
if (jump == null) {
jump = new PotionEffect(PotionEffectType.JUMP, 60, 1);
} else if (jump.getAmplifier() == 1 && jump.getDuration() < 60) {
jump = new PotionEffect(PotionEffectType.JUMP, jump.getDuration() + 21, 1);
}
player.addPotionEffect(jump, true);
}
}
}
}