diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index af4d8cea5..6644d927d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -4,6 +4,7 @@ import java.io.File; import java.util.ArrayList; import java.util.HashSet; +import mineplex.core.google.GoogleSheetsManager; import net.minecraft.server.v1_8_R3.EntityLiving; import org.bukkit.Bukkit; @@ -233,6 +234,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation private ScoreboardManager _scoreboardManager; private NextBestGameManager _nextBestGameManager; private TrackManager _trackManager; + private GoogleSheetsManager _sheetsManager; private IncognitoManager _incognitoManager; @@ -578,6 +580,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation _trackManager = require(TrackManager.class); _titles = require(Titles.class); Titles.BOOK_SLOT = 4; + + _sheetsManager = require(GoogleSheetsManager.class); } @Override @@ -790,6 +794,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation return _customDataManager; } + public GoogleSheetsManager getSheetsManager() + { + return _sheetsManager; + } + public ChatColor GetColor(Player player) { if (_game == null) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index 89fe831d5..8fa799ffb 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -1,27 +1,52 @@ package nautilus.game.arcade.game; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; - +import com.google.common.collect.Lists; +import com.mojang.authlib.GameProfile; +import mineplex.core.Managers; +import mineplex.core.antihack.AntiHack; +import mineplex.core.arcadeevents.CoreGameStartEvent; +import mineplex.core.arcadeevents.CoreGameStopEvent; +import mineplex.core.command.CommandCenter; +import mineplex.core.common.Rank; +import mineplex.core.common.util.*; +import mineplex.core.disguise.disguises.DisguisePlayer; +import mineplex.core.elo.EloPlayer; +import mineplex.core.elo.EloTeam; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.lifetimes.Lifetimed; +import mineplex.core.lifetimes.ListenerComponent; +import mineplex.core.lifetimes.PhasedLifetime; +import mineplex.core.packethandler.IPacketHandler; +import mineplex.core.packethandler.PacketInfo; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.core.utils.UtilGameProfile; +import mineplex.minecraft.game.classcombat.event.ClassCombatCreatureAllowSpawnEvent; +import mineplex.minecraft.game.core.combat.DeathMessageType; +import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; +import nautilus.game.arcade.ArcadeFormat; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.events.PlayerGameRespawnEvent; +import nautilus.game.arcade.events.PlayerStateChangeEvent; +import nautilus.game.arcade.game.GameTeam.PlayerState; +import nautilus.game.arcade.game.games.build.Build; +import nautilus.game.arcade.game.games.draw.Draw; +import nautilus.game.arcade.game.games.speedbuilders.SpeedBuilders; +import nautilus.game.arcade.game.modules.AntiExpOrbModule; +import nautilus.game.arcade.game.modules.Module; +import nautilus.game.arcade.kit.*; +import nautilus.game.arcade.managers.chat.ChatStatData; +import nautilus.game.arcade.managers.lobby.LobbyManager; +import nautilus.game.arcade.scoreboard.GameScoreboard; +import nautilus.game.arcade.stats.*; +import nautilus.game.arcade.wineffect.WinEffectManager; +import nautilus.game.arcade.world.WorldData; import net.minecraft.server.v1_8_R3.EntityItem; import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity; - import org.apache.commons.lang3.tuple.Triple; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; @@ -41,79 +66,12 @@ import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.world.WorldLoadEvent; -import org.bukkit.inventory.PlayerInventory; import org.bukkit.scoreboard.NameTagVisibility; import org.bukkit.scoreboard.Team; import org.bukkit.util.Vector; -import com.google.common.collect.Lists; -import com.mojang.authlib.GameProfile; - -import mineplex.core.Managers; -import mineplex.core.antihack.AntiHack; -import mineplex.core.arcadeevents.CoreGameStartEvent; -import mineplex.core.arcadeevents.CoreGameStopEvent; -import mineplex.core.command.CommandCenter; -import mineplex.core.common.Rank; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.NautHashMap; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilEnt; -import mineplex.core.common.util.UtilMath; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilTabTitle; -import mineplex.core.common.util.UtilTextMiddle; -import mineplex.core.common.util.UtilTime; -import mineplex.core.disguise.disguises.DisguisePlayer; -import mineplex.core.elo.EloPlayer; -import mineplex.core.elo.EloTeam; -import mineplex.core.itemstack.ItemBuilder; -import mineplex.core.lifetimes.Lifetimed; -import mineplex.core.lifetimes.ListenerComponent; -import mineplex.core.lifetimes.PhasedLifetime; -import mineplex.core.packethandler.IPacketHandler; -import mineplex.core.packethandler.PacketInfo; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.core.utils.UtilGameProfile; -import mineplex.minecraft.game.classcombat.event.ClassCombatCreatureAllowSpawnEvent; -import mineplex.minecraft.game.core.combat.DeathMessageType; -import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; - -import nautilus.game.arcade.ArcadeFormat; -import nautilus.game.arcade.ArcadeManager; -import nautilus.game.arcade.GameType; -import nautilus.game.arcade.events.GameStateChangeEvent; -import nautilus.game.arcade.events.PlayerGameRespawnEvent; -import nautilus.game.arcade.events.PlayerStateChangeEvent; -import nautilus.game.arcade.game.GameTeam.PlayerState; -import nautilus.game.arcade.game.games.build.Build; -import nautilus.game.arcade.game.games.draw.Draw; -import nautilus.game.arcade.game.games.speedbuilders.SpeedBuilders; -import nautilus.game.arcade.game.modules.AntiExpOrbModule; -import nautilus.game.arcade.game.modules.Module; -import nautilus.game.arcade.kit.ChampionsKit; -import nautilus.game.arcade.kit.Kit; -import nautilus.game.arcade.kit.KitAvailability; -import nautilus.game.arcade.kit.Perk; -import nautilus.game.arcade.kit.ProgressingKit; -import nautilus.game.arcade.managers.chat.ChatStatData; -import nautilus.game.arcade.managers.lobby.LobbyManager; -import nautilus.game.arcade.scoreboard.GameScoreboard; -import nautilus.game.arcade.stats.AssistsStatTracker; -import nautilus.game.arcade.stats.DamageDealtStatTracker; -import nautilus.game.arcade.stats.DamageTakenStatTracker; -import nautilus.game.arcade.stats.DeathsStatTracker; -import nautilus.game.arcade.stats.ExperienceStatTracker; -import nautilus.game.arcade.stats.GamesPlayedStatTracker; -import nautilus.game.arcade.stats.KillsStatTracker; -import nautilus.game.arcade.stats.LoseStatTracker; -import nautilus.game.arcade.stats.StatTracker; -import nautilus.game.arcade.stats.WinStatTracker; -import nautilus.game.arcade.wineffect.WinEffectManager; -import nautilus.game.arcade.world.WorldData; +import java.util.*; +import java.util.Map.Entry; public abstract class Game extends ListenerComponent implements Lifetimed { @@ -2460,7 +2418,6 @@ public abstract class Game extends ListenerComponent implements Lifetimed public void cleanupCommands() { this._debugCommands.forEach(command -> CommandCenter.Instance.removeCommand(command)); - this._debugCommands.clear(); } public T getModule(Class clazz) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/SuperSmash.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/SuperSmash.java index 7e607018e..3d2f3f2f0 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/SuperSmash.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/SuperSmash.java @@ -24,6 +24,7 @@ import nautilus.game.arcade.game.games.smash.perks.SmashUltimate; import nautilus.game.arcade.game.modules.compass.CompassModule; import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Perk; +import nautilus.game.arcade.managers.PerkSpreadsheetModule; import org.bukkit.*; import org.bukkit.FireworkEffect.Type; import org.bukkit.block.Block; @@ -39,7 +40,6 @@ import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.scheduler.BukkitRunnable; import java.util.HashMap; @@ -89,10 +89,13 @@ public abstract class SuperSmash extends Game WorldWaterDamage = 1000; HideTeamSheep = true; ReplaceTeamsWithKits = true; + new CompassModule() .setGiveCompassToAlive(true) .register(this); + new PerkSpreadsheetModule(this, "SMASH_KITS"); + registerDebugCommand(new DebugCommand("cooldown", Rank.ADMIN) { @Override diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/SuperSmashTraining.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/SuperSmashTraining.java index a12fd581c..7ca13623e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/SuperSmashTraining.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/SuperSmashTraining.java @@ -19,15 +19,18 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.PlayerDeathEvent; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.function.Function; public class SuperSmashTraining extends SuperSmash { - private static final long GAME_TIME = TimeUnit.HOURS.toMillis(3); - private static final long GAME_WARN_TIME = GAME_TIME - TimeUnit.MINUTES.toMillis(5); + private static final long GAME_TIME = TimeUnit.MINUTES.toMillis(3); + private static final long GAME_WARN_TIME = GAME_TIME - TimeUnit.MINUTES.toMillis(1); private static final String[] INFO_HOLOGRAM = { C.cYellow + "Select a " + C.cGreen + "Kit", C.cYellow + "Jump off the island to use your abilities", @@ -37,10 +40,8 @@ public class SuperSmashTraining extends SuperSmash private Location _borderA; private Location _borderB; - private Function safeFunction = player -> - { - return !UtilAlg.inBoundingBox(player.getLocation(), _borderA, _borderB); - }; + private Function _safeFunction = player -> !UtilAlg.inBoundingBox(player.getLocation(), _borderA, _borderB); + private Map _lastDeath; private boolean _announceEnd; @@ -56,9 +57,11 @@ public class SuperSmashTraining extends SuperSmash GiveClock = false; HungerSet = 20; + _lastDeath = new HashMap<>(); + new TrainingGameModule() - .setSkillFunction(safeFunction) - .setDamageFunction(safeFunction) + .setSkillFunction(_safeFunction) + .setDamageFunction(_safeFunction) .addBot(TrainingBot.class) .register(this); } @@ -155,12 +158,30 @@ public class SuperSmashTraining extends SuperSmash @EventHandler public void playerDeath(PlayerDeathEvent event) { + _lastDeath.put(event.getEntity().getUniqueId(), System.currentTimeMillis()); } @EventHandler - public void smashActivating(SmashActivateEvent event) + public void cleanlastDeath(UpdateEvent event) { - if (!safeFunction.apply(event.getPlayer())) + if (!IsLive() || event.getType() != UpdateType.FAST) + { + return; + } + + for (Player player : GetPlayers(true)) + { + if (_safeFunction.apply(player)) + { + _lastDeath.remove(player.getUniqueId()); + } + } + } + + @EventHandler + public void smashActivate(SmashActivateEvent event) + { + if (!_safeFunction.apply(event.getPlayer())) { event.setCancelled(true); } @@ -195,7 +216,12 @@ public class SuperSmashTraining extends SuperSmash @Override protected boolean displayKitInfo(Player player) { - return super.displayKitInfo(player) || !safeFunction.apply(player); + if (_lastDeath.containsKey(player.getUniqueId())) + { + return UtilTime.elapsed(_lastDeath.get(player.getUniqueId()), 2000); + } + + return super.displayKitInfo(player) || !_safeFunction.apply(player); } private void spawnInfoHologram(Location location) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/kits/KitGolem.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/kits/KitGolem.java index 00c38f95f..649a3c072 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/kits/KitGolem.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/kits/KitGolem.java @@ -27,8 +27,8 @@ public class KitGolem extends SmashKit { private static final Perk[] PERKS = { - new PerkSmashStats(7, 1.0, 0.2, 8), - new PerkDoubleJump("Double Jump", 0.9, 0.9, false), + new PerkSmashStats(), + new PerkDoubleJump("Double Jump"), new PerkSlow(0), new PerkFissure(), new PerkIronHook(), diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/kits/KitSkeleton.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/kits/KitSkeleton.java index 07f123e5b..8237cf19a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/kits/KitSkeleton.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/kits/KitSkeleton.java @@ -35,13 +35,13 @@ public class KitSkeleton extends SmashKit private static double ARROW_DAMAGE = 6; private static final Perk[] PERKS = { - new PerkSmashStats(5, 1.25, 0.2, 6), - new PerkDoubleJump("Double Jump", 0.9, 0.9, false), - new PerkFletcher(3, 3, false), - new PerkKnockbackArrow(1.5), + new PerkSmashStats(), + new PerkDoubleJump("Double Jump"), + new PerkFletcher(), + new PerkKnockbackArrow(), new PerkBoneExplosion(), - new PerkRopedArrow("Roped Arrow", 1, 5000), - new PerkBarrage(5, 300, true, false, true), + new PerkRopedArrow("Roped Arrow"), + new PerkBarrage(), new SmashSkeleton() }; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/PerkSmashStats.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/PerkSmashStats.java index 2b5d00808..a545ca357 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/PerkSmashStats.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/PerkSmashStats.java @@ -17,67 +17,99 @@ public class PerkSmashStats extends Perk private double _damage; private double _knockbackTaken; private double _regen; - - public PerkSmashStats(double damage, double knockbackTaken, double regen, double armor) + private double _armor; + + public PerkSmashStats() { - super("Smash Stats", new String[] - { - - (C.cAqua + "Damage: " + C.cWhite + damage) + C.cWhite + " " + (C.cAqua + "Knockback Taken: " + C.cWhite + (int)(knockbackTaken*100) + "%"), - (C.cAqua + "Armor: " + C.cWhite + armor) + C.cWhite + " " + (C.cAqua + "Health Regeneration: " + C.cWhite + regen + " per Second"), - }); - + super("Smash Stats"); + } + + public PerkSmashStats(double damage, double knockbackTaken, double regen, double armor) + { + super("Smash Stats", new String[]{}); + _damage = damage; _knockbackTaken = knockbackTaken; _regen = regen; - } - + _armor = armor; + + setDesc( + (C.cAqua + "Damage: " + C.cWhite + _damage) + C.cWhite + " " + (C.cAqua + "Knockback Taken: " + C.cWhite + (int) (_knockbackTaken * 100) + "%"), + (C.cAqua + "Armor: " + C.cWhite + _armor) + C.cWhite + " " + (C.cAqua + "Health Regeneration: " + C.cWhite + _regen + " per Second") + ); + } + + @Override + public void setupValues() + { + _damage = getPerkDouble("Damage"); + _knockbackTaken = getPerkPercentage("Knockback Taken"); + _regen = getPerkDouble("Regeneration"); + _armor = getPerkDouble("Armor"); + + setDesc( + (C.cAqua + "Damage: " + C.cWhite + _damage) + C.cWhite + " " + (C.cAqua + "Knockback Taken: " + C.cWhite + (int) (_knockbackTaken * 100) + "%"), + (C.cAqua + "Armor: " + C.cWhite + _armor) + C.cWhite + " " + (C.cAqua + "Health Regeneration: " + C.cWhite + _regen + " per Second") + ); + } + @EventHandler(priority = EventPriority.HIGH) public void Damage(CustomDamageEvent event) { if (event.GetCause() != DamageCause.ENTITY_ATTACK) + { return; - + } + Player damager = event.GetDamagerPlayer(false); - if (damager == null) return; - - if (!Kit.HasKit(damager)) + + if (damager == null || !Kit.HasKit(damager) || !Manager.IsAlive(damager)) + { return; - - if (!Manager.IsAlive(damager)) - return; - + } + double mod = _damage - event.GetDamageInitial(); - + event.AddMod(damager.getName(), "Attack", mod, true); } - + @EventHandler(priority = EventPriority.HIGH) public void Knockback(CustomDamageEvent event) { Player damagee = event.GetDamageePlayer(); - if (damagee == null) return; - + if (damagee == null) + { + return; + } + if (!Kit.HasKit(damagee)) + { return; - + } + if (!Manager.IsAlive(damagee)) + { return; - + } + event.AddKnockback("Knockback Multiplier", _knockbackTaken); } - + @EventHandler public void Regeneration(UpdateEvent event) { if (event.getType() != UpdateType.SEC) + { return; - + } + for (Player player : Manager.GetGame().GetPlayers(true)) { if (!Kit.HasKit(player)) + { continue; - + } + UtilPlayer.health(player, _regen); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/SmashUltimate.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/SmashUltimate.java index 7fbee53c9..cb0c4f566 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/SmashUltimate.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/SmashUltimate.java @@ -1,17 +1,5 @@ package nautilus.game.arcade.game.games.smash.perks; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import mineplex.core.common.util.UtilServer; -import nautilus.game.arcade.game.games.smash.events.SmashActivateEvent; -import org.bukkit.Sound; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; - import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilTime; @@ -19,10 +7,14 @@ import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; - import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.kit.Perk; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import java.util.*; public class SmashUltimate extends Perk { @@ -42,6 +34,12 @@ public class SmashUltimate extends Perk _length = length; } + @Override + public void setupValues() + { + _length = getPerkTime("Duration", _length); + } + public void activate(Player player) { _lastUltimate.put(player.getUniqueId(), System.currentTimeMillis()); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/golem/PerkFissure.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/golem/PerkFissure.java index ad8cd2688..e625809ba 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/golem/PerkFissure.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/golem/PerkFissure.java @@ -24,7 +24,7 @@ import nautilus.game.arcade.kit.perks.data.FissureData; public class PerkFissure extends Perk { - private static final int COOLDOWN = 8000; + private int _cooldown; private Set _active = new HashSet<>(); @@ -33,6 +33,12 @@ public class PerkFissure extends Perk super("Fissure", new String[] { C.cYellow + "Right-Click" + C.cGray + " with Axe to " + C.cGreen + "Fissure" }); } + @Override + public void setupValues() + { + _cooldown = getPerkTime("Cooldown"); + } + @EventHandler public void Leap(PlayerInteractEvent event) { @@ -69,7 +75,7 @@ public class PerkFissure extends Perk return; } - if (!Recharge.Instance.use(player, GetName(), COOLDOWN, true, true)) + if (!Recharge.Instance.use(player, GetName(), _cooldown, true, true)) { return; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/golem/SmashGolem.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/golem/SmashGolem.java index a92739364..0cfd4b163 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/golem/SmashGolem.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/golem/SmashGolem.java @@ -25,14 +25,23 @@ import nautilus.game.arcade.game.games.smash.perks.SmashUltimate; public class SmashGolem extends SmashUltimate { - private static final int DURATION = 16000; - private static final int HIT_FREQUENCY = 400; - private static final int DAMAGE_RADIUS = 2; - private static final int EFFECT_RADIUS = 5; + private int _hitFrequency; + private int _damageRadius; + private int _effectRadius; public SmashGolem() { - super("Earthquake", new String[] {}, Sound.IRONGOLEM_HIT, DURATION); + super("Earthquake", new String[] {}, Sound.IRONGOLEM_HIT, 0); + } + + @Override + public void setupValues() + { + super.setupValues(); + + _hitFrequency = getPerkInt("Hit Frequency (ms)"); + _damageRadius = getPerkInt("Damage Radius"); + _effectRadius = getPerkInt("Effect Radius"); } @Override @@ -71,7 +80,7 @@ public class SmashGolem extends SmashUltimate boolean grounded = false; - for (Block block : UtilBlock.getInRadius(other.getLocation(), DAMAGE_RADIUS).keySet()) + for (Block block : UtilBlock.getInRadius(other.getLocation(), _damageRadius).keySet()) { if (block.getType() != Material.AIR) { @@ -89,13 +98,13 @@ public class SmashGolem extends SmashUltimate Manager.GetDamage().NewDamageEvent(other, player, null, DamageCause.CUSTOM, 1 + 2 * Math.random(), false, false, false, other.getName(), GetName()); // Velocity - if (Recharge.Instance.use(other, GetName() + " Hit", HIT_FREQUENCY, false, false)) + if (Recharge.Instance.use(other, GetName() + " Hit", _hitFrequency, false, false)) { UtilAction.velocity(other, new Vector(Math.random() - 0.5, Math.random() * 0.2, Math.random() - 0.5), Math.random() * 1 + 1, false, 0, 0.1 + Math.random() * 0.2, 2, true); } // Effect - for (Block block : UtilBlock.getInRadius(other.getLocation(), EFFECT_RADIUS).keySet()) + for (Block block : UtilBlock.getInRadius(other.getLocation(), _effectRadius).keySet()) { if (Math.random() < 0.98) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/skeleton/PerkBarrage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/skeleton/PerkBarrage.java index d8089da13..8dc18f5ad 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/skeleton/PerkBarrage.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/skeleton/PerkBarrage.java @@ -33,6 +33,7 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent; import nautilus.game.arcade.game.games.smash.perks.SmashPerk; +import org.jooq.util.derby.sys.Sys; public class PerkBarrage extends SmashPerk { @@ -48,6 +49,11 @@ public class PerkBarrage extends SmashPerk private boolean _noDelay; private boolean _useExp; + public PerkBarrage() + { + this(0, 0, false, false); + } + public PerkBarrage(int max, int tick, boolean remove, boolean noDelay) { this(max, tick, remove, noDelay, false); @@ -63,6 +69,16 @@ public class PerkBarrage extends SmashPerk _noDelay = noDelay; } + @Override + public void setupValues() + { + _max = getPerkInt("Max", _max); + _tick = getPerkInt("Tick", _tick); + _remove = getPerkBoolean("Remove", _remove); + _noDelay = getPerkBoolean("No Delay", _noDelay); + _useExp = getPerkBoolean("Exp Bar", _useExp); + } + @EventHandler public void BarrageDrawBow(PlayerInteractEvent event) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/skeleton/PerkBoneExplosion.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/skeleton/PerkBoneExplosion.java index 5fe9a20db..37f301290 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/skeleton/PerkBoneExplosion.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/skeleton/PerkBoneExplosion.java @@ -23,16 +23,25 @@ import nautilus.game.arcade.game.games.smash.perks.SmashPerk; public class PerkBoneExplosion extends SmashPerk { - private static final int COOLDOWN = 10000; - private static final int DAMAGE_RADIUS = 7; - private static final int DAMAGE = 6; - private static final float KNOCKBACK_MAGNITUDE = 2.5F; + private int _cooldown; + private int _damageRadius; + private int _damage; + private float _knockbackMagnitude; public PerkBoneExplosion() { super("Bone Explosion", new String[] { C.cYellow + "Right-Click" + C.cGray + " with Axe to " + C.cGreen + "Bone Explosion" }); } + @Override + public void setupValues() + { + _cooldown = getPerkTime("Cooldown"); + _damageRadius = getPerkInt("Damage Radius"); + _damage = getPerkInt("Damage"); + _knockbackMagnitude = getPerkFloat("Knockback Magnitude"); + } + @EventHandler public void Skill(PlayerInteractEvent event) { @@ -68,12 +77,12 @@ public class PerkBoneExplosion extends SmashPerk return; } - if (!Recharge.Instance.use(player, GetName(), COOLDOWN, true, true)) + if (!Recharge.Instance.use(player, GetName(), _cooldown, true, true)) { return; } - Map nearby = UtilPlayer.getInRadius(player.getLocation(), DAMAGE_RADIUS); + Map nearby = UtilPlayer.getInRadius(player.getLocation(), _damageRadius); for (Player other : nearby.keySet()) { @@ -86,7 +95,7 @@ public class PerkBoneExplosion extends SmashPerk UtilPlayer.message(other, F.main("Game", F.elem(Manager.GetColor(player) + player.getName()) + " used " + F.skill(GetName()) + ".")); // Damage Event - Manager.GetDamage().NewDamageEvent(other, player, null, DamageCause.CUSTOM, DAMAGE * nearby.get(other), true, true, false, player.getName(), GetName()); + Manager.GetDamage().NewDamageEvent(other, player, null, DamageCause.CUSTOM, _damage * nearby.get(other), true, true, false, player.getName(), GetName()); } // Inform @@ -104,6 +113,6 @@ public class PerkBoneExplosion extends SmashPerk return; } - event.AddKnockback(GetName(), KNOCKBACK_MAGNITUDE); + event.AddKnockback(GetName(), _knockbackMagnitude); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/skeleton/SmashSkeleton.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/skeleton/SmashSkeleton.java index bb86fdbcf..1e5e9c635 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/skeleton/SmashSkeleton.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/skeleton/SmashSkeleton.java @@ -20,14 +20,12 @@ import nautilus.game.arcade.game.games.smash.perks.SmashUltimate; public class SmashSkeleton extends SmashUltimate { - - private static final int DURATION = 10000; - - private Set _arrows = new HashSet(); + + private Set _arrows = new HashSet<>(); public SmashSkeleton() { - super("Arrow Storm", new String[] {}, Sound.SKELETON_HURT, DURATION); + super("Arrow Storm", new String[] {}, Sound.SKELETON_HURT, 0); } @EventHandler @@ -71,15 +69,7 @@ public class SmashSkeleton extends SmashUltimate { return; } - - for (Iterator arrowIterator = _arrows.iterator(); arrowIterator.hasNext();) - { - Projectile arrow = arrowIterator.next(); - if (arrow.isDead() || !arrow.isValid()) - { - arrowIterator.remove(); - } - } + _arrows.removeIf(arrow -> arrow.isDead() || !arrow.isValid()); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/Perk.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/Perk.java index 18a51d276..0b26d69b6 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/Perk.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/Perk.java @@ -1,9 +1,7 @@ package nautilus.game.arcade.kit; import nautilus.game.arcade.ArcadeManager; - -import org.bukkit.Bukkit; -import org.bukkit.Material; +import nautilus.game.arcade.managers.PerkSpreadsheetModule; import org.bukkit.entity.Player; import org.bukkit.event.Listener; @@ -17,57 +15,79 @@ public abstract class Perk implements Listener private boolean _display; private int _upgradeLevel; - + + private PerkSpreadsheetModule _spreadsheet; + + public Perk(String name) + { + this(name, new String[0], true); + } + public Perk(String name, String[] perkDesc) { this(name, perkDesc, true); } - + public Perk(String name, String[] perkDesc, boolean display) { _perkName = name; _perkDesc = perkDesc; _display = display; } - + public boolean hasPerk(Player player) - { + { if (Manager.GetGame() == null) { return false; } - + if (!Manager.GetGame().IsLive()) { return false; } - + if (!(Kit instanceof ProgressingKit)) { return Kit.HasKit(player); } - + ProgressingKit progressingKit = (ProgressingKit) Kit; - + return Kit.HasKit(player) && progressingKit.getUpgradeLevel(player.getUniqueId()) == _upgradeLevel; } - + public void setUpgradeLevel(int upgradeLevel) { _upgradeLevel = upgradeLevel; } - + public void SetHost(Kit kit) { Manager = kit.Manager; Kit = kit; } + public final void setSpreadsheet(PerkSpreadsheetModule spreadsheet) + { + _spreadsheet = spreadsheet; + setupValues(); + } + + public void setupValues() + { + } + public String GetName() - { + { return _perkName; } - + + public void setDesc(String... desc) + { + _perkDesc = desc; + } + public String[] GetDesc() { return _perkDesc; @@ -77,8 +97,8 @@ public abstract class Perk implements Listener { return _display; } - - public void Apply(Player player) + + public void Apply(Player player) { //Null Default } @@ -93,8 +113,92 @@ public abstract class Perk implements Listener // When listener has been registered } - public Material getIcon() + private String getPerkObject(String id) { - return Material.SLIME_BALL; + String key = _spreadsheet.getKey(this, id); + + if (!_spreadsheet.getDataMap().containsKey(key)) + { + return null; + } + + return _spreadsheet.getDataMap().get(key); } -} + + protected boolean getPerkBoolean(String id) + { + return Boolean.valueOf(getPerkObject(id)); + } + + protected int getPerkInt(String id) + { + return Integer.parseInt(getPerkObject(id)); + } + + protected double getPerkDouble(String id) + { + return Double.parseDouble(getPerkObject(id)); + } + + protected float getPerkFloat(String id) + { + return Float.parseFloat(getPerkObject(id)); + } + + protected double getPerkPercentage(String id) + { + String value = getPerkObject(id); + value = value.substring(0, value.length() - 1); + double doubleValue = Double.parseDouble(value); + return doubleValue / 100; + } + + protected int getPerkTime(String id) + { + return getPerkInt(id) * 1000; + } + + protected boolean getPerkBoolean(String id, boolean defaultV) + { + String v = getPerkObject(id); + return v != null ? Boolean.valueOf(v) : defaultV; + } + + protected int getPerkInt(String id, int defaultV) + { + String v = getPerkObject(id); + return v != null ? Integer.valueOf(v) : defaultV; + } + + protected double getPerkDouble(String id, double defaultV) + { + String v = getPerkObject(id); + return v != null ? Double.valueOf(v) : defaultV; + } + + protected double getPerkFloat(String id, float defaultV) + { + String v = getPerkObject(id); + return v != null ? Float.valueOf(v) : defaultV; + } + + protected double getPerkPercentage(String id, double defaultV) + { + String value = getPerkObject(id); + + if (value == null) + { + return defaultV; + } + + value = value.substring(0, value.length() - 1); + double doubleValue = Double.parseDouble(value); + return doubleValue / 100; + } + + protected int getPerkTime(String id, int defaultV) + { + int v = getPerkInt(id, Integer.MIN_VALUE); + return v == Integer.MIN_VALUE ? defaultV : v * 1000; + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkDoubleJump.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkDoubleJump.java index 1af48f4f8..415a2060b 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkDoubleJump.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkDoubleJump.java @@ -29,7 +29,12 @@ public class PerkDoubleJump extends Perk private boolean _displayForce; private HashSet _disabled = new HashSet(); - + + public PerkDoubleJump(String name) + { + this(name, 0, 0, false); + } + public PerkDoubleJump(String name, double power, double heightLimit, boolean control) { super(name, new String[] @@ -70,6 +75,14 @@ public class PerkDoubleJump extends Perk _displayForce = displayForce; } + @Override + public void setupValues() + { + _power = getPerkDouble("Power", _power); + _heightMax = getPerkDouble("Height Limit", _heightMax); + _control = getPerkBoolean("Control", _control); + } + @EventHandler public void FlightHop(PlayerToggleFlightEvent event) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkFletcher.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkFletcher.java index 3867996c0..98db019eb 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkFletcher.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkFletcher.java @@ -39,7 +39,12 @@ public class PerkFletcher extends Perk private int _slot; private boolean _instant = true; private String _name; - + + public PerkFletcher() + { + this(0, 0, false); + } + public PerkFletcher(int time, int max, boolean remove) { this(time, max, remove, -1); @@ -75,6 +80,16 @@ public class PerkFletcher extends Perk _name = name; } + @Override + public void setupValues() + { + _time = getPerkInt("Time", _time); + _max = getPerkInt("Max", _max); + _remove = getPerkBoolean("Remove", _remove); + + setDesc("Receive 1 Arrow every " + _time + " seconds. Maximum of " + _max + "."); + } + public boolean isFletchedArrow(ItemStack stack) { if (!UtilGear.isMat(stack, Material.ARROW)) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkIronHook.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkIronHook.java index 1f9f786f4..1b86acc73 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkIronHook.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkIronHook.java @@ -31,14 +31,21 @@ import nautilus.game.arcade.kit.Perk; public class PerkIronHook extends Perk implements IThrown { - private static final long COOLDOWN = 8000; - private static final int DAMAGE = 4; + private long _cooldown; + private int _damage; public PerkIronHook() { super("Iron Hook", new String[] { C.cYellow + "Right-Click" + C.cGray + " with Pickaxe to " + C.cGreen + "Iron Hook" }); } + @Override + public void setupValues() + { + _cooldown = getPerkTime("Cooldown"); + _damage = getPerkInt("Damage"); + } + @EventHandler public void Activate(PlayerInteractEvent event) { @@ -69,7 +76,7 @@ public class PerkIronHook extends Perk implements IThrown return; } - if (!Recharge.Instance.use(player, GetName(), COOLDOWN, true, true)) + if (!Recharge.Instance.use(player, GetName(), _cooldown, true, true)) { return; } @@ -118,7 +125,7 @@ public class PerkIronHook extends Perk implements IThrown Manager.GetCondition().Factory().Falling(GetName(), target, player, 10, false, true); // Damage Event - Manager.GetDamage().NewDamageEvent(target, player, null, DamageCause.CUSTOM, velocity * DAMAGE, false, true, false, player.getName(), GetName()); + Manager.GetDamage().NewDamageEvent(target, player, null, DamageCause.CUSTOM, velocity * _damage, false, true, false, player.getName(), GetName()); // Inform UtilPlayer.message(target, F.main("Skill", F.name(player.getName()) + " hit you with " + F.skill(GetName()) + ".")); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkKnockbackArrow.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkKnockbackArrow.java index 26f9979a0..403560712 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkKnockbackArrow.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkKnockbackArrow.java @@ -12,17 +12,27 @@ import nautilus.game.arcade.kit.Perk; public class PerkKnockbackArrow extends Perk { private double _power; - + + public PerkKnockbackArrow() + { + this(0); + } + public PerkKnockbackArrow(double power) { - super("Arrow Knockback", new String[] - { - C.cGray + "Arrows deal " + (int)(power*100) + "% Knockback.", - }); + super("Knockback Arrow"); _power = power; } - + + @Override + public void setupValues() + { + _power = getPerkPercentage("Power", _power); + + setDesc(C.cGray + "Arrows deal " + (int)(_power * 100) + "% Knockback."); + } + @EventHandler(priority = EventPriority.HIGH) public void Knockback(CustomDamageEvent event) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkRopedArrow.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkRopedArrow.java index 1f022bd35..2a206a065 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkRopedArrow.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkRopedArrow.java @@ -1,7 +1,6 @@ package nautilus.game.arcade.kit.perks; import java.util.HashSet; -import java.util.Iterator; import org.bukkit.Material; import org.bukkit.Sound; @@ -32,9 +31,14 @@ public class PerkRopedArrow extends SmashPerk private String _name; private double _power; - private long _recharge; + private int _recharge; - public PerkRopedArrow(String name, double power, long recharge) + public PerkRopedArrow(String name) + { + this(name, 0, 0); + } + + public PerkRopedArrow(String name, double power, int recharge) { super(name, new String[] { @@ -46,6 +50,13 @@ public class PerkRopedArrow extends SmashPerk _recharge = recharge; } + @Override + public void setupValues() + { + _power = getPerkDouble("Power", _power); + _recharge = getPerkTime("Cooldown", _recharge); + } + @EventHandler public void Fire(PlayerInteractEvent event) { @@ -111,12 +122,6 @@ public class PerkRopedArrow extends SmashPerk if (event.getType() != UpdateType.SEC) return; - for (Iterator arrowIterator = _arrows.iterator(); arrowIterator.hasNext();) - { - Entity arrow = arrowIterator.next(); - - if (!arrow.isValid()) - arrowIterator.remove(); - } + _arrows.removeIf(arrow -> !arrow.isValid()); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkSeismicSlam.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkSeismicSlam.java index 9b93d6fe8..db45b760e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkSeismicSlam.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkSeismicSlam.java @@ -34,11 +34,11 @@ import nautilus.game.arcade.kit.Perk; public class PerkSeismicSlam extends Perk { - private static final long COOLDOWN = 7000; - private static final long TIME = 1000; - private static final int DAMAGE = 10; - private static final int RADIUS = 8; - private static final float KNOCKBACK_MAGNITUDE = 2.4F; + private long _cooldown; + private long _time; + private int _damage; + private int _radius; + private float _knockbackMagnitude; private Map _live = new HashMap<>(); @@ -47,6 +47,16 @@ public class PerkSeismicSlam extends Perk super("Seismic Slam", new String[] { C.cYellow + "Right-Click" + C.cGray + " with Spade to " + C.cGreen + "Seismic Slam" }); } + @Override + public void setupValues() + { + _cooldown = getPerkTime("Cooldown"); + _time = getPerkTime("Time"); + _damage = getPerkInt("Damage"); + _radius = getPerkInt("Radius"); + _knockbackMagnitude = getPerkFloat("Knockback Magnitude"); + } + @EventHandler public void deactivateDeath(PlayerDeathEvent event) { @@ -93,7 +103,7 @@ public class PerkSeismicSlam extends Perk return; } - if (!Recharge.Instance.use(player, GetName(), COOLDOWN, true, true)) + if (!Recharge.Instance.use(player, GetName(), _cooldown, true, true)) return; // Action @@ -132,7 +142,7 @@ public class PerkSeismicSlam extends Perk continue; } - if (!UtilTime.elapsed(_live.get(player), TIME)) + if (!UtilTime.elapsed(_live.get(player), _time)) { continue; } @@ -141,7 +151,7 @@ public class PerkSeismicSlam extends Perk // Action - Map targets = UtilEnt.getInRadius(player.getLocation(), RADIUS); + Map targets = UtilEnt.getInRadius(player.getLocation(), _radius); for (LivingEntity cur : targets.keySet()) { @@ -156,7 +166,7 @@ public class PerkSeismicSlam extends Perk } // Damage Event - Manager.GetDamage().NewDamageEvent(cur, player, null, DamageCause.CUSTOM, DAMAGE * targets.get(cur) + 0.5, true, true, false, player.getName(), GetName()); + Manager.GetDamage().NewDamageEvent(cur, player, null, DamageCause.CUSTOM, _damage * targets.get(cur) + 0.5, true, true, false, player.getName(), GetName()); // Condition Manager.GetCondition().Factory().Falling(GetName(), cur, player, 10, false, true); @@ -187,6 +197,6 @@ public class PerkSeismicSlam extends Perk return; } - event.AddKnockback(GetName(), KNOCKBACK_MAGNITUDE); + event.AddKnockback(GetName(), _knockbackMagnitude); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/PerkSpreadsheetModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/PerkSpreadsheetModule.java new file mode 100644 index 000000000..7eec2ff42 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/PerkSpreadsheetModule.java @@ -0,0 +1,180 @@ +package nautilus.game.arcade.managers; + +import mineplex.core.common.Pair; +import mineplex.core.common.util.UtilServer; +import mineplex.core.google.GoogleSheetsManager; +import mineplex.core.google.SheetObjectDeserialiser; +import mineplex.core.slack.SlackAPI; +import mineplex.core.slack.SlackMessage; +import mineplex.core.slack.SlackTeam; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.Game; +import nautilus.game.arcade.kit.Kit; +import nautilus.game.arcade.kit.Perk; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class PerkSpreadsheetModule implements Listener +{ + + private static final String SLACK_CHANNEL_NAME = "#google-sheet-errors"; + private static final String SLACK_USERNAME = "Google Sheets"; + private static final String SLACK_ICON = "http://moppletop.github.io/mineplex/google-sheets-image.png"; + private static boolean _reportedError; + + private static final SheetObjectDeserialiser> DESERIALISER = values -> Pair.create(values[0], values.length == 1 ? "" : values[1]); + + private final Game _game; + private final Map _dataMap; + private final String _fileName; + + public PerkSpreadsheetModule(Game game, String fileName) + { + _game = game; + _fileName = fileName; + + _dataMap = new HashMap<>(); + + UtilServer.RegisterEvents(this); + + setup(); + } + + @EventHandler + public void cleanup(GameStateChangeEvent event) + { + if (event.GetState() != Game.GameState.End) + { + return; + } + + UtilServer.Unregister(this); + } + + private void setup() + { + // File Name must not be null + Objects.requireNonNull(_fileName); + + GoogleSheetsManager manager = _game.getArcadeManager().getSheetsManager(); + + Map>> map = manager.getSheetData(_fileName); + + for (Map.Entry>> entry : map.entrySet()) + { + String key = entry.getKey(); + List> value = entry.getValue(); + + Kit kit = getFromName(key); + + if (kit == null) + { + manager.log("No kit found for the name " + key); + continue; + } + + Perk currentPerk = null; + + for (List rows : value) + { + try + { + Pair pair = DESERIALISER.deserialise(rows.toArray(new String[0])); + + Perk perk = getFromName(kit, pair.getLeft()); + + if (perk != null) + { + currentPerk = perk; + continue; + } + + if (currentPerk != null) + { + String id = getKey(currentPerk, pair.getLeft()); + _dataMap.put(id, pair.getRight()); + } + } + catch (Exception e) + { + // Continue the loop + } + } + } + + for (Kit kit : _game.GetKits()) + { + for (Perk perk : kit.GetPerks()) + { + perk.setSpreadsheet(this); + } + } + } + + private Kit getFromName(String name) + { + for (Kit kit : _game.GetKits()) + { + if (kit.GetName().equalsIgnoreCase(name)) + { + return kit; + } + } + + return null; + } + + private Perk getFromName(Kit kit, String name) + { + for (Perk perk : kit.GetPerks()) + { + if (perk.GetName().equalsIgnoreCase(name)) + { + return perk; + } + } + + return null; + } + + public String getKey(Perk perk, String value) + { + return perk.GetName() + "." + value; + } + + public Map getDataMap() + { + return _dataMap; + } + + public void reportError(Exception exception, String sheetName, String dataKey) + { + // Only allow one error report per lifetime, as the game causes an infinite loop. + if (_reportedError) + { + return; + } + + _reportedError = true; + + String message = "A parsing error has occurred on spreadsheet *" + sheetName + "* with data key *" + dataKey + "*.\n Details: " + exception.getMessage(); + + System.out.println(message); + try + { + SlackAPI.getInstance().sendMessage(SlackTeam.DEVELOPER, SLACK_CHANNEL_NAME, new SlackMessage(SLACK_USERNAME, new URL(SLACK_ICON), message), true); + } + catch (MalformedURLException e) + { + e.printStackTrace(); + } + } + +} diff --git a/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/GoogleSheetController.java b/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/GoogleSheetController.java index f6244df65..0c96d03b8 100644 --- a/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/GoogleSheetController.java +++ b/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/GoogleSheetController.java @@ -14,11 +14,23 @@ public class GoogleSheetController public static void main(String[] args) throws InterruptedException { + String sheetToRead = System.getProperty("sheet"); + SpreadsheetType[] types; + + if (sheetToRead == null) + { + types = SpreadsheetType.values(); + } + else + { + types = new SpreadsheetType[]{SpreadsheetType.valueOf(sheetToRead)}; + } + System.out.println("Loading Sheet Provider"); SheetProvider provider = new SheetProvider(); System.out.println("Loaded Sheet Provider"); - for (SpreadsheetType type : SpreadsheetType.values()) + for (SpreadsheetType type : types) { System.out.println("Sleeping..."); Thread.sleep(SLEEP_TIME); @@ -28,10 +40,10 @@ public class GoogleSheetController System.out.println("Done"); System.out.println("Saving to file..."); - + File dir = new File(DATA_STORE_DIR); File file = new File(dir + File.separator + type.name() + ".json"); - + if (!dir.exists()) { System.out.println("mkdir"); @@ -44,12 +56,12 @@ public class GoogleSheetController file.delete(); System.out.println("new File"); file.createNewFile(); - + FileWriter writer = new FileWriter(file); System.out.println("Writing"); writer.write(object.toString()); - + System.out.println("Closing..."); writer.close(); } diff --git a/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/SpreadsheetType.java b/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/SpreadsheetType.java index af2acf11c..953d4be08 100644 --- a/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/SpreadsheetType.java +++ b/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/SpreadsheetType.java @@ -8,11 +8,12 @@ public enum SpreadsheetType GEM_HUNTERS_CHESTS("11Noztgbpu_gUKkc5F4evKKfyxS-Jv1coE0IrBToX_gg"), GEM_HUNTERS_SHOP("1OcYktxVZaW6Fm29Zh6w4Lb-UVyuN8r1x-TFb_3USYYI"), + SMASH_KITS("1Z_SLBzjiIVqu25PMGw9TwNKR3wd9Y9sX7rSDBl_rpxk") ; private String _id; - private SpreadsheetType(String id) + SpreadsheetType(String id) { _id = id; }