From 19a214b4540bda6404776e9ddaef5e489977bc15 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 6 Dec 2016 19:28:23 +0000 Subject: [PATCH 001/101] Gem Hunters base --- Plugins/mineplex-game-gemhunters/plugin.yml | 5 + Plugins/mineplex-game-gemhunters/pom.xml | 22 ++ .../src/mineplex/gemhunters/GemHunters.java | 216 ++++++++++++++++++ .../mineplex/gemhunters/ModuleGemHunters.java | 21 ++ .../mineplex/gemhunters/bounties/Bounty.java | 36 +++ .../scoreboard/GemHuntersScoreboard.java | 81 +++++++ .../scoreboard/ModuleScoreboard.java | 117 ++++++++++ .../supplydrop/ModuleSupplyDrop.java | 44 ++++ .../gemhunters/supplydrop/SupplyDrop.java | 128 +++++++++++ .../supplydrop/SupplyDropState.java | 8 + .../commands/CommandSupplyDropTest.java | 24 ++ Plugins/pom.xml | 1 + 12 files changed, 703 insertions(+) create mode 100644 Plugins/mineplex-game-gemhunters/plugin.yml create mode 100644 Plugins/mineplex-game-gemhunters/pom.xml create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/ModuleGemHunters.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/bounties/Bounty.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ModuleScoreboard.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/ModuleSupplyDrop.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropState.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/CommandSupplyDropTest.java diff --git a/Plugins/mineplex-game-gemhunters/plugin.yml b/Plugins/mineplex-game-gemhunters/plugin.yml new file mode 100644 index 000000000..a0a9f1660 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/plugin.yml @@ -0,0 +1,5 @@ +name: Gem-Hunters +main: mineplex.gemhunters.GemHunters +version: 0.1 +commands: + playwire: \ No newline at end of file diff --git a/Plugins/mineplex-game-gemhunters/pom.xml b/Plugins/mineplex-game-gemhunters/pom.xml new file mode 100644 index 000000000..83638006a --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + + + com.mineplex + mineplex-plugin + dev-SNAPSHOT + ../plugin.xml + + + Gem-Hunters + mineplex-game-gemhunters + + + + ${project.groupId} + mineplex-core + ${project.version} + + + \ No newline at end of file diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java new file mode 100644 index 000000000..ceb718264 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -0,0 +1,216 @@ +package mineplex.gemhunters; + +import static mineplex.core.Managers.require; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.plugin.java.JavaPlugin; +import org.spigotmc.SpigotConfig; + +import mineplex.core.CustomTagFix; +import mineplex.core.FoodDupeFix; +import mineplex.core.TimingsFix; +import mineplex.core.account.CoreClientManager; +import mineplex.core.achievement.AchievementManager; +import mineplex.core.antihack.AntiHack; +import mineplex.core.blockrestore.BlockRestore; +import mineplex.core.chat.Chat; +import mineplex.core.chatsnap.SnapshotManager; +import mineplex.core.chatsnap.SnapshotPlugin; +import mineplex.core.chatsnap.SnapshotRepository; +import mineplex.core.command.CommandCenter; +import mineplex.core.common.events.ServerShutdownEvent; +import mineplex.core.creature.Creature; +import mineplex.core.delayedtask.DelayedTask; +import mineplex.core.disguise.DisguiseManager; +import mineplex.core.donation.DonationManager; +import mineplex.core.elo.EloManager; +import mineplex.core.explosion.Explosion; +import mineplex.core.friend.FriendManager; +import mineplex.core.give.Give; +import mineplex.core.hologram.HologramManager; +import mineplex.core.ignore.IgnoreManager; +import mineplex.core.incognito.IncognitoManager; +import mineplex.core.inventory.InventoryManager; +import mineplex.core.itemstack.ItemStackFactory; +import mineplex.core.memory.MemoryFix; +import mineplex.core.message.MessageManager; +import mineplex.core.monitor.LagMeter; +import mineplex.core.packethandler.PacketHandler; +import mineplex.core.portal.Portal; +import mineplex.core.preferences.PreferencesManager; +import mineplex.core.punish.Punish; +import mineplex.core.recharge.Recharge; +import mineplex.core.report.ReportManager; +import mineplex.core.report.ReportPlugin; +import mineplex.core.serverConfig.ServerConfiguration; +import mineplex.core.stats.StatsManager; +import mineplex.core.status.ServerStatusManager; +import mineplex.core.teleport.Teleport; +import mineplex.core.updater.FileUpdater; +import mineplex.core.updater.Updater; +import mineplex.core.visibility.VisibilityManager; +import net.minecraft.server.v1_8_R3.MinecraftServer; + +/** + * Gem Hunters main class
+ * + * TODO make documentation and a nice header + * + * @author Sam + */ +public class GemHunters extends JavaPlugin +{ + + private static final String WEB_CONFIG = "webServer"; + + private CoreClientManager _clientManager; + private DonationManager _donationManager; + + @Override + public void onEnable() + { + // Load configuration + getConfig().addDefault(WEB_CONFIG, "http://accounts.mineplex.com/"); + getConfig().set(WEB_CONFIG, getConfig().getString(WEB_CONFIG)); + saveConfig(); + + // Get the web server address + String webServerAddress = getConfig().getString(WEB_CONFIG); + + // Load core modules + CommandCenter.Initialize(this); + + // Client Manager + _clientManager = new CoreClientManager(this, webServerAddress); + + // Donation Manager + _donationManager = new DonationManager(this, _clientManager, webServerAddress); + + // Command Centre + CommandCenter.Instance.setClientManager(_clientManager); + + // Timings + require(TimingsFix.class); + + // ItemStacks + ItemStackFactory.Initialize(this, false); + + // Delayed Tasks + DelayedTask.Initialize(this); + + // Recharge + Recharge.Initialize(this); + + // Visibility + VisibilityManager.Initialize(this); + + // Give + Give.Initialize(this); + + // Server config + new ServerConfiguration(this, _clientManager); + + // Teleport + new Teleport(this, _clientManager); + + // Packets + PacketHandler packetHandler = require(PacketHandler.class); + + // Vanish + IncognitoManager incognito = new IncognitoManager(this, _clientManager, packetHandler); + + // Preferences + PreferencesManager preferenceManager = new PreferencesManager(this, incognito, _clientManager); + + // Why do these depend on each other... :( + incognito.setPreferencesManager(preferenceManager); + + // Server Status + ServerStatusManager serverStatusManager = new ServerStatusManager(this, _clientManager, new LagMeter(this, _clientManager)); + + // Portal + Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName()); + + // File Updater + new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); + + // Punish + Punish punish = new Punish(this, webServerAddress, _clientManager); + + // Disguises + require(DisguiseManager.class); + + // Creatures + new Creature(this); + + // GWEN + AntiHack antiHack = require(AntiHack.class); + antiHack.setKick(false); + Bukkit.getScheduler().runTask(this, antiHack::enableNewAnticheat); + + // Block Restore + BlockRestore blockRestore = new BlockRestore(this); + + // Ignoring + IgnoreManager ignoreManager = new IgnoreManager(this, _clientManager, preferenceManager, portal); + + // Statistics + StatsManager statsManager = new StatsManager(this, _clientManager); + + // Elo + EloManager eloManager = new EloManager(this, _clientManager); + + // Achievements + AchievementManager achievementManager = new AchievementManager(statsManager, _clientManager, _donationManager, incognito, eloManager); + + // Chat/Messaging + Chat chat = new Chat(this, incognito, _clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); + new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, new FriendManager(this, _clientManager, preferenceManager, portal), chat); + + // Fixes + new MemoryFix(this); + new FoodDupeFix(this); + + // Explosions + new Explosion(this, blockRestore); + + // Inventories + new InventoryManager(this, _clientManager); + + // Reports + SnapshotManager snapshotManager = new SnapshotManager(this, new SnapshotRepository(serverStatusManager.getCurrentServerName(), getLogger())); + new SnapshotPlugin(this, snapshotManager, _clientManager); + new ReportPlugin(this, new ReportManager(this, snapshotManager, _clientManager, incognito, punish, serverStatusManager.getRegion(), serverStatusManager.getCurrentServerName(), 1)); + + // Tag fix + new CustomTagFix(this, packetHandler); + + // Holograms + new HologramManager(this, packetHandler); + + // Now we finally get to enable the Gem Hunters main module + new ModuleGemHunters(_clientManager); + + //UpdateEvent!!! + new Updater(this); + + // Disable spigot's item merging + for (World world : getServer().getWorlds()) + { + ((CraftWorld) world).getHandle().spigotConfig.itemMerge = 0; + } + + // Turn off the server's debugging + MinecraftServer.getServer().getPropertyManager().setProperty("debug", false); + SpigotConfig.debug = false; + } + + @Override + public void onDisable() + { + getServer().getPluginManager().callEvent(new ServerShutdownEvent(this)); + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/ModuleGemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/ModuleGemHunters.java new file mode 100644 index 000000000..fac3afa74 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/ModuleGemHunters.java @@ -0,0 +1,21 @@ +package mineplex.gemhunters; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.gemhunters.scoreboard.ModuleScoreboard; +import mineplex.gemhunters.supplydrop.ModuleSupplyDrop; + +@ReflectivelyCreateMiniPlugin +public class ModuleGemHunters extends MiniPlugin +{ + + public ModuleGemHunters(CoreClientManager clientManager) + { + super("Gem Hunters"); + + require(ModuleSupplyDrop.class); + + new ModuleScoreboard(clientManager); + } +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/bounties/Bounty.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/bounties/Bounty.java new file mode 100644 index 000000000..6e9069d16 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/bounties/Bounty.java @@ -0,0 +1,36 @@ +package mineplex.gemhunters.bounties; + +import java.util.UUID; + +import org.bukkit.entity.Player; + +public class Bounty +{ + + private UUID _target; + private UUID _setter; + private int _amount; + + public Bounty(Player target, Player setter, int amount) + { + _target = target.getUniqueId(); + _setter = setter.getUniqueId(); + _amount = amount; + } + + public UUID getTarget() + { + return _target; + } + + public UUID getSetter() + { + return _setter; + } + + public int getAmount() + { + return _amount; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java new file mode 100644 index 000000000..99e381d50 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java @@ -0,0 +1,81 @@ +package mineplex.gemhunters.scoreboard; + +import org.bukkit.entity.Player; + +import mineplex.core.common.util.C; +import mineplex.core.scoreboard.WritableMineplexScoreboard; + +public class GemHuntersScoreboard extends WritableMineplexScoreboard +{ + + private static final String PRIMARY_COLOUR = C.cGreenB; + private static final String SECONDARY_COLOUR = C.cWhiteB; + private static final String TRANSITION_COLOUR = C.cDGreenB; + + private String _title; + private int _shineIndex; + private boolean _shineDirection = true; + + public GemHuntersScoreboard(Player player) + { + super(player); + + _title = " GEM HUNTERS "; + + setSidebarName(PRIMARY_COLOUR + _title); + } + + public void writeContent(Player player) + { + writeNewLine(); + + write(C.cGreen + "Testing for " + player.getName()); + + writeNewLine(); + } + + public String getSuffix(Player perspective, Player subject) + { + return C.cGray + " " + perspective.getName(); + } + + public void updateTitle() + { + String out = (_shineDirection ? PRIMARY_COLOUR : SECONDARY_COLOUR); + + for (int i = 0; i < _title.length(); i++) + { + char c = _title.charAt(i); + + if (_shineDirection) + { + if (i == _shineIndex) + out += TRANSITION_COLOUR; + + if (i == _shineIndex + 1) + out += SECONDARY_COLOUR; + } + else + { + if (i == _shineIndex) + out += TRANSITION_COLOUR; + + if (i == _shineIndex + 1) + out += PRIMARY_COLOUR; + } + + out += c; + } + + setSidebarName(out); + + _shineIndex++; + + if (_shineIndex == _title.length() * 2) + { + _shineIndex = 0; + _shineDirection = !_shineDirection; + } + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ModuleScoreboard.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ModuleScoreboard.java new file mode 100644 index 000000000..a9620965d --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ModuleScoreboard.java @@ -0,0 +1,117 @@ +package mineplex.gemhunters.scoreboard; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.Team; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +@ReflectivelyCreateMiniPlugin +public class ModuleScoreboard extends MiniPlugin +{ + + private CoreClientManager _clientManager; + + private Map _scoreboards; + + public ModuleScoreboard(CoreClientManager clientManager) + { + super("Scoreboard"); + + _clientManager = clientManager; + _scoreboards = new HashMap<>(); + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() == UpdateType.FAST) + { + for (UUID key : _scoreboards.keySet()) + { + GemHuntersScoreboard scoreboard = _scoreboards.get(key); + Player player = UtilPlayer.searchExact(key); + + scoreboard.writeContent(player); + scoreboard.draw(); + } + } + else if (event.getType() == UpdateType.FASTEST) + { + for (GemHuntersScoreboard scoreboard : _scoreboards.values()) + { + scoreboard.updateTitle(); + } + } + } + + @EventHandler + public void playerJoin(PlayerJoinEvent event) + { + createPlayerScoreboard(event.getPlayer()); + } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + Player player = event.getPlayer(); + + for (GemHuntersScoreboard scoreboard : _scoreboards.values()) + { + scoreboard.getHandle().getTeam(player.getName()).unregister(); + } + + _scoreboards.remove(player.getUniqueId()); + } + + public void createPlayerScoreboard(Player player) + { + if (!_scoreboards.containsKey(player.getUniqueId())) + { + GemHuntersScoreboard scoreboard = new GemHuntersScoreboard(player); + Scoreboard handle = scoreboard.getHandle(); + + _scoreboards.put(player.getUniqueId(), scoreboard); + + String tag = _clientManager.Get(player).GetRank().getTag(true, true); + + for (GemHuntersScoreboard other : _scoreboards.values()) + { + Player otherPlayer = other.getOwner(); + Team team = handle.registerNewTeam(otherPlayer.getName()); + + team.setPrefix(_clientManager.Get(otherPlayer).GetRank().getTag(true, true) + C.Reset + " "); + team.setSuffix(scoreboard.getSuffix(player, otherPlayer)); + team.addEntry(otherPlayer.getName()); + + if (player.equals(otherPlayer)) + { + continue; + } + + Scoreboard otherHandle = other.getHandle(); + Team otherTeam = otherHandle.registerNewTeam(player.getName()); + + otherTeam.setPrefix(tag + C.Reset + " "); + otherTeam.setSuffix(other.getSuffix(other.getOwner(), player)); + otherTeam.addEntry(player.getName()); + } + + player.setScoreboard(scoreboard.getHandle()); + } + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/ModuleSupplyDrop.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/ModuleSupplyDrop.java new file mode 100644 index 000000000..728db7fe8 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/ModuleSupplyDrop.java @@ -0,0 +1,44 @@ +package mineplex.gemhunters.supplydrop; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.supplydrop.commands.CommandSupplyDropTest; + +@ReflectivelyCreateMiniPlugin +public class ModuleSupplyDrop extends MiniPlugin +{ + + private SupplyDrop _current; + + private ModuleSupplyDrop() + { + super("Supply Drop"); + } + + @Override + public void addCommands() + { + addCommand(new CommandSupplyDropTest(this)); + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC || _current == null) + { + return; + } + + _current.advancePath(); + } + + public void startHelicopter(Player player) + { + _current = new SupplyDrop(player.getLocation(), player.getLocation(), player.getLocation()); + } +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java new file mode 100644 index 000000000..8001a401c --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java @@ -0,0 +1,128 @@ +package mineplex.gemhunters.supplydrop; + +import java.util.HashSet; +import java.util.Set; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; + +import mineplex.core.common.util.UtilShapes; + +/** + * Represents an instance of a Supply Drop.
+ * A supply drop consists of a helicopter flying through the map from a one + * location to another. Upon reaching it's destination it will drop a loot chest + * which players can then fight over.
+ * The helicopter will then fly away towards a despawning location.
+ *
+ * The helicopter will be made up of a collection of blocks that are moved along + * a linear path. The look of this helicopter is saved in the map and is stored + * in internal memory on startup.
+ *
+ * The blades of the helicopter rotate, this is done within this class.
+ *
+ * {@link ModuleSupplyDrop} handles when and where these supply drops will + * spawn. + * + * @author Sam + */ +public class SupplyDrop +{ + + private static final int BLADE_LENGTH = 7; + + private Location _spawn; + private Location _destination; + private Location _despawn; + private Location _current; + + private SupplyDropState _state; + + private Set _bladeBlocks; + private boolean _diagonal; + + public SupplyDrop(Location spawn, Location destination, Location despawn) + { + _spawn = spawn; + _destination = destination; + _despawn = despawn; + _current = spawn; + _state = SupplyDropState.MOVING_TO_DESTINATION; + _bladeBlocks = new HashSet<>(); + _diagonal = false; + } + + public void advancePath() + { + if (!isStopped()) + { + + } + + _current.add(1, 0, 0); + + rotateBlades(); + } + + public void rotateBlades() + { + _diagonal = !_diagonal; + + for (Block block : _bladeBlocks) + { + block.setType(Material.AIR); + } + + _bladeBlocks.clear(); + + if (_diagonal) + { + for (int x = -1; x <= 1; x += 2) + { + for (int z = -1; z <= 1; z += 2) + { + for (Location location : UtilShapes.getLinesLimitedPoints(_current, _current.clone().add(x * BLADE_LENGTH, 0, z * BLADE_LENGTH), BLADE_LENGTH)) + { + Block block = location.getBlock(); + + _bladeBlocks.add(block); + block.setType(Material.STEP); + } + } + } + } + else + { + for (int x = -1; x <= 1; x += 2) + { + for (Location location : UtilShapes.getLinesLimitedPoints(_current, _current.clone().add(x * BLADE_LENGTH, 0, 0), BLADE_LENGTH)) + { + Block block = location.getBlock(); + + _bladeBlocks.add(block); + block.setType(Material.STEP); + } + } + + for (int z = -1; z <= 1; z += 2) + { + for (Location location : UtilShapes.getLinesLimitedPoints(_current, _current.clone().add(0, 0, z * BLADE_LENGTH), BLADE_LENGTH)) + { + Block block = location.getBlock(); + + _bladeBlocks.add(block); + block.setType(Material.STEP); + } + } + } + } + + public boolean isStopped() + { + return _state == SupplyDropState.STOPPED; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropState.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropState.java new file mode 100644 index 000000000..4fefe368a --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropState.java @@ -0,0 +1,8 @@ +package mineplex.gemhunters.supplydrop; + +public enum SupplyDropState +{ + + MOVING_TO_DESTINATION, STOPPED, MOVING_TO_DESPAWN + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/CommandSupplyDropTest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/CommandSupplyDropTest.java new file mode 100644 index 000000000..33ad007ac --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/CommandSupplyDropTest.java @@ -0,0 +1,24 @@ +package mineplex.gemhunters.supplydrop.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.gemhunters.supplydrop.ModuleSupplyDrop; + +public class CommandSupplyDropTest extends CommandBase +{ + + public CommandSupplyDropTest(ModuleSupplyDrop plugin) + { + super(plugin, Rank.ADMIN, "stest"); + } + + @Override + public void Execute(Player caller, String[] args) + { + caller.sendMessage("Running!"); + Plugin.startHelicopter(caller); + } + +} diff --git a/Plugins/pom.xml b/Plugins/pom.xml index 137620d6a..ed3d13494 100644 --- a/Plugins/pom.xml +++ b/Plugins/pom.xml @@ -39,6 +39,7 @@ Nautilus.Game.Arcade.UHC.WorldGen mavericks-review-hub + mineplex-game-gemhunters From b6173c49905cb5c25db68f56c5c276d030be9011 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 8 Dec 2016 19:25:48 +0000 Subject: [PATCH 002/101] Google Sheets implementation --- Plugins/Mineplex.Core.Common/pom.xml | 71 ++-- .../common/google/GoogleSheetProvider.java | 194 +++++++++++ .../core/google/GoogleSheetsManager.java | 66 ++++ .../core/google/MineplexGoogleSheet.java | 26 ++ .../src/mineplex/gemhunters/GemHunters.java | 2 +- .../mineplex/gemhunters/GemHuntersModule.java | 23 ++ .../mineplex/gemhunters/ModuleGemHunters.java | 21 -- .../mineplex/gemhunters/loot/LootItem.java | 52 +++ .../mineplex/gemhunters/loot/LootModule.java | 256 ++++++++++++++ .../loot/command/UpdateLootCommand.java | 33 ++ .../scoreboard/GemHuntersScoreboard.java | 50 --- ...eScoreboard.java => ScoreboardModule.java} | 97 ++++-- .../gemhunters/supplydrop/SupplyDrop.java | 38 ++- ...eSupplyDrop.java => SupplyDropModule.java} | 4 +- .../commands/CommandSupplyDropTest.java | 6 +- .../gemhunters/world/WorldDataModule.java | 315 ++++++++++++++++++ 16 files changed, 1118 insertions(+), 136 deletions(-) create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/google/GoogleSheetProvider.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/google/MineplexGoogleSheet.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHuntersModule.java delete mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/ModuleGemHunters.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java rename Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/{ModuleScoreboard.java => ScoreboardModule.java} (71%) rename Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/{ModuleSupplyDrop.java => SupplyDropModule.java} (91%) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java diff --git a/Plugins/Mineplex.Core.Common/pom.xml b/Plugins/Mineplex.Core.Common/pom.xml index 3e9fed6c9..99dd8dafe 100644 --- a/Plugins/Mineplex.Core.Common/pom.xml +++ b/Plugins/Mineplex.Core.Common/pom.xml @@ -1,35 +1,50 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - com.mineplex - mineplex-parent - dev-SNAPSHOT - + + com.mineplex + mineplex-parent + dev-SNAPSHOT + - mineplex-core-common + mineplex-core-common - - - com.mineplex - spigot - - - org.apache.httpcomponents - httpclient - - + + + com.mineplex + spigot + + + org.apache.httpcomponents + httpclient + + + com.google.api-client + google-api-client + 1.22.0 + + + com.google.oauth-client + google-oauth-client-jetty + 1.22.0 + + + com.google.apis + google-api-services-sheets + v4-rev20-1.22.0 + + - - - - - - ascii.png - - - - + + + + + + ascii.png + + + + diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/google/GoogleSheetProvider.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/google/GoogleSheetProvider.java new file mode 100644 index 000000000..d26c97896 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/google/GoogleSheetProvider.java @@ -0,0 +1,194 @@ +package mineplex.core.common.google; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.List; + +import com.google.api.client.auth.oauth2.Credential; +import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp; +import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver; +import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow; +import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; +import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; +import com.google.api.client.http.HttpTransport; +import com.google.api.client.json.JsonFactory; +import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.client.util.store.FileDataStoreFactory; +import com.google.api.services.sheets.v4.Sheets; +import com.google.api.services.sheets.v4.SheetsScopes; +import com.google.api.services.sheets.v4.model.AddSheetRequest; +import com.google.api.services.sheets.v4.model.BatchUpdateSpreadsheetRequest; +import com.google.api.services.sheets.v4.model.GridProperties; +import com.google.api.services.sheets.v4.model.GridRange; +import com.google.api.services.sheets.v4.model.MergeCellsRequest; +import com.google.api.services.sheets.v4.model.Request; +import com.google.api.services.sheets.v4.model.SheetProperties; +import com.google.api.services.sheets.v4.model.Spreadsheet; +import com.google.api.services.sheets.v4.model.ValueRange; + +public class GoogleSheetProvider +{ + + /** Application name. */ + private static final String APPLICATION_NAME = "Mineplex Google Sheets"; + + /** Directory to store user credentials for this application. */ + private static final File DATA_STORE_DIR = new java.io.File(".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "files"); + + /** Global instance of the {@link FileDataStoreFactory}. */ + private static FileDataStoreFactory DATA_STORE_FACTORY; + + /** Global instance of the JSON factory. */ + private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance(); + + /** Global instance of the HTTP transport. */ + private static HttpTransport HTTP_TRANSPORT; + + private static final List SCOPES = Arrays.asList(SheetsScopes.SPREADSHEETS); + + private Sheets _service; + private Credential _credential; + + static + { + try + { + HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); + DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR); + } catch (Throwable t) + { + t.printStackTrace(); + } + } + + public GoogleSheetProvider() + { + try + { + _credential = authorize(); + _service = getSheetsService(); + } catch (IOException e) + { + e.printStackTrace(); + } + } + + /** + * Creates an authorized Credential object. + * + * @return an authorized Credential object. + * @throws IOException + */ + public Credential authorize() throws IOException + { + // Load client secrets. + InputStream in = new FileInputStream(DATA_STORE_DIR + File.separator + "client_secret.json"); + GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in)); + + // Build flow and trigger user authorization request. + GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES).setDataStoreFactory(DATA_STORE_FACTORY).setAccessType("offline").build(); + Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); + return credential; + } + + /** + * Build and return an authorized Sheets API client service. + * + * @return an authorized Sheets API client service + * @throws IOException + */ + public Sheets getSheetsService() + { + return new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, _credential).setApplicationName(APPLICATION_NAME).build(); + } + + public void create(String spreadsheetID, String name, int id, int maxColumn, int maxRow) throws IOException + { + BatchUpdateSpreadsheetRequest spreadsheetRequest = new BatchUpdateSpreadsheetRequest(); + Request request = new Request(); + AddSheetRequest addSheetRequest = new AddSheetRequest(); + SheetProperties sheetProperties = new SheetProperties(); + GridProperties gridProperties = new GridProperties(); + + gridProperties.setColumnCount(maxColumn); + gridProperties.setRowCount(maxRow); + + sheetProperties.setGridProperties(gridProperties); + sheetProperties.setTitle(name); + sheetProperties.setSheetId(id); + + addSheetRequest.setProperties(sheetProperties); + + request.setAddSheet(addSheetRequest); + + spreadsheetRequest.setRequests(Arrays.asList(request)); + _service.spreadsheets().batchUpdate(spreadsheetID, spreadsheetRequest).execute(); + } + + public void write(String spreadsheetID, String sheetName, String range, List> values) throws IOException + { + ValueRange valueRange = new ValueRange(); + + valueRange.setValues(values); + + _service.spreadsheets().values().update(spreadsheetID, sheetName + "!" + range, valueRange).setValueInputOption("RAW").execute(); + } + + public void read(String spreadsheetID, String sheetName, String range) throws IOException + { + ValueRange response = _service.spreadsheets().values().get(spreadsheetID, sheetName + "!" + range).execute(); + List> values = response.getValues(); + + if (values == null || values.isEmpty()) + { + System.out.println("No data found."); + return; + } + + for (List row : values) + { + for (int i = 0; i < row.size(); i++) + { + System.out.println(row.get(i) + ", "); + } + + System.out.print("\n"); + } + } + + public void merge(String spreadsheetID, String sheetName, int id, String mergeType, int startRow, int endRow, int startColumn, int endColumn) throws IOException + { + BatchUpdateSpreadsheetRequest spreadsheetRequest = new BatchUpdateSpreadsheetRequest(); + Request request = new Request(); + MergeCellsRequest mergeCellsRequest = new MergeCellsRequest(); + GridRange gridRange = new GridRange(); + + gridRange.setSheetId(id); + + gridRange.setStartRowIndex(startRow); + gridRange.setEndRowIndex(endRow); + + gridRange.setStartColumnIndex(startColumn); + gridRange.setEndColumnIndex(endColumn); + + mergeCellsRequest.setMergeType(mergeType); + mergeCellsRequest.setRange(gridRange); + + request.setMergeCells(mergeCellsRequest); + + spreadsheetRequest.setRequests(Arrays.asList(request)); + _service.spreadsheets().batchUpdate(spreadsheetID, spreadsheetRequest).execute(); + } + + public int getNextSheetID(String spreadsheetID) throws IOException + { + Spreadsheet spreadsheet = _service.spreadsheets().get(spreadsheetID).execute(); + + return spreadsheet.getSheets().size(); + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java b/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java new file mode 100644 index 000000000..6ad973730 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java @@ -0,0 +1,66 @@ +package mineplex.core.google; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.google.api.services.sheets.v4.model.Sheet; +import com.google.api.services.sheets.v4.model.Spreadsheet; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.google.GoogleSheetProvider; + +@ReflectivelyCreateMiniPlugin +public class GoogleSheetsManager extends MiniPlugin +{ + + private GoogleSheetProvider _sheets; + + private GoogleSheetsManager() + { + super("Google Sheets"); + + _sheets = new GoogleSheetProvider(); + } + + public void addSheet(MineplexGoogleSheet sheet, String sheetName, int maxColumn, int maxRow) throws IOException + { + _sheets.create(sheet.getID(), sheetName, _sheets.getNextSheetID(sheet.getID()), maxColumn, maxRow); + } + + public List> getCellValues(MineplexGoogleSheet spreadsheet, String sheetName, String a1Notation) throws IOException + { + return _sheets.getSheetsService().spreadsheets().values().get(spreadsheet.getID(), sheetName + "!" + a1Notation).execute().getValues(); + } + + public List> getCellValues(MineplexGoogleSheet spreadsheet, String sheetName) throws IOException + { + return _sheets.getSheetsService().spreadsheets().values().get(spreadsheet.getID(), sheetName).execute().getValues(); + } + + public Map>> getCellValues(MineplexGoogleSheet spreadsheet) throws IOException + { + Spreadsheet googleSpreadsheet = _sheets.getSheetsService().spreadsheets().get(spreadsheet.getID()).execute(); + + Map>> valuesMap = new HashMap<>(googleSpreadsheet.getSheets().size() - 1); + + int index = 0; + + for (Sheet sheet : googleSpreadsheet.getSheets()) + { + if (index++ == 0) + { + continue; + } + + String name = sheet.getProperties().getTitle(); + + valuesMap.put(name, getCellValues(spreadsheet, name)); + } + + return valuesMap; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/google/MineplexGoogleSheet.java b/Plugins/Mineplex.Core/src/mineplex/core/google/MineplexGoogleSheet.java new file mode 100644 index 000000000..ea72ecb74 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/google/MineplexGoogleSheet.java @@ -0,0 +1,26 @@ +package mineplex.core.google; + +/** + * An enum containing all the google spreadsheet links relating to Mineplex.
+ *
+ * This should really be changed to a config. + */ +public enum MineplexGoogleSheet +{ + + GEM_HUNTERS_CHESTS("11Noztgbpu_gUKkc5F4evKKfyxS-Jv1coE0IrBToX_gg"), + ; + + private String _id; + + private MineplexGoogleSheet(String id) + { + _id = id; + } + + public String getID() + { + return _id; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index ceb718264..6a637b80e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -191,7 +191,7 @@ public class GemHunters extends JavaPlugin new HologramManager(this, packetHandler); // Now we finally get to enable the Gem Hunters main module - new ModuleGemHunters(_clientManager); + new GemHuntersModule(_clientManager); //UpdateEvent!!! new Updater(this); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHuntersModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHuntersModule.java new file mode 100644 index 000000000..07e34cd58 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHuntersModule.java @@ -0,0 +1,23 @@ +package mineplex.gemhunters; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.gemhunters.loot.LootModule; +import mineplex.gemhunters.scoreboard.ScoreboardModule; +import mineplex.gemhunters.supplydrop.SupplyDropModule; + +@ReflectivelyCreateMiniPlugin +public class GemHuntersModule extends MiniPlugin +{ + + public GemHuntersModule(CoreClientManager clientManager) + { + super("Gem Hunters"); + + require(SupplyDropModule.class); + require(LootModule.class); + + new ScoreboardModule(clientManager); + } +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/ModuleGemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/ModuleGemHunters.java deleted file mode 100644 index fac3afa74..000000000 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/ModuleGemHunters.java +++ /dev/null @@ -1,21 +0,0 @@ -package mineplex.gemhunters; - -import mineplex.core.MiniPlugin; -import mineplex.core.ReflectivelyCreateMiniPlugin; -import mineplex.core.account.CoreClientManager; -import mineplex.gemhunters.scoreboard.ModuleScoreboard; -import mineplex.gemhunters.supplydrop.ModuleSupplyDrop; - -@ReflectivelyCreateMiniPlugin -public class ModuleGemHunters extends MiniPlugin -{ - - public ModuleGemHunters(CoreClientManager clientManager) - { - super("Gem Hunters"); - - require(ModuleSupplyDrop.class); - - new ModuleScoreboard(clientManager); - } -} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java new file mode 100644 index 000000000..f8f9e3ba9 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java @@ -0,0 +1,52 @@ +package mineplex.gemhunters.loot; + +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.UtilMath; + +public class LootItem +{ + + private ItemStack _itemStack; + private int _minAmount; + private int _maxAmount; + private double _probability; + private String _metadata; + + public LootItem(ItemStack itemStack, int minAmount, int maxAmount, double probability, String metadata) + { + _itemStack = itemStack; + _minAmount = minAmount; + _maxAmount = maxAmount; + _probability = probability; + _metadata = metadata; + } + + public ItemStack getItemStack() + { + _itemStack.setAmount(_minAmount + UtilMath.r(_maxAmount - _minAmount + 1)); + + return _itemStack; + } + + public int getMinAmount() + { + return _minAmount; + } + + public int getMaxAmount() + { + return _maxAmount; + } + + public double getProbability() + { + return _probability; + } + + public String getMetadata() + { + return _metadata; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java new file mode 100644 index 000000000..ac8884a19 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -0,0 +1,256 @@ +package mineplex.gemhunters.loot; + +import java.io.IOException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.Chest; +import org.bukkit.block.DoubleChest; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.util.UtilMath; +import mineplex.core.google.GoogleSheetsManager; +import mineplex.core.google.MineplexGoogleSheet; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.gemhunters.loot.command.UpdateLootCommand; +import mineplex.gemhunters.world.WorldDataModule; +import net.md_5.bungee.api.ChatColor; + +@ReflectivelyCreateMiniPlugin +public class LootModule extends MiniPlugin +{ + + private static final int MINIMUM_CHEST_ITEMS = 3; + private static final int MAXIMUM_CHEST_ITEMS = 8; + + private static final MineplexGoogleSheet CHEST_LOOT_SHEET = MineplexGoogleSheet.GEM_HUNTERS_CHESTS; + + private GoogleSheetsManager _sheets; + private WorldDataModule _worldData; + + private Map> _chestLoot; + + private LootModule() + { + super("Loot"); + + _sheets = require(GoogleSheetsManager.class); + _worldData = require(WorldDataModule.class); + _chestLoot = new HashMap<>(); + + updateChestLoot(); + } + + @Override + public void addCommands() + { + addCommand(new UpdateLootCommand(this)); + } + + public void updateChestLoot() + { + try + { + Map>> map = _sheets.getCellValues(CHEST_LOOT_SHEET); + + for (String key : map.keySet()) + { + Set items = new HashSet<>(); + List> grid = map.get(key); + int index = 0; + + try + { + for (List values : grid) + { + if (index++ < 2) + { + continue; + } + + Material material = Material.valueOf(String.valueOf(values.get(0))); + byte data = Byte.parseByte(String.valueOf(values.get(1))); + int minAmount = 1; + int maxAmount = 1; + + try + { + String[] numbers = String.valueOf(values.get(2)).split("-"); + + if (numbers.length < 2) + { + minAmount = Integer.parseInt(String.valueOf(values.get(2))); + maxAmount = minAmount; + } + else + { + minAmount = Integer.parseInt(numbers[0]); + maxAmount = Integer.parseInt(numbers[1]); + } + } + catch (NumberFormatException e) + { + } + + ItemBuilder builder = new ItemBuilder(material, data); + + String title = ChatColor.translateAlternateColorCodes('&', String.valueOf(values.get(3))); + String[] lore = String.valueOf(values.get(4)).split(":"); + String[] colouredLore = new String[lore.length]; + + int loreIndex = 0; + for (String line : lore) + { + colouredLore[loreIndex++] = ChatColor.translateAlternateColorCodes('&', line); + } + + builder.setTitle(title); + builder.setLore(colouredLore); + + String[] enchants = String.valueOf(values.get(5)).split(","); + + for (String enchant : enchants) + { + String[] enchantData = enchant.split(":"); + + if (enchantData.length < 2) + { + continue; + } + + builder.addEnchantment(Enchantment.getByName(enchantData[0]), Integer.parseInt(enchantData[1])); + } + + double probability = Double.parseDouble(String.valueOf(values.get(6))); + String metadata = null; + + if (values.size() < 7) + { + metadata = String.valueOf(values.get(7)); + } + + items.add(new LootItem(builder.build(), minAmount, maxAmount, probability, metadata)); + } + + _chestLoot.put(key, items); + } + catch (Exception e) + { + // TODO send slack message? + System.out.println("An error occured while parsing spreadsheet data!"); + e.printStackTrace(); + continue; + } + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + public void fillChest(Player player, Block block) + { + if (block.getType() != Material.CHEST) + { + return; + } + + // TODO implement data points + String key = "Example"; + + Set used = new HashSet<>(); + Set items = _chestLoot.get(key); + + int sizeMultiplier = 1; + BlockState state = block.getState(); + + //TODO fix double chests + if (state instanceof DoubleChest) + { + sizeMultiplier = 2; + } + + Chest chest = (Chest) state; + Inventory inventory = chest.getBlockInventory(); + + inventory.clear(); + + for (int i = 0; i < (MINIMUM_CHEST_ITEMS + UtilMath.r(MAXIMUM_CHEST_ITEMS - MINIMUM_CHEST_ITEMS + 1)) * sizeMultiplier; i++) + { + ItemStack itemStack = getRandomItem(items); + int index = getFreeIndex(inventory.getSize(), used); + + inventory.setItem(index, itemStack); + } + } + + private ItemStack getRandomItem(Set items) + { + double totalWeight = 0; + + for (LootItem item : items) + { + totalWeight += item.getProbability(); + } + + double select = Math.random() * totalWeight; + + for (LootItem item : items) + { + if ((select -= item.getProbability()) <= 0) + { + return item.getItemStack(); + } + } + + return null; + } + + private int getFreeIndex(int endIndex, Set used) + { + int index = -1; + + while (index == -1 || used.contains(index)) + { + index = UtilMath.r(endIndex); + } + + used.add(index); + + return index; + } + + @EventHandler + public void chestOpen(PlayerInteractEvent event) + { + if (event.isCancelled()) + { + return; + } + + Player player = event.getPlayer(); + Block block = event.getClickedBlock(); + + if (block == null) + { + return; + } + + fillChest(player, block); + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java new file mode 100644 index 000000000..b51086f26 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java @@ -0,0 +1,33 @@ +package mineplex.gemhunters.loot.command; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.gemhunters.loot.LootModule; + +public class UpdateLootCommand extends CommandBase +{ + + public UpdateLootCommand(LootModule plugin) + { + super(plugin, Rank.ADMIN, "updateloot"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args.length > 1) + { + //TODO send redis message + } + + caller.sendMessage(F.main(Plugin.getName(), "Updating loot tables asynchronusly...")); + + Plugin.runAsync(() -> Plugin.updateChestLoot()); + + caller.sendMessage(F.main(Plugin.getName(), "Finished!")); + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java index 99e381d50..74e7fb7ba 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java @@ -8,21 +8,9 @@ import mineplex.core.scoreboard.WritableMineplexScoreboard; public class GemHuntersScoreboard extends WritableMineplexScoreboard { - private static final String PRIMARY_COLOUR = C.cGreenB; - private static final String SECONDARY_COLOUR = C.cWhiteB; - private static final String TRANSITION_COLOUR = C.cDGreenB; - - private String _title; - private int _shineIndex; - private boolean _shineDirection = true; - public GemHuntersScoreboard(Player player) { super(player); - - _title = " GEM HUNTERS "; - - setSidebarName(PRIMARY_COLOUR + _title); } public void writeContent(Player player) @@ -39,43 +27,5 @@ public class GemHuntersScoreboard extends WritableMineplexScoreboard return C.cGray + " " + perspective.getName(); } - public void updateTitle() - { - String out = (_shineDirection ? PRIMARY_COLOUR : SECONDARY_COLOUR); - - for (int i = 0; i < _title.length(); i++) - { - char c = _title.charAt(i); - - if (_shineDirection) - { - if (i == _shineIndex) - out += TRANSITION_COLOUR; - - if (i == _shineIndex + 1) - out += SECONDARY_COLOUR; - } - else - { - if (i == _shineIndex) - out += TRANSITION_COLOUR; - - if (i == _shineIndex + 1) - out += PRIMARY_COLOUR; - } - - out += c; - } - - setSidebarName(out); - - _shineIndex++; - - if (_shineIndex == _title.length() * 2) - { - _shineIndex = 0; - _shineDirection = !_shineDirection; - } - } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ModuleScoreboard.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java similarity index 71% rename from Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ModuleScoreboard.java rename to Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java index a9620965d..abf48748a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ModuleScoreboard.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java @@ -20,21 +20,31 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @ReflectivelyCreateMiniPlugin -public class ModuleScoreboard extends MiniPlugin +public class ScoreboardModule extends MiniPlugin { + + private static final String PRIMARY_COLOUR = C.cGreenB; + private static final String SECONDARY_COLOUR = C.cWhiteB; + private static final String TRANSITION_COLOUR = C.cDGreenB; private CoreClientManager _clientManager; - + private Map _scoreboards; - - public ModuleScoreboard(CoreClientManager clientManager) + + private String _title; + private int _shineIndex; + private boolean _shineDirection = true; + + public ScoreboardModule(CoreClientManager clientManager) { super("Scoreboard"); - + _clientManager = clientManager; _scoreboards = new HashMap<>(); + + _title = " GEM HUNTERS "; } - + @EventHandler public void update(UpdateEvent event) { @@ -44,74 +54,113 @@ public class ModuleScoreboard extends MiniPlugin { GemHuntersScoreboard scoreboard = _scoreboards.get(key); Player player = UtilPlayer.searchExact(key); - + scoreboard.writeContent(player); scoreboard.draw(); } } else if (event.getType() == UpdateType.FASTEST) { - for (GemHuntersScoreboard scoreboard : _scoreboards.values()) - { - scoreboard.updateTitle(); - } + updateTitles(); } } - + @EventHandler public void playerJoin(PlayerJoinEvent event) { createPlayerScoreboard(event.getPlayer()); } - + @EventHandler public void playerQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); - + for (GemHuntersScoreboard scoreboard : _scoreboards.values()) { scoreboard.getHandle().getTeam(player.getName()).unregister(); } - + _scoreboards.remove(player.getUniqueId()); } - + public void createPlayerScoreboard(Player player) { if (!_scoreboards.containsKey(player.getUniqueId())) { GemHuntersScoreboard scoreboard = new GemHuntersScoreboard(player); Scoreboard handle = scoreboard.getHandle(); - + _scoreboards.put(player.getUniqueId(), scoreboard); - + String tag = _clientManager.Get(player).GetRank().getTag(true, true); - + for (GemHuntersScoreboard other : _scoreboards.values()) { Player otherPlayer = other.getOwner(); Team team = handle.registerNewTeam(otherPlayer.getName()); - + team.setPrefix(_clientManager.Get(otherPlayer).GetRank().getTag(true, true) + C.Reset + " "); team.setSuffix(scoreboard.getSuffix(player, otherPlayer)); team.addEntry(otherPlayer.getName()); - + if (player.equals(otherPlayer)) { continue; } - + Scoreboard otherHandle = other.getHandle(); Team otherTeam = otherHandle.registerNewTeam(player.getName()); - + otherTeam.setPrefix(tag + C.Reset + " "); otherTeam.setSuffix(other.getSuffix(other.getOwner(), player)); otherTeam.addEntry(player.getName()); } - + player.setScoreboard(scoreboard.getHandle()); } } + public void updateTitles() + { + String out = (_shineDirection ? PRIMARY_COLOUR : SECONDARY_COLOUR); + + for (int i = 0; i < _title.length(); i++) + { + char c = _title.charAt(i); + + if (_shineDirection) + { + if (i == _shineIndex) + out += TRANSITION_COLOUR; + + if (i == _shineIndex + 1) + out += SECONDARY_COLOUR; + } + else + { + if (i == _shineIndex) + out += TRANSITION_COLOUR; + + if (i == _shineIndex + 1) + out += PRIMARY_COLOUR; + } + + out += c; + } + + for (GemHuntersScoreboard scoreboard : _scoreboards.values()) + { + scoreboard.setSidebarName(out); + } + + _shineIndex++; + + if (_shineIndex == _title.length() * 2) + { + _shineIndex = 0; + _shineDirection = !_shineDirection; + } + } + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java index 8001a401c..6c55703a8 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java @@ -1,15 +1,17 @@ package mineplex.gemhunters.supplydrop; import java.util.HashSet; +import java.util.List; import java.util.Set; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; +import mineplex.core.Managers; +import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilShapes; +import mineplex.gemhunters.world.WorldDataModule; /** * Represents an instance of a Supply Drop.
@@ -24,7 +26,7 @@ import mineplex.core.common.util.UtilShapes; *
* The blades of the helicopter rotate, this is done within this class.
*
- * {@link ModuleSupplyDrop} handles when and where these supply drops will + * {@link SupplyDropModule} handles when and where these supply drops will * spawn. * * @author Sam @@ -33,7 +35,7 @@ public class SupplyDrop { private static final int BLADE_LENGTH = 7; - + private Location _spawn; private Location _destination; private Location _despawn; @@ -41,6 +43,7 @@ public class SupplyDrop private SupplyDropState _state; + private Set _helicopterBlocks; private Set _bladeBlocks; private boolean _diagonal; @@ -51,20 +54,41 @@ public class SupplyDrop _despawn = despawn; _current = spawn; _state = SupplyDropState.MOVING_TO_DESTINATION; + _helicopterBlocks = new HashSet<>(); _bladeBlocks = new HashSet<>(); _diagonal = false; + + List helicopterSchematic = Managers.get(WorldDataModule.class).getCustomLocation("SCHEM Helicopter"); + + for (Block block : UtilBlock.getInBoundingBox(helicopterSchematic.get(0), helicopterSchematic.get(1))) + { + _helicopterBlocks.add(block); + } } public void advancePath() { if (!isStopped()) { - + moveHelicopter(); } - - _current.add(1, 0, 0); rotateBlades(); + + _current.add(1, 0, 0); + } + + public void moveHelicopter() + { + for (Block block : _helicopterBlocks) + { + Block newBlock = block.getLocation().add(1, 0, 0).getBlock(); + + newBlock.setType(block.getType()); + newBlock.setData(block.getData()); + + block.setType(Material.AIR); + } } public void rotateBlades() diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/ModuleSupplyDrop.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java similarity index 91% rename from Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/ModuleSupplyDrop.java rename to Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java index 728db7fe8..14e5f7b6c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/ModuleSupplyDrop.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java @@ -10,12 +10,12 @@ import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.supplydrop.commands.CommandSupplyDropTest; @ReflectivelyCreateMiniPlugin -public class ModuleSupplyDrop extends MiniPlugin +public class SupplyDropModule extends MiniPlugin { private SupplyDrop _current; - private ModuleSupplyDrop() + private SupplyDropModule() { super("Supply Drop"); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/CommandSupplyDropTest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/CommandSupplyDropTest.java index 33ad007ac..4ba3bfc32 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/CommandSupplyDropTest.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/CommandSupplyDropTest.java @@ -4,12 +4,12 @@ import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; -import mineplex.gemhunters.supplydrop.ModuleSupplyDrop; +import mineplex.gemhunters.supplydrop.SupplyDropModule; -public class CommandSupplyDropTest extends CommandBase +public class CommandSupplyDropTest extends CommandBase { - public CommandSupplyDropTest(ModuleSupplyDrop plugin) + public CommandSupplyDropTest(SupplyDropModule plugin) { super(plugin, Rank.ADMIN, "stest"); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java new file mode 100644 index 000000000..b9a4b7443 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java @@ -0,0 +1,315 @@ +package mineplex.gemhunters.world; + +import java.io.BufferedReader; +import java.io.DataInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.Difficulty; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.WorldCreator; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.timing.TimingManager; +import mineplex.core.common.util.WorldUtil; +import mineplex.core.common.util.ZipUtil; +import mineplex.core.common.util.worldgen.WorldGenCleanRoom; + +@ReflectivelyCreateMiniPlugin +public class WorldDataModule extends MiniPlugin +{ + + public String Folder = null; + + public World World; + public int MinX = 0; + public int MinZ = 0; + public int MaxX = 0; + public int MaxZ = 0; + + public int MinY = -1; + public int MaxY = 256; + + private final Map> SPAWN_LOCATIONS = new LinkedHashMap<>(); + private final Map> DATA_LOCATIONS = new LinkedHashMap<>(); + private final Map> CUSTOM_LOCAITONS = new LinkedHashMap<>(); + + private WorldDataModule() + { + super("World Data"); + + initialize(); + } + + public void initialize() + { + final WorldDataModule worldData = this; + + runAsync(() -> { + + // Unzip + worldData.unzipWorld(); + + // Load world data + runSync(() -> { + TimingManager.start("WorldData loading world."); + + WorldCreator creator = new WorldCreator(getFolder()); + creator.generator(new WorldGenCleanRoom()); + World = WorldUtil.LoadWorld(creator); + + TimingManager.stop("WorldData loading world."); + + World.setDifficulty(Difficulty.HARD); + World.setGameRuleValue("showDeathMessages", "false"); + + TimingManager.start("WorldData loading WorldConfig."); + // Load World Data + worldData.loadWorldConfig(); + TimingManager.stop("WorldData loading WorldConfig."); + }); + }); + } + + public String getFolder() + { + if (Folder == null) + { + Folder = "world"; + } + + return Folder; + } + + protected void unzipWorld() + { + TimingManager.start("UnzipWorld creating folders"); + String folder = getFolder(); + new File(folder).mkdir(); + new File(folder + File.separator + "region").mkdir(); + new File(folder + File.separator + "data").mkdir(); + TimingManager.stop("UnzipWorld creating folders"); + + TimingManager.start("UnzipWorld UnzipToDirectory"); + ZipUtil.UnzipToDirectory("../../update/maps/Gem-Hunters/None_Moppletop City Testing.zip", folder); + TimingManager.stop("UnzipWorld UnzipToDirectory"); + } + + public void loadWorldConfig() + { + // Load Track Data + String line = null; + + try + { + FileInputStream fstream = new FileInputStream(getFolder() + File.separator + "WorldConfig.dat"); + DataInputStream in = new DataInputStream(fstream); + BufferedReader br = new BufferedReader(new InputStreamReader(in)); + + List currentTeam = null; + List currentData = null; + + int currentDirection = 0; + + while ((line = br.readLine()) != null) + { + String[] tokens = line.split(":"); + + if (tokens.length < 2) + { + continue; + } + + String key = tokens[0]; + String value = tokens[1]; + + if (key.length() == 0) + { + continue; + } + + // Spawn Locations + if (key.equalsIgnoreCase("TEAM_NAME")) + { + SPAWN_LOCATIONS.put(value, new ArrayList()); + currentTeam = SPAWN_LOCATIONS.get(value); + currentDirection = 0; + } + else if (key.equalsIgnoreCase("TEAM_DIRECTION")) + { + currentDirection = Integer.parseInt(value); + } + else if (key.equalsIgnoreCase("TEAM_SPAWNS")) + { + for (int i = 1; i < tokens.length; i++) + { + Location loc = stringToLocation(tokens[i]); + if (loc == null) + continue; + + loc.setYaw(currentDirection); + + currentTeam.add(loc); + } + } + + // Data Locations + else if (key.equalsIgnoreCase("DATA_NAME")) + { + DATA_LOCATIONS.put(value, new ArrayList()); + currentData = DATA_LOCATIONS.get(value); + } + else if (key.equalsIgnoreCase("DATA_LOCS")) + { + for (int i = 1; i < tokens.length; i++) + { + Location loc = stringToLocation(tokens[i]); + if (loc == null) + continue; + + currentData.add(loc); + } + } + + // Custom Locations + else if (key.equalsIgnoreCase("CUSTOM_NAME")) + { + CUSTOM_LOCAITONS.put(value, new ArrayList()); + currentData = CUSTOM_LOCAITONS.get(value); + } + else if (key.equalsIgnoreCase("CUSTOM_LOCS")) + { + for (int i = 1; i < tokens.length; i++) + { + Location loc = stringToLocation(tokens[i]); + if (loc == null) + continue; + + currentData.add(loc); + } + } + + // Map Bounds + else if (key.equalsIgnoreCase("MIN_X")) + { + try + { + MinX = Integer.parseInt(value); + } catch (Exception e) + { + System.out.println("World Data Read Error: Invalid MinX [" + value + "]"); + } + + } + else if (key.equalsIgnoreCase("MAX_X")) + { + try + { + MaxX = Integer.parseInt(value); + } catch (Exception e) + { + System.out.println("World Data Read Error: Invalid MaxX [" + value + "]"); + } + } + else if (key.equalsIgnoreCase("MIN_Z")) + { + try + { + MinZ = Integer.parseInt(value); + } catch (Exception e) + { + System.out.println("World Data Read Error: Invalid MinZ [" + value + "]"); + } + } + else if (key.equalsIgnoreCase("MAX_Z")) + { + try + { + MaxZ = Integer.parseInt(value); + } catch (Exception e) + { + System.out.println("World Data Read Error: Invalid MaxZ [" + value + "]"); + } + } + else if (key.equalsIgnoreCase("MIN_Y")) + { + try + { + MinY = Integer.parseInt(value); + } catch (Exception e) + { + System.out.println("World Data Read Error: Invalid MinY [" + value + "]"); + } + } + else if (key.equalsIgnoreCase("MAX_Y")) + { + try + { + MaxY = Integer.parseInt(value); + } catch (Exception e) + { + System.out.println("World Data Read Error: Invalid MaxY [" + value + "]"); + } + } + } + + in.close(); + } catch (Exception e) + { + e.printStackTrace(); + System.err.println("Line: " + line); + } + } + + private Location stringToLocation(String loc) + { + String[] coords = loc.split(","); + + try + { + return new Location(World, Integer.valueOf(coords[0]) + 0.5, Integer.valueOf(coords[1]), Integer.valueOf(coords[2]) + 0.5); + } catch (Exception e) + { + System.out.println("World Data Read Error: Invalid Location String [" + loc + "]"); + } + + return null; + } + + public List getDataLocation(String data) + { + if (!DATA_LOCATIONS.containsKey(data)) + { + return new ArrayList(); + } + + return DATA_LOCATIONS.get(data); + } + + public List getCustomLocation(String id) + { + if (!CUSTOM_LOCAITONS.containsKey(id)) + { + return new ArrayList(); + } + + return CUSTOM_LOCAITONS.get(id); + } + + public Map> getAllCustomLocations() + { + return CUSTOM_LOCAITONS; + } + + public Map> getAllDataLocations() + { + return DATA_LOCATIONS; + } +} From 6bb76db05b933964fef02a44f2009d65dd4eb50c Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 9 Dec 2016 18:05:17 +0000 Subject: [PATCH 003/101] Helicopter --- .../gemhunters/supplydrop/SupplyDrop.java | 68 ++++++++++++------- .../supplydrop/SupplyDropModule.java | 11 +++ .../gemhunters/world/WorldDataModule.java | 14 ++-- 3 files changed, 63 insertions(+), 30 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java index 6c55703a8..13defe20a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java @@ -1,23 +1,26 @@ package mineplex.gemhunters.supplydrop; +import java.io.File; +import java.io.IOException; import java.util.HashSet; -import java.util.List; import java.util.Set; +import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.util.BlockVector; -import mineplex.core.Managers; -import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.block.schematic.Schematic; +import mineplex.core.common.block.schematic.SchematicData; +import mineplex.core.common.block.schematic.UtilSchematic; import mineplex.core.common.util.UtilShapes; -import mineplex.gemhunters.world.WorldDataModule; /** * Represents an instance of a Supply Drop.
* A supply drop consists of a helicopter flying through the map from a one * location to another. Upon reaching it's destination it will drop a loot chest - * which players can then fight over.
+ * which players can then fight over.
* The helicopter will then fly away towards a despawning location.
*
* The helicopter will be made up of a collection of blocks that are moved along @@ -34,16 +37,19 @@ import mineplex.gemhunters.world.WorldDataModule; public class SupplyDrop { + private static final String SCHEMATIC_PATH = "../../update/files/Helicopter.schematic"; private static final int BLADE_LENGTH = 7; private Location _spawn; private Location _destination; private Location _despawn; private Location _current; - + private Location _blade; + private SupplyDropState _state; - private Set _helicopterBlocks; + private Schematic _schematic; + private Set _lastHelicopter; private Set _bladeBlocks; private boolean _diagonal; @@ -54,16 +60,20 @@ public class SupplyDrop _despawn = despawn; _current = spawn; _state = SupplyDropState.MOVING_TO_DESTINATION; - _helicopterBlocks = new HashSet<>(); - _bladeBlocks = new HashSet<>(); - _diagonal = false; - List helicopterSchematic = Managers.get(WorldDataModule.class).getCustomLocation("SCHEM Helicopter"); - - for (Block block : UtilBlock.getInBoundingBox(helicopterSchematic.get(0), helicopterSchematic.get(1))) + try { - _helicopterBlocks.add(block); + _schematic = UtilSchematic.loadSchematic(new File(SCHEMATIC_PATH)); } + catch (IOException e) + { + e.printStackTrace(); + return; + } + + _lastHelicopter = new HashSet<>(100); + _bladeBlocks = new HashSet<>(20); + _diagonal = false; } public void advancePath() @@ -75,20 +85,30 @@ public class SupplyDrop rotateBlades(); - _current.add(1, 0, 0); + _current.add(0, 0, 1); } public void moveHelicopter() { - for (Block block : _helicopterBlocks) + for (Block block : _lastHelicopter) { - Block newBlock = block.getLocation().add(1, 0, 0).getBlock(); - - newBlock.setType(block.getType()); - newBlock.setData(block.getData()); - block.setType(Material.AIR); } + + _lastHelicopter.clear(); + + SchematicData data = _schematic.paste(_current, true, true); + + _blade = data.getDataLocationMap().getIronLocations(DyeColor.RED).get(0); + + for (BlockVector vector : data.getBlocks()) + { + Location location = _current.add(vector); + + _lastHelicopter.add(location.getBlock()); + + _current.subtract(vector); + } } public void rotateBlades() @@ -108,7 +128,7 @@ public class SupplyDrop { for (int z = -1; z <= 1; z += 2) { - for (Location location : UtilShapes.getLinesLimitedPoints(_current, _current.clone().add(x * BLADE_LENGTH, 0, z * BLADE_LENGTH), BLADE_LENGTH)) + for (Location location : UtilShapes.getLinesLimitedPoints(_blade, _blade.clone().add(x * BLADE_LENGTH, 0, z * BLADE_LENGTH), BLADE_LENGTH)) { Block block = location.getBlock(); @@ -122,7 +142,7 @@ public class SupplyDrop { for (int x = -1; x <= 1; x += 2) { - for (Location location : UtilShapes.getLinesLimitedPoints(_current, _current.clone().add(x * BLADE_LENGTH, 0, 0), BLADE_LENGTH)) + for (Location location : UtilShapes.getLinesLimitedPoints(_blade, _blade.clone().add(x * BLADE_LENGTH, 0, 0), BLADE_LENGTH)) { Block block = location.getBlock(); @@ -133,7 +153,7 @@ public class SupplyDrop for (int z = -1; z <= 1; z += 2) { - for (Location location : UtilShapes.getLinesLimitedPoints(_current, _current.clone().add(0, 0, z * BLADE_LENGTH), BLADE_LENGTH)) + for (Location location : UtilShapes.getLinesLimitedPoints(_blade, _blade.clone().add(0, 0, z * BLADE_LENGTH), BLADE_LENGTH)) { Block block = location.getBlock(); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java index 14e5f7b6c..b191371fa 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java @@ -1,7 +1,9 @@ package mineplex.gemhunters.supplydrop; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.ItemSpawnEvent; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; @@ -37,6 +39,15 @@ public class SupplyDropModule extends MiniPlugin _current.advancePath(); } + @EventHandler + public void itemSpawn(ItemSpawnEvent event) + { + if (event.getEntity().getItemStack().getType() == Material.IRON_DOOR) + { + event.setCancelled(true); + } + } + public void startHelicopter(Player player) { _current = new SupplyDrop(player.getLocation(), player.getLocation(), player.getLocation()); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java index b9a4b7443..1b50b6266 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java @@ -1,4 +1,4 @@ -package mineplex.gemhunters.world; +package mineplex.gemhunters.w orld; import java.io.BufferedReader; import java.io.DataInputStream; @@ -26,7 +26,9 @@ import mineplex.core.common.util.worldgen.WorldGenCleanRoom; public class WorldDataModule extends MiniPlugin { - public String Folder = null; + private static final String MAP_PATH = "../../update/maps/Gem-Hunters/None_Moppletop City Testing.zip"; + + private String folder = null; public World World; public int MinX = 0; @@ -80,12 +82,12 @@ public class WorldDataModule extends MiniPlugin public String getFolder() { - if (Folder == null) + if (folder == null) { - Folder = "world"; + folder = "world"; } - return Folder; + return folder; } protected void unzipWorld() @@ -98,7 +100,7 @@ public class WorldDataModule extends MiniPlugin TimingManager.stop("UnzipWorld creating folders"); TimingManager.start("UnzipWorld UnzipToDirectory"); - ZipUtil.UnzipToDirectory("../../update/maps/Gem-Hunters/None_Moppletop City Testing.zip", folder); + ZipUtil.UnzipToDirectory(MAP_PATH, folder); TimingManager.stop("UnzipWorld UnzipToDirectory"); } From 63673300210b22966d297233fb4d65eb698516da Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 10 Dec 2016 11:21:19 +0000 Subject: [PATCH 004/101] WorldEvent Base --- .../scoreboard/GemHuntersScoreboard.java | 6 +-- .../gemhunters/world/WorldDataModule.java | 28 +++++++++----- .../gemhunters/worldevent/WorldEvent.java | 22 +++++++++++ .../gemhunters/worldevent/WorldEventType.java | 38 +++++++++++++++++++ .../coldweather/ColdWeatherEvent.java | 8 ++++ 5 files changed, 89 insertions(+), 13 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEvent.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/coldweather/ColdWeatherEvent.java diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java index 74e7fb7ba..395d8f7e7 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java @@ -7,7 +7,7 @@ import mineplex.core.scoreboard.WritableMineplexScoreboard; public class GemHuntersScoreboard extends WritableMineplexScoreboard { - + public GemHuntersScoreboard(Player player) { super(player); @@ -17,8 +17,8 @@ public class GemHuntersScoreboard extends WritableMineplexScoreboard { writeNewLine(); - write(C.cGreen + "Testing for " + player.getName()); - + write(C.cGreen + ""); + writeNewLine(); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java index 1b50b6266..3c3d259b7 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java @@ -1,4 +1,4 @@ -package mineplex.gemhunters.w orld; +package mineplex.gemhunters.world; import java.io.BufferedReader; import java.io.DataInputStream; @@ -27,7 +27,7 @@ public class WorldDataModule extends MiniPlugin { private static final String MAP_PATH = "../../update/maps/Gem-Hunters/None_Moppletop City Testing.zip"; - + private String folder = null; public World World; @@ -204,7 +204,8 @@ public class WorldDataModule extends MiniPlugin try { MinX = Integer.parseInt(value); - } catch (Exception e) + } + catch (Exception e) { System.out.println("World Data Read Error: Invalid MinX [" + value + "]"); } @@ -215,7 +216,8 @@ public class WorldDataModule extends MiniPlugin try { MaxX = Integer.parseInt(value); - } catch (Exception e) + } + catch (Exception e) { System.out.println("World Data Read Error: Invalid MaxX [" + value + "]"); } @@ -225,7 +227,8 @@ public class WorldDataModule extends MiniPlugin try { MinZ = Integer.parseInt(value); - } catch (Exception e) + } + catch (Exception e) { System.out.println("World Data Read Error: Invalid MinZ [" + value + "]"); } @@ -235,7 +238,8 @@ public class WorldDataModule extends MiniPlugin try { MaxZ = Integer.parseInt(value); - } catch (Exception e) + } + catch (Exception e) { System.out.println("World Data Read Error: Invalid MaxZ [" + value + "]"); } @@ -245,7 +249,8 @@ public class WorldDataModule extends MiniPlugin try { MinY = Integer.parseInt(value); - } catch (Exception e) + } + catch (Exception e) { System.out.println("World Data Read Error: Invalid MinY [" + value + "]"); } @@ -255,7 +260,8 @@ public class WorldDataModule extends MiniPlugin try { MaxY = Integer.parseInt(value); - } catch (Exception e) + } + catch (Exception e) { System.out.println("World Data Read Error: Invalid MaxY [" + value + "]"); } @@ -263,7 +269,8 @@ public class WorldDataModule extends MiniPlugin } in.close(); - } catch (Exception e) + } + catch (Exception e) { e.printStackTrace(); System.err.println("Line: " + line); @@ -277,7 +284,8 @@ public class WorldDataModule extends MiniPlugin try { return new Location(World, Integer.valueOf(coords[0]) + 0.5, Integer.valueOf(coords[1]), Integer.valueOf(coords[2]) + 0.5); - } catch (Exception e) + } + catch (Exception e) { System.out.println("World Data Read Error: Invalid Location String [" + loc + "]"); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEvent.java new file mode 100644 index 000000000..ca6ac647a --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEvent.java @@ -0,0 +1,22 @@ +package mineplex.gemhunters.worldevent; + +import mineplex.core.updater.event.UpdateEvent; + +public class WorldEvent +{ + + public boolean onCheckTrigger(UpdateEvent event) + { + return false; + } + + public void onStart() + { + + } + + public void onEnd() + { + + } +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java new file mode 100644 index 000000000..89cefec65 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java @@ -0,0 +1,38 @@ +package mineplex.gemhunters.worldevent; + +import mineplex.gemhunters.worldevent.coldweather.ColdWeatherEvent; + +public enum WorldEventType +{ + + COLD_WEATHER("Cold Weather", ColdWeatherEvent.class); + + private String _name; + private Class _clazz; + + private WorldEventType(String name, Class clazz) + { + _name = name; + _clazz = clazz; + } + + public WorldEvent createInstance() + { + try + { + return (WorldEvent) _clazz.getConstructors()[0].newInstance(); + } + catch (Exception e) + { + e.printStackTrace(); + } + + return null; + } + + public String getName() + { + return _name; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/coldweather/ColdWeatherEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/coldweather/ColdWeatherEvent.java new file mode 100644 index 000000000..5680b9ef0 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/coldweather/ColdWeatherEvent.java @@ -0,0 +1,8 @@ +package mineplex.gemhunters.worldevent.coldweather; + +import mineplex.gemhunters.worldevent.WorldEvent; + +public class ColdWeatherEvent extends WorldEvent +{ + +} From 33ac4f49fd7c5ece784be50ac041f1151de84e1c Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 13 Dec 2016 22:39:38 +0000 Subject: [PATCH 005/101] Some progress --- .../mineplex/gemhunters/loot/LootItem.java | 56 ++++++++++++++++--- .../mineplex/gemhunters/loot/LootModule.java | 6 +- .../loot/command/UpdateLootCommand.java | 14 +++-- .../worldevent/WorldEventState.java | 8 +++ 4 files changed, 69 insertions(+), 15 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventState.java diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java index f8f9e3ba9..963a457b7 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java @@ -4,6 +4,12 @@ import org.bukkit.inventory.ItemStack; import mineplex.core.common.util.UtilMath; +/** + * Represents an item that can be contained in a chest inside the Gem Hunters + * world. + * + * @author Sam + */ public class LootItem { @@ -12,7 +18,7 @@ public class LootItem private int _maxAmount; private double _probability; private String _metadata; - + public LootItem(ItemStack itemStack, int minAmount, int maxAmount, double probability, String metadata) { _itemStack = itemStack; @@ -21,32 +27,66 @@ public class LootItem _probability = probability; _metadata = metadata; } - + + /** + * Returns the Minecraft {@link ItemStack} bound to this + * {@link LootItem}.
+ * The {@link ItemStack} returned will have an amount/size between the + * minAmount and maxAmount integers (set within the constuctor's parameters) + * inclusively. + * + * @return + */ public ItemStack getItemStack() { _itemStack.setAmount(_minAmount + UtilMath.r(_maxAmount - _minAmount + 1)); - + return _itemStack; } - + + /** + * The minimum amount or size an {@link ItemStack} of this {@link LootItem} + * can have. + * + * @return + */ public int getMinAmount() { return _minAmount; } - + + /** + * The maximum amount or size an {@link ItemStack} of this {@link LootItem} + * can have. + * + * @return + */ public int getMaxAmount() { return _maxAmount; } - + + /** + * The double value of the item's probability of being chosen to when + * picking an individual chest's loot. + * + * @return + */ public double getProbability() { return _probability; } - + + /** + * Any metadata bound to a {@link LootItem}. Useful for determining if an + * item has a particular skill or ability attached to it which + * you can use in code. + * + * @return + */ public String getMetadata() { return _metadata; } - + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index ac8884a19..4b1cc4dee 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -61,7 +61,7 @@ public class LootModule extends MiniPlugin } public void updateChestLoot() - { + { try { Map>> map = _sheets.getCellValues(CHEST_LOOT_SHEET); @@ -178,12 +178,12 @@ public class LootModule extends MiniPlugin int sizeMultiplier = 1; BlockState state = block.getState(); - //TODO fix double chests + // TODO fix double chests if (state instanceof DoubleChest) { sizeMultiplier = 2; } - + Chest chest = (Chest) state; Inventory inventory = chest.getBlockInventory(); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java index b51086f26..9bffb277c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java @@ -7,6 +7,12 @@ import mineplex.core.common.Rank; import mineplex.core.common.util.F; import mineplex.gemhunters.loot.LootModule; +/** + * An ADMIN command that allows users to retrieve the latest data from the + * google sheet and update all locally cached loot tables. + * + * @author Sam + */ public class UpdateLootCommand extends CommandBase { @@ -20,13 +26,13 @@ public class UpdateLootCommand extends CommandBase { if (args.length > 1) { - //TODO send redis message + // TODO send redis message } - + caller.sendMessage(F.main(Plugin.getName(), "Updating loot tables asynchronusly...")); - + Plugin.runAsync(() -> Plugin.updateChestLoot()); - + caller.sendMessage(F.main(Plugin.getName(), "Finished!")); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventState.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventState.java new file mode 100644 index 000000000..b0d9cb287 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventState.java @@ -0,0 +1,8 @@ +package mineplex.gemhunters.worldevent; + +public enum WorldEventState +{ + + + +} From 94f8419187092149e219c680e6d822a354cd7b80 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 20 Dec 2016 16:45:41 +0000 Subject: [PATCH 006/101] Cashing out and safezones --- Plugins/mineplex-game-gemhunters/pom.xml | 5 + .../src/mineplex/gemhunters/GemHunters.java | 56 ++-- .../mineplex/gemhunters/GemHuntersModule.java | 12 +- .../gemhunters/economy/CashOutModule.java | 267 ++++++++++++++++++ .../gemhunters/economy/CashOutSession.java | 59 ++++ .../mineplex/gemhunters/loot/LootModule.java | 30 +- .../loot/rewards/LootItemReward.java | 24 ++ .../loot/rewards/LootRankReward.java | 78 +++++ .../gemhunters/safezone/SafezoneModule.java | 174 ++++++++++++ .../scoreboard/GemHuntersScoreboard.java | 7 +- .../scoreboard/ScoreboardModule.java | 32 ++- 11 files changed, 697 insertions(+), 47 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutSession.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java diff --git a/Plugins/mineplex-game-gemhunters/pom.xml b/Plugins/mineplex-game-gemhunters/pom.xml index 83638006a..270c67554 100644 --- a/Plugins/mineplex-game-gemhunters/pom.xml +++ b/Plugins/mineplex-game-gemhunters/pom.xml @@ -18,5 +18,10 @@ mineplex-core ${project.version} + + ${project.groupId} + mineplex-minecraft-game-core + ${project.version} + \ No newline at end of file diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 6a637b80e..07d7d3f77 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -37,6 +37,7 @@ import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.memory.MemoryFix; import mineplex.core.message.MessageManager; import mineplex.core.monitor.LagMeter; +import mineplex.core.npc.NpcManager; import mineplex.core.packethandler.PacketHandler; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; @@ -51,6 +52,9 @@ import mineplex.core.teleport.Teleport; import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; import mineplex.core.visibility.VisibilityManager; +import mineplex.minecraft.game.core.combat.CombatManager; +import mineplex.minecraft.game.core.condition.ConditionManager; +import mineplex.minecraft.game.core.damage.DamageManager; import net.minecraft.server.v1_8_R3.MinecraftServer; /** @@ -64,10 +68,7 @@ public class GemHunters extends JavaPlugin { private static final String WEB_CONFIG = "webServer"; - - private CoreClientManager _clientManager; - private DonationManager _donationManager; - + @Override public void onEnable() { @@ -83,13 +84,13 @@ public class GemHunters extends JavaPlugin CommandCenter.Initialize(this); // Client Manager - _clientManager = new CoreClientManager(this, webServerAddress); + CoreClientManager clientManager = new CoreClientManager(this, webServerAddress); // Donation Manager - _donationManager = new DonationManager(this, _clientManager, webServerAddress); + DonationManager donationManager = require(DonationManager.class); // Command Centre - CommandCenter.Instance.setClientManager(_clientManager); + CommandCenter.Instance.setClientManager(clientManager); // Timings require(TimingsFix.class); @@ -110,41 +111,44 @@ public class GemHunters extends JavaPlugin Give.Initialize(this); // Server config - new ServerConfiguration(this, _clientManager); + new ServerConfiguration(this, clientManager); // Teleport - new Teleport(this, _clientManager); + new Teleport(this, clientManager); // Packets PacketHandler packetHandler = require(PacketHandler.class); // Vanish - IncognitoManager incognito = new IncognitoManager(this, _clientManager, packetHandler); + IncognitoManager incognito = new IncognitoManager(this, clientManager, packetHandler); // Preferences - PreferencesManager preferenceManager = new PreferencesManager(this, incognito, _clientManager); + PreferencesManager preferenceManager = new PreferencesManager(this, incognito, clientManager); // Why do these depend on each other... :( incognito.setPreferencesManager(preferenceManager); // Server Status - ServerStatusManager serverStatusManager = new ServerStatusManager(this, _clientManager, new LagMeter(this, _clientManager)); + ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager)); // Portal - Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName()); + Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName()); // File Updater new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); // Punish - Punish punish = new Punish(this, webServerAddress, _clientManager); + Punish punish = new Punish(this, webServerAddress, clientManager); // Disguises - require(DisguiseManager.class); + DisguiseManager disguiseManager = require(DisguiseManager.class); // Creatures - new Creature(this); + Creature creature = new Creature(this); + // The old classic Damage Manager + new DamageManager(this, new CombatManager(this), new NpcManager(this, creature), disguiseManager, new ConditionManager(this)); + // GWEN AntiHack antiHack = require(AntiHack.class); antiHack.setKick(false); @@ -154,20 +158,20 @@ public class GemHunters extends JavaPlugin BlockRestore blockRestore = new BlockRestore(this); // Ignoring - IgnoreManager ignoreManager = new IgnoreManager(this, _clientManager, preferenceManager, portal); + IgnoreManager ignoreManager = new IgnoreManager(this, clientManager, preferenceManager, portal); // Statistics - StatsManager statsManager = new StatsManager(this, _clientManager); + StatsManager statsManager = new StatsManager(this, clientManager); // Elo - EloManager eloManager = new EloManager(this, _clientManager); + EloManager eloManager = new EloManager(this, clientManager); // Achievements - AchievementManager achievementManager = new AchievementManager(statsManager, _clientManager, _donationManager, incognito, eloManager); + AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager, incognito, eloManager); // Chat/Messaging - Chat chat = new Chat(this, incognito, _clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); - new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, new FriendManager(this, _clientManager, preferenceManager, portal), chat); + Chat chat = new Chat(this, incognito, clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); + new MessageManager(this, incognito, clientManager, preferenceManager, ignoreManager, punish, new FriendManager(this, clientManager, preferenceManager, portal), chat); // Fixes new MemoryFix(this); @@ -177,12 +181,12 @@ public class GemHunters extends JavaPlugin new Explosion(this, blockRestore); // Inventories - new InventoryManager(this, _clientManager); + new InventoryManager(this, clientManager); // Reports SnapshotManager snapshotManager = new SnapshotManager(this, new SnapshotRepository(serverStatusManager.getCurrentServerName(), getLogger())); - new SnapshotPlugin(this, snapshotManager, _clientManager); - new ReportPlugin(this, new ReportManager(this, snapshotManager, _clientManager, incognito, punish, serverStatusManager.getRegion(), serverStatusManager.getCurrentServerName(), 1)); + new SnapshotPlugin(this, snapshotManager, clientManager); + new ReportPlugin(this, new ReportManager(this, snapshotManager, clientManager, incognito, punish, serverStatusManager.getRegion(), serverStatusManager.getCurrentServerName(), 1)); // Tag fix new CustomTagFix(this, packetHandler); @@ -191,7 +195,7 @@ public class GemHunters extends JavaPlugin new HologramManager(this, packetHandler); // Now we finally get to enable the Gem Hunters main module - new GemHuntersModule(_clientManager); + require(GemHuntersModule.class); //UpdateEvent!!! new Updater(this); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHuntersModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHuntersModule.java index 07e34cd58..1e2758d1c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHuntersModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHuntersModule.java @@ -2,8 +2,9 @@ package mineplex.gemhunters; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; -import mineplex.core.account.CoreClientManager; +import mineplex.gemhunters.economy.CashOutModule; import mineplex.gemhunters.loot.LootModule; +import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.scoreboard.ScoreboardModule; import mineplex.gemhunters.supplydrop.SupplyDropModule; @@ -11,13 +12,14 @@ import mineplex.gemhunters.supplydrop.SupplyDropModule; public class GemHuntersModule extends MiniPlugin { - public GemHuntersModule(CoreClientManager clientManager) + public GemHuntersModule() { super("Gem Hunters"); - require(SupplyDropModule.class); + require(CashOutModule.class); require(LootModule.class); - - new ScoreboardModule(clientManager); + require(SafezoneModule.class); + require(ScoreboardModule.class); + require(SupplyDropModule.class); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java new file mode 100644 index 000000000..b8a439b9e --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -0,0 +1,267 @@ +package mineplex.gemhunters.economy; + +import java.text.DecimalFormat; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.Material; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.recharge.Recharge; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +@ReflectivelyCreateMiniPlugin +public class CashOutModule extends MiniPlugin +{ + + private static final DecimalFormat ARMOUR_STAND_FORMAT = new DecimalFormat("0.0"); + private static final ItemStack CASH_OUT_ITEM = new ItemBuilder(Material.EMERALD).setTitle(C.cGreen + "Cash Out").addLore("", C.cGray + "Click to begin the process to cash out.", C.cGray + "Cashing out saves your current loot.").build(); + + private static final int CASH_OUT_COOLDOWN = 10000; + private static final int CASH_OUT_MAX_MOVE_DISTANCE_SQUARED = 4; + + private final Map _sessions; + + public CashOutModule() + { + super("CashOut"); + + _sessions = new HashMap<>(); + } + + @EventHandler + public void playerInteract(PlayerInteractEvent event) + { + if (!UtilEvent.isAction(event, ActionType.R)) + { + return; + } + + Player player = event.getPlayer(); + ItemStack itemStack = player.getItemInHand(); + + if (itemStack == null) + { + return; + } + + if (!itemStack.isSimilar(CASH_OUT_ITEM)) + { + return; + } + + attemptCashOut(player); + } + + @EventHandler + public void itemDrop(PlayerDropItemEvent event) + { + if (event.getItemDrop().getItemStack().isSimilar(CASH_OUT_ITEM)) + { + event.getPlayer().sendMessage(F.main("Game", "You cannnot drop the" + F.item("Cash Out Item") + ".")); + event.setCancelled(true); + } + } + + @EventHandler + public void inventoryClick(InventoryClickEvent event) + { + Inventory inv = event.getInventory(); + ItemStack itemStack = event.getCurrentItem(); + + if (inv == null || itemStack == null) + { + return; + } + + if (itemStack.isSimilar(CASH_OUT_ITEM)) + { + event.setCancelled(true); + } + } + + @EventHandler + public void playerJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + + player.getInventory().setItem(8, CASH_OUT_ITEM); + } + + // TODO this probably + // @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + attemptCashOut(event.getPlayer()); + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + Iterator iterator = _sessions.keySet().iterator(); + + while (iterator.hasNext()) + { + UUID key = iterator.next(); + Player player = UtilPlayer.searchExact(key); + CashOutSession session = _sessions.get(key); + double current = session.getCurrent(); + ArmorStand stand = session.getArmourStand(); + String standName = ARMOUR_STAND_FORMAT.format(current) + " seconds"; + + if (player == null) + { + session.endSession(); + iterator.remove(); + continue; + } + + UtilTextMiddle.display("", UtilTextMiddle.progress((float) (1 - current / session.getMax())), 0, 10, 0, player); + stand.setCustomName(standName); + session.setCurrent(current - 0.05); + + if (session.getCurrent() <= 0) + { + session.endSession(); + iterator.remove(); + player.sendMessage(C.cGreen + "Imagine you are being sent to the Lobby."); + rewardCashOut(player, session); + // Portal.getInstance().sendToHub(player, "You cashed out!"); + } + } + } + + @EventHandler + public void updateMove(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST) + { + return; + } + + for (UUID key : _sessions.keySet()) + { + Player player = UtilPlayer.searchExact(key); + CashOutSession session = _sessions.get(key); + + if (session.getLocation().distanceSquared(player.getLocation()) > CASH_OUT_MAX_MOVE_DISTANCE_SQUARED) + { + cancelCashOut(player, "You moved!"); + } + } + } + + @EventHandler + public void entityDamage(EntityDamageEvent event) + { + if (!(event.getEntity() instanceof Player)) + { + return; + } + + Player player = (Player) event.getEntity(); + + if (isCashingOut(player)) + { + cancelCashOut(player, "You took damage!"); + } + } + + @EventHandler + public void entityAttack(EntityDamageByEntityEvent event) + { + if (!(event.getDamager() instanceof Player)) + { + return; + } + + Player player = (Player) event.getDamager(); + + if (isCashingOut(player)) + { + cancelCashOut(player, "You attacked a player!"); + } + } + + public void attemptCashOut(Player player) + { + UUID key = player.getUniqueId(); + + if (_sessions.containsKey(key)) + { + player.sendMessage(F.main("Game", "You are already cashing out.")); + return; + } + + if (!Recharge.Instance.use(player, "Cash Out", CASH_OUT_COOLDOWN, true, false)) + { + return; + } + + // Test time + _sessions.put(key, new CashOutSession(player, 10)); + } + + public void rewardCashOut(Player player, CashOutSession session) + { + + } + + public void cancelCashOut(Player player, String message) + { + UUID key = player.getUniqueId(); + CashOutSession session = _sessions.get(key); + + player.sendMessage(F.main("Game", message + " Your cash out has been cancelled.")); + + session.endSession(); + _sessions.remove(key); + } + + public boolean isCashingOut(Player player) + { + return getCashOutSession(player) != null; + } + + public CashOutSession getCashOutSession(Player player) + { + for (UUID key : _sessions.keySet()) + { + if (key.equals(player.getUniqueId())) + { + return _sessions.get(key); + } + } + + return null; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutSession.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutSession.java new file mode 100644 index 000000000..41a2ac0fc --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutSession.java @@ -0,0 +1,59 @@ +package mineplex.gemhunters.economy; + +import org.bukkit.Location; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Player; + +public class CashOutSession +{ + + private double _current; + private double _max; + private ArmorStand _stand; + private Location _location; + + public CashOutSession(Player player, double max) + { + _current = max; + _max = max; + _stand = player.getWorld().spawn(player.getLocation().add(0, 0.5, 0), ArmorStand.class); + + _stand.setCustomName("Cashing Out"); + _stand.setCustomNameVisible(true); + _stand.setVisible(false); + _stand.setGravity(false); + + _location = player.getLocation(); + } + + public void endSession() + { + _stand.remove(); + } + + public void setCurrent(double current) + { + _current = current; + } + + public double getCurrent() + { + return _current; + } + + public double getMax() + { + return _max; + } + + public ArmorStand getArmourStand() + { + return _stand; + } + + public Location getLocation() + { + return _location; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 4b1cc4dee..0425ad706 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -1,12 +1,14 @@ package mineplex.gemhunters.loot; 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 org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockState; @@ -42,6 +44,7 @@ public class LootModule extends MiniPlugin private WorldDataModule _worldData; private Map> _chestLoot; + private List _opened; private LootModule() { @@ -50,7 +53,8 @@ public class LootModule extends MiniPlugin _sheets = require(GoogleSheetsManager.class); _worldData = require(WorldDataModule.class); _chestLoot = new HashMap<>(); - + _opened = new ArrayList<>(200); + updateChestLoot(); } @@ -103,6 +107,7 @@ public class LootModule extends MiniPlugin } catch (NumberFormatException e) { + continue; } ItemBuilder builder = new ItemBuilder(material, data); @@ -234,6 +239,23 @@ public class LootModule extends MiniPlugin return index; } + private LootItem isLootItem(ItemStack itemStack) + { + for (Set items : _chestLoot.values()) + { + for (LootItem item : items) + { + if (item.getItemStack().isSimilar(itemStack)) + { + return item; + } + } + } + + return null; + } + + @EventHandler public void chestOpen(PlayerInteractEvent event) { @@ -250,6 +272,12 @@ public class LootModule extends MiniPlugin return; } + if (_opened.contains(block.getLocation())) + { + return; + } + + _opened.add(block.getLocation()); fillChest(player, block); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java new file mode 100644 index 000000000..31d6ef820 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java @@ -0,0 +1,24 @@ +package mineplex.gemhunters.loot.rewards; + +import org.bukkit.entity.Player; + +/** + * @author Sam + */ +public abstract class LootItemReward +{ + + private long _cashOutDelay; + + public LootItemReward(long cashOutDelay) + { + _cashOutDelay = cashOutDelay; + } + + public abstract void onCollectItem(Player player); + + public abstract void onSucessful(Player player); + + public abstract void onDeath(Player player); + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java new file mode 100644 index 000000000..9518baa40 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java @@ -0,0 +1,78 @@ +package mineplex.gemhunters.loot.rewards; + +import java.util.concurrent.TimeUnit; + +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClient; +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.Rank; + +public class LootRankReward extends LootItemReward +{ + + private static final long CASH_OUT_DELAY = TimeUnit.SECONDS.toMillis(60); + + private final CoreClientManager _clientManager; + + public LootRankReward(CoreClientManager clientManager) + { + super(CASH_OUT_DELAY); + + _clientManager = clientManager; + } + + @Override + public void onCollectItem(Player player) + { + } + + @Override + public void onSucessful(Player player) + { + CoreClient client = _clientManager.Get(player); + Rank rank = client.GetRank(); + Rank newRank = null; + + // I could have done this so it runs off the order of the Rank enum, + // however knowing some people that might get changed so I'm just going + // to hard code what you get. + + switch (rank) + { + case ALL: + newRank = Rank.ULTRA; + break; + case ULTRA: + newRank = Rank.HERO; + break; + case HERO: + newRank = Rank.LEGEND; + break; + case LEGEND: + newRank = Rank.TITAN; + break; + case TITAN: + newRank = Rank.ETERNAL; + break; + default: + break; + } + + // A suitable rank could not be found. + if (newRank == null) + { + // TODO implement shard reward. + return; + } + + client.SetRank(newRank, false); + _clientManager.getRepository().saveRank(null, player.getName(), player.getUniqueId(), newRank, true); + } + + @Override + public void onDeath(Player player) + { + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java new file mode 100644 index 000000000..89baacd2d --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java @@ -0,0 +1,174 @@ +package mineplex.gemhunters.safezone; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.world.WorldDataModule; + +@ReflectivelyCreateMiniPlugin +public class SafezoneModule extends MiniPlugin +{ + + private static final String SAFEZONE_DATA_PREFIX = "SAFEZONE"; + + private final WorldDataModule _worldData; + + private Map _currentSafezone; + + private SafezoneModule() + { + super("Safezone"); + + _worldData = require(WorldDataModule.class); + + _currentSafezone = new HashMap<>(); + } + + @EventHandler + public void updateSafeZone(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST) + { + return; + } + + for (Player player : Bukkit.getOnlinePlayers()) + { + UUID key = player.getUniqueId(); + String oldSafezone = _currentSafezone.get(key); + boolean isInOldSafezone = isInSafeZone(player.getLocation(), oldSafezone); + String newSafezone = getSafezone(player.getLocation()); + boolean isInNewSafezone = newSafezone != null; + + // null -> not null + // not null -> null + // null -> null + // not null -> not null + + if (!isInOldSafezone && isInNewSafezone) + { + UtilTextMiddle.display("", C.cYellow + "Entering " + newSafezone, 10, 40, 10, player); + _currentSafezone.put(key, newSafezone); + } + else if (isInOldSafezone && !isInNewSafezone) + { + UtilTextMiddle.display("", C.cYellow + "Leaving " + newSafezone, 10, 40, 10, player); + _currentSafezone.put(key, null); + } + } + } + + @EventHandler + public void playerJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + + // Temporary + player.teleport(UtilAlg.Random(_worldData.getDataLocation("LIME"))); + } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + Player player = event.getPlayer(); + + _currentSafezone.remove(player.getUniqueId()); + } + + @EventHandler + public void entityDamage(EntityDamageEvent event) + { + if (!(event.getEntity() instanceof Player)) + { + return; + } + + Player player = (Player) event.getEntity(); + + if (getSafezone(player.getLocation()) != null) + { + event.setCancelled(true); + } + } + + @EventHandler + public void entityAttack(EntityDamageByEntityEvent event) + { + if (!(event.getDamager() instanceof Player)) + { + return; + } + + Player player = (Player) event.getDamager(); + + if (getSafezone(player.getLocation()) != null) + { + event.setCancelled(true); + } + } + + public boolean isInSafeZone(Location location, String safezone) + { + if (safezone == null) + { + return false; + } + + List bounds = _worldData.getCustomLocation(safezone); + + if (bounds == null || bounds.size() != 2) + { + log("Error regarding safezone bounds for region " + safezone + " there are " + bounds.size() + " points instead of 2. Ignoring this safezone!"); + return false; + } + + return UtilAlg.inBoundingBox(location, bounds.get(0), bounds.get(1)); + } + + public String getSafezone(Location location) + { + Map> customLocations = _worldData.getAllCustomLocations(); + + for (String key : customLocations.keySet()) + { + if (!key.startsWith(SAFEZONE_DATA_PREFIX)) + { + continue; + } + + List bounds = customLocations.get(key); + + if (bounds.size() != 2) + { + log("Error regarding safezone bounds for region " + key + " there are " + bounds.size() + " points instead of 2. Ignoring this safezone!"); + continue; + } + + if (UtilAlg.inBoundingBox(location, bounds.get(0), bounds.get(1))) + { + return key.split(" ")[1]; + } + } + + return null; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java index 395d8f7e7..388acdded 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java @@ -17,7 +17,12 @@ public class GemHuntersScoreboard extends WritableMineplexScoreboard { writeNewLine(); - write(C.cGreen + ""); + write(C.cGreenB + "Top Players"); + + writeNewLine(); + + write(C.cYellowB + "Reset Time"); + write("0 seconds"); writeNewLine(); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java index abf48748a..f1e2abb89 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java @@ -26,23 +26,21 @@ public class ScoreboardModule extends MiniPlugin private static final String PRIMARY_COLOUR = C.cGreenB; private static final String SECONDARY_COLOUR = C.cWhiteB; private static final String TRANSITION_COLOUR = C.cDGreenB; + private static final String SCOREBOARD_TITLE = " GEM HUNTERS "; - private CoreClientManager _clientManager; + private final CoreClientManager _clientManager; - private Map _scoreboards; + private final Map _scoreboards; - private String _title; private int _shineIndex; private boolean _shineDirection = true; - public ScoreboardModule(CoreClientManager clientManager) + public ScoreboardModule() { super("Scoreboard"); - _clientManager = clientManager; + _clientManager = require(CoreClientManager.class); _scoreboards = new HashMap<>(); - - _title = " GEM HUNTERS "; } @EventHandler @@ -125,25 +123,31 @@ public class ScoreboardModule extends MiniPlugin { String out = (_shineDirection ? PRIMARY_COLOUR : SECONDARY_COLOUR); - for (int i = 0; i < _title.length(); i++) + for (int i = 0; i < SCOREBOARD_TITLE.length(); i++) { - char c = _title.charAt(i); + char c = SCOREBOARD_TITLE.charAt(i); if (_shineDirection) { if (i == _shineIndex) + { out += TRANSITION_COLOUR; - - if (i == _shineIndex + 1) + } + else if (i == _shineIndex + 1) + { out += SECONDARY_COLOUR; + } } else { if (i == _shineIndex) + { out += TRANSITION_COLOUR; - - if (i == _shineIndex + 1) + } + else if (i == _shineIndex + 1) + { out += PRIMARY_COLOUR; + } } out += c; @@ -156,7 +160,7 @@ public class ScoreboardModule extends MiniPlugin _shineIndex++; - if (_shineIndex == _title.length() * 2) + if (_shineIndex == SCOREBOARD_TITLE.length() * 2) { _shineIndex = 0; _shineDirection = !_shineDirection; From a1dc9135c871c8d22a479ca679200d3610bac296 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 25 Dec 2016 22:06:10 +0000 Subject: [PATCH 007/101] Sprint work --- .../src/mineplex/gemhunters/GemHunters.java | 9 +- .../mineplex/gemhunters/GemHuntersModule.java | 2 + .../gemhunters/death/DeathModule.java | 56 +++++++++++ .../gemhunters/economy/CashOutModule.java | 9 +- .../mineplex/gemhunters/loot/LootModule.java | 51 +++++----- .../loot/rewards/LootRankReward.java | 5 +- .../gemhunters/safezone/SafezoneModule.java | 19 ++-- .../gemhunters/supplydrop/SupplyDrop.java | 93 ++++++++++++------- .../supplydrop/SupplyDropModule.java | 66 +++++++++++-- .../supplydrop/SupplyDropState.java | 8 -- .../commands/CommandSupplyDropTest.java | 2 +- .../gemhunters/world/WorldDataModule.java | 21 ++++- 12 files changed, 240 insertions(+), 101 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java delete mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropState.java diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 07d7d3f77..af1a832d6 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -2,7 +2,6 @@ package mineplex.gemhunters; import static mineplex.core.Managers.require; -import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.plugin.java.JavaPlugin; @@ -13,7 +12,6 @@ import mineplex.core.FoodDupeFix; import mineplex.core.TimingsFix; import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; -import mineplex.core.antihack.AntiHack; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.chat.Chat; import mineplex.core.chatsnap.SnapshotManager; @@ -150,9 +148,10 @@ public class GemHunters extends JavaPlugin new DamageManager(this, new CombatManager(this), new NpcManager(this, creature), disguiseManager, new ConditionManager(this)); // GWEN - AntiHack antiHack = require(AntiHack.class); - antiHack.setKick(false); - Bukkit.getScheduler().runTask(this, antiHack::enableNewAnticheat); + //TODO enable GWEN, gives some annoying errors +// AntiHack antiHack = require(AntiHack.class); +// antiHack.setKick(false); +// Bukkit.getScheduler().runTask(this, antiHack::enableNewAnticheat); // Block Restore BlockRestore blockRestore = new BlockRestore(this); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHuntersModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHuntersModule.java index 1e2758d1c..bf88d4a29 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHuntersModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHuntersModule.java @@ -2,6 +2,7 @@ package mineplex.gemhunters; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.gemhunters.death.DeathModule; import mineplex.gemhunters.economy.CashOutModule; import mineplex.gemhunters.loot.LootModule; import mineplex.gemhunters.safezone.SafezoneModule; @@ -17,6 +18,7 @@ public class GemHuntersModule extends MiniPlugin super("Gem Hunters"); require(CashOutModule.class); + require(DeathModule.class); require(LootModule.class); require(SafezoneModule.class); require(ScoreboardModule.class); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java new file mode 100644 index 000000000..a7dbf99ab --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java @@ -0,0 +1,56 @@ +package mineplex.gemhunters.death; + +import java.util.Iterator; +import java.util.Set; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.inventory.ItemStack; + +import com.google.common.collect.Sets; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.util.UtilAction; +import mineplex.gemhunters.world.WorldDataModule; + +@ReflectivelyCreateMiniPlugin +public class DeathModule extends MiniPlugin +{ + + private static final Set DISALLOWED_DROPS = Sets.newHashSet(Material.EMERALD, Material.BONE); + + private final WorldDataModule _worldData; + + private DeathModule() + { + super("Death"); + + _worldData = require(WorldDataModule.class); + } + + @EventHandler + public void death(PlayerDeathEvent event) + { + Player player = event.getEntity(); + + player.setHealth(20); + UtilAction.zeroVelocity(player); + player.teleport(_worldData.getSpawnLocation("Yellow").get(0)); + + Iterator iterator = event.getDrops().iterator(); + + while (iterator.hasNext()) + { + ItemStack itemStack = iterator.next(); + + if (DISALLOWED_DROPS.contains(itemStack.getType())) + { + iterator.remove(); + } + } + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java index b8a439b9e..7c234c95a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -25,6 +25,7 @@ import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilTextMiddle; @@ -41,7 +42,7 @@ public class CashOutModule extends MiniPlugin private static final ItemStack CASH_OUT_ITEM = new ItemBuilder(Material.EMERALD).setTitle(C.cGreen + "Cash Out").addLore("", C.cGray + "Click to begin the process to cash out.", C.cGray + "Cashing out saves your current loot.").build(); private static final int CASH_OUT_COOLDOWN = 10000; - private static final int CASH_OUT_MAX_MOVE_DISTANCE_SQUARED = 4; + private static final int CASH_OUT_MAX_MOVE_DISTANCE = 2; private final Map _sessions; @@ -81,7 +82,7 @@ public class CashOutModule extends MiniPlugin { if (event.getItemDrop().getItemStack().isSimilar(CASH_OUT_ITEM)) { - event.getPlayer().sendMessage(F.main("Game", "You cannnot drop the" + F.item("Cash Out Item") + ".")); + event.getPlayer().sendMessage(F.main("Game", "You cannnot drop the " + F.item("Cash Out Item") + ".")); event.setCancelled(true); } } @@ -172,7 +173,7 @@ public class CashOutModule extends MiniPlugin Player player = UtilPlayer.searchExact(key); CashOutSession session = _sessions.get(key); - if (session.getLocation().distanceSquared(player.getLocation()) > CASH_OUT_MAX_MOVE_DISTANCE_SQUARED) + if (UtilMath.offset(session.getLocation(), player.getLocation()) > CASH_OUT_MAX_MOVE_DISTANCE) { cancelCashOut(player, "You moved!"); } @@ -198,7 +199,7 @@ public class CashOutModule extends MiniPlugin @EventHandler public void entityAttack(EntityDamageByEntityEvent event) { - if (!(event.getDamager() instanceof Player)) + if (!(event.getDamager() instanceof Player) || event.getEntity() instanceof ArmorStand) { return; } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 0425ad706..5a2c2593a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -54,8 +54,10 @@ public class LootModule extends MiniPlugin _worldData = require(WorldDataModule.class); _chestLoot = new HashMap<>(); _opened = new ArrayList<>(200); - + updateChestLoot(); + + runSyncLater(() -> _worldData.getDataLocation("PINK").forEach(location -> location.getBlock().setType(Material.CHEST)), 50); } @Override @@ -65,7 +67,7 @@ public class LootModule extends MiniPlugin } public void updateChestLoot() - { + { try { Map>> map = _sheets.getCellValues(CHEST_LOOT_SHEET); @@ -140,12 +142,7 @@ public class LootModule extends MiniPlugin } double probability = Double.parseDouble(String.valueOf(values.get(6))); - String metadata = null; - - if (values.size() < 7) - { - metadata = String.valueOf(values.get(7)); - } + String metadata = String.valueOf(values.get(7)); items.add(new LootItem(builder.build(), minAmount, maxAmount, probability, metadata)); } @@ -167,16 +164,8 @@ public class LootModule extends MiniPlugin } } - public void fillChest(Player player, Block block) + public void fillChest(Player player, Block block, String key) { - if (block.getType() != Material.CHEST) - { - return; - } - - // TODO implement data points - String key = "Example"; - Set used = new HashSet<>(); Set items = _chestLoot.get(key); @@ -239,7 +228,7 @@ public class LootModule extends MiniPlugin return index; } - private LootItem isLootItem(ItemStack itemStack) + public LootItem isLootItem(ItemStack itemStack) { for (Set items : _chestLoot.values()) { @@ -255,7 +244,6 @@ public class LootModule extends MiniPlugin return null; } - @EventHandler public void chestOpen(PlayerInteractEvent event) { @@ -267,7 +255,7 @@ public class LootModule extends MiniPlugin Player player = event.getPlayer(); Block block = event.getClickedBlock(); - if (block == null) + if (block == null || block.getType() != Material.CHEST) { return; } @@ -276,9 +264,28 @@ public class LootModule extends MiniPlugin { return; } - + + String key = null; + + colourLoop: for (String colour : _worldData.getAllDataLocations().keySet()) + { + for (Location location : _worldData.getDataLocation(colour)) + { + if (UtilMath.offset(block.getLocation(), location) < 1) + { + key = colour; + break colourLoop; + } + } + } + + if (key == null) + { + return; + } + _opened.add(block.getLocation()); - fillChest(player, block); + fillChest(player, block, key); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java index 9518baa40..d2c2a3f11 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java @@ -4,6 +4,7 @@ import java.util.concurrent.TimeUnit; import org.bukkit.entity.Player; +import mineplex.core.Managers; import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClientManager; import mineplex.core.common.Rank; @@ -15,11 +16,11 @@ public class LootRankReward extends LootItemReward private final CoreClientManager _clientManager; - public LootRankReward(CoreClientManager clientManager) + public LootRankReward() { super(CASH_OUT_DELAY); - _clientManager = clientManager; + _clientManager = Managers.require(CoreClientManager.class); } @Override diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java index 89baacd2d..5a0ff43d5 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -18,6 +17,7 @@ import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -50,19 +50,14 @@ public class SafezoneModule extends MiniPlugin return; } - for (Player player : Bukkit.getOnlinePlayers()) + for (Player player : UtilServer.getPlayers()) { UUID key = player.getUniqueId(); String oldSafezone = _currentSafezone.get(key); - boolean isInOldSafezone = isInSafeZone(player.getLocation(), oldSafezone); + boolean isInOldSafezone = oldSafezone != null; String newSafezone = getSafezone(player.getLocation()); boolean isInNewSafezone = newSafezone != null; - - // null -> not null - // not null -> null - // null -> null - // not null -> not null - + if (!isInOldSafezone && isInNewSafezone) { UtilTextMiddle.display("", C.cYellow + "Entering " + newSafezone, 10, 40, 10, player); @@ -70,7 +65,7 @@ public class SafezoneModule extends MiniPlugin } else if (isInOldSafezone && !isInNewSafezone) { - UtilTextMiddle.display("", C.cYellow + "Leaving " + newSafezone, 10, 40, 10, player); + UtilTextMiddle.display("", C.cYellow + "Leaving " + oldSafezone, 10, 40, 10, player); _currentSafezone.put(key, null); } } @@ -82,7 +77,7 @@ public class SafezoneModule extends MiniPlugin Player player = event.getPlayer(); // Temporary - player.teleport(UtilAlg.Random(_worldData.getDataLocation("LIME"))); + player.teleport(UtilAlg.Random(_worldData.getSpawnLocation("Lime"))); } @EventHandler @@ -132,7 +127,7 @@ public class SafezoneModule extends MiniPlugin return false; } - List bounds = _worldData.getCustomLocation(safezone); + List bounds = _worldData.getCustomLocation(SAFEZONE_DATA_PREFIX + " " + safezone); if (bounds == null || bounds.size() != 2) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java index 13defe20a..f834a0064 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java @@ -5,22 +5,26 @@ import java.io.IOException; import java.util.HashSet; import java.util.Set; +import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.entity.FallingBlock; import org.bukkit.util.BlockVector; import mineplex.core.common.block.schematic.Schematic; import mineplex.core.common.block.schematic.SchematicData; import mineplex.core.common.block.schematic.UtilSchematic; +import mineplex.core.common.util.UtilFirework; +import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilShapes; /** * Represents an instance of a Supply Drop.
* A supply drop consists of a helicopter flying through the map from a one * location to another. Upon reaching it's destination it will drop a loot chest - * which players can then fight over.
+ * which players can then fight over.
* The helicopter will then fly away towards a despawning location.
*
* The helicopter will be made up of a collection of blocks that are moved along @@ -39,14 +43,11 @@ public class SupplyDrop private static final String SCHEMATIC_PATH = "../../update/files/Helicopter.schematic"; private static final int BLADE_LENGTH = 7; - - private Location _spawn; + private Location _destination; private Location _despawn; private Location _current; private Location _blade; - - private SupplyDropState _state; private Schematic _schematic; private Set _lastHelicopter; @@ -55,12 +56,10 @@ public class SupplyDrop public SupplyDrop(Location spawn, Location destination, Location despawn) { - _spawn = spawn; - _destination = destination; - _despawn = despawn; - _current = spawn; - _state = SupplyDropState.MOVING_TO_DESTINATION; - + _destination = destination.clone(); + _despawn = despawn.clone(); + _current = spawn.clone().add(-2, 0, 0); + try { _schematic = UtilSchematic.loadSchematic(new File(SCHEMATIC_PATH)); @@ -70,45 +69,66 @@ public class SupplyDrop e.printStackTrace(); return; } - + _lastHelicopter = new HashSet<>(100); _bladeBlocks = new HashSet<>(20); _diagonal = false; } - public void advancePath() + public boolean advancePath() { - if (!isStopped()) + boolean done = moveHelicopter(); + + if (!done) { - moveHelicopter(); + rotateBlades(); } - - rotateBlades(); - + _current.add(0, 0, 1); + + return done; } - - public void moveHelicopter() + + public boolean moveHelicopter() { for (Block block : _lastHelicopter) { block.setType(Material.AIR); } - + _lastHelicopter.clear(); - - SchematicData data = _schematic.paste(_current, true, true); - + + if (_blade != null) + { + if (UtilMath.offset2d(_blade, _destination) < 1) + { + spawnLootChest(); + } + else if (UtilMath.offset2d(_blade, _despawn) < 1) + { + for (Block block : _bladeBlocks) + { + block.setType(Material.AIR); + } + + return true; + } + } + + SchematicData data = _schematic.paste(_current, true); + _blade = data.getDataLocationMap().getIronLocations(DyeColor.RED).get(0); - + for (BlockVector vector : data.getBlocks()) { Location location = _current.add(vector); - + _lastHelicopter.add(location.getBlock()); - - _current.subtract(vector); + + _current.subtract(vector); } + + return false; } public void rotateBlades() @@ -119,11 +139,11 @@ public class SupplyDrop { block.setType(Material.AIR); } - + _bladeBlocks.clear(); - + if (_diagonal) - { + { for (int x = -1; x <= 1; x += 2) { for (int z = -1; z <= 1; z += 2) @@ -139,7 +159,7 @@ public class SupplyDrop } } else - { + { for (int x = -1; x <= 1; x += 2) { for (Location location : UtilShapes.getLinesLimitedPoints(_blade, _blade.clone().add(x * BLADE_LENGTH, 0, 0), BLADE_LENGTH)) @@ -164,9 +184,14 @@ public class SupplyDrop } } - public boolean isStopped() + public void spawnLootChest() { - return _state == SupplyDropState.STOPPED; + FallingBlock fallingBlock = _blade.getWorld().spawnFallingBlock(_blade.clone().subtract(0, 10, 0), Material.WOOD, (byte) 0); + + fallingBlock.setHurtEntities(false); + fallingBlock.setDropItem(false); + + UtilFirework.playFreedomFirework(fallingBlock.getLocation()); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java index b191371fa..382312bc3 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java @@ -1,8 +1,14 @@ package mineplex.gemhunters.supplydrop; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.entity.Player; +import org.bukkit.block.Block; +import org.bukkit.entity.FallingBlock; import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.ItemSpawnEvent; import mineplex.core.MiniPlugin; @@ -10,35 +16,44 @@ import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.supplydrop.commands.CommandSupplyDropTest; +import mineplex.gemhunters.world.WorldDataModule; @ReflectivelyCreateMiniPlugin public class SupplyDropModule extends MiniPlugin { - + + private final WorldDataModule _worldData; + private SupplyDrop _current; - + private SupplyDropModule() { super("Supply Drop"); + + _worldData = require(WorldDataModule.class); } - + @Override public void addCommands() { addCommand(new CommandSupplyDropTest(this)); } - + @EventHandler public void update(UpdateEvent event) { if (event.getType() != UpdateType.SEC || _current == null) + { return; } - - _current.advancePath(); + + if (_current.advancePath()) + { + _current = null; + } } - + @EventHandler public void itemSpawn(ItemSpawnEvent event) { @@ -48,8 +63,39 @@ public class SupplyDropModule extends MiniPlugin } } - public void startHelicopter(Player player) + @EventHandler + public void fallingBlockChange(EntityChangeBlockEvent event) { - _current = new SupplyDrop(player.getLocation(), player.getLocation(), player.getLocation()); + if (event.getEntity() instanceof FallingBlock && event.getTo() == Material.WOOD) + { + Block block = event.getBlock(); + + block.setType(Material.CHEST); + + List chests = _worldData.getAllDataLocations().get("RED"); + + if (chests == null) + { + chests = new ArrayList<>(); + } + + if (!chests.contains(block.getLocation())) + { + chests.add(block.getLocation()); + } + + _worldData.getAllDataLocations().put("RED", chests); + + event.setCancelled(true); + } + } + + public void startHelicopter() + { + Location spawn = _worldData.getCustomLocation("SUPPLY_DROP Fountain Spawn").get(0); + Location destination = _worldData.getCustomLocation("SUPPLY_DROP Fountain Chest").get(0); + Location despawn = _worldData.getCustomLocation("SUPPLY_DROP Fountain End").get(0); + + _current = new SupplyDrop(spawn, destination, despawn); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropState.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropState.java deleted file mode 100644 index 4fefe368a..000000000 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropState.java +++ /dev/null @@ -1,8 +0,0 @@ -package mineplex.gemhunters.supplydrop; - -public enum SupplyDropState -{ - - MOVING_TO_DESTINATION, STOPPED, MOVING_TO_DESPAWN - -} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/CommandSupplyDropTest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/CommandSupplyDropTest.java index 4ba3bfc32..40da25fb3 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/CommandSupplyDropTest.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/CommandSupplyDropTest.java @@ -18,7 +18,7 @@ public class CommandSupplyDropTest extends CommandBase public void Execute(Player caller, String[] args) { caller.sendMessage("Running!"); - Plugin.startHelicopter(caller); + Plugin.startHelicopter(); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java index 3c3d259b7..8549caa84 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java @@ -293,14 +293,24 @@ public class WorldDataModule extends MiniPlugin return null; } - public List getDataLocation(String data) + public List getSpawnLocation(String colour) { - if (!DATA_LOCATIONS.containsKey(data)) + if (!SPAWN_LOCATIONS.containsKey(colour)) { return new ArrayList(); } - return DATA_LOCATIONS.get(data); + return SPAWN_LOCATIONS.get(colour); + } + + public List getDataLocation(String colour) + { + if (!DATA_LOCATIONS.containsKey(colour)) + { + return new ArrayList(); + } + + return DATA_LOCATIONS.get(colour); } public List getCustomLocation(String id) @@ -313,6 +323,11 @@ public class WorldDataModule extends MiniPlugin return CUSTOM_LOCAITONS.get(id); } + public Map> getAllSpawnLocations() + { + return SPAWN_LOCATIONS; + } + public Map> getAllCustomLocations() { return CUSTOM_LOCAITONS; From e114ab03b571b199e5ef8a517d906735c240e5da Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 27 Dec 2016 17:20:53 +0000 Subject: [PATCH 008/101] Chest spawning --- .../common/google/GoogleSheetProvider.java | 22 -- .../core/google/GoogleSheetsManager.java | 10 +- .../mineplex/gemhunters/loot/LootModule.java | 224 ++++++++++++++++-- .../gemhunters/loot/SpawnedChest.java | 59 +++++ .../gemhunters/supplydrop/SupplyDrop.java | 1 - .../supplydrop/SupplyDropModule.java | 22 +- 6 files changed, 271 insertions(+), 67 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/SpawnedChest.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/google/GoogleSheetProvider.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/google/GoogleSheetProvider.java index d26c97896..342a7abd2 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/google/GoogleSheetProvider.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/google/GoogleSheetProvider.java @@ -138,28 +138,6 @@ public class GoogleSheetProvider _service.spreadsheets().values().update(spreadsheetID, sheetName + "!" + range, valueRange).setValueInputOption("RAW").execute(); } - public void read(String spreadsheetID, String sheetName, String range) throws IOException - { - ValueRange response = _service.spreadsheets().values().get(spreadsheetID, sheetName + "!" + range).execute(); - List> values = response.getValues(); - - if (values == null || values.isEmpty()) - { - System.out.println("No data found."); - return; - } - - for (List row : values) - { - for (int i = 0; i < row.size(); i++) - { - System.out.println(row.get(i) + ", "); - } - - System.out.print("\n"); - } - } - public void merge(String spreadsheetID, String sheetName, int id, String mergeType, int startRow, int endRow, int startColumn, int endColumn) throws IOException { BatchUpdateSpreadsheetRequest spreadsheetRequest = new BatchUpdateSpreadsheetRequest(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java b/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java index 6ad973730..2c9de13b6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java @@ -16,7 +16,7 @@ import mineplex.core.common.google.GoogleSheetProvider; public class GoogleSheetsManager extends MiniPlugin { - private GoogleSheetProvider _sheets; + private final GoogleSheetProvider _sheets; private GoogleSheetsManager() { @@ -25,22 +25,22 @@ public class GoogleSheetsManager extends MiniPlugin _sheets = new GoogleSheetProvider(); } - public void addSheet(MineplexGoogleSheet sheet, String sheetName, int maxColumn, int maxRow) throws IOException + public final void addSheet(MineplexGoogleSheet sheet, String sheetName, int maxColumn, int maxRow) throws IOException { _sheets.create(sheet.getID(), sheetName, _sheets.getNextSheetID(sheet.getID()), maxColumn, maxRow); } - public List> getCellValues(MineplexGoogleSheet spreadsheet, String sheetName, String a1Notation) throws IOException + public final List> getCellValues(MineplexGoogleSheet spreadsheet, String sheetName, String a1Notation) throws IOException { return _sheets.getSheetsService().spreadsheets().values().get(spreadsheet.getID(), sheetName + "!" + a1Notation).execute().getValues(); } - public List> getCellValues(MineplexGoogleSheet spreadsheet, String sheetName) throws IOException + public final List> getCellValues(MineplexGoogleSheet spreadsheet, String sheetName) throws IOException { return _sheets.getSheetsService().spreadsheets().values().get(spreadsheet.getID(), sheetName).execute().getValues(); } - public Map>> getCellValues(MineplexGoogleSheet spreadsheet) throws IOException + public final Map>> getCellValues(MineplexGoogleSheet spreadsheet) throws IOException { Spreadsheet googleSpreadsheet = _sheets.getSheetsService().spreadsheets().get(spreadsheet.getID()).execute(); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 5a2c2593a..578fff2c0 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -4,13 +4,18 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.TimeUnit; +import org.bukkit.Bukkit; +import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.Chest; import org.bukkit.block.DoubleChest; @@ -23,10 +28,15 @@ import org.bukkit.inventory.ItemStack; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilWorld; import mineplex.core.google.GoogleSheetsManager; import mineplex.core.google.MineplexGoogleSheet; import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.loot.command.UpdateLootCommand; import mineplex.gemhunters.world.WorldDataModule; import net.md_5.bungee.api.ChatColor; @@ -36,15 +46,22 @@ public class LootModule extends MiniPlugin { private static final int MINIMUM_CHEST_ITEMS = 3; - private static final int MAXIMUM_CHEST_ITEMS = 8; + private static final int MAXIMUM_CHEST_ITEMS = 6; + private static final long CHEST_DESPAWN_TIME_OPENED = TimeUnit.SECONDS.toMillis(15); + private static final long CHEST_DESPAWN_TIME_NATURAL = TimeUnit.MINUTES.toMillis(30); + private static final String[] IGNORED_COLOURS = { "RED" }; + private static final float MAX_CHESTS_FACTOR = 0.25F; + private static final int MAX_SEARCH_ATTEMPTS = 40; + private static final int MAX_CHEST_PLACEMENT_RANGE = 5; private static final MineplexGoogleSheet CHEST_LOOT_SHEET = MineplexGoogleSheet.GEM_HUNTERS_CHESTS; - private GoogleSheetsManager _sheets; - private WorldDataModule _worldData; + private final GoogleSheetsManager _sheets; + private final WorldDataModule _worldData; - private Map> _chestLoot; - private List _opened; + private final Map> _chestLoot; + private final List _spawnedChest; + private final Map> _spawnedIndexes; private LootModule() { @@ -53,11 +70,10 @@ public class LootModule extends MiniPlugin _sheets = require(GoogleSheetsManager.class); _worldData = require(WorldDataModule.class); _chestLoot = new HashMap<>(); - _opened = new ArrayList<>(200); + _spawnedChest = new ArrayList<>(200); + _spawnedIndexes = new HashMap<>(15); updateChestLoot(); - - runSyncLater(() -> _worldData.getDataLocation("PINK").forEach(location -> location.getBlock().setType(Material.CHEST)), 50); } @Override @@ -66,6 +82,148 @@ public class LootModule extends MiniPlugin addCommand(new UpdateLootCommand(this)); } + @EventHandler + public void updateSpawnChests(UpdateEvent event) + { + if (event.getType() != UpdateType.SLOWER) + { + return; + } + + // Despawn opened chests + Iterator iterator = _spawnedChest.iterator(); + + while (iterator.hasNext()) + { + SpawnedChest chest = iterator.next(); + + if (chest.isOpened() && UtilTime.elapsed(chest.getOpenedAt(), CHEST_DESPAWN_TIME_OPENED) || UtilTime.elapsed(chest.getSpawnedAt(), CHEST_DESPAWN_TIME_NATURAL)) + { + if (chest.getID() != -1) + { + _spawnedIndexes.get(chest.getColour()).remove(chest.getID()); + } + + Block block = chest.getLocation().getBlock(); + + if (block.getState() instanceof Chest) + { + ((Chest) block.getState()).getBlockInventory().clear(); + } + + block.getWorld().playEffect(chest.getLocation(), Effect.STEP_SOUND, block.getType()); + block.setType(Material.AIR); + iterator.remove(); + } + } + + // Spawn new chests + dataPointLoop: for (String key : _worldData.getAllDataLocations().keySet()) + { + // Some data points are ignored like the chest loot related to supply drops. + for (String ignore : IGNORED_COLOURS) + { + if (key.equals(ignore)) + { + continue dataPointLoop; + } + } + + List locations = _worldData.getDataLocation(key); + + // Only spawn more chests if we need to + int max = (int) (locations.size() * MAX_CHESTS_FACTOR); + int spawned = 0; + + for (SpawnedChest chest : _spawnedChest) + { + if (chest.getColour().equals(key)) + { + spawned++; + } + } + + // If there are too many chests of this type we can ignore it + if (spawned > max) + { + continue; + } + + Set usedIndexes = _spawnedIndexes.get(key); + + if (usedIndexes == null) + { + _spawnedIndexes.put(key, new HashSet<>()); + usedIndexes = _spawnedIndexes.get(key); + } + + if (locations.size() == usedIndexes.size()) + { + return; + } + + Location randomLocation = null; + int attempts = 0; + int index = -1; + + while (index == -1 || usedIndexes.contains(index) && attempts < MAX_SEARCH_ATTEMPTS) + { + index = UtilMath.r(locations.size()); + + attempts++; + } + + if (index == -1) + { + continue; + } + + usedIndexes.add(index); + randomLocation = locations.get(index); + + Location chestToPlace = UtilAlg.getRandomLocation(randomLocation, MAX_CHEST_PLACEMENT_RANGE, 0, MAX_CHEST_PLACEMENT_RANGE); + Block block = chestToPlace.getBlock(); + + attempts = 0; + boolean suitable = false; + + while (!suitable && attempts < MAX_SEARCH_ATTEMPTS) + { + suitable = isSuitable(block); + attempts++; + } + + if (!suitable) + { + continue; + } + + Bukkit.broadcastMessage("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index); + _spawnedChest.add(new SpawnedChest(chestToPlace, key, index)); + block.setType(Material.CHEST); + } + } + + public boolean isSuitable(Block block) + { + if (block.getType() != Material.AIR) + { + return false; + } + + if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR) + { + return false; + } + + if (block.getRelative(BlockFace.UP).getType() != Material.AIR) + { + return false; + } + + return true; + } + public void updateChestLoot() { try @@ -142,8 +300,13 @@ public class LootModule extends MiniPlugin } double probability = Double.parseDouble(String.valueOf(values.get(6))); - String metadata = String.valueOf(values.get(7)); + String metadata = null; + if (values.size() < 7) + { + metadata = String.valueOf(values.get(7)); + + } items.add(new LootItem(builder.build(), minAmount, maxAmount, probability, metadata)); } @@ -153,7 +316,6 @@ public class LootModule extends MiniPlugin { // TODO send slack message? System.out.println("An error occured while parsing spreadsheet data!"); - e.printStackTrace(); continue; } } @@ -164,6 +326,11 @@ public class LootModule extends MiniPlugin } } + public void addSpawnedChest(Location location, String colour) + { + _spawnedChest.add(new SpawnedChest(location, colour, -1)); + } + public void fillChest(Player player, Block block, String key) { Set used = new HashSet<>(); @@ -244,6 +411,19 @@ public class LootModule extends MiniPlugin return null; } + public boolean hasChestBeenOpened(Location location) + { + for (SpawnedChest chest : _spawnedChest) + { + if (UtilMath.offset(location, chest.getLocation()) < 2 && chest.isOpened()) + { + return true; + } + } + + return false; + } + @EventHandler public void chestOpen(PlayerInteractEvent event) { @@ -251,7 +431,7 @@ public class LootModule extends MiniPlugin { return; } - + Player player = event.getPlayer(); Block block = event.getClickedBlock(); @@ -260,31 +440,29 @@ public class LootModule extends MiniPlugin return; } - if (_opened.contains(block.getLocation())) + if (hasChestBeenOpened(block.getLocation())) { return; } String key = null; - - colourLoop: for (String colour : _worldData.getAllDataLocations().keySet()) - { - for (Location location : _worldData.getDataLocation(colour)) + + for (SpawnedChest chest : _spawnedChest) + { + if (UtilMath.offset(chest.getLocation(), block.getLocation()) < 2) { - if (UtilMath.offset(block.getLocation(), location) < 1) - { - key = colour; - break colourLoop; - } + key = chest.getColour(); + chest.setOpened(); + break; } } - + if (key == null) { + event.setCancelled(true); return; } - _opened.add(block.getLocation()); fillChest(player, block, key); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/SpawnedChest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/SpawnedChest.java new file mode 100644 index 000000000..4294a9473 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/SpawnedChest.java @@ -0,0 +1,59 @@ +package mineplex.gemhunters.loot; + +import org.bukkit.Location; + +public class SpawnedChest +{ + + private Location _location; + private String _colour; + private int _id; + private long _spawnedAt; + + private long _openedAt; + + public SpawnedChest(Location location, String colour, int id) + { + _location = location; + _colour = colour; + _id = id; + _spawnedAt = System.currentTimeMillis(); + _openedAt = 0; + } + + public void setOpened() + { + _openedAt = System.currentTimeMillis(); + } + + public Location getLocation() + { + return _location; + } + + public String getColour() + { + return _colour; + } + + public int getID() + { + return _id; + } + + public long getSpawnedAt() + { + return _spawnedAt; + } + + public long getOpenedAt() + { + return _openedAt; + } + + public boolean isOpened() + { + return _openedAt != 0; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java index f834a0064..60b7635f5 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java @@ -5,7 +5,6 @@ import java.io.IOException; import java.util.HashSet; import java.util.Set; -import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Material; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java index 382312bc3..9b3085c87 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java @@ -1,8 +1,5 @@ package mineplex.gemhunters.supplydrop; -import java.util.ArrayList; -import java.util.List; - import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -11,10 +8,12 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.ItemSpawnEvent; +import mineplex.core.Managers; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.loot.LootModule; import mineplex.gemhunters.supplydrop.commands.CommandSupplyDropTest; import mineplex.gemhunters.world.WorldDataModule; @@ -22,6 +21,8 @@ import mineplex.gemhunters.world.WorldDataModule; public class SupplyDropModule extends MiniPlugin { + private static final String CHEST_COLOUR = "RED"; + private final WorldDataModule _worldData; private SupplyDrop _current; @@ -72,19 +73,8 @@ public class SupplyDropModule extends MiniPlugin block.setType(Material.CHEST); - List chests = _worldData.getAllDataLocations().get("RED"); - - if (chests == null) - { - chests = new ArrayList<>(); - } - - if (!chests.contains(block.getLocation())) - { - chests.add(block.getLocation()); - } - - _worldData.getAllDataLocations().put("RED", chests); + // Add location that the chest will appear at into the spawned chest lists so that LootModule can populate it with loot. + Managers.require(LootModule.class).addSpawnedChest(block.getLocation(), CHEST_COLOUR); event.setCancelled(true); } From 4f497a202557bb84742f9586e40dfbe859fc547d Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 28 Dec 2016 18:48:19 +0000 Subject: [PATCH 009/101] Rank rewards --- .../mineplex/gemhunters/loot/LootModule.java | 76 +++++++++++++++++-- .../loot/rewards/LootItemReward.java | 74 ++++++++++++++++-- .../loot/rewards/LootRankReward.java | 5 +- .../gemhunters/supplydrop/SupplyDrop.java | 2 +- 4 files changed, 140 insertions(+), 17 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 578fff2c0..abb4d9ba5 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -22,13 +22,16 @@ import org.bukkit.block.DoubleChest; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import mineplex.core.Managers; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilFirework; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilWorld; @@ -38,6 +41,9 @@ import mineplex.core.itemstack.ItemBuilder; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.loot.command.UpdateLootCommand; +import mineplex.gemhunters.loot.rewards.LootItemReward; +import mineplex.gemhunters.loot.rewards.LootRankReward; +import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.world.WorldDataModule; import net.md_5.bungee.api.ChatColor; @@ -53,7 +59,7 @@ public class LootModule extends MiniPlugin private static final float MAX_CHESTS_FACTOR = 0.25F; private static final int MAX_SEARCH_ATTEMPTS = 40; private static final int MAX_CHEST_PLACEMENT_RANGE = 5; - + private static final MineplexGoogleSheet CHEST_LOOT_SHEET = MineplexGoogleSheet.GEM_HUNTERS_CHESTS; private final GoogleSheetsManager _sheets; @@ -221,6 +227,11 @@ public class LootModule extends MiniPlugin return false; } + if (Managers.require(SafezoneModule.class).getSafezone(block.getLocation()) != null) + { + return false; + } + return true; } @@ -302,10 +313,10 @@ public class LootModule extends MiniPlugin double probability = Double.parseDouble(String.valueOf(values.get(6))); String metadata = null; - if (values.size() < 7) + if (values.size() > 7) { metadata = String.valueOf(values.get(7)); - + Bukkit.broadcastMessage(metadata); } items.add(new LootItem(builder.build(), minAmount, maxAmount, probability, metadata)); } @@ -315,7 +326,8 @@ public class LootModule extends MiniPlugin catch (Exception e) { // TODO send slack message? - System.out.println("An error occured while parsing spreadsheet data!"); + e.printStackTrace(); + log("An error occured while parsing spreadsheet data! " + key); continue; } } @@ -352,14 +364,20 @@ public class LootModule extends MiniPlugin for (int i = 0; i < (MINIMUM_CHEST_ITEMS + UtilMath.r(MAXIMUM_CHEST_ITEMS - MINIMUM_CHEST_ITEMS + 1)) * sizeMultiplier; i++) { - ItemStack itemStack = getRandomItem(items); + LootItem lootItem = getRandomItem(items); + ItemStack itemStack = lootItem.getItemStack(); int index = getFreeIndex(inventory.getSize(), used); + if (lootItem.getMetadata() != null) + { + UtilFirework.playFirework(block.getLocation().add(0.5, 1, 0.5), UtilFirework.getRandomFireworkEffect(false, 2, 1)); + } + inventory.setItem(index, itemStack); } } - private ItemStack getRandomItem(Set items) + private LootItem getRandomItem(Set items) { double totalWeight = 0; @@ -374,7 +392,7 @@ public class LootModule extends MiniPlugin { if ((select -= item.getProbability()) <= 0) { - return item.getItemStack(); + return item; } } @@ -395,7 +413,7 @@ public class LootModule extends MiniPlugin return index; } - public LootItem isLootItem(ItemStack itemStack) + public LootItem fromItemStack(ItemStack itemStack) { for (Set items : _chestLoot.values()) { @@ -465,5 +483,47 @@ public class LootModule extends MiniPlugin fillChest(player, block, key); } + + @EventHandler + public void inventoryClick(InventoryClickEvent event) + { + if (event.getClickedInventory() == null) + { + return; + } + + ItemStack itemStack = event.getCurrentItem(); + + if (itemStack == null) + { + return; + } + + LootItem lootItem = fromItemStack(itemStack); + + if (lootItem == null || lootItem.getMetadata() == null) + { + Bukkit.broadcastMessage("Metadata null"); + return; + } + + Player player = (Player) event.getWhoClicked(); + LootItemReward reward; + + Bukkit.broadcastMessage(lootItem.getMetadata()); + + switch (lootItem.getMetadata()) + { + case "RANK_UPGRADE": + reward = new LootRankReward(); + break; + default: + return; + } + + Bukkit.broadcastMessage("collect"); + reward.collectItem(player); + } + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java index 31d6ef820..34cbb0a2c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java @@ -1,6 +1,15 @@ package mineplex.gemhunters.loot.rewards; +import java.util.UUID; + import org.bukkit.entity.Player; +import org.bukkit.event.entity.PlayerDeathEvent; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.common.util.UtilTime; /** * @author Sam @@ -8,17 +17,72 @@ import org.bukkit.entity.Player; public abstract class LootItemReward { + private String _name; + + private long _firstItemPickup; private long _cashOutDelay; - public LootItemReward(long cashOutDelay) + private UUID _player; + + public LootItemReward(String name, long cashOutDelay) { + _name = name; + _firstItemPickup = 0; _cashOutDelay = cashOutDelay; } - + public abstract void onCollectItem(Player player); - - public abstract void onSucessful(Player player); - + + public abstract void onSuccessful(Player player); + public abstract void onDeath(Player player); + public final void collectItem(Player player) + { + if (_player.equals(player.getUniqueId())) + { + return; + } + + if (_firstItemPickup == 0) + { + String title = C.cYellow + player.getName(); + String subtitle = "Collected a " + F.elem(_name) + C.cWhite + " reward. Killing them will drop it!"; + String chatMessage = F.main("Game", title + " " + subtitle + " They will not be able to quit out of the game for " + UtilTime.MakeStr(_cashOutDelay)); + + UtilTextMiddle.display(title, subtitle, 20, 60, 20, UtilServer.getPlayers()); + UtilServer.broadcast(chatMessage); + + _firstItemPickup = System.currentTimeMillis(); + } + else + { + String message = F.main("Game", C.cYellow + player.getName() + " now has the " + F.elem(_name) + " reward!"); + + UtilServer.broadcast(message); + } + + onCollectItem(player); + } + + public final void success() + { + + } + + public final void death(PlayerDeathEvent event) + { + + } + + public final void update() + { + if (!UtilTime.elapsed(_firstItemPickup, _cashOutDelay)) + { + return; + } + + + } + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java index d2c2a3f11..aaacff923 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java @@ -18,7 +18,7 @@ public class LootRankReward extends LootItemReward public LootRankReward() { - super(CASH_OUT_DELAY); + super("Rank", CASH_OUT_DELAY); _clientManager = Managers.require(CoreClientManager.class); } @@ -29,7 +29,7 @@ public class LootRankReward extends LootItemReward } @Override - public void onSucessful(Player player) + public void onSuccessful(Player player) { CoreClient client = _clientManager.Get(player); Rank rank = client.GetRank(); @@ -75,5 +75,4 @@ public class LootRankReward extends LootItemReward public void onDeath(Player player) { } - } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java index 60b7635f5..cd31f9b87 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java @@ -190,7 +190,7 @@ public class SupplyDrop fallingBlock.setHurtEntities(false); fallingBlock.setDropItem(false); - UtilFirework.playFreedomFirework(fallingBlock.getLocation()); + UtilFirework.playFirework(fallingBlock.getLocation().add(0.5, 1, 0.5), UtilFirework.getRandomFireworkEffect(false, 2, 1)); } } From 571840e2493cf3c9e21a78afbfe385b0c95cfaab Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 2 Jan 2017 14:40:13 +0000 Subject: [PATCH 010/101] Lots more changes --- .../treasure/gui/pages/NextPageButton.java | 35 ----- .../src/mineplex/gemhunters/GemHunters.java | 44 +++++-- .../mineplex/gemhunters/GemHuntersModule.java | 27 ---- .../mineplex/gemhunters/chat/ChatModule.java | 50 ++++++++ .../gemhunters/economy/CashOutModule.java | 32 +++-- .../economy/PlayerCashOutCompleteEvent.java | 27 ++++ .../mineplex/gemhunters/loot/LootModule.java | 81 +++++++----- .../loot/rewards/LootItemReward.java | 31 +++-- .../loot/rewards/LootRankReward.java | 11 +- .../gemhunters/safezone/SafezoneModule.java | 27 ++-- .../mineplex/gemhunters/shop/ShopModule.java | 15 +++ .../gemhunters/spawn/SpawnModule.java | 121 ++++++++++++++++++ .../mineplex/gemhunters/util/SimpleNPC.java | 81 ++++++++++++ .../gemhunters/world/WorldDataModule.java | 2 +- .../gemhunters/worldevent/WorldEvent.java | 18 ++- .../worldevent/WorldEventModule.java | 67 ++++++++++ .../worldevent/WorldEventState.java | 1 + .../gemhunters/worldevent/WorldEventType.java | 4 +- .../coldweather/ColdWeatherEvent.java | 8 -- .../worldevent/command/AddCommand.java | 6 + .../worldevent/command/WorldEventCommand.java | 26 ++++ 21 files changed, 538 insertions(+), 176 deletions(-) delete mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHuntersModule.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/PlayerCashOutCompleteEvent.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java delete mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/coldweather/ColdWeatherEvent.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/AddCommand.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/WorldEventCommand.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/pages/NextPageButton.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/pages/NextPageButton.java index df28e16e1..a26b6446c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/pages/NextPageButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/pages/NextPageButton.java @@ -1,37 +1,3 @@ -<<<<<<< HEAD -package mineplex.core.treasure.gui.pages; - -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; - -import mineplex.core.shop.item.IButton; -import mineplex.core.treasure.gui.TreasurePage; - -public class NextPageButton implements IButton -{ - - private TreasurePage _treasurePage; - private Player _player; - - public NextPageButton(TreasurePage treasurePage, Player player) - { - _treasurePage = treasurePage; - _player = player; - } - - @Override - public void onClick(Player player, ClickType clickType) - { - if (_player != player) - return; - player.closeInventory(); - TreasurePage nextPage = new TreasurePage(_treasurePage.getTreasureManager(), _treasurePage.getTreasureShop(), _treasurePage.getTreasureLocation(), - _treasurePage.getClientManager(), _treasurePage.getDonationManager(), _treasurePage.getInventoryManager(), - _treasurePage.getGadgetManager(), _player, _treasurePage.getActualPage() + 1); - _treasurePage.getTreasureShop().openPageForPlayer(player, nextPage); - } -} -======= package mineplex.core.treasure.gui.pages; import org.bukkit.entity.Player; @@ -64,4 +30,3 @@ public class NextPageButton implements IButton _treasurePage.getTreasureShop().openPageForPlayer(player, nextPage); } } ->>>>>>> refs/remotes/origin/develop diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index af1a832d6..c114d3122 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -14,9 +14,6 @@ import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.chat.Chat; -import mineplex.core.chatsnap.SnapshotManager; -import mineplex.core.chatsnap.SnapshotPlugin; -import mineplex.core.chatsnap.SnapshotRepository; import mineplex.core.command.CommandCenter; import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.creature.Creature; @@ -37,19 +34,29 @@ import mineplex.core.message.MessageManager; import mineplex.core.monitor.LagMeter; import mineplex.core.npc.NpcManager; import mineplex.core.packethandler.PacketHandler; +import mineplex.core.party.PartyManager; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; import mineplex.core.punish.Punish; import mineplex.core.recharge.Recharge; -import mineplex.core.report.ReportManager; -import mineplex.core.report.ReportPlugin; import mineplex.core.serverConfig.ServerConfiguration; import mineplex.core.stats.StatsManager; import mineplex.core.status.ServerStatusManager; +import mineplex.core.task.TaskManager; import mineplex.core.teleport.Teleport; +import mineplex.core.texttutorial.TextTutorialManager; import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; import mineplex.core.visibility.VisibilityManager; +import mineplex.gemhunters.chat.ChatModule; +import mineplex.gemhunters.death.DeathModule; +import mineplex.gemhunters.economy.CashOutModule; +import mineplex.gemhunters.loot.LootModule; +import mineplex.gemhunters.safezone.SafezoneModule; +import mineplex.gemhunters.scoreboard.ScoreboardModule; +import mineplex.gemhunters.shop.ShopModule; +import mineplex.gemhunters.spawn.SpawnModule; +import mineplex.gemhunters.supplydrop.SupplyDropModule; import mineplex.minecraft.game.core.combat.CombatManager; import mineplex.minecraft.game.core.condition.ConditionManager; import mineplex.minecraft.game.core.damage.DamageManager; @@ -148,10 +155,7 @@ public class GemHunters extends JavaPlugin new DamageManager(this, new CombatManager(this), new NpcManager(this, creature), disguiseManager, new ConditionManager(this)); // GWEN - //TODO enable GWEN, gives some annoying errors -// AntiHack antiHack = require(AntiHack.class); -// antiHack.setKick(false); -// Bukkit.getScheduler().runTask(this, antiHack::enableNewAnticheat); + //require(AntiHack.class); // Block Restore BlockRestore blockRestore = new BlockRestore(this); @@ -172,6 +176,8 @@ public class GemHunters extends JavaPlugin Chat chat = new Chat(this, incognito, clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); new MessageManager(this, incognito, clientManager, preferenceManager, ignoreManager, punish, new FriendManager(this, clientManager, preferenceManager, portal), chat); + new PartyManager(this, portal, clientManager, preferenceManager); + // Fixes new MemoryFix(this); new FoodDupeFix(this); @@ -183,9 +189,9 @@ public class GemHunters extends JavaPlugin new InventoryManager(this, clientManager); // Reports - SnapshotManager snapshotManager = new SnapshotManager(this, new SnapshotRepository(serverStatusManager.getCurrentServerName(), getLogger())); - new SnapshotPlugin(this, snapshotManager, clientManager); - new ReportPlugin(this, new ReportManager(this, snapshotManager, clientManager, incognito, punish, serverStatusManager.getRegion(), serverStatusManager.getCurrentServerName(), 1)); +// SnapshotManager snapshotManager = new SnapshotManager(this, new SnapshotRepository(serverStatusManager.getCurrentServerName(), getLogger())); +// new SnapshotPlugin(this, snapshotManager, clientManager); +// new ReportPlugin(this, new ReportManager(this, snapshotManager, clientManager, incognito, punish, serverStatusManager.getRegion(), serverStatusManager.getCurrentServerName(), 1)); // Tag fix new CustomTagFix(this, packetHandler); @@ -193,8 +199,18 @@ public class GemHunters extends JavaPlugin // Holograms new HologramManager(this, packetHandler); - // Now we finally get to enable the Gem Hunters main module - require(GemHuntersModule.class); + new TextTutorialManager(this, donationManager, new TaskManager(this, clientManager, webServerAddress)); + + // Now we finally get to enable the Gem Hunters modules + require(CashOutModule.class); + require(ChatModule.class); + require(DeathModule.class); + require(LootModule.class); + require(SafezoneModule.class); + require(ScoreboardModule.class); + require(SpawnModule.class); + require(ShopModule.class); + require(SupplyDropModule.class); //UpdateEvent!!! new Updater(this); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHuntersModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHuntersModule.java deleted file mode 100644 index bf88d4a29..000000000 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHuntersModule.java +++ /dev/null @@ -1,27 +0,0 @@ -package mineplex.gemhunters; - -import mineplex.core.MiniPlugin; -import mineplex.core.ReflectivelyCreateMiniPlugin; -import mineplex.gemhunters.death.DeathModule; -import mineplex.gemhunters.economy.CashOutModule; -import mineplex.gemhunters.loot.LootModule; -import mineplex.gemhunters.safezone.SafezoneModule; -import mineplex.gemhunters.scoreboard.ScoreboardModule; -import mineplex.gemhunters.supplydrop.SupplyDropModule; - -@ReflectivelyCreateMiniPlugin -public class GemHuntersModule extends MiniPlugin -{ - - public GemHuntersModule() - { - super("Gem Hunters"); - - require(CashOutModule.class); - require(DeathModule.class); - require(LootModule.class); - require(SafezoneModule.class); - require(ScoreboardModule.class); - require(SupplyDropModule.class); - } -} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java new file mode 100644 index 000000000..b8a5ab4b2 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java @@ -0,0 +1,50 @@ +package mineplex.gemhunters.chat; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.chat.Chat; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; + +@ReflectivelyCreateMiniPlugin +public class ChatModule extends MiniPlugin +{ + + private final CoreClientManager _clientManager; + private final Chat _chat; + + private ChatModule() + { + super("Chat"); + + _clientManager = require(CoreClientManager.class); + _chat = require(Chat.class); + } + + @EventHandler + public void chat(AsyncPlayerChatEvent event) + { + if (event.isCancelled()) + { + return; + } + + Player player = event.getPlayer(); + String playerName = player.getName(); + + Rank rank = _clientManager.Get(player).getRealOrDisguisedRank(); + String rankString = rank == Rank.ALL ? "" : rank.getTag(true, true); + + String message = (rankString + " " + C.cYellow + playerName + " " + C.cWhite + _chat.getFilteredMessage(player, event.getMessage())).trim(); + + event.setCancelled(true); + Bukkit.broadcastMessage(message); + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java index 7c234c95a..da52cf0d6 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -25,9 +25,9 @@ import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilEvent; -import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.recharge.Recharge; @@ -42,13 +42,13 @@ public class CashOutModule extends MiniPlugin private static final ItemStack CASH_OUT_ITEM = new ItemBuilder(Material.EMERALD).setTitle(C.cGreen + "Cash Out").addLore("", C.cGray + "Click to begin the process to cash out.", C.cGray + "Cashing out saves your current loot.").build(); private static final int CASH_OUT_COOLDOWN = 10000; - private static final int CASH_OUT_MAX_MOVE_DISTANCE = 2; - - private final Map _sessions; + private static final int CASH_OUT_MAX_MOVE_DISTANCE_SQUARED = 4; + private final Map _sessions; + public CashOutModule() { - super("CashOut"); + super("Cash Out"); _sessions = new HashMap<>(); } @@ -76,7 +76,7 @@ public class CashOutModule extends MiniPlugin attemptCashOut(player); } - + @EventHandler public void itemDrop(PlayerDropItemEvent event) { @@ -86,24 +86,24 @@ public class CashOutModule extends MiniPlugin event.setCancelled(true); } } - + @EventHandler public void inventoryClick(InventoryClickEvent event) { Inventory inv = event.getInventory(); ItemStack itemStack = event.getCurrentItem(); - + if (inv == null || itemStack == null) { return; } - + if (itemStack.isSimilar(CASH_OUT_ITEM)) { event.setCancelled(true); } } - + @EventHandler public void playerJoin(PlayerJoinEvent event) { @@ -126,7 +126,7 @@ public class CashOutModule extends MiniPlugin { return; } - + Iterator iterator = _sessions.keySet().iterator(); while (iterator.hasNext()) @@ -151,6 +151,10 @@ public class CashOutModule extends MiniPlugin if (session.getCurrent() <= 0) { + PlayerCashOutCompleteEvent completeEvent = new PlayerCashOutCompleteEvent(player); + + UtilServer.CallEvent(completeEvent); + session.endSession(); iterator.remove(); player.sendMessage(C.cGreen + "Imagine you are being sent to the Lobby."); @@ -167,13 +171,13 @@ public class CashOutModule extends MiniPlugin { return; } - + for (UUID key : _sessions.keySet()) { Player player = UtilPlayer.searchExact(key); CashOutSession session = _sessions.get(key); - - if (UtilMath.offset(session.getLocation(), player.getLocation()) > CASH_OUT_MAX_MOVE_DISTANCE) + + if (session.getLocation().distanceSquared(player.getLocation()) > CASH_OUT_MAX_MOVE_DISTANCE_SQUARED) { cancelCashOut(player, "You moved!"); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/PlayerCashOutCompleteEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/PlayerCashOutCompleteEvent.java new file mode 100644 index 000000000..8057b4047 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/PlayerCashOutCompleteEvent.java @@ -0,0 +1,27 @@ +package mineplex.gemhunters.economy; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +public class PlayerCashOutCompleteEvent extends PlayerEvent +{ + + private static final HandlerList HANDLERS = new HandlerList(); + + public PlayerCashOutCompleteEvent(Player player) + { + super(player); + } + + public HandlerList getHandlers() + { + return HANDLERS; + } + + public static HandlerList getHandlerList() + { + return HANDLERS; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index ad10199b0..88d8e574a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -24,13 +24,14 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import mineplex.core.Managers; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilFirework; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilTime; @@ -40,6 +41,7 @@ import mineplex.core.google.MineplexGoogleSheet; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.economy.PlayerCashOutCompleteEvent; import mineplex.gemhunters.loot.command.UpdateLootCommand; import mineplex.gemhunters.loot.rewards.LootItemReward; import mineplex.gemhunters.loot.rewards.LootRankReward; @@ -59,10 +61,12 @@ public class LootModule extends MiniPlugin private static final float MAX_CHESTS_FACTOR = 0.25F; private static final int MAX_SEARCH_ATTEMPTS = 40; private static final int MAX_CHEST_PLACEMENT_RANGE = 5; - + private static final int MAX_CHEST_CHECK_DISTANCE_SQUARED = 4; + private static final MineplexGoogleSheet CHEST_LOOT_SHEET = MineplexGoogleSheet.GEM_HUNTERS_CHESTS; private final GoogleSheetsManager _sheets; + private final SafezoneModule _safezone; private final WorldDataModule _worldData; private final Map> _chestLoot; @@ -75,6 +79,7 @@ public class LootModule extends MiniPlugin super("Loot"); _sheets = require(GoogleSheetsManager.class); + _safezone = require(SafezoneModule.class); _worldData = require(WorldDataModule.class); _chestLoot = new HashMap<>(); _spawnedChest = new ArrayList<>(200); @@ -215,22 +220,10 @@ public class LootModule extends MiniPlugin public boolean isSuitable(Block block) { - if (block.getType() != Material.AIR) - { - return false; - } + Block up = block.getRelative(BlockFace.UP); + Block down = block.getRelative(BlockFace.DOWN); - if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR) - { - return false; - } - - if (block.getRelative(BlockFace.UP).getType() != Material.AIR) - { - return false; - } - - if (Managers.require(SafezoneModule.class).getSafezone(block.getLocation()) != null) + if (block.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block) || _safezone.getSafezone(block.getLocation()) != null) { return false; } @@ -436,7 +429,7 @@ public class LootModule extends MiniPlugin { for (SpawnedChest chest : _spawnedChest) { - if (UtilMath.offset(location, chest.getLocation()) < 2 && chest.isOpened()) + if (chest.getLocation().distanceSquared(location) < 4 && chest.isOpened()) { return true; } @@ -470,7 +463,7 @@ public class LootModule extends MiniPlugin for (SpawnedChest chest : _spawnedChest) { - if (UtilMath.offset(chest.getLocation(), block.getLocation()) < 2) + if (UtilMath.offset(chest.getLocation(), block.getLocation()) < MAX_CHEST_CHECK_DISTANCE_SQUARED) { key = chest.getColour(); chest.setOpened(); @@ -495,22 +488,36 @@ public class LootModule extends MiniPlugin return; } - ItemStack itemStack = event.getCurrentItem(); + ItemStack itemStack = event.getCursor(); if (itemStack == null) { return; } + handleRewardItem((Player) event.getWhoClicked(), itemStack); + } + + @EventHandler + public void pickupItem(PlayerPickupItemEvent event) + { + if (event.getItem() == null) + { + return; + } + + handleRewardItem(event.getPlayer(), event.getItem().getItemStack()); + } + + public void handleRewardItem(Player player, ItemStack itemStack) + { LootItem lootItem = fromItemStack(itemStack); if (lootItem == null || lootItem.getMetadata() == null) { - Bukkit.broadcastMessage("Metadata null"); return; } - - Player player = (Player) event.getWhoClicked(); + LootItemReward reward = null; for (LootItemReward storedReward : _itemRewards) @@ -520,7 +527,7 @@ public class LootModule extends MiniPlugin reward = storedReward; } } - + if (reward == null) { Bukkit.broadcastMessage(lootItem.getMetadata()); @@ -535,15 +542,27 @@ public class LootModule extends MiniPlugin return; } - reward.setPlayer(player); _itemRewards.add(reward); - Bukkit.broadcastMessage("collect"); - reward.collectItem(player); - } - else - { - reward.setPlayer(player); } + + reward.collectItem(player); } + @EventHandler + public void cashOutComplete(PlayerCashOutCompleteEvent event) + { + Player player = event.getPlayer(); + Iterator iterator = _itemRewards.iterator(); + + while (iterator.hasNext()) + { + LootItemReward reward = iterator.next(); + + if (player.equals(reward.getPlayer())) + { + reward.success(); + iterator.remove(); + } + } + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java index 78dfc30e5..d12bc52b9 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java @@ -1,5 +1,6 @@ package mineplex.gemhunters.loot.rewards; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.inventory.ItemStack; @@ -9,6 +10,7 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; +import mineplex.core.recharge.Recharge; public abstract class LootItemReward { @@ -18,7 +20,7 @@ public abstract class LootItemReward private long _firstItemPickup; private long _cashOutDelay; - private Player _player; + protected Player _player; private ItemStack _itemStack; public LootItemReward(String name, long cashOutDelay, ItemStack itemStack) @@ -29,15 +31,15 @@ public abstract class LootItemReward _itemStack = itemStack; } - public abstract void onCollectItem(Player player); + public abstract void onCollectItem(); - public abstract void onSuccessful(Player player); + public abstract void onSuccessful(); - public abstract void onDeath(Player player); + public abstract void onDeath(); public final void collectItem(Player player) { - if (_player.equals(player)) + if (player.equals(_player)) { return; } @@ -45,8 +47,8 @@ public abstract class LootItemReward if (_firstItemPickup == 0) { String title = C.cYellow + player.getName(); - String subtitle = "Collected a " + F.elem(_name) + C.cWhite + " reward. Killing them will drop it!"; - String chatMessage = F.main("Game", title + " " + subtitle + " They will not be able to quit out of the game for " + UtilTime.MakeStr(_cashOutDelay)); + String subtitle = C.cGray + "Collected a " + F.elem(_name) + " reward. Killing them will drop it!"; + String chatMessage = F.main("Game", title + " " + subtitle + " They will not be able to quit out of the game for " + F.time(UtilTime.MakeStr(_cashOutDelay) + ".")); UtilTextMiddle.display(title, subtitle, 20, 60, 20, UtilServer.getPlayers()); UtilServer.broadcast(chatMessage); @@ -55,33 +57,30 @@ public abstract class LootItemReward } else { - String message = F.main("Game", C.cYellow + player.getName() + " now has the " + F.elem(_name) + " reward!"); + String message = F.main("Game", F.name(player.getName()) + " now has the " + F.elem(_name) + " reward!"); UtilServer.broadcast(message); } - onCollectItem(player); + Recharge.Instance.useForce(player, "Cash Out", _cashOutDelay, false); + _player = player; + onCollectItem(); } public final void success() { - + Bukkit.broadcastMessage("Success"); + onSuccessful(); } public final void death(PlayerDeathEvent event) { - } public boolean isFirstPickup() { return _firstItemPickup == 0; } - - public void setPlayer(Player player) - { - _player = player; - } public Player getPlayer() { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java index ba37af3f9..56e782511 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java @@ -2,7 +2,6 @@ package mineplex.gemhunters.loot.rewards; import java.util.concurrent.TimeUnit; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import mineplex.core.Managers; @@ -25,14 +24,14 @@ public class LootRankReward extends LootItemReward } @Override - public void onCollectItem(Player player) + public void onCollectItem() { } @Override - public void onSuccessful(Player player) + public void onSuccessful() { - CoreClient client = _clientManager.Get(player); + CoreClient client = _clientManager.Get(_player); Rank rank = client.GetRank(); Rank newRank = null; @@ -69,11 +68,11 @@ public class LootRankReward extends LootItemReward } client.SetRank(newRank, false); - _clientManager.getRepository().saveRank(null, player.getName(), player.getUniqueId(), newRank, true); + _clientManager.getRepository().saveRank(null, _player.getName(), _player.getUniqueId(), newRank, true); } @Override - public void onDeath(Player player) + public void onDeath() { } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java index 5a0ff43d5..25a9ea89d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java @@ -10,7 +10,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import mineplex.core.MiniPlugin; @@ -31,8 +30,8 @@ public class SafezoneModule extends MiniPlugin private final WorldDataModule _worldData; - private Map _currentSafezone; - + private final Map _currentSafezone; + private SafezoneModule() { super("Safezone"); @@ -58,11 +57,13 @@ public class SafezoneModule extends MiniPlugin String newSafezone = getSafezone(player.getLocation()); boolean isInNewSafezone = newSafezone != null; + // null -> not null if (!isInOldSafezone && isInNewSafezone) { UtilTextMiddle.display("", C.cYellow + "Entering " + newSafezone, 10, 40, 10, player); _currentSafezone.put(key, newSafezone); } + // not null -> null else if (isInOldSafezone && !isInNewSafezone) { UtilTextMiddle.display("", C.cYellow + "Leaving " + oldSafezone, 10, 40, 10, player); @@ -71,15 +72,6 @@ public class SafezoneModule extends MiniPlugin } } - @EventHandler - public void playerJoin(PlayerJoinEvent event) - { - Player player = event.getPlayer(); - - // Temporary - player.teleport(UtilAlg.Random(_worldData.getSpawnLocation("Lime"))); - } - @EventHandler public void playerQuit(PlayerQuitEvent event) { @@ -159,11 +151,18 @@ public class SafezoneModule extends MiniPlugin if (UtilAlg.inBoundingBox(location, bounds.get(0), bounds.get(1))) { - return key.split(" ")[1]; + String name = ""; + String[] split = key.split(" "); + + for (int i = 1; i < split.length; i++) + { + name += split[i] + " "; + } + + return name.trim(); } } return null; } - } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java new file mode 100644 index 000000000..b005bf9d3 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java @@ -0,0 +1,15 @@ +package mineplex.gemhunters.shop; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; + +@ReflectivelyCreateMiniPlugin +public class ShopModule extends MiniPlugin +{ + + private ShopModule() + { + super("Shop"); + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java new file mode 100644 index 000000000..6f3bec5d9 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -0,0 +1,121 @@ +package mineplex.gemhunters.spawn; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.WorldBorder; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.entity.Villager; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; +import mineplex.gemhunters.safezone.SafezoneModule; +import mineplex.gemhunters.util.SimpleNPC; +import mineplex.gemhunters.world.WorldDataModule; + +@ReflectivelyCreateMiniPlugin +public class SpawnModule extends MiniPlugin +{ + + private static final int WORLD_BORDER_RADIUS = 300; + + private final SafezoneModule _safezone; + private final WorldDataModule _worldData; + + private Location _spawn; + private Location _center; + private boolean _npcsSpawned; + + private SpawnModule() + { + super("Spawn"); + + _safezone = require(SafezoneModule.class); + _worldData = require(WorldDataModule.class); + } + + @EventHandler + public void playerJoin(PlayerJoinEvent event) + { + if (_spawn == null || _center == null) + { + _spawn = _worldData.getSpawnLocation("Yellow").get(0); + _center = _worldData.getCustomLocation("CENTER").get(0); + } + + event.getPlayer().teleport(_spawn); + + if (_npcsSpawned) + { + return; + } + + WorldBorder border = _spawn.getWorld().getWorldBorder(); + + border.setCenter(_spawn); + border.setSize(WORLD_BORDER_RADIUS * 2); + + _npcsSpawned = true; + + new SimpleNPC(_plugin, _worldData.getSpawnLocation("Purple").get(0), Villager.class, C.cDRed + "! " + C.cRedB + "Enter The World" + C.cDRed + " !", new Callback() + { + + @Override + public void run(Player data) + { + Location location = getRandomLocation(); + + if (location == null) + { + data.sendMessage(F.main(_moduleName, "A suitable teleport location could not be found. Please try again in a few seconds.")); + return; + } + + data.teleport(location); + } + + }); + } + + public boolean isSuitable(Block block) + { + Block up = block.getRelative(BlockFace.UP); + Block down = block.getRelative(BlockFace.DOWN); + + if (block.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block) || _safezone.getSafezone(block.getLocation()) != null) + { + return false; + } + + return true; + } + + public Location getRandomLocation() + { + int attempts = 0; + double range = WORLD_BORDER_RADIUS * 0.95; + + while (attempts < 100) + { + Location possible = UtilAlg.getRandomLocation(_center, range, 10, range); + + if (isSuitable(possible.getBlock())) + { + return possible; + } + + attempts++; + } + + return null; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java new file mode 100644 index 000000000..37bc256bb --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java @@ -0,0 +1,81 @@ +package mineplex.gemhunters.util; + +import org.bukkit.Location; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.UtilEnt; + +public class SimpleNPC implements Listener +{ + + private final LivingEntity _entity; + private final Callback _clickEvent; + private final boolean _vegetated; + + public SimpleNPC(JavaPlugin plugin, Location spawn, Class type, String name, Callback clickEvent) + { + this(plugin, spawn, type, name, clickEvent, true); + } + + public SimpleNPC(JavaPlugin plugin, Location spawn, Class type, String name, Callback clickEvent, boolean vegetated) + { + _entity = spawn.getWorld().spawn(spawn, type); + + _entity.setRemoveWhenFarAway(false); + _entity.setCustomName(name); + _entity.setCustomNameVisible(true); + + UtilEnt.Vegetate(_entity, true); + UtilEnt.ghost(_entity, true, false); + UtilEnt.setFakeHead(_entity, true); + + _clickEvent = clickEvent; + _vegetated = vegetated; + + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @EventHandler + public void npcClick(PlayerInteractEntityEvent event) + { + if (!event.getRightClicked().equals(_entity)) + { + return; + } + + event.setCancelled(true); + _clickEvent.run(event.getPlayer()); + } + + @EventHandler + public void npcDamage(EntityDamageEvent event) + { + if (!event.getEntity().equals(_entity) || !_vegetated) + { + return; + } + + event.setCancelled(true); + } + + @EventHandler + public void npcDeath(EntityDeathEvent event) + { + if (!event.getEntity().equals(_entity) || !_vegetated) + { + return; + } + + HandlerList.unregisterAll(this); + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java index 8549caa84..df4e3014f 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java @@ -26,7 +26,7 @@ import mineplex.core.common.util.worldgen.WorldGenCleanRoom; public class WorldDataModule extends MiniPlugin { - private static final String MAP_PATH = "../../update/maps/Gem-Hunters/None_Moppletop City Testing.zip"; + private static final String MAP_PATH = "../../update/maps/Gem-Hunters/Test.zip"; private String folder = null; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEvent.java index ca6ac647a..db86ba1bc 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEvent.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEvent.java @@ -1,22 +1,26 @@ package mineplex.gemhunters.worldevent; +import org.bukkit.event.Listener; + import mineplex.core.updater.event.UpdateEvent; -public class WorldEvent +public abstract class WorldEvent implements Listener { - public boolean onCheckTrigger(UpdateEvent event) - { - return false; - } + public abstract boolean onCheckTrigger(UpdateEvent event); - public void onStart() + public abstract void onStart(); + + public abstract void onEnd(); + + public final void start() { } - public void onEnd() + public final void end() { } + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java new file mode 100644 index 000000000..5309431ce --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java @@ -0,0 +1,67 @@ +package mineplex.gemhunters.worldevent; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import org.bukkit.event.EventHandler; + +import mineplex.core.MiniPlugin; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilTime; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class WorldEventModule extends MiniPlugin +{ + + private static final long EVENT_TIMER = TimeUnit.MINUTES.toMillis(15); + + private List _currentEvents; + private long _lastEventComplete; + + private WorldEventModule() + { + super("World Event"); + + _currentEvents = new ArrayList<>(); + _lastEventComplete = System.currentTimeMillis(); + } + + @Override + public void addCommands() + { + + } + + public void startEvent(WorldEventType eventType) + { + WorldEvent event = eventType.createInstance(); + + _currentEvents.add(event); + + event.start(); + } + + public void startRandomEvent() + { + WorldEventType[] eventTypes = WorldEventType.values(); + + startEvent(eventTypes[UtilMath.r(eventTypes.length)]); + } + + @EventHandler + public void checkNextEvent(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + { + return; + } + + if (UtilTime.elapsed(_lastEventComplete, EVENT_TIMER)) + { + + } + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventState.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventState.java index b0d9cb287..87ed9b9f4 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventState.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventState.java @@ -5,4 +5,5 @@ public enum WorldEventState + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java index 89cefec65..4bbedb653 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java @@ -1,11 +1,9 @@ package mineplex.gemhunters.worldevent; -import mineplex.gemhunters.worldevent.coldweather.ColdWeatherEvent; - public enum WorldEventType { - COLD_WEATHER("Cold Weather", ColdWeatherEvent.class); + COLD_WEATHER("Cold Weather", null); private String _name; private Class _clazz; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/coldweather/ColdWeatherEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/coldweather/ColdWeatherEvent.java deleted file mode 100644 index 5680b9ef0..000000000 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/coldweather/ColdWeatherEvent.java +++ /dev/null @@ -1,8 +0,0 @@ -package mineplex.gemhunters.worldevent.coldweather; - -import mineplex.gemhunters.worldevent.WorldEvent; - -public class ColdWeatherEvent extends WorldEvent -{ - -} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/AddCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/AddCommand.java new file mode 100644 index 000000000..167f475b8 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/AddCommand.java @@ -0,0 +1,6 @@ +package mineplex.gemhunters.worldevent.command; + +public class AddCommand +{ + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/WorldEventCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/WorldEventCommand.java new file mode 100644 index 000000000..2f17e7352 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/WorldEventCommand.java @@ -0,0 +1,26 @@ +package mineplex.gemhunters.worldevent.command; + +import org.bukkit.entity.Player; + +import mineplex.core.command.MultiCommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.gemhunters.worldevent.WorldEventModule; + +public class WorldEventCommand extends MultiCommandBase +{ + + public WorldEventCommand(WorldEventModule plugin) + { + super(plugin, Rank.ADMIN, "worldevent", "we", "event"); + } + + @Override + protected void Help(Player caller, String[] args) + { + caller.sendMessage(F.help("/" + _aliasUsed + " start", "Start a World Event", Rank.ADMIN)); + caller.sendMessage(F.help("/" + _aliasUsed + " clear", "Clears all World Events", Rank.ADMIN)); + caller.sendMessage(F.help("/" + _aliasUsed + " random", "Starts a random World Event", Rank.ADMIN)); + } + +} From 0218965bee5f3be338ee17f1b529680a74ab53dc Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 8 Jan 2017 15:44:04 +0000 Subject: [PATCH 011/101] Villager trading and loot upgrades --- .../mineplex/core/common/util/UtilBlock.java | 55 +++++- .../core/blockrestore/BlockRestore.java | 7 +- .../core/google/MineplexGoogleSheet.java | 1 + .../src/mineplex/game/clans/Clans.java | 2 +- .../src/mineplex/clanshub/ClansHub.java | 2 +- .../Mineplex.Hub/src/mineplex/hub/Hub.java | 2 +- .../src/nautilus/game/arcade/Arcade.java | 2 +- .../src/nautilus/game/pvp/PvP.java | 2 +- .../src/mineplex/mavericks/review/Hub.java | 2 +- .../src/mineplex/gemhunters/GemHunters.java | 102 +++++----- .../mineplex/gemhunters/chat/ChatModule.java | 17 +- .../gemhunters/death/DeathModule.java | 8 + .../mineplex/gemhunters/loot/LootModule.java | 8 +- .../loot/command/UpdateLootCommand.java | 9 +- .../gemhunters/safezone/SafezoneModule.java | 19 +- .../scoreboard/GemHuntersScoreboard.java | 15 +- .../mineplex/gemhunters/shop/ShopModule.java | 175 ++++++++++++++++++ .../gemhunters/shop/TradeableItem.java | 24 +++ .../mineplex/gemhunters/shop/TraderNPC.java | 118 ++++++++++++ .../gemhunters/spawn/SpawnModule.java | 36 +++- .../gemhunters/supplydrop/SupplyDrop.java | 15 ++ .../supplydrop/SupplyDropModule.java | 117 ++++++++++-- .../commands/CommandSupplyDropTest.java | 24 --- .../supplydrop/commands/EndCommand.java | 31 ++++ .../supplydrop/commands/StartCommand.java | 72 +++++++ .../commands/SupplyDropCommand.java | 29 +++ .../util/ColouredTextAnimation.java | 123 ++++++++++++ .../mineplex/gemhunters/util/SimpleNPC.java | 34 ++-- .../gemhunters/world/WorldDataModule.java | 6 +- .../worldevent/command/WorldEventCommand.java | 2 +- 30 files changed, 914 insertions(+), 145 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TradeableItem.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java delete mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/CommandSupplyDropTest.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/EndCommand.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/StartCommand.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/SupplyDropCommand.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/ColouredTextAnimation.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java index f6287b349..aa2950933 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java @@ -4,18 +4,9 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Set; import java.util.UUID; -import net.minecraft.server.v1_8_R3.BlockPosition; -import net.minecraft.server.v1_8_R3.Blocks; -import net.minecraft.server.v1_8_R3.IBlockData; -import net.minecraft.server.v1_8_R3.Item; -import net.minecraft.server.v1_8_R3.MathHelper; -import net.minecraft.server.v1_8_R3.MinecraftKey; -import net.minecraft.server.v1_8_R3.NBTTagCompound; -import net.minecraft.server.v1_8_R3.TileEntityFlowerPot; -import net.minecraft.server.v1_8_R3.WorldServer; - import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.SkullType; @@ -41,8 +32,18 @@ import org.bukkit.material.Bed; import com.mojang.authlib.GameProfile; +import mineplex.core.common.Pair; import mineplex.core.common.block.MultiBlockUpdaterAgent; import mineplex.core.common.skin.SkinData; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.Blocks; +import net.minecraft.server.v1_8_R3.IBlockData; +import net.minecraft.server.v1_8_R3.Item; +import net.minecraft.server.v1_8_R3.MathHelper; +import net.minecraft.server.v1_8_R3.MinecraftKey; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.TileEntityFlowerPot; +import net.minecraft.server.v1_8_R3.WorldServer; public class UtilBlock { @@ -1670,4 +1671,38 @@ public class UtilBlock return null; } + /** + * Returns a Pair> {@link HashSet} containing all the relevant data regarding beacon construction. + * Useful for adding them to block restore. + * + * @param surface + * The Location of the glass coloured block (at surface level). The beacon is placed one block below this. + * @param glassData + * The colour data value of glass that colours the beacon + */ + public static Set>> getBeaconBlocks(Location surface, byte glassData) + { + Set>> blocks = new HashSet<>(); + + for (int x = -1; x <= 1; x++) + { + for (int z = -1; z <= 1; z++) + { + blocks.add(Pair.create(surface.clone().add(x, -3, z), Pair.create(Material.IRON_BLOCK, (byte) 0))); + + if (x == 0 && z == 0) + { + continue; + } + + blocks.add(Pair.create(surface.clone().add(x, -1, z), Pair.create(Material.QUARTZ_BLOCK, (byte) 0))); + } + } + + blocks.add(Pair.create(surface.clone().add(0, -2, 0), Pair.create(Material.BEACON, (byte) 0))); + blocks.add(Pair.create(surface.clone().add(0, -1, 0), Pair.create(Material.STAINED_GLASS, glassData))); + + return blocks; + } + } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/blockrestore/BlockRestore.java b/Plugins/Mineplex.Core/src/mineplex/core/blockrestore/BlockRestore.java index 664a742de..c2859d691 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/blockrestore/BlockRestore.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/blockrestore/BlockRestore.java @@ -18,22 +18,23 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.world.ChunkUnloadEvent; -import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilMath; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +@ReflectivelyCreateMiniPlugin public class BlockRestore extends MiniPlugin { private HashMap _blocks = new HashMap(); private LinkedList _restoreMaps; - public BlockRestore(JavaPlugin plugin) + private BlockRestore() { - super("Block Restore", plugin); + super("Block Restore"); _restoreMaps = new LinkedList(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/google/MineplexGoogleSheet.java b/Plugins/Mineplex.Core/src/mineplex/core/google/MineplexGoogleSheet.java index ea72ecb74..3bc9ea265 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/google/MineplexGoogleSheet.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/google/MineplexGoogleSheet.java @@ -9,6 +9,7 @@ public enum MineplexGoogleSheet { GEM_HUNTERS_CHESTS("11Noztgbpu_gUKkc5F4evKKfyxS-Jv1coE0IrBToX_gg"), + GEM_HUNTERS_VILLAGERS("1OcYktxVZaW6Fm29Zh6w4Lb-UVyuN8r1x-TFb_3USYYI"), ; private String _id; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index d865e5d6e..efa2af761 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -221,7 +221,7 @@ public class Clans extends JavaPlugin } } - BlockRestore blockRestore = new BlockRestore(this); + BlockRestore blockRestore = require(BlockRestore.class); IgnoreManager ignoreManager = new IgnoreManager(this, _clientManager, preferenceManager, portal); diff --git a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java index 04cf7bd71..1f66fa395 100644 --- a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java +++ b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java @@ -96,7 +96,7 @@ public class ClansHub extends JavaPlugin Recharge.Initialize(this); VisibilityManager.Initialize(this); Give.Initialize(this); Punish punish = new Punish(this, webServerAddress, clientManager); - BlockRestore blockRestore = new BlockRestore(this); + BlockRestore blockRestore = require(BlockRestore.class); DonationManager donationManager = require(DonationManager.class); ServerConfiguration serverConfiguration = new ServerConfiguration(this, clientManager); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index cd87eaf8e..c385d8f2d 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -118,7 +118,7 @@ public class Hub extends JavaPlugin implements IRelation Recharge.Initialize(this); VisibilityManager.Initialize(this); Give.Initialize(this); Punish punish = new Punish(this, webServerAddress, clientManager); - BlockRestore blockRestore = new BlockRestore(this); + BlockRestore blockRestore = require(BlockRestore.class); DonationManager donationManager = require(DonationManager.class); ServerConfiguration serverConfiguration = new ServerConfiguration(this, clientManager); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 5f8828c95..58e452ffd 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -166,7 +166,7 @@ public class Arcade extends JavaPlugin new SnapshotPlugin(this, snapshotManager, _clientManager); new ReportPlugin(this, reportManager); - BlockRestore blockRestore = new BlockRestore(this); + BlockRestore blockRestore = require(BlockRestore.class); ProjectileManager projectileManager = new ProjectileManager(this); HologramManager hologramManager = new HologramManager(this, packetHandler); diff --git a/Plugins/Nautilus.Game.PvP/src/nautilus/game/pvp/PvP.java b/Plugins/Nautilus.Game.PvP/src/nautilus/game/pvp/PvP.java index cfe3add2b..d6732cbad 100644 --- a/Plugins/Nautilus.Game.PvP/src/nautilus/game/pvp/PvP.java +++ b/Plugins/Nautilus.Game.PvP/src/nautilus/game/pvp/PvP.java @@ -328,7 +328,7 @@ public class PvP extends JavaPlugin implements IPlugin, Listener public BlockRestore GetBlockRestore() { if (_blockRestore == null) - _blockRestore = new BlockRestore(this); + _blockRestore = require(BlockRestore.class); return _blockRestore; } diff --git a/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java b/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java index 73a0de67e..8943c3353 100644 --- a/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java +++ b/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java @@ -120,7 +120,7 @@ public class Hub extends JavaPlugin Chat chat = new Chat(this, incognito, _clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, friendManager, chat); - BlockRestore blockRestore = new BlockRestore(this); + BlockRestore blockRestore = require(BlockRestore.class); ProjectileManager projectileManager = new ProjectileManager(this); HologramManager hologramManager = new HologramManager(this, packetHandler); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index c114d3122..e0e7758cf 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -4,6 +4,8 @@ import static mineplex.core.Managers.require; import org.bukkit.World; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.spigotmc.SpigotConfig; @@ -42,9 +44,7 @@ import mineplex.core.recharge.Recharge; import mineplex.core.serverConfig.ServerConfiguration; import mineplex.core.stats.StatsManager; import mineplex.core.status.ServerStatusManager; -import mineplex.core.task.TaskManager; import mineplex.core.teleport.Teleport; -import mineplex.core.texttutorial.TextTutorialManager; import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; import mineplex.core.visibility.VisibilityManager; @@ -73,7 +73,7 @@ public class GemHunters extends JavaPlugin { private static final String WEB_CONFIG = "webServer"; - + @Override public void onEnable() { @@ -81,84 +81,84 @@ public class GemHunters extends JavaPlugin getConfig().addDefault(WEB_CONFIG, "http://accounts.mineplex.com/"); getConfig().set(WEB_CONFIG, getConfig().getString(WEB_CONFIG)); saveConfig(); - + // Get the web server address String webServerAddress = getConfig().getString(WEB_CONFIG); - + // Load core modules CommandCenter.Initialize(this); - + // Client Manager CoreClientManager clientManager = new CoreClientManager(this, webServerAddress); - + // Donation Manager DonationManager donationManager = require(DonationManager.class); - + // Command Centre CommandCenter.Instance.setClientManager(clientManager); - + // Timings require(TimingsFix.class); - + // ItemStacks ItemStackFactory.Initialize(this, false); - + // Delayed Tasks DelayedTask.Initialize(this); - + // Recharge Recharge.Initialize(this); - + // Visibility VisibilityManager.Initialize(this); - + // Give Give.Initialize(this); - + // Server config new ServerConfiguration(this, clientManager); - + // Teleport new Teleport(this, clientManager); - + // Packets PacketHandler packetHandler = require(PacketHandler.class); - + // Vanish IncognitoManager incognito = new IncognitoManager(this, clientManager, packetHandler); - + // Preferences PreferencesManager preferenceManager = new PreferencesManager(this, incognito, clientManager); - + // Why do these depend on each other... :( incognito.setPreferencesManager(preferenceManager); // Server Status - ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager)); - + ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager)); + // Portal Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName()); - + // File Updater new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); - + // Punish Punish punish = new Punish(this, webServerAddress, clientManager); // Disguises DisguiseManager disguiseManager = require(DisguiseManager.class); - + // Creatures Creature creature = new Creature(this); // The old classic Damage Manager new DamageManager(this, new CombatManager(this), new NpcManager(this, creature), disguiseManager, new ConditionManager(this)); - + // GWEN - //require(AntiHack.class); - + // require(AntiHack.class); + // Block Restore - BlockRestore blockRestore = new BlockRestore(this); + BlockRestore blockRestore = require(BlockRestore.class); // Ignoring IgnoreManager ignoreManager = new IgnoreManager(this, clientManager, preferenceManager, portal); @@ -168,10 +168,10 @@ public class GemHunters extends JavaPlugin // Elo EloManager eloManager = new EloManager(this, clientManager); - + // Achievements AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager, incognito, eloManager); - + // Chat/Messaging Chat chat = new Chat(this, incognito, clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); new MessageManager(this, incognito, clientManager, preferenceManager, ignoreManager, punish, new FriendManager(this, clientManager, preferenceManager, portal), chat); @@ -181,17 +181,21 @@ public class GemHunters extends JavaPlugin // Fixes new MemoryFix(this); new FoodDupeFix(this); - + // Explosions new Explosion(this, blockRestore); - + // Inventories new InventoryManager(this, clientManager); // Reports -// SnapshotManager snapshotManager = new SnapshotManager(this, new SnapshotRepository(serverStatusManager.getCurrentServerName(), getLogger())); -// new SnapshotPlugin(this, snapshotManager, clientManager); -// new ReportPlugin(this, new ReportManager(this, snapshotManager, clientManager, incognito, punish, serverStatusManager.getRegion(), serverStatusManager.getCurrentServerName(), 1)); + // SnapshotManager snapshotManager = new SnapshotManager(this, new + // SnapshotRepository(serverStatusManager.getCurrentServerName(), + // getLogger())); + // new SnapshotPlugin(this, snapshotManager, clientManager); + // new ReportPlugin(this, new ReportManager(this, snapshotManager, + // clientManager, incognito, punish, serverStatusManager.getRegion(), + // serverStatusManager.getCurrentServerName(), 1)); // Tag fix new CustomTagFix(this, packetHandler); @@ -199,8 +203,6 @@ public class GemHunters extends JavaPlugin // Holograms new HologramManager(this, packetHandler); - new TextTutorialManager(this, donationManager, new TaskManager(this, clientManager, webServerAddress)); - // Now we finally get to enable the Gem Hunters modules require(CashOutModule.class); require(ChatModule.class); @@ -211,10 +213,10 @@ public class GemHunters extends JavaPlugin require(SpawnModule.class); require(ShopModule.class); require(SupplyDropModule.class); - - //UpdateEvent!!! + + // UpdateEvent!!! new Updater(this); - + // Disable spigot's item merging for (World world : getServer().getWorlds()) { @@ -225,11 +227,25 @@ public class GemHunters extends JavaPlugin MinecraftServer.getServer().getPropertyManager().setProperty("debug", false); SpigotConfig.debug = false; } - + @Override public void onDisable() { getServer().getPluginManager().callEvent(new ServerShutdownEvent(this)); + + // Cleanup all rouge entities + for (World world : getServer().getWorlds()) + { + for (Entity entity : world.getEntities()) + { + if (entity instanceof Player) + { + continue; + } + + entity.remove(); + } + } } - + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java index b8a5ab4b2..31fd7a80a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java @@ -3,6 +3,7 @@ package mineplex.gemhunters.chat; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.player.AsyncPlayerChatEvent; import mineplex.core.MiniPlugin; @@ -12,6 +13,11 @@ import mineplex.core.chat.Chat; import mineplex.core.common.Rank; import mineplex.core.common.util.C; +/** + * This module handles player chat. + * + * @author Sam + */ @ReflectivelyCreateMiniPlugin public class ChatModule extends MiniPlugin { @@ -27,9 +33,10 @@ public class ChatModule extends MiniPlugin _chat = require(Chat.class); } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void chat(AsyncPlayerChatEvent event) { + // Checks if the player has been muted/chat is silenced etc... if (event.isCancelled()) { return; @@ -41,10 +48,16 @@ public class ChatModule extends MiniPlugin Rank rank = _clientManager.Get(player).getRealOrDisguisedRank(); String rankString = rank == Rank.ALL ? "" : rank.getTag(true, true); + // Create a message that follows the rest of the network's chat format String message = (rankString + " " + C.cYellow + playerName + " " + C.cWhite + _chat.getFilteredMessage(player, event.getMessage())).trim(); + // We will handle the broadcast event.setCancelled(true); - Bukkit.broadcastMessage(message); + + for (Player other : Bukkit.getOnlinePlayers()) + { + other.sendMessage(message); + } } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java index a7dbf99ab..249597e9c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java @@ -16,10 +16,16 @@ import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.UtilAction; import mineplex.gemhunters.world.WorldDataModule; +/** + * This module handles anything to do with a players death + * + * @author Sam + */ @ReflectivelyCreateMiniPlugin public class DeathModule extends MiniPlugin { + // Some items like the cash out item (and for some reason players drop bones?) don't need to be dropped to avoid duplication. private static final Set DISALLOWED_DROPS = Sets.newHashSet(Material.EMERALD, Material.BONE); private final WorldDataModule _worldData; @@ -36,12 +42,14 @@ public class DeathModule extends MiniPlugin { Player player = event.getEntity(); + // Stop the player dieing player.setHealth(20); UtilAction.zeroVelocity(player); player.teleport(_worldData.getSpawnLocation("Yellow").get(0)); Iterator iterator = event.getDrops().iterator(); + // Iterate through all items and clear any disallowed items while (iterator.hasNext()) { ItemStack itemStack = iterator.next(); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 88d8e574a..919db2f8c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -60,7 +60,7 @@ public class LootModule extends MiniPlugin private static final String[] IGNORED_COLOURS = { "RED" }; private static final float MAX_CHESTS_FACTOR = 0.25F; private static final int MAX_SEARCH_ATTEMPTS = 40; - private static final int MAX_CHEST_PLACEMENT_RANGE = 5; + private static final int MAX_CHEST_PLACEMENT_RANGE = 10; private static final int MAX_CHEST_CHECK_DISTANCE_SQUARED = 4; private static final MineplexGoogleSheet CHEST_LOOT_SHEET = MineplexGoogleSheet.GEM_HUNTERS_CHESTS; @@ -212,6 +212,7 @@ public class LootModule extends MiniPlugin continue; } + //TODO remove debug message Bukkit.broadcastMessage("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index); _spawnedChest.add(new SpawnedChest(chestToPlace, key, index)); block.setType(Material.CHEST); @@ -312,7 +313,6 @@ public class LootModule extends MiniPlugin if (values.size() > 7) { metadata = String.valueOf(values.get(7)); - Bukkit.broadcastMessage(metadata); } items.add(new LootItem(builder.build(), minAmount, maxAmount, probability, metadata)); } @@ -488,7 +488,7 @@ public class LootModule extends MiniPlugin return; } - ItemStack itemStack = event.getCursor(); + ItemStack itemStack = event.getCurrentItem(); if (itemStack == null) { @@ -530,8 +530,6 @@ public class LootModule extends MiniPlugin if (reward == null) { - Bukkit.broadcastMessage(lootItem.getMetadata()); - switch (lootItem.getMetadata()) { case "RANK_UPGRADE": diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java index 9bffb277c..f454e62c2 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java @@ -2,10 +2,12 @@ package mineplex.gemhunters.loot.command; import org.bukkit.entity.Player; +import mineplex.core.Managers; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.F; import mineplex.gemhunters.loot.LootModule; +import mineplex.gemhunters.shop.ShopModule; /** * An ADMIN command that allows users to retrieve the latest data from the @@ -31,7 +33,12 @@ public class UpdateLootCommand extends CommandBase caller.sendMessage(F.main(Plugin.getName(), "Updating loot tables asynchronusly...")); - Plugin.runAsync(() -> Plugin.updateChestLoot()); + final ShopModule shop = Managers.require(ShopModule.class); + + Plugin.runAsync(() -> { + Plugin.updateChestLoot(); + shop.updateVillagerLoot(); + }); caller.sendMessage(F.main(Plugin.getName(), "Finished!")); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java index 25a9ea89d..29a039970 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java @@ -27,11 +27,12 @@ public class SafezoneModule extends MiniPlugin { private static final String SAFEZONE_DATA_PREFIX = "SAFEZONE"; + private static final String SAFEZONE_DATA_IGNORE = "IGNORE"; private final WorldDataModule _worldData; private final Map _currentSafezone; - + private SafezoneModule() { super("Safezone"); @@ -56,17 +57,23 @@ public class SafezoneModule extends MiniPlugin boolean isInOldSafezone = oldSafezone != null; String newSafezone = getSafezone(player.getLocation()); boolean isInNewSafezone = newSafezone != null; - + // null -> not null if (!isInOldSafezone && isInNewSafezone) { - UtilTextMiddle.display("", C.cYellow + "Entering " + newSafezone, 10, 40, 10, player); + if (!newSafezone.contains(SAFEZONE_DATA_IGNORE)) + { + UtilTextMiddle.display("", C.cYellow + "Entering " + newSafezone, 10, 40, 10, player); + } _currentSafezone.put(key, newSafezone); } // not null -> null else if (isInOldSafezone && !isInNewSafezone) { - UtilTextMiddle.display("", C.cYellow + "Leaving " + oldSafezone, 10, 40, 10, player); + if (!oldSafezone.contains(SAFEZONE_DATA_IGNORE)) + { + UtilTextMiddle.display("", C.cYellow + "Leaving " + oldSafezone, 10, 40, 10, player); + } _currentSafezone.put(key, null); } } @@ -153,12 +160,12 @@ public class SafezoneModule extends MiniPlugin { String name = ""; String[] split = key.split(" "); - + for (int i = 1; i < split.length; i++) { name += split[i] + " "; } - + return name.trim(); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java index 388acdded..342b405ad 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java @@ -2,27 +2,30 @@ package mineplex.gemhunters.scoreboard; import org.bukkit.entity.Player; +import mineplex.core.Managers; +import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.C; +import mineplex.core.donation.DonationManager; import mineplex.core.scoreboard.WritableMineplexScoreboard; public class GemHuntersScoreboard extends WritableMineplexScoreboard { + private final DonationManager _donation; + public GemHuntersScoreboard(Player player) { super(player); + + _donation = Managers.require(DonationManager.class); } public void writeContent(Player player) { writeNewLine(); - - write(C.cGreenB + "Top Players"); - writeNewLine(); - - write(C.cYellowB + "Reset Time"); - write("0 seconds"); + write(C.cGreenB + "Gems"); + write(String.valueOf(_donation.Get(player).getBalance(GlobalCurrency.GEM))); writeNewLine(); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java index b005bf9d3..0b8f6934d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java @@ -1,15 +1,190 @@ package mineplex.gemhunters.shop; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Villager; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.inventory.ItemStack; + +import com.google.common.collect.Sets; + import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.Pair; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.google.GoogleSheetsManager; +import mineplex.core.google.MineplexGoogleSheet; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.gemhunters.loot.LootItem; +import mineplex.gemhunters.safezone.SafezoneModule; +import mineplex.gemhunters.world.WorldDataModule; +import mineplex.serverdata.commands.PlayerJoinCommand; +import net.md_5.bungee.api.ChatColor; @ReflectivelyCreateMiniPlugin public class ShopModule extends MiniPlugin { + private static final MineplexGoogleSheet VILLAGER_LOOT_SHEET = MineplexGoogleSheet.GEM_HUNTERS_VILLAGERS; + + private final GoogleSheetsManager _sheets; + private final WorldDataModule _worldData; + + private final Map> _tradeItems; + + private boolean _npcsSpawned; + private ShopModule() { super("Shop"); + + _sheets = require(GoogleSheetsManager.class); + _worldData = require(WorldDataModule.class); + + _tradeItems = new HashMap<>(); + + updateVillagerLoot(); + } + + public void updateVillagerLoot() + { + try + { + Map>> map = _sheets.getCellValues(VILLAGER_LOOT_SHEET); + + for (String key : map.keySet()) + { + Set items = new HashSet<>(); + List> grid = map.get(key); + int index = 0; + + try + { + for (List values : grid) + { + if (index++ < 2) + { + continue; + } + + log("Size = " + values.size()); + + Material material = Material.valueOf(String.valueOf(values.get(0))); + byte data = Byte.parseByte(String.valueOf(values.get(1))); + int minAmount = 1; + int maxAmount = 1; + + try + { + String[] numbers = String.valueOf(values.get(2)).split("-"); + + if (numbers.length < 2) + { + minAmount = Integer.parseInt(String.valueOf(values.get(2))); + maxAmount = minAmount; + } + else + { + minAmount = Integer.parseInt(numbers[0]); + maxAmount = Integer.parseInt(numbers[1]); + } + } + catch (NumberFormatException e) + { + continue; + } + + ItemBuilder builder = new ItemBuilder(material, data); + + String title = ChatColor.translateAlternateColorCodes('&', String.valueOf(values.get(3))); + String[] lore = String.valueOf(values.get(4)).split(":"); + String[] colouredLore = new String[lore.length]; + + int loreIndex = 0; + for (String line : lore) + { + colouredLore[loreIndex++] = ChatColor.translateAlternateColorCodes('&', line); + } + + builder.setTitle(title); + builder.setLore(colouredLore); + + String[] enchants = String.valueOf(values.get(5)).split(","); + + for (String enchant : enchants) + { + String[] enchantData = enchant.split(":"); + + if (enchantData.length < 2) + { + continue; + } + + builder.addEnchantment(Enchantment.getByName(enchantData[0]), Integer.parseInt(enchantData[1])); + } + + double probability = Double.parseDouble(String.valueOf(values.get(6))); + String metadata = null; + int cost = Integer.parseInt(String.valueOf(values.get(7))); + + if (values.size() > 8) + { + metadata = String.valueOf(values.get(8)); + } + + items.add(new TradeableItem(builder.build(), minAmount, maxAmount, probability, metadata, cost)); + } + + _tradeItems.put(key, items); + } + catch (Exception e) + { + // TODO send slack message? + e.printStackTrace(); + log("An error occured while parsing spreadsheet data! " + key); + continue; + } + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + @EventHandler + public void playerJoin(PlayerJoinEvent event) + { + if (_npcsSpawned) + { + return; + } + + _npcsSpawned = true; + + for (String key : _worldData.getAllSpawnLocations().keySet()) + { + if (!_tradeItems.containsKey(key)) + { + continue; + } + + for (Location location : _worldData.getSpawnLocation(key)) + { + new TraderNPC(_plugin, location, Villager.class, "Bob", true, Sets.newHashSet(UtilAlg.Random(_tradeItems.get(key)))); + } + } } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TradeableItem.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TradeableItem.java new file mode 100644 index 000000000..9af2d72c6 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TradeableItem.java @@ -0,0 +1,24 @@ +package mineplex.gemhunters.shop; + +import org.bukkit.inventory.ItemStack; + +import mineplex.gemhunters.loot.LootItem; + +public class TradeableItem extends LootItem +{ + + private int _cost; + + public TradeableItem(ItemStack itemStack, int minAmount, int maxAmount, double probability, String metadata, int cost) + { + super(itemStack, minAmount, maxAmount, probability, metadata); + + _cost = cost; + } + + public int getCost() + { + return _cost; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java new file mode 100644 index 000000000..cac169faa --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java @@ -0,0 +1,118 @@ +package mineplex.gemhunters.shop; + +import java.util.Set; + +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.Managers; +import mineplex.core.common.Pair; +import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.donation.DonationManager; +import mineplex.core.donation.Donor; +import mineplex.gemhunters.util.SimpleNPC; + +public class TraderNPC extends SimpleNPC +{ + + private final DonationManager _donation; + + private final Set _selling; + private final Inventory _inv; + + public TraderNPC(JavaPlugin plugin, Location spawn, Class type, String name, boolean vegetated, Set selling) + { + super(plugin, spawn, type, name, null, vegetated); + + _donation = Managers.require(DonationManager.class); + + _selling = selling; + _inv = plugin.getServer().createInventory(null, 9, name); + + int index = 1; + + for (TradeableItem item : selling) + { + _inv.setItem(index++, item.getItemStack()); + } + } + + @Override + @EventHandler + public void npcClick(PlayerInteractEntityEvent event) + { + super.npcClick(event); + + if (event.getRightClicked().equals(_entity)) + { + event.getPlayer().openInventory(_inv); + } + } + + @EventHandler + public void inventoryClick(InventoryClickEvent event) + { + if (event.getInventory() == null) + { + return; + } + + if (!event.getInventory().equals(_inv)) + { + return; + } + + ItemStack itemStack = event.getCurrentItem(); + + if (itemStack == null) + { + return; + } + + Player player = (Player) event.getWhoClicked(); + Donor donor = _donation.Get(player); + int gems = donor.getBalance(GlobalCurrency.GEM); + int cost = fromItemStack(itemStack); + + if (cost == 0) + { + return; + } + + event.setCancelled(true); + + if (cost > gems) + { + player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0.6F); + return; + } + + donor.addBalance(GlobalCurrency.GEM, -cost); + + player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 1.2F); + player.getInventory().addItem(itemStack); + player.closeInventory(); + } + + public int fromItemStack(ItemStack itemStack) + { + for (TradeableItem item : _selling) + { + if (item.getItemStack().isSimilar(itemStack)) + { + return item.getCost(); + } + } + + return 0; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index 6f3bec5d9..b2abbd133 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -9,6 +9,9 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Villager; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; @@ -18,6 +21,7 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; import mineplex.gemhunters.safezone.SafezoneModule; +import mineplex.gemhunters.util.ColouredTextAnimation; import mineplex.gemhunters.util.SimpleNPC; import mineplex.gemhunters.world.WorldDataModule; @@ -50,9 +54,9 @@ public class SpawnModule extends MiniPlugin _spawn = _worldData.getSpawnLocation("Yellow").get(0); _center = _worldData.getCustomLocation("CENTER").get(0); } - + event.getPlayer().teleport(_spawn); - + if (_npcsSpawned) { return; @@ -72,16 +76,32 @@ public class SpawnModule extends MiniPlugin public void run(Player data) { Location location = getRandomLocation(); - + if (location == null) { data.sendMessage(F.main(_moduleName, "A suitable teleport location could not be found. Please try again in a few seconds.")); return; } - - data.teleport(location); - } + data.teleport(location); + data.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 4 * 20, 9)); + data.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 4 * 20, 9)); + + ColouredTextAnimation animation = new ColouredTextAnimation("GEM HUNTERS", C.cGoldB + "M ", C.cGoldB + " M", new String[] { C.cDGreenB, C.cGreenB, C.cWhiteB }); + + runSyncTimer(new BukkitRunnable() + { + + @Override + public void run() + { + if (animation.displayAsTitle(data)) + { + cancel(); + } + } + }, 10, 4); + } }); } @@ -105,11 +125,11 @@ public class SpawnModule extends MiniPlugin while (attempts < 100) { - Location possible = UtilAlg.getRandomLocation(_center, range, 10, range); + Location possible = UtilBlock.getHighest(_worldData.World, UtilAlg.getRandomLocation(_center, range)).getLocation(); if (isSuitable(possible.getBlock())) { - return possible; + return possible.add(0, 1, 0); } attempts++; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java index cd31f9b87..6478f2fca 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java @@ -72,6 +72,8 @@ public class SupplyDrop _lastHelicopter = new HashSet<>(100); _bladeBlocks = new HashSet<>(20); _diagonal = false; + + spawn.getChunk().load(); } public boolean advancePath() @@ -182,6 +184,19 @@ public class SupplyDrop } } } + + public void stop() + { + for (Block block : _bladeBlocks) + { + block.setType(Material.AIR); + } + + for (Block block : _lastHelicopter) + { + block.setType(Material.AIR); + } + } public void spawnLootChest() { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java index 9b3085c87..d55f125b1 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java @@ -1,5 +1,10 @@ package mineplex.gemhunters.supplydrop; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -8,13 +13,21 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.ItemSpawnEvent; -import mineplex.core.Managers; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.blockrestore.BlockRestore; +import mineplex.core.common.Pair; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.common.util.UtilWorld; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.loot.LootModule; -import mineplex.gemhunters.supplydrop.commands.CommandSupplyDropTest; +import mineplex.gemhunters.supplydrop.commands.SupplyDropCommand; import mineplex.gemhunters.world.WorldDataModule; @ReflectivelyCreateMiniPlugin @@ -22,33 +35,42 @@ public class SupplyDropModule extends MiniPlugin { private static final String CHEST_COLOUR = "RED"; + private static final String LOCATION_DATA = "SUPPLY_DROP"; + private final BlockRestore _blockRestore; + private final LootModule _loot; private final WorldDataModule _worldData; - + + private final Set _beaconBlocks; + + private String[] _locationKeys; private SupplyDrop _current; private SupplyDropModule() { super("Supply Drop"); + _blockRestore = require(BlockRestore.class); + _loot = require(LootModule.class); _worldData = require(WorldDataModule.class); + + _beaconBlocks = new HashSet<>(); } @Override public void addCommands() { - addCommand(new CommandSupplyDropTest(this)); + addCommand(new SupplyDropCommand(this)); } @EventHandler public void update(UpdateEvent event) { - if (event.getType() != UpdateType.SEC || _current == null) - + if (event.getType() != UpdateType.SEC || !isActive()) { return; } - + if (_current.advancePath()) { _current = null; @@ -58,6 +80,7 @@ public class SupplyDropModule extends MiniPlugin @EventHandler public void itemSpawn(ItemSpawnEvent event) { + // The Helicopter has a door. This stops it dropping items when it moves. if (event.getEntity().getItemStack().getType() == Material.IRON_DOOR) { event.setCancelled(true); @@ -73,19 +96,87 @@ public class SupplyDropModule extends MiniPlugin block.setType(Material.CHEST); - // Add location that the chest will appear at into the spawned chest lists so that LootModule can populate it with loot. - Managers.require(LootModule.class).addSpawnedChest(block.getLocation(), CHEST_COLOUR); + // Add location that the chest will appear at into the spawned chests list so that LootModule can populate it with loot. + _loot.addSpawnedChest(block.getLocation(), CHEST_COLOUR); + // Remove beacon + for (Block beacon : _beaconBlocks) + { + _blockRestore.restore(beacon); + } + + _beaconBlocks.clear(); + event.setCancelled(true); } } - public void startHelicopter() + public void startSequence(String locationKey) { - Location spawn = _worldData.getCustomLocation("SUPPLY_DROP Fountain Spawn").get(0); - Location destination = _worldData.getCustomLocation("SUPPLY_DROP Fountain Chest").get(0); - Location despawn = _worldData.getCustomLocation("SUPPLY_DROP Fountain End").get(0); + Location spawn = _worldData.getCustomLocation(LOCATION_DATA + " " + locationKey + " Start").get(0); + Location destination = _worldData.getCustomLocation(LOCATION_DATA + " " + locationKey + " Chest").get(0); + Location despawn = _worldData.getCustomLocation(LOCATION_DATA + " " + locationKey + " End").get(0); + // Construct a beacon + for (Pair> pair : UtilBlock.getBeaconBlocks(destination, (byte) 0)) + { + // Look it's like a maze + _beaconBlocks.add(pair.getLeft().getBlock()); + _blockRestore.add(pair.getLeft().getBlock(), pair.getRight().getLeft().getId(), pair.getRight().getRight(), Long.MAX_VALUE); + } + + // Inform the masses + UtilTextMiddle.display(C.cYellow + locationKey, C.cGray + "A Supply Drop is spawning!", 10, 40, 10); + UtilServer.broadcast(F.main(_moduleName, "A Supply Drop is spawning at " + F.elem(locationKey) + " - " + C.cYellow + UtilWorld.locToStrClean(destination))); + _current = new SupplyDrop(spawn, destination, despawn); } + + public void startSequence() + { + startSequence(getLocationKeys()[UtilMath.r(getLocationKeys().length)]); + } + + public void stopSequence() + { + // Remove beacon (only needed incase the command was executed) + for (Block block : _beaconBlocks) + { + _blockRestore.restore(block); + } + + _beaconBlocks.clear(); + _current.stop(); + _current = null; + } + + public boolean isActive() + { + return _current != null; + } + + public String[] getLocationKeys() + { + if (_locationKeys == null) + { + List supplyDropKeys = new ArrayList<>(); + + for (String key : _worldData.getAllCustomLocations().keySet()) + { + if (key.startsWith(LOCATION_DATA)) + { + String splitKey = key.split(" ")[1]; + + if (!supplyDropKeys.contains(splitKey)) + { + supplyDropKeys.add(splitKey); + } + } + } + + _locationKeys = supplyDropKeys.toArray(new String[supplyDropKeys.size()]); + } + + return _locationKeys; + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/CommandSupplyDropTest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/CommandSupplyDropTest.java deleted file mode 100644 index 40da25fb3..000000000 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/CommandSupplyDropTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package mineplex.gemhunters.supplydrop.commands; - -import org.bukkit.entity.Player; - -import mineplex.core.command.CommandBase; -import mineplex.core.common.Rank; -import mineplex.gemhunters.supplydrop.SupplyDropModule; - -public class CommandSupplyDropTest extends CommandBase -{ - - public CommandSupplyDropTest(SupplyDropModule plugin) - { - super(plugin, Rank.ADMIN, "stest"); - } - - @Override - public void Execute(Player caller, String[] args) - { - caller.sendMessage("Running!"); - Plugin.startHelicopter(); - } - -} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/EndCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/EndCommand.java new file mode 100644 index 000000000..41de1ab1b --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/EndCommand.java @@ -0,0 +1,31 @@ +package mineplex.gemhunters.supplydrop.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.gemhunters.supplydrop.SupplyDropModule; + +public class EndCommand extends CommandBase +{ + + public EndCommand(SupplyDropModule plugin) + { + super(plugin, Rank.ADMIN, "stop"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (!Plugin.isActive()) + { + caller.sendMessage(F.main(Plugin.getName(), "There is no current supply drop.")); + return; + } + + caller.sendMessage(F.main(Plugin.getName(), "Stopping the current supply drop.")); + Plugin.stopSequence(); + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/StartCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/StartCommand.java new file mode 100644 index 000000000..233cefa0e --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/StartCommand.java @@ -0,0 +1,72 @@ +package mineplex.gemhunters.supplydrop.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.gemhunters.supplydrop.SupplyDropModule; + +public class StartCommand extends CommandBase +{ + + public StartCommand(SupplyDropModule plugin) + { + super(plugin, Rank.ADMIN, "start"); + } + + @Override + public void Execute(Player caller, String[] args) + { + boolean override = false; + + if (Plugin.isActive()) + { + for (String arg : args) + { + if (arg.equalsIgnoreCase("-f")) + { + override = true; + caller.sendMessage(F.main(Plugin.getName(), "Overriding the current supply drop. You know best.")); + Plugin.stopSequence(); + break; + } + } + + if (!override) + { + caller.sendMessage(F.main(Plugin.getName(), "Just saying there is another supply drop already running. If you really really want to override the current one. Add " + F.elem("-f") + " as an additional argument.")); + return; + } + } + + if (args.length == 0 || override && args.length == 1) + { + caller.sendMessage(F.main(Plugin.getName(), "Starting the supply drop sequence at one of the random locations.")); + Plugin.startSequence(); + } + else + { + String input = args[0]; + + for (String key : Plugin.getLocationKeys()) + { + if (input.equalsIgnoreCase(key)) + { + caller.sendMessage(F.main(Plugin.getName(), "Starting the supply drop sequence at " + F.elem(key) + ".")); + Plugin.startSequence(key); + return; + } + } + + caller.sendMessage(F.main(Plugin.getName(), "I wasn\'t able to find a location key of the name " + F.elem(input) + ". Possible values:")); + + for (String key : Plugin.getLocationKeys()) + { + caller.sendMessage(C.cGray + "- " + F.elem(key)); + } + } + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/SupplyDropCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/SupplyDropCommand.java new file mode 100644 index 000000000..4f5c0db51 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/SupplyDropCommand.java @@ -0,0 +1,29 @@ +package mineplex.gemhunters.supplydrop.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.command.MultiCommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.gemhunters.supplydrop.SupplyDropModule; + +public class SupplyDropCommand extends MultiCommandBase +{ + + public SupplyDropCommand(SupplyDropModule plugin) + { + super(plugin, Rank.ADMIN, "supplydrop", "supply", "sd"); + + AddCommand(new StartCommand(plugin)); + AddCommand(new EndCommand(plugin)); + } + + @Override + protected void Help(Player caller, String[] args) + { + caller.sendMessage(F.main(Plugin.getName(), "Command List:")); + caller.sendMessage(F.help("/" + _aliasUsed + " start [location]", "Starts the supply drop sequence at a certain location. Leaving [location] blank picks a random one.", Rank.ADMIN)); + caller.sendMessage(F.help("/" + _aliasUsed + " stop", "Ends the current supply drop.", Rank.ADMIN)); + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/ColouredTextAnimation.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/ColouredTextAnimation.java new file mode 100644 index 000000000..fc7dbee75 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/ColouredTextAnimation.java @@ -0,0 +1,123 @@ +package mineplex.gemhunters.util; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import mineplex.core.common.util.UtilTextMiddle; + +public class ColouredTextAnimation +{ + + private final String _text; + private final String _prefix; + private final String _suffix; + private final String[] _colours; + + private final double _colourChange; + private final double _colourRequirement; + + // Stage 0 + private int _lastIndex; + private double _colour; + private int _colourIndex; + + // Stage 1 + private int _iterations; + + // Stage 2 + private int _colourStage; + + private String _last; + + private int _stage; + + public ColouredTextAnimation(String text, String... colours) + { + this(text, null, null, colours); + } + + public ColouredTextAnimation(String text, String prefix, String suffix, String[] colours) + { + _text = text; + _prefix = prefix; + _suffix = suffix; + _colours = colours; + + _colourChange = (double) 1 / text.length() * 2; + _colourRequirement = (double) 1 / colours.length; + + _lastIndex = text.length() / 2; + _colour = 0; + _colourIndex = 0; + + _iterations = 0; + + _colourStage = 0; + + _stage = 0; + } + + public boolean displayAsTitle(Player... players) + { + String text = next(); + + UtilTextMiddle.display(text, null, 0, 20, 20, players); + + return _stage == -1; + } + + private String next() + { + String display = ""; + + switch (_stage) + { + case 0: + String text = _text.substring(_lastIndex, _text.length() - _lastIndex); + String colour = _colours[_colourIndex]; + + if (_colour >= _colourRequirement * (_colourIndex + 1)) + { + _colourIndex++; + } + + _colour += _colourChange; + _lastIndex--; + + if (_lastIndex == -1) + { + _stage++; + } + + display = colour + text; + break; + case 1: + _iterations++; + + if (_iterations > 4) + { + _stage++; + } + + display = _last; + break; + case 2: + _colourStage++; + + if (_colourStage > 10) + { + // Stop the cycle + _stage = -1; + } + + display = _colours[_colourStage % _colours.length] + ChatColor.stripColor(_last); + break; + default: + break; + } + + _last = display; + return _prefix + display + _suffix; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java index 37bc256bb..78d89ba30 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java @@ -17,33 +17,33 @@ import mineplex.core.common.util.UtilEnt; public class SimpleNPC implements Listener { - private final LivingEntity _entity; + protected final LivingEntity _entity; private final Callback _clickEvent; private final boolean _vegetated; - + public SimpleNPC(JavaPlugin plugin, Location spawn, Class type, String name, Callback clickEvent) { this(plugin, spawn, type, name, clickEvent, true); } - + public SimpleNPC(JavaPlugin plugin, Location spawn, Class type, String name, Callback clickEvent, boolean vegetated) { _entity = spawn.getWorld().spawn(spawn, type); - + _entity.setRemoveWhenFarAway(false); _entity.setCustomName(name); _entity.setCustomNameVisible(true); - + UtilEnt.Vegetate(_entity, true); UtilEnt.ghost(_entity, true, false); UtilEnt.setFakeHead(_entity, true); - + _clickEvent = clickEvent; _vegetated = vegetated; - + plugin.getServer().getPluginManager().registerEvents(this, plugin); } - + @EventHandler public void npcClick(PlayerInteractEntityEvent event) { @@ -51,11 +51,15 @@ public class SimpleNPC implements Listener { return; } - + event.setCancelled(true); - _clickEvent.run(event.getPlayer()); + + if (_clickEvent != null) + { + _clickEvent.run(event.getPlayer()); + } } - + @EventHandler public void npcDamage(EntityDamageEvent event) { @@ -63,10 +67,10 @@ public class SimpleNPC implements Listener { return; } - + event.setCancelled(true); } - + @EventHandler public void npcDeath(EntityDeathEvent event) { @@ -74,8 +78,8 @@ public class SimpleNPC implements Listener { return; } - + HandlerList.unregisterAll(this); } - + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java index df4e3014f..e371a4cff 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java @@ -4,12 +4,14 @@ import java.io.BufferedReader; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.apache.commons.io.FileUtils; import org.bukkit.Difficulty; import org.bukkit.Location; import org.bukkit.World; @@ -53,9 +55,9 @@ public class WorldDataModule extends MiniPlugin public void initialize() { final WorldDataModule worldData = this; - + runAsync(() -> { - + // Unzip worldData.unzipWorld(); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/WorldEventCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/WorldEventCommand.java index 2f17e7352..fb77d9063 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/WorldEventCommand.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/WorldEventCommand.java @@ -12,7 +12,7 @@ public class WorldEventCommand extends MultiCommandBase public WorldEventCommand(WorldEventModule plugin) { - super(plugin, Rank.ADMIN, "worldevent", "we", "event"); + super(plugin, Rank.ADMIN, "worldevent", "we"); } @Override From 3d643191805a3b28cb85de724f67c981bfeed8ef Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 12 Jan 2017 18:03:40 +0000 Subject: [PATCH 012/101] Missing commands --- .../core/portal/Commands/SendCommand.java | 2 +- .../core/portal/Commands/ServerCommand.java | 28 ++++++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/SendCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/SendCommand.java index 40bfe8476..f0c7c59bf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/SendCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/SendCommand.java @@ -1,4 +1,4 @@ -package mineplex.core.portal.Commands; +package mineplex.core.portal.commands; import org.bukkit.entity.Player; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java index 918a8a2fb..5511e0105 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java @@ -1,4 +1,4 @@ -package mineplex.core.portal.Commands; +package mineplex.core.portal.commands; import org.bukkit.entity.Player; @@ -8,6 +8,7 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.portal.Intent; import mineplex.core.portal.Portal; public class ServerCommand extends CommandBase @@ -27,7 +28,6 @@ public class ServerCommand extends CommandBase { UtilPlayer.message(player, F.main(Plugin.getName(), C.cGray + "You are currently on server: " + C.cGold + serverName)); - return; } else if (args.length == 1) { @@ -58,28 +58,21 @@ public class ServerCommand extends CommandBase if (servUp.contains("STAFF")) { - if (playerRank.has(Rank.HELPER)) - Plugin.sendPlayerToServer(player, args[0]); - else + if (!playerRank.has(Rank.HELPER)) deniedAccess = true; } else if (servUp.contains("TEST")) { - if (playerRank.has(Rank.MODERATOR)) - Plugin.sendPlayerToServer(player, args[0]); - else + if (!playerRank.has(Rank.MODERATOR)) deniedAccess = true; } else if (servUp.startsWith("CLANS-")) { - if (playerRank.has(Rank.HELPER)) - Plugin.sendPlayerToServer(player, args[0]); - else + if (!playerRank.has(Rank.HELPER)) + { UtilPlayer.message(player, F.main(Plugin.getName(), "Clans servers can only be joined via the Clans Hub!")); - } - else - { - Plugin.sendPlayerToServer(player, args[0]); + return; + } } if (deniedAccess) @@ -88,6 +81,10 @@ public class ServerCommand extends CommandBase player, F.main(Plugin.getName(), C.cRed + "You don't have permission to join " + C.cGold + args[0])); } + else + { + Plugin.sendPlayerToServer(player, args[0], Intent.PLAYER_REQUEST); + } } }); } @@ -96,7 +93,6 @@ public class ServerCommand extends CommandBase { UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "Your arguments are inappropriate for this command!")); - return; } } } From d5be0f5061ce0b214fade1b5232c8e5fa9fe8135 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 12 Jan 2017 18:04:59 +0000 Subject: [PATCH 013/101] Remove args to match new parameters --- .../src/mineplex/clanshub/ClansHub.java | 12 ++++++------ Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java index 11d35f13d..44933a98f 100644 --- a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java +++ b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java @@ -90,14 +90,14 @@ public class ClansHub extends JavaPlugin //Static Modules require(ProfileCacheManager.class); CommandCenter.Initialize(this); - CoreClientManager clientManager = new CoreClientManager(this, webServerAddress); + CoreClientManager clientManager = new CoreClientManager(this); CommandCenter.Instance.setClientManager(clientManager); // new ProfileCacheManager(this); ItemStackFactory.Initialize(this, false); Recharge.Initialize(this); VisibilityManager.Initialize(this); Give.Initialize(this); - Punish punish = new Punish(this, webServerAddress, clientManager); + Punish punish = new Punish(this, clientManager); BlockRestore blockRestore = require(BlockRestore.class); DonationManager donationManager = require(DonationManager.class); @@ -115,14 +115,14 @@ public class ClansHub extends JavaPlugin Creature creature = new Creature(this); NpcManager npcManager = new NpcManager(this, creature); InventoryManager inventoryManager = new InventoryManager(this, clientManager); - PetManager petManager = new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore, webServerAddress); + PetManager petManager = new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore); PollManager pollManager = new PollManager(this, clientManager, donationManager); //Main Modules ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager)); new TitanGiveawayManager(this, clientManager, serverStatusManager); - Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName()); + Portal portal = new Portal(); AntiHack antiHack = require(AntiHack.class); GuardianManager guardianManager = require(GuardianManager.class); @@ -140,14 +140,14 @@ public class ClansHub extends JavaPlugin EloManager eloManager = new EloManager(this, clientManager); AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager, incognito, eloManager); - PartyManager partyManager = new PartyManager(this, portal, clientManager, preferenceManager); + PartyManager partyManager = new PartyManager(); CustomDataManager customDataManager = new CustomDataManager(this, clientManager); ConditionManager condition = new ConditionManager(this); ThankManager thankManager = new ThankManager(this, clientManager, donationManager); BoosterManager boosterManager = new BoosterManager(this, "", clientManager, donationManager, inventoryManager, thankManager); - HubManager hubManager = new HubManager(this, blockRestore, clientManager, incognito, donationManager, inventoryManager, condition, disguiseManager, new TaskManager(this, clientManager, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this, packetHandler), npcManager, packetHandler, punish, serverStatusManager, customDataManager, thankManager, boosterManager); + HubManager hubManager = new HubManager(this, blockRestore, clientManager, incognito, donationManager, inventoryManager, condition, disguiseManager, new TaskManager(this, clientManager), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this, packetHandler), npcManager, packetHandler, punish, serverStatusManager, customDataManager, thankManager, boosterManager); HologramManager hologramManager = new HologramManager(this, packetHandler); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index ae6bfed0b..0a31bcb05 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -111,14 +111,14 @@ public class Hub extends JavaPlugin implements IRelation //Static Modules require(ProfileCacheManager.class); CommandCenter.Initialize(this); - CoreClientManager clientManager = new CoreClientManager(this, webServerAddress); + CoreClientManager clientManager = new CoreClientManager(this); CommandCenter.Instance.setClientManager(clientManager); // new ProfileCacheManager(this); ItemStackFactory.Initialize(this, false); Recharge.Initialize(this); VisibilityManager.Initialize(this); Give.Initialize(this); - Punish punish = new Punish(this, webServerAddress, clientManager); + Punish punish = new Punish(this, clientManager); BlockRestore blockRestore = require(BlockRestore.class); DonationManager donationManager = require(DonationManager.class); @@ -137,7 +137,7 @@ public class Hub extends JavaPlugin implements IRelation NpcManager npcManager = new NpcManager(this, creature); _npcManager = npcManager; InventoryManager inventoryManager = new InventoryManager(this, clientManager); - PetManager petManager = new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore, webServerAddress); + PetManager petManager = new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore); PollManager pollManager = new PollManager(this, clientManager, donationManager); //new TournamentManager(this, clientManager, donationManager); @@ -147,7 +147,7 @@ public class Hub extends JavaPlugin implements IRelation ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager)); new TitanGiveawayManager(this, clientManager, serverStatusManager); - Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName()); + Portal portal = new Portal(); AntiHack antiHack = require(AntiHack.class); GuardianManager guardianManager = require(GuardianManager.class); @@ -165,7 +165,7 @@ public class Hub extends JavaPlugin implements IRelation EloManager eloManager = new EloManager(this, clientManager); AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager, incognito, eloManager); - PartyManager partyManager = new PartyManager(this, portal, clientManager, preferenceManager); + PartyManager partyManager = new PartyManager(); SkillConditionManager conditionManager = new SkillConditionManager(this); @@ -175,7 +175,7 @@ public class Hub extends JavaPlugin implements IRelation String boosterGroup = serverConfiguration.getServerGroup().getBoosterGroup(); ThankManager thankManager = new ThankManager(this, clientManager, donationManager); BoosterManager boosterManager = new BoosterManager(this, boosterGroup, clientManager, donationManager, inventoryManager, thankManager); - HubManager hubManager = new HubManager(this, blockRestore, clientManager, incognito, donationManager, inventoryManager, conditionManager, disguiseManager, new TaskManager(this, clientManager, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this, packetHandler), npcManager, personalServerManager, packetHandler, punish, serverStatusManager, customDataManager, thankManager, boosterManager); + HubManager hubManager = new HubManager(this, blockRestore, clientManager, incognito, donationManager, inventoryManager, conditionManager, disguiseManager, new TaskManager(this, clientManager), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this, packetHandler), npcManager, personalServerManager, packetHandler, punish, serverStatusManager, customDataManager, thankManager, boosterManager); HologramManager hologramManager = new HologramManager(this, packetHandler); QueueManager queueManager = new QueueManager(this, clientManager, donationManager, eloManager, partyManager); @@ -213,9 +213,9 @@ public class Hub extends JavaPlugin implements IRelation Energy energy = new Energy(this); energy.setEnabled(false); - ItemFactory itemFactory = new ItemFactory(this, blockRestore, conditionManager, damage, energy, fire, throwManager, webServerAddress); - SkillFactory skillManager = new SkillFactory(this, damage, this, combatManager, conditionManager, throwManager, disguiseManager, blockRestore, fire, new Movement(this), teleport, energy, webServerAddress); - ClassManager classManager = new ClassManager(this, clientManager, donationManager, hubManager.GetGadget(), skillManager, itemFactory, webServerAddress); + ItemFactory itemFactory = new ItemFactory(this, blockRestore, conditionManager, damage, energy, fire, throwManager); + SkillFactory skillManager = new SkillFactory(this, damage, this, combatManager, conditionManager, throwManager, disguiseManager, blockRestore, fire, new Movement(this), teleport, energy); + ClassManager classManager = new ClassManager(this, clientManager, donationManager, hubManager.GetGadget(), skillManager, itemFactory); ClassShopManager shopManager = new ClassShopManager(this, classManager, skillManager, itemFactory, achievementManager, clientManager); From b55902f853a96931575e62a63dd0d9343fdedec3 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 13 Jan 2017 17:16:36 +0000 Subject: [PATCH 014/101] World events --- .../src/mineplex/gemhunters/GemHunters.java | 2 -- .../worldevent/WorldEventModule.java | 2 ++ .../worldevent/giant/CustomGiant.java | 30 +++++++++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 271ef4dde..7aebf6b28 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -74,8 +74,6 @@ import net.minecraft.server.v1_8_R3.MinecraftServer; public class GemHunters extends JavaPlugin { - private static final String WEB_CONFIG = "webServer"; - @Override public void onEnable() { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java index 478be7ff0..26c859e9d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java @@ -8,11 +8,13 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilTime; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +@ReflectivelyCreateMiniPlugin public class WorldEventModule extends MiniPlugin { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/CustomGiant.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/CustomGiant.java index 2857b688d..f8efaab00 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/CustomGiant.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/CustomGiant.java @@ -5,15 +5,21 @@ import java.util.Collection; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.FallingBlock; import org.bukkit.entity.Giant; import org.bukkit.entity.Monster; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.util.Vector; import mineplex.core.Managers; +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.updater.UpdateType; @@ -24,7 +30,8 @@ public class CustomGiant implements Listener { private static final int GIANT_HEALTH = 100; - private static final int DESTORY_BLOCK_RADIUS = 5; + private static final int DESTORY_BLOCK_RADIUS = 7; + private static final float DESTORY_FALLING_BLOCK_CHANCE = 0.05F; private final Monster _giant; @@ -38,7 +45,8 @@ public class CustomGiant implements Listener _giant.setHealth(_giant.getMaxHealth()); UtilEnt.vegetate(_giant); - + UtilEnt.setStepHeight(_giant, 2); + Managers.get(WorldEventModule.class).registerEvents(this); } @@ -52,10 +60,10 @@ public class CustomGiant implements Listener if (_target == null) { - _target = acquireTarget(); + _target = acquireTarget(); } - UtilEnt.CreatureMoveFast(_giant, _target.getLocation(), 1.5F); + UtilEnt.CreatureMove(_giant, _target.getLocation(), 0.5F); } @EventHandler @@ -66,7 +74,19 @@ public class CustomGiant implements Listener return; } - _giant.getWorld().createExplosion(_giant.getLocation().add(0, 10, 0), DESTORY_BLOCK_RADIUS); + for (Block block : UtilBlock.getInBoundingBox(_giant.getLocation().subtract(5, 0, 5), _giant.getLocation().add(5, 13, 5))) + { + if (Math.random() < DESTORY_FALLING_BLOCK_CHANCE) + { + FallingBlock fallingBlock = block.getWorld().spawnFallingBlock(block.getLocation(), block.getType(), block.getData()); + + fallingBlock.setDropItem(false); + fallingBlock.setHurtEntities(false); + fallingBlock.setVelocity(new Vector(UtilMath.random(-1, 1), UtilMath.random(0.5, 1), UtilMath.random(-1, 1))); + } + + block.setType(Material.AIR); + } } @EventHandler From 36c0c56f274a66ca854ed74d77fb6d548af344a7 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 19 Jan 2017 21:15:06 +0000 Subject: [PATCH 015/101] World Events and Sheets rewrite --- Plugins/Mineplex.Core.Common/pom.xml | 15 -- .../mineplex/core/common/util/UtilBlock.java | 2 +- .../core/google/GoogleSheetsManager.java | 122 +++++++---- .../src/mineplex/gemhunters/GemHunters.java | 2 + .../gemhunters/economy/CashOutModule.java | 17 +- .../gemhunters/economy/EconomyModule.java | 95 +++++++++ .../economy/PlayerCashOutCompleteEvent.java | 21 +- .../mineplex/gemhunters/loot/LootItem.java | 5 + .../mineplex/gemhunters/loot/LootModule.java | 172 ++++++++-------- .../scoreboard/GemHuntersScoreboard.java | 43 ++-- .../mineplex/gemhunters/shop/ShopModule.java | 190 ++++++++---------- .../gemhunters/spawn/SpawnModule.java | 7 +- .../supplydrop/SupplyDropModule.java | 74 ++++--- .../commands/SupplyDropCommand.java | 2 +- .../gemhunters/world/WorldDataModule.java | 2 - .../worldevent/TriggerableWorldEvent.java | 10 - .../gemhunters/worldevent/WorldEvent.java | 104 +++++++++- .../worldevent/WorldEventModule.java | 90 +++++++-- .../worldevent/WorldEventState.java | 8 +- .../gemhunters/worldevent/WorldEventType.java | 24 ++- .../worldevent/command/AddCommand.java | 6 - .../worldevent/command/StartCommand.java | 48 +++++ .../worldevent/command/StopCommand.java | 53 +++++ .../worldevent/command/WorldEventCommand.java | 9 +- .../worldevent/giant/CustomGiant.java | 96 ++++++--- .../worldevent/giant/GiantWorldEvent.java | 76 ++++++- Plugins/mineplex-google-sheets/pom.xml | 61 ++++++ .../googlesheets/GoogleSheetController.java | 63 ++++++ .../mineplex/googlesheets/SheetProvider.java} | 124 ++++++------ .../googlesheets/SpreadsheetType.java} | 10 +- Plugins/pom.xml | 1 + 31 files changed, 1103 insertions(+), 449 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java delete mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/TriggerableWorldEvent.java delete mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/AddCommand.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/StartCommand.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/StopCommand.java create mode 100644 Plugins/mineplex-google-sheets/pom.xml create mode 100644 Plugins/mineplex-google-sheets/src/mineplex/googlesheets/GoogleSheetController.java rename Plugins/{Mineplex.Core.Common/src/mineplex/core/common/google/GoogleSheetProvider.java => mineplex-google-sheets/src/mineplex/googlesheets/SheetProvider.java} (50%) rename Plugins/{Mineplex.Core/src/mineplex/core/google/MineplexGoogleSheet.java => mineplex-google-sheets/src/mineplex/googlesheets/SpreadsheetType.java} (64%) diff --git a/Plugins/Mineplex.Core.Common/pom.xml b/Plugins/Mineplex.Core.Common/pom.xml index 43716281c..65ec63dd8 100644 --- a/Plugins/Mineplex.Core.Common/pom.xml +++ b/Plugins/Mineplex.Core.Common/pom.xml @@ -25,21 +25,6 @@ mineplex-serverdata dev-SNAPSHOT - - com.google.api-client - google-api-client - 1.22.0 - - - com.google.oauth-client - google-oauth-client-jetty - 1.22.0 - - - com.google.apis - google-api-services-sheets - v4-rev20-1.22.0 - diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java index aa2950933..6a43363de 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java @@ -1672,7 +1672,7 @@ public class UtilBlock } /** - * Returns a Pair> {@link HashSet} containing all the relevant data regarding beacon construction. + * Returns a {@link Set} containing all the relevant data regarding beacon construction. * Useful for adding them to block restore. * * @param surface diff --git a/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java b/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java index 2c9de13b6..383884f9f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java @@ -1,66 +1,120 @@ package mineplex.core.google; -import java.io.IOException; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.lang.reflect.Constructor; +import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; -import com.google.api.services.sheets.v4.model.Sheet; -import com.google.api.services.sheets.v4.model.Spreadsheet; +import org.bukkit.Bukkit; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; -import mineplex.core.common.google.GoogleSheetProvider; @ReflectivelyCreateMiniPlugin public class GoogleSheetsManager extends MiniPlugin { - private final GoogleSheetProvider _sheets; + private static final File DATA_STORE_DIR = new File(".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "files"); - private GoogleSheetsManager() + public GoogleSheetsManager() { super("Google Sheets"); - - _sheets = new GoogleSheetProvider(); } - public final void addSheet(MineplexGoogleSheet sheet, String sheetName, int maxColumn, int maxRow) throws IOException + public Map> getSheetData(String name, Class clazz) { - _sheets.create(sheet.getID(), sheetName, _sheets.getNextSheetID(sheet.getID()), maxColumn, maxRow); + return getSheetData(new File(DATA_STORE_DIR + File.separator + name + ".json"), clazz); } - public final List> getCellValues(MineplexGoogleSheet spreadsheet, String sheetName, String a1Notation) throws IOException + public Map> getSheetData(File file, Class clazz) { - return _sheets.getSheetsService().spreadsheets().values().get(spreadsheet.getID(), sheetName + "!" + a1Notation).execute().getValues(); - } - - public final List> getCellValues(MineplexGoogleSheet spreadsheet, String sheetName) throws IOException - { - return _sheets.getSheetsService().spreadsheets().values().get(spreadsheet.getID(), sheetName).execute().getValues(); - } - - public final Map>> getCellValues(MineplexGoogleSheet spreadsheet) throws IOException - { - Spreadsheet googleSpreadsheet = _sheets.getSheetsService().spreadsheets().get(spreadsheet.getID()).execute(); - - Map>> valuesMap = new HashMap<>(googleSpreadsheet.getSheets().size() - 1); - - int index = 0; - - for (Sheet sheet : googleSpreadsheet.getSheets()) + if (!file.exists()) { - if (index++ == 0) + Bukkit.broadcastMessage("No file"); + return null; + } + + Map> valuesMap = new HashMap<>(); + + try + { + JsonParser parser = new JsonParser(); + JsonElement data = parser.parse(new FileReader(file)); + JsonArray parent = data.getAsJsonObject().getAsJsonArray("data"); + + Bukkit.broadcastMessage("p=" + parent.size()); + + for (int i = 0; i < parent.size(); i++) { - continue; + JsonObject sheet = parent.get(i).getAsJsonObject(); + String name = sheet.get("name").getAsString(); + JsonArray values = sheet.getAsJsonArray("values"); + List> valuesList = new ArrayList<>(values.size()); + + for (int j = 0; j < values.size(); j++) + { + List list = new ArrayList<>(); + Iterator iterator = values.get(j).getAsJsonArray().iterator(); + + while (iterator.hasNext()) + { + String value = iterator.next().getAsString(); + list.add(value); + } + + valuesList.add(list); + } + + valuesMap.put(name, toSet(valuesList, clazz)); } - - String name = sheet.getProperties().getTitle(); - - valuesMap.put(name, getCellValues(spreadsheet, name)); + } + catch (FileNotFoundException e) + { + e.printStackTrace(); } + for (String key : valuesMap.keySet()) + { + Set set = valuesMap.get(key); + + for (T t : set) + { + Bukkit.broadcastMessage(t.toString()); + } + } + return valuesMap; } + public Set toSet(List> values, Class clazz) + { + Set result = new HashSet<>(); + Constructor constructor = clazz.getConstructors()[0]; + + for (List objects : values) + { + try + { + result.add(clazz.cast(constructor.newInstance(objects))); + } + catch (Exception e) + { + continue; + } + } + + return result; + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 7aebf6b28..0bce76706 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -52,6 +52,7 @@ import mineplex.core.visibility.VisibilityManager; import mineplex.gemhunters.chat.ChatModule; import mineplex.gemhunters.death.DeathModule; import mineplex.gemhunters.economy.CashOutModule; +import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.loot.LootModule; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.scoreboard.ScoreboardModule; @@ -208,6 +209,7 @@ public class GemHunters extends JavaPlugin require(CashOutModule.class); require(ChatModule.class); require(DeathModule.class); + require(EconomyModule.class); require(LootModule.class); require(SafezoneModule.class); require(ScoreboardModule.class); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java index da52cf0d6..ee6a10ede 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -22,10 +22,12 @@ import org.bukkit.inventory.ItemStack; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.donation.DonationManager; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; @@ -44,12 +46,16 @@ public class CashOutModule extends MiniPlugin private static final int CASH_OUT_COOLDOWN = 10000; private static final int CASH_OUT_MAX_MOVE_DISTANCE_SQUARED = 4; + private final DonationManager _donation; + private final Map _sessions; public CashOutModule() { super("Cash Out"); + _donation = require(DonationManager.class); + _sessions = new HashMap<>(); } @@ -155,10 +161,11 @@ public class CashOutModule extends MiniPlugin UtilServer.CallEvent(completeEvent); + _donation.Get(player).addBalance(GlobalCurrency.GEM, completeEvent.getGems()); + session.endSession(); iterator.remove(); - player.sendMessage(C.cGreen + "Imagine you are being sent to the Lobby."); - rewardCashOut(player, session); + player.sendMessage(C.cGreen + "Imagine you are being sent to the Lobby."); // Portal.getInstance().sendToHub(player, "You cashed out!"); } } @@ -235,18 +242,12 @@ public class CashOutModule extends MiniPlugin _sessions.put(key, new CashOutSession(player, 10)); } - public void rewardCashOut(Player player, CashOutSession session) - { - - } - public void cancelCashOut(Player player, String message) { UUID key = player.getUniqueId(); CashOutSession session = _sessions.get(key); player.sendMessage(F.main("Game", message + " Your cash out has been cancelled.")); - session.endSession(); _sessions.remove(key); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java new file mode 100644 index 000000000..8e9f733fd --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -0,0 +1,95 @@ +package mineplex.gemhunters.economy; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.common.util.F; +import mineplex.core.google.GoogleSheetsManager; +import mineplex.gemhunters.loot.LootItem; + +@ReflectivelyCreateMiniPlugin +public class EconomyModule extends MiniPlugin +{ + + private static final float GEM_KILL_FACTOR = 0.5F; + + private Map _storedGems; + + public EconomyModule() + { + super("Economy"); + + _storedGems = new HashMap<>(); + } + + @EventHandler + public void join(PlayerJoinEvent event) + { + _storedGems.put(event.getPlayer().getUniqueId(), 0); + } + + @EventHandler + public void death(PlayerDeathEvent event) + { + Player player = event.getEntity(); + Entity killer = event.getEntity().getKiller(); + + if (!(killer instanceof Player)) + { + return; + } + + Player killerPlayer = (Player) killer; + + int gems = (int) (_storedGems.get(player.getUniqueId()) * GEM_KILL_FACTOR); + + addToStore(killerPlayer, "Killing " + F.name(player.getName()), gems); + } + + + @EventHandler + public void quit(PlayerQuitEvent event) + { + _storedGems.remove(event.getPlayer().getUniqueId()); + } + + public void addToStore(Player player, String reason, int gems) + { + _storedGems.put(player.getUniqueId(), _storedGems.get(player.getUniqueId()) + gems); + + if (reason != null) + { + player.sendMessage(F.main(_moduleName, "+" + F.currency(GlobalCurrency.GEM, gems) + " (" + reason + ").")); + } + } + + public int getGems(Player player) + { + return _storedGems.get(player.getUniqueId()); + } + + @EventHandler + public void test(PlayerCommandPreprocessEvent event) + { + if (event.getMessage().startsWith("/test")) + { + event.setCancelled(true); + + require(GoogleSheetsManager.class).getSheetData("GEM_HUNTERS_CHESTS", LootItem.class); + //addToStore(event.getPlayer(), "Testing", 100); + } + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/PlayerCashOutCompleteEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/PlayerCashOutCompleteEvent.java index 8057b4047..6862c5da0 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/PlayerCashOutCompleteEvent.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/PlayerCashOutCompleteEvent.java @@ -9,11 +9,28 @@ public class PlayerCashOutCompleteEvent extends PlayerEvent private static final HandlerList HANDLERS = new HandlerList(); + private int _gems; + public PlayerCashOutCompleteEvent(Player player) { super(player); } - + + public void incrementGems(int gems) + { + _gems += gems; + } + + public void setGems(int gems) + { + _gems = gems; + } + + public int getGems() + { + return _gems; + } + public HandlerList getHandlers() { return HANDLERS; @@ -23,5 +40,5 @@ public class PlayerCashOutCompleteEvent extends PlayerEvent { return HANDLERS; } - + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java index 963a457b7..176420ef8 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java @@ -19,6 +19,11 @@ public class LootItem private double _probability; private String _metadata; + public LootItem(String... strings) + { + + } + public LootItem(ItemStack itemStack, int minAmount, int maxAmount, double probability, String metadata) { _itemStack = itemStack; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index b5f3b04e5..abdc1691e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -37,7 +37,6 @@ import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilWorld; import mineplex.core.google.GoogleSheetsManager; -import mineplex.core.google.MineplexGoogleSheet; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -63,8 +62,6 @@ public class LootModule extends MiniPlugin private static final int MAX_CHEST_PLACEMENT_RANGE = 10; private static final int MAX_CHEST_CHECK_DISTANCE_SQUARED = 4; - private static final MineplexGoogleSheet CHEST_LOOT_SHEET = MineplexGoogleSheet.GEM_HUNTERS_CHESTS; - private final GoogleSheetsManager _sheets; private final SafezoneModule _safezone; private final WorldDataModule _worldData; @@ -234,103 +231,96 @@ public class LootModule extends MiniPlugin public void updateChestLoot() { - try + Map>> map = null; + + for (String key : map.keySet()) { - Map>> map = _sheets.getCellValues(CHEST_LOOT_SHEET); + Set items = new HashSet<>(); + List> grid = map.get(key); + int index = 0; - for (String key : map.keySet()) + try { - Set items = new HashSet<>(); - List> grid = map.get(key); - int index = 0; - - try + for (List values : grid) { - for (List values : grid) + if (index++ < 2) { - if (index++ < 2) - { - continue; - } - - Material material = Material.valueOf(String.valueOf(values.get(0))); - byte data = Byte.parseByte(String.valueOf(values.get(1))); - int minAmount = 1; - int maxAmount = 1; - - try - { - String[] numbers = String.valueOf(values.get(2)).split("-"); - - if (numbers.length < 2) - { - minAmount = Integer.parseInt(String.valueOf(values.get(2))); - maxAmount = minAmount; - } - else - { - minAmount = Integer.parseInt(numbers[0]); - maxAmount = Integer.parseInt(numbers[1]); - } - } - catch (NumberFormatException e) - { - continue; - } - - ItemBuilder builder = new ItemBuilder(material, data); - - String title = ChatColor.translateAlternateColorCodes('&', String.valueOf(values.get(3))); - String[] lore = String.valueOf(values.get(4)).split(":"); - String[] colouredLore = new String[lore.length]; - - int loreIndex = 0; - for (String line : lore) - { - colouredLore[loreIndex++] = ChatColor.translateAlternateColorCodes('&', line); - } - - builder.setTitle(title); - builder.setLore(colouredLore); - - String[] enchants = String.valueOf(values.get(5)).split(","); - - for (String enchant : enchants) - { - String[] enchantData = enchant.split(":"); - - if (enchantData.length < 2) - { - continue; - } - - builder.addEnchantment(Enchantment.getByName(enchantData[0]), Integer.parseInt(enchantData[1])); - } - - double probability = Double.parseDouble(String.valueOf(values.get(6))); - String metadata = null; - - if (values.size() > 7) - { - metadata = String.valueOf(values.get(7)); - } - items.add(new LootItem(builder.build(), minAmount, maxAmount, probability, metadata)); + continue; } - _chestLoot.put(key, items); - } - catch (Exception e) - { - // TODO send slack message? - e.printStackTrace(); - log("An error occured while parsing spreadsheet data! " + key); - continue; + Material material = Material.valueOf(String.valueOf(values.get(0))); + byte data = Byte.parseByte(String.valueOf(values.get(1))); + int minAmount = 1; + int maxAmount = 1; + + try + { + String[] numbers = String.valueOf(values.get(2)).split("-"); + + if (numbers.length < 2) + { + minAmount = Integer.parseInt(String.valueOf(values.get(2))); + maxAmount = minAmount; + } + else + { + minAmount = Integer.parseInt(numbers[0]); + maxAmount = Integer.parseInt(numbers[1]); + } + } + catch (NumberFormatException e) + { + continue; + } + + ItemBuilder builder = new ItemBuilder(material, data); + + String title = ChatColor.translateAlternateColorCodes('&', String.valueOf(values.get(3))); + String[] lore = String.valueOf(values.get(4)).split(":"); + String[] colouredLore = new String[lore.length]; + + int loreIndex = 0; + for (String line : lore) + { + colouredLore[loreIndex++] = ChatColor.translateAlternateColorCodes('&', line); + } + + builder.setTitle(title); + builder.setLore(colouredLore); + + String[] enchants = String.valueOf(values.get(5)).split(","); + + for (String enchant : enchants) + { + String[] enchantData = enchant.split(":"); + + if (enchantData.length < 2) + { + continue; + } + + builder.addEnchantment(Enchantment.getByName(enchantData[0]), Integer.parseInt(enchantData[1])); + } + + double probability = Double.parseDouble(String.valueOf(values.get(6))); + String metadata = null; + + if (values.size() > 7) + { + metadata = String.valueOf(values.get(7)); + } + items.add(new LootItem(builder.build(), minAmount, maxAmount, probability, metadata)); } + + _chestLoot.put(key, items); + } + catch (Exception e) + { + // TODO send slack message? + e.printStackTrace(); + log("An error occured while parsing spreadsheet data! " + key); + continue; } - } - catch (IOException e) - { - e.printStackTrace(); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java index 342b405ad..e118c7121 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java @@ -3,37 +3,56 @@ package mineplex.gemhunters.scoreboard; import org.bukkit.entity.Player; import mineplex.core.Managers; -import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.C; -import mineplex.core.donation.DonationManager; +import mineplex.core.common.util.UtilTime; import mineplex.core.scoreboard.WritableMineplexScoreboard; +import mineplex.gemhunters.economy.EconomyModule; +import mineplex.gemhunters.worldevent.WorldEvent; +import mineplex.gemhunters.worldevent.WorldEventModule; public class GemHuntersScoreboard extends WritableMineplexScoreboard { - - private final DonationManager _donation; - + + private final EconomyModule _economy; + private final WorldEventModule _worldEvent; + public GemHuntersScoreboard(Player player) { super(player); - - _donation = Managers.require(DonationManager.class); + + _economy = Managers.require(EconomyModule.class); + _worldEvent = Managers.require(WorldEventModule.class); } public void writeContent(Player player) { writeNewLine(); - + write(C.cGreenB + "Gems"); - write(String.valueOf(_donation.Get(player).getBalance(GlobalCurrency.GEM))); - + write(String.valueOf(_economy.getGems(player))); + + writeNewLine(); + + write(C.cYellowB + "World Event"); + + if (!_worldEvent.isMajorEventActive()) + { + write(UtilTime.MakeStr(_worldEvent.getLastEventComplete() + _worldEvent.getEventTimer() - System.currentTimeMillis())); + } + else + { + for (WorldEvent event : _worldEvent.getActiveEvents()) + { + write(event.getEventType().getName() + " (" + event.getEventState().getName() + ")"); + } + } + writeNewLine(); } - + public String getSuffix(Player perspective, Player subject) { return C.cGray + " " + perspective.getName(); } - } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java index 0b8f6934d..2dcb2045b 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java @@ -1,43 +1,32 @@ package mineplex.gemhunters.shop; -import java.io.IOException; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Villager; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.inventory.ItemStack; import com.google.common.collect.Sets; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; -import mineplex.core.common.Pair; import mineplex.core.common.util.UtilAlg; import mineplex.core.google.GoogleSheetsManager; -import mineplex.core.google.MineplexGoogleSheet; import mineplex.core.itemstack.ItemBuilder; -import mineplex.gemhunters.loot.LootItem; -import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.world.WorldDataModule; -import mineplex.serverdata.commands.PlayerJoinCommand; import net.md_5.bungee.api.ChatColor; @ReflectivelyCreateMiniPlugin public class ShopModule extends MiniPlugin { - private static final MineplexGoogleSheet VILLAGER_LOOT_SHEET = MineplexGoogleSheet.GEM_HUNTERS_VILLAGERS; - private final GoogleSheetsManager _sheets; private final WorldDataModule _worldData; @@ -54,112 +43,105 @@ public class ShopModule extends MiniPlugin _tradeItems = new HashMap<>(); - updateVillagerLoot(); + //updateVillagerLoot(); } public void updateVillagerLoot() { - try + Map>> map = null; + + for (String key : map.keySet()) { - Map>> map = _sheets.getCellValues(VILLAGER_LOOT_SHEET); + Set items = new HashSet<>(); + List> grid = map.get(key); + int index = 0; - for (String key : map.keySet()) + try { - Set items = new HashSet<>(); - List> grid = map.get(key); - int index = 0; - - try + for (List values : grid) { - for (List values : grid) + if (index++ < 2) { - if (index++ < 2) - { - continue; - } - - log("Size = " + values.size()); - - Material material = Material.valueOf(String.valueOf(values.get(0))); - byte data = Byte.parseByte(String.valueOf(values.get(1))); - int minAmount = 1; - int maxAmount = 1; - - try - { - String[] numbers = String.valueOf(values.get(2)).split("-"); - - if (numbers.length < 2) - { - minAmount = Integer.parseInt(String.valueOf(values.get(2))); - maxAmount = minAmount; - } - else - { - minAmount = Integer.parseInt(numbers[0]); - maxAmount = Integer.parseInt(numbers[1]); - } - } - catch (NumberFormatException e) - { - continue; - } - - ItemBuilder builder = new ItemBuilder(material, data); - - String title = ChatColor.translateAlternateColorCodes('&', String.valueOf(values.get(3))); - String[] lore = String.valueOf(values.get(4)).split(":"); - String[] colouredLore = new String[lore.length]; - - int loreIndex = 0; - for (String line : lore) - { - colouredLore[loreIndex++] = ChatColor.translateAlternateColorCodes('&', line); - } - - builder.setTitle(title); - builder.setLore(colouredLore); - - String[] enchants = String.valueOf(values.get(5)).split(","); - - for (String enchant : enchants) - { - String[] enchantData = enchant.split(":"); - - if (enchantData.length < 2) - { - continue; - } - - builder.addEnchantment(Enchantment.getByName(enchantData[0]), Integer.parseInt(enchantData[1])); - } - - double probability = Double.parseDouble(String.valueOf(values.get(6))); - String metadata = null; - int cost = Integer.parseInt(String.valueOf(values.get(7))); - - if (values.size() > 8) - { - metadata = String.valueOf(values.get(8)); - } - - items.add(new TradeableItem(builder.build(), minAmount, maxAmount, probability, metadata, cost)); + continue; } - _tradeItems.put(key, items); - } - catch (Exception e) - { - // TODO send slack message? - e.printStackTrace(); - log("An error occured while parsing spreadsheet data! " + key); - continue; + log("Size = " + values.size()); + + Material material = Material.valueOf(String.valueOf(values.get(0))); + byte data = Byte.parseByte(String.valueOf(values.get(1))); + int minAmount = 1; + int maxAmount = 1; + + try + { + String[] numbers = String.valueOf(values.get(2)).split("-"); + + if (numbers.length < 2) + { + minAmount = Integer.parseInt(String.valueOf(values.get(2))); + maxAmount = minAmount; + } + else + { + minAmount = Integer.parseInt(numbers[0]); + maxAmount = Integer.parseInt(numbers[1]); + } + } + catch (NumberFormatException e) + { + continue; + } + + ItemBuilder builder = new ItemBuilder(material, data); + + String title = ChatColor.translateAlternateColorCodes('&', String.valueOf(values.get(3))); + String[] lore = String.valueOf(values.get(4)).split(":"); + String[] colouredLore = new String[lore.length]; + + int loreIndex = 0; + for (String line : lore) + { + colouredLore[loreIndex++] = ChatColor.translateAlternateColorCodes('&', line); + } + + builder.setTitle(title); + builder.setLore(colouredLore); + + String[] enchants = String.valueOf(values.get(5)).split(","); + + for (String enchant : enchants) + { + String[] enchantData = enchant.split(":"); + + if (enchantData.length < 2) + { + continue; + } + + builder.addEnchantment(Enchantment.getByName(enchantData[0]), Integer.parseInt(enchantData[1])); + } + + double probability = Double.parseDouble(String.valueOf(values.get(6))); + String metadata = null; + int cost = Integer.parseInt(String.valueOf(values.get(7))); + + if (values.size() > 8) + { + metadata = String.valueOf(values.get(8)); + } + + items.add(new TradeableItem(builder.build(), minAmount, maxAmount, probability, metadata, cost)); } + + _tradeItems.put(key, items); + } + catch (Exception e) + { + // TODO send slack message? + e.printStackTrace(); + log("An error occured while parsing spreadsheet data! " + key); + continue; } - } - catch (IOException e) - { - e.printStackTrace(); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index b2abbd133..8ad4004ee 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -20,6 +20,7 @@ import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilEnt; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.util.ColouredTextAnimation; import mineplex.gemhunters.util.SimpleNPC; @@ -69,7 +70,11 @@ public class SpawnModule extends MiniPlugin _npcsSpawned = true; - new SimpleNPC(_plugin, _worldData.getSpawnLocation("Purple").get(0), Villager.class, C.cDRed + "! " + C.cRedB + "Enter The World" + C.cDRed + " !", new Callback() + Location location = _worldData.getSpawnLocation("Purple").get(0); + + location.setYaw(UtilAlg.GetYaw(location.toVector())); + + new SimpleNPC(_plugin, location, Villager.class, C.cDRed + "! " + C.cRedB + "Enter The World" + C.cDRed + " !", new Callback() { @Override diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java index d55f125b1..5cd4030d7 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.concurrent.TimeUnit; import org.bukkit.Location; import org.bukkit.Material; @@ -23,6 +24,7 @@ import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilWorld; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -34,18 +36,22 @@ import mineplex.gemhunters.world.WorldDataModule; public class SupplyDropModule extends MiniPlugin { + private static final long SEQUENCE_TIMER = TimeUnit.MINUTES.toMillis(15); + private static final String CHEST_COLOUR = "RED"; private static final String LOCATION_DATA = "SUPPLY_DROP"; - + private final BlockRestore _blockRestore; private final LootModule _loot; private final WorldDataModule _worldData; - + private final Set _beaconBlocks; - + private String[] _locationKeys; private SupplyDrop _current; + private long _lastSupplyDrop; + private SupplyDropModule() { super("Supply Drop"); @@ -53,8 +59,10 @@ public class SupplyDropModule extends MiniPlugin _blockRestore = require(BlockRestore.class); _loot = require(LootModule.class); _worldData = require(WorldDataModule.class); - + _beaconBlocks = new HashSet<>(); + + _lastSupplyDrop = System.currentTimeMillis(); } @Override @@ -66,45 +74,54 @@ public class SupplyDropModule extends MiniPlugin @EventHandler public void update(UpdateEvent event) { - if (event.getType() != UpdateType.SEC || !isActive()) + if (event.getType() != UpdateType.SEC) { return; } - - if (_current.advancePath()) + + if (isActive()) { - _current = null; + if (_current.advancePath()) + { + stopSequence(); + } + } + else if (UtilTime.elapsed(_lastSupplyDrop, SEQUENCE_TIMER)) + { + startSequence(); } } @EventHandler public void itemSpawn(ItemSpawnEvent event) { - // The Helicopter has a door. This stops it dropping items when it moves. + // The Helicopter has a door. This stops it dropping items when it + // moves. if (event.getEntity().getItemStack().getType() == Material.IRON_DOOR) { event.setCancelled(true); } } - + @EventHandler public void fallingBlockChange(EntityChangeBlockEvent event) { - if (event.getEntity() instanceof FallingBlock && event.getTo() == Material.WOOD) - { + if (event.getEntity() instanceof FallingBlock && event.getTo() == Material.WOOD && isActive()) + { Block block = event.getBlock(); - + block.setType(Material.CHEST); - - // Add location that the chest will appear at into the spawned chests list so that LootModule can populate it with loot. + + // Add location that the chest will appear at into the spawned + // chests list so that LootModule can populate it with loot. _loot.addSpawnedChest(block.getLocation(), CHEST_COLOUR); - + // Remove beacon for (Block beacon : _beaconBlocks) { _blockRestore.restore(beacon); } - + _beaconBlocks.clear(); event.setCancelled(true); @@ -124,19 +141,20 @@ public class SupplyDropModule extends MiniPlugin _beaconBlocks.add(pair.getLeft().getBlock()); _blockRestore.add(pair.getLeft().getBlock(), pair.getRight().getLeft().getId(), pair.getRight().getRight(), Long.MAX_VALUE); } - + // Inform the masses UtilTextMiddle.display(C.cYellow + locationKey, C.cGray + "A Supply Drop is spawning!", 10, 40, 10); UtilServer.broadcast(F.main(_moduleName, "A Supply Drop is spawning at " + F.elem(locationKey) + " - " + C.cYellow + UtilWorld.locToStrClean(destination))); - + + _lastSupplyDrop = System.currentTimeMillis(); _current = new SupplyDrop(spawn, destination, despawn); } - + public void startSequence() { startSequence(getLocationKeys()[UtilMath.r(getLocationKeys().length)]); } - + public void stopSequence() { // Remove beacon (only needed incase the command was executed) @@ -144,39 +162,39 @@ public class SupplyDropModule extends MiniPlugin { _blockRestore.restore(block); } - + _beaconBlocks.clear(); _current.stop(); _current = null; } - + public boolean isActive() { return _current != null; } - + public String[] getLocationKeys() { if (_locationKeys == null) { List supplyDropKeys = new ArrayList<>(); - + for (String key : _worldData.getAllCustomLocations().keySet()) { if (key.startsWith(LOCATION_DATA)) { String splitKey = key.split(" ")[1]; - + if (!supplyDropKeys.contains(splitKey)) { supplyDropKeys.add(splitKey); } } } - + _locationKeys = supplyDropKeys.toArray(new String[supplyDropKeys.size()]); } - + return _locationKeys; } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/SupplyDropCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/SupplyDropCommand.java index 4f5c0db51..65e1c8218 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/SupplyDropCommand.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/SupplyDropCommand.java @@ -23,7 +23,7 @@ public class SupplyDropCommand extends MultiCommandBase { caller.sendMessage(F.main(Plugin.getName(), "Command List:")); caller.sendMessage(F.help("/" + _aliasUsed + " start [location]", "Starts the supply drop sequence at a certain location. Leaving [location] blank picks a random one.", Rank.ADMIN)); - caller.sendMessage(F.help("/" + _aliasUsed + " stop", "Ends the current supply drop.", Rank.ADMIN)); + caller.sendMessage(F.help("/" + _aliasUsed + " stop", "Stops the current supply drop.", Rank.ADMIN)); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java index e371a4cff..a3b7111ef 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java @@ -4,14 +4,12 @@ import java.io.BufferedReader; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; -import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.apache.commons.io.FileUtils; import org.bukkit.Difficulty; import org.bukkit.Location; import org.bukkit.World; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/TriggerableWorldEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/TriggerableWorldEvent.java deleted file mode 100644 index e9c3f9130..000000000 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/TriggerableWorldEvent.java +++ /dev/null @@ -1,10 +0,0 @@ -package mineplex.gemhunters.worldevent; - -import mineplex.core.updater.event.UpdateEvent; - -public abstract class TriggerableWorldEvent extends WorldEvent -{ - - public abstract boolean onTriggerCheck(UpdateEvent event); - -} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEvent.java index 0ef3ef3f2..1b1ecf4ac 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEvent.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEvent.java @@ -1,21 +1,53 @@ package mineplex.gemhunters.worldevent; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import mineplex.core.Managers; +import mineplex.core.common.util.UtilServer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.world.WorldDataModule; public abstract class WorldEvent implements Listener { - protected WorldEventModule _worldEventModule; + private final WorldEventType _eventType; - public WorldEvent() + private WorldEventState _eventState; + + protected final WorldDataModule _worldData; + protected final WorldEventModule _worldEvent; + + protected final Set _entities; + + protected final long _start; + private long _complete; + + public WorldEvent(WorldEventType eventType) { - _worldEventModule = Managers.get(WorldEventModule.class); + _eventType = eventType; + _eventState = null; + + _worldData = Managers.get(WorldDataModule.class); + _worldEvent = Managers.get(WorldEventModule.class); + + _entities = new HashSet<>(); + _start = System.currentTimeMillis(); + + _worldEvent.registerEvents(this); } public abstract void onStart(); + public abstract boolean checkToEnd(); + public abstract void onEnd(); public final void start() @@ -25,7 +57,73 @@ public abstract class WorldEvent implements Listener public final void end() { + _complete = System.currentTimeMillis(); + + for (LivingEntity entity : _entities) + { + entity.damage(Double.MAX_VALUE); + } + + UtilServer.Unregister(this); + onEnd(); } + @EventHandler + public void updateEntities(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + { + return; + } + + Iterator iterator = _entities.iterator(); + + while (iterator.hasNext()) + { + Entity entity = iterator.next(); + + if (entity.isDead() || !entity.isValid()) + { + entity.remove(); + iterator.remove(); + } + } + } + + public void addEntity(LivingEntity entity) + { + _entities.add(entity); + } + + public WorldEventType getEventType() + { + return _eventType; + } + + public void setEventState(WorldEventState eventState) + { + _eventState = eventState; + + switch (eventState) + { + case WARMUP: + start(); + break; + case COMPLETE: + end(); + default: + break; + } + } + + public WorldEventState getEventState() + { + return _eventState; + } + + public long getCompleteTime() + { + return _complete; + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java index 26c859e9d..8c091f2b1 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java @@ -1,27 +1,32 @@ package mineplex.gemhunters.worldevent; import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; +import java.util.Set; import java.util.concurrent.TimeUnit; import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; -import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilTime; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.worldevent.command.WorldEventCommand; @ReflectivelyCreateMiniPlugin public class WorldEventModule extends MiniPlugin { private static final long EVENT_TIMER = TimeUnit.MINUTES.toMillis(15); - + private static final long COMPLETE_TIMER = TimeUnit.SECONDS.toMillis(30); + private final List _events; private long _lastEventComplete; + private int _lastEventId; private WorldEventModule() { @@ -34,21 +39,41 @@ public class WorldEventModule extends MiniPlugin @Override public void addCommands() { - + addCommand(new WorldEventCommand(this)); } public void startEvent(WorldEventType eventType) { WorldEvent event = eventType.createInstance(); + + _events.add(event); + _lastEventId = eventType.ordinal(); - event.start(); + event.setEventState(WorldEventState.WARMUP); } public void startRandomEvent() { WorldEventType[] eventTypes = WorldEventType.values(); - startEvent(eventTypes[UtilMath.r(eventTypes.length)]); + Set possibleWorldEvents = new HashSet<>(); + + for (WorldEventType eventType : eventTypes) + { + if (_lastEventId == eventType.ordinal() || eventType.isMajor() || eventType.isTriggerable()) + { + continue; + } + + possibleWorldEvents.add(eventType); + } + + if (possibleWorldEvents.isEmpty()) + { + return; + } + + startEvent(UtilAlg.Random(possibleWorldEvents)); } @EventHandler @@ -59,20 +84,59 @@ public class WorldEventModule extends MiniPlugin return; } + Iterator iterator = _events.iterator(); + + while (iterator.hasNext()) + { + WorldEvent worldEvent = iterator.next(); + + if (worldEvent.getEventState() == WorldEventState.COMPLETE && UtilTime.elapsed(worldEvent.getCompleteTime(), COMPLETE_TIMER)) + { + if (!worldEvent.getEventType().isTriggerable()) + { + _lastEventComplete = System.currentTimeMillis(); + } + + iterator.remove(); + } + + if (worldEvent.getEventState() == WorldEventState.LIVE && worldEvent.checkToEnd()) + { + worldEvent.setEventState(WorldEventState.COMPLETE); + } + } + if (UtilTime.elapsed(_lastEventComplete, EVENT_TIMER)) { - + startRandomEvent(); } } - @EventHandler - public void test(PlayerCommandPreprocessEvent event) - { - if (event.getMessage().startsWith("/test")) + public boolean isMajorEventActive() + { + for (WorldEvent event : _events) { - event.setCancelled(true); - startEvent(WorldEventType.GIANT); + if (event.getEventType().isMajor()) + { + return true; + } } + + return false; } + public List getActiveEvents() + { + return _events; + } + + public long getLastEventComplete() + { + return _lastEventComplete; + } + + public long getEventTimer() + { + return EVENT_TIMER; + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventState.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventState.java index 87ed9b9f4..81e322a47 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventState.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventState.java @@ -3,7 +3,13 @@ package mineplex.gemhunters.worldevent; public enum WorldEventState { + WARMUP, + LIVE, + COMPLETE; - + public String getName() + { + return Character.toUpperCase(name().charAt(0)) + name().substring(1); + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java index 7a2518967..4e7b1fe18 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java @@ -5,22 +5,25 @@ import mineplex.gemhunters.worldevent.giant.GiantWorldEvent; public enum WorldEventType { - GIANT("Giant", GiantWorldEvent.class, true); + GIANT("Zombie Awakening", GiantWorldEvent.class, true, false); private String _name; private Class _clazz; - private boolean _major; + private boolean _major, _triggerable; + private long _last; private WorldEventType(String name, Class clazz) { - this(name, clazz, false); + this(name, clazz, false, false); } - private WorldEventType(String name, Class clazz, boolean major) + private WorldEventType(String name, Class clazz, boolean major, boolean triggerable) { _name = name; _clazz = clazz; _major = major; + _triggerable = triggerable; + _last = 0; } @SuppressWarnings("unchecked") @@ -28,7 +31,8 @@ public enum WorldEventType { try { - return (T) _clazz.newInstance(); + _last = System.currentTimeMillis(); + return (T) _clazz.getConstructor(this.getClass()).newInstance(this); } catch (Exception e) { @@ -47,5 +51,15 @@ public enum WorldEventType { return _major; } + + public boolean isTriggerable() + { + return _triggerable; + } + + public long getLast() + { + return _last; + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/AddCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/AddCommand.java deleted file mode 100644 index 167f475b8..000000000 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/AddCommand.java +++ /dev/null @@ -1,6 +0,0 @@ -package mineplex.gemhunters.worldevent.command; - -public class AddCommand -{ - -} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/StartCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/StartCommand.java new file mode 100644 index 000000000..6290b4ee5 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/StartCommand.java @@ -0,0 +1,48 @@ +package mineplex.gemhunters.worldevent.command; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.gemhunters.worldevent.WorldEventModule; +import mineplex.gemhunters.worldevent.WorldEventType; + +public class StartCommand extends CommandBase +{ + + public StartCommand(WorldEventModule plugin) + { + super(plugin, Rank.ADMIN, "start"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args.length == 0) + { + caller.sendMessage(F.main(Plugin.getName(), "Starting a random world event.")); + Plugin.startRandomEvent(); + return; + } + + for (WorldEventType eventType : WorldEventType.values()) + { + if (args[0].equalsIgnoreCase(eventType.name())) + { + caller.sendMessage(F.main(Plugin.getName(), "Starting the " + F.elem(eventType.name()) + " world event.")); + Plugin.startEvent(eventType); + return; + } + } + + caller.sendMessage(F.main(Plugin.getName(), "I wasn\'t able to find a world event by the name " + F.elem(args[0]) + ". Possible values:")); + + for (WorldEventType eventType : WorldEventType.values()) + { + caller.sendMessage(C.cGray + "- " + F.elem(eventType.name())); + } + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/StopCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/StopCommand.java new file mode 100644 index 000000000..0c2887354 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/StopCommand.java @@ -0,0 +1,53 @@ +package mineplex.gemhunters.worldevent.command; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.gemhunters.worldevent.WorldEvent; +import mineplex.gemhunters.worldevent.WorldEventModule; +import mineplex.gemhunters.worldevent.WorldEventState; + +public class StopCommand extends CommandBase +{ + + public StopCommand(WorldEventModule plugin) + { + super(plugin, Rank.ADMIN, "stop"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args.length == 0) + { + caller.sendMessage(F.main(Plugin.getName(), "Stopping all world events.")); + + for (WorldEvent event : Plugin.getActiveEvents()) + { + event.setEventState(WorldEventState.COMPLETE); + } + return; + } + + for (WorldEvent event : Plugin.getActiveEvents()) + { + if (args[0].equalsIgnoreCase(event.getEventType().name()) && event.getEventState() != WorldEventState.COMPLETE) + { + caller.sendMessage(F.main(Plugin.getName(), "Stopping " + F.elem(event.getEventType().name()) + ".")); + event.setEventState(WorldEventState.COMPLETE); + return; + } + } + + caller.sendMessage(F.main(Plugin.getName(), "I wasn\'t able to find an active world event by the name " + F.elem(args[0]) + ". Possible values:")); + + for (WorldEvent event : Plugin.getActiveEvents()) + { + caller.sendMessage(C.cGray + "- " + F.elem(event.getEventType().name())); + } + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/WorldEventCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/WorldEventCommand.java index fb77d9063..9669379b4 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/WorldEventCommand.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/command/WorldEventCommand.java @@ -13,14 +13,17 @@ public class WorldEventCommand extends MultiCommandBase public WorldEventCommand(WorldEventModule plugin) { super(plugin, Rank.ADMIN, "worldevent", "we"); + + AddCommand(new StartCommand(plugin)); + AddCommand(new StopCommand(plugin)); } @Override protected void Help(Player caller, String[] args) { - caller.sendMessage(F.help("/" + _aliasUsed + " start", "Start a World Event", Rank.ADMIN)); - caller.sendMessage(F.help("/" + _aliasUsed + " clear", "Clears all World Events", Rank.ADMIN)); - caller.sendMessage(F.help("/" + _aliasUsed + " random", "Starts a random World Event", Rank.ADMIN)); + caller.sendMessage(F.main(Plugin.getName(), "Command List:")); + caller.sendMessage(F.help("/" + _aliasUsed + " start [name]", "Starts a world event. Leaving [name] blank picks a random one.", Rank.ADMIN)); + caller.sendMessage(F.help("/" + _aliasUsed + " stop [name]", "Stops a world event. Leaving [name] blank stops all events.", Rank.ADMIN)); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/CustomGiant.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/CustomGiant.java index f8efaab00..104cf9c46 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/CustomGiant.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/CustomGiant.java @@ -17,6 +17,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.util.Vector; import mineplex.core.Managers; +import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilMath; @@ -24,48 +25,68 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.gemhunters.worldevent.WorldEventModule; +import mineplex.gemhunters.safezone.SafezoneModule; +import mineplex.gemhunters.world.WorldDataModule; public class CustomGiant implements Listener { private static final int GIANT_HEALTH = 100; - private static final int DESTORY_BLOCK_RADIUS = 7; - private static final float DESTORY_FALLING_BLOCK_CHANCE = 0.05F; + private static final int GIANT_WIDTH = 5; + private static final int GIANT_HEIGHT = 13; + private static final float DESTORY_FALLING_BLOCK_CHANCE = 0.04F; + private static final float MOVE_FACTOR = 0.3F; + private static final int MAX_SEARCH_DISTANCE_SQUARED = 2500; + + private final SafezoneModule _safezone; private final Monster _giant; - - private Player _target; - + + private final Location _fallback; + private Location _target; + public CustomGiant(Location spawn) { + _safezone = Managers.get(SafezoneModule.class); + _giant = spawn.getWorld().spawn(spawn, Giant.class); - + _giant.setMaxHealth(GIANT_HEALTH); _giant.setHealth(_giant.getMaxHealth()); - + _giant.setRemoveWhenFarAway(false); + UtilEnt.vegetate(_giant); - UtilEnt.setStepHeight(_giant, 2); - Managers.get(WorldEventModule.class).registerEvents(this); + _fallback = Managers.get(WorldDataModule.class).getCustomLocation("CENTER").get(0); } - + @EventHandler public void updateMovement(UpdateEvent event) { - if (event.getType() != UpdateType.SEC || Bukkit.getOnlinePlayers().isEmpty()) + if (event.getType() != UpdateType.FASTEST || Bukkit.getOnlinePlayers().isEmpty()) + { + if (event.getType() == UpdateType.SEC) + { + _target = acquireTarget(); + } + + return; + } + + if (_target == null) { return; } - if (_target == null) - { - _target = acquireTarget(); - } - - UtilEnt.CreatureMove(_giant, _target.getLocation(), 0.5F); + Vector direction = UtilAlg.getTrajectory2d(_giant.getLocation(), _target).multiply(MOVE_FACTOR); + Location toTeleport = _giant.getLocation().add(direction); + + toTeleport.setYaw(UtilAlg.GetYaw(direction)); + toTeleport.setPitch(UtilAlg.GetPitch(direction)); + + _giant.teleport(toTeleport); } - + @EventHandler public void updateBlockDestrory(UpdateEvent event) { @@ -73,22 +94,22 @@ public class CustomGiant implements Listener { return; } - - for (Block block : UtilBlock.getInBoundingBox(_giant.getLocation().subtract(5, 0, 5), _giant.getLocation().add(5, 13, 5))) + + for (Block block : UtilBlock.getInBoundingBox(_giant.getLocation().subtract(GIANT_WIDTH, 0, GIANT_WIDTH), _giant.getLocation().add(GIANT_WIDTH, GIANT_HEIGHT, GIANT_WIDTH))) { if (Math.random() < DESTORY_FALLING_BLOCK_CHANCE) { FallingBlock fallingBlock = block.getWorld().spawnFallingBlock(block.getLocation(), block.getType(), block.getData()); - + fallingBlock.setDropItem(false); fallingBlock.setHurtEntities(false); fallingBlock.setVelocity(new Vector(UtilMath.random(-1, 1), UtilMath.random(0.5, 1), UtilMath.random(-1, 1))); } - + block.setType(Material.AIR); } } - + @EventHandler public void playerQuit(PlayerQuitEvent event) { @@ -97,21 +118,32 @@ public class CustomGiant implements Listener _target = acquireTarget(); } } - - public Player acquireTarget() + + public Location acquireTarget() { Collection ignore = new ArrayList<>(); - + for (Player player : UtilServer.getPlayers()) { - if (UtilPlayer.isSpectator(player)) + if (UtilPlayer.isSpectator(player) || _safezone.getSafezone(player.getLocation()) != null) { ignore.add(player); } } - - return UtilPlayer.getClosest(_giant.getLocation(), ignore); + + Player player = UtilPlayer.getClosest(_giant.getLocation(), ignore); + + if (player == null) + { + return _fallback; + } + + return UtilMath.offsetSquared(_giant, player) > MAX_SEARCH_DISTANCE_SQUARED ? _fallback : player.getLocation(); } - - + + public Monster getGiant() + { + return _giant; + } + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/GiantWorldEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/GiantWorldEvent.java index 29ab6f383..bfd803be9 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/GiantWorldEvent.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/GiantWorldEvent.java @@ -1,21 +1,91 @@ package mineplex.gemhunters.worldevent.giant; -import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Zombie; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityCombustEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilTime; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.worldevent.WorldEvent; +import mineplex.gemhunters.worldevent.WorldEventState; +import mineplex.gemhunters.worldevent.WorldEventType; public class GiantWorldEvent extends WorldEvent { + private static final int MINI_ZOMBIES = 10; + private static final int MINI_ZOMBIES_MAX_DISTANCE_SQUARED = 900; + private static final int MAX_TIME = 180000; + + private CustomGiant _giant; + + public GiantWorldEvent(WorldEventType eventType) + { + super(eventType); + } + @Override public void onStart() { - new CustomGiant(Bukkit.getPlayer("Moppletop").getLocation()); + _giant = new CustomGiant(_worldData.getCustomLocation("GIANT_SPAWN").get(0)); + addEntity(_giant.getGiant()); + + _worldEvent.registerEvents(_giant); + + setEventState(WorldEventState.LIVE); } + @Override + public boolean checkToEnd() + { + return UtilTime.elapsed(_start, MAX_TIME) || _giant.getGiant().isDead() || !_giant.getGiant().isValid(); + } + @Override public void onEnd() - { + { + } + + @EventHandler + public void zombieCombust(EntityCombustEvent event) + { + if (_entities.contains(event.getEntity())) + { + event.setCancelled(true); + } + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC || _giant == null) + { + return; + } + + for (Entity entity : _entities) + { + if (UtilMath.offsetSquared(entity, _giant.getGiant()) > MINI_ZOMBIES_MAX_DISTANCE_SQUARED) + { + entity.teleport(_giant.getGiant()); + } + } + + // -1 for the giant + if (_entities.size() - 1 < MINI_ZOMBIES) + { + Zombie zombie = _worldData.World.spawn(_giant.getGiant().getLocation(), Zombie.class); + + zombie.setRemoveWhenFarAway(false); + zombie.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1)); + + addEntity(zombie); + } } } diff --git a/Plugins/mineplex-google-sheets/pom.xml b/Plugins/mineplex-google-sheets/pom.xml new file mode 100644 index 000000000..864b42200 --- /dev/null +++ b/Plugins/mineplex-google-sheets/pom.xml @@ -0,0 +1,61 @@ + + 4.0.0 + + + com.mineplex + mineplex-plugin + dev-SNAPSHOT + ../plugin.xml + + + Google Sheets + mineplex-google-sheets + + + + org.json + json + 20160212 + compile + + + com.google.api-client + google-api-client + 1.22.0 + compile + + + com.google.oauth-client + google-oauth-client-jetty + 1.22.0 + compile + + + com.google.apis + google-api-services-sheets + v4-rev20-1.22.0 + compile + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + lib/ + mineplex.googlesheets.GoogleSheetController + + + + + + + + \ No newline at end of file diff --git a/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/GoogleSheetController.java b/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/GoogleSheetController.java new file mode 100644 index 000000000..0a1c0d213 --- /dev/null +++ b/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/GoogleSheetController.java @@ -0,0 +1,63 @@ +package mineplex.googlesheets; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +import org.json.JSONObject; + +public class GoogleSheetController +{ + + private static final int SLEEP_TIME = 2000; + private static final String DATA_STORE_DIR = ".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "files"; + + public static void main(String[] args) throws InterruptedException + { + System.out.println("Loading Sheet Provider"); + SheetProvider provider = new SheetProvider(); + System.out.println("Loaded Sheet Provider"); + + for (SpreadsheetType type : SpreadsheetType.values()) + { + System.out.println("Sleeping..."); + Thread.sleep(SLEEP_TIME); + System.out.println("Getting data for " + type.name() + " (" + type.getID() + ")"); + + JSONObject object = provider.asJSONObject(type); + + 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"); + dir.mkdirs(); + } + + try + { + System.out.println("Deleting"); + 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(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/google/GoogleSheetProvider.java b/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/SheetProvider.java similarity index 50% rename from Plugins/Mineplex.Core.Common/src/mineplex/core/common/google/GoogleSheetProvider.java rename to Plugins/mineplex-google-sheets/src/mineplex/googlesheets/SheetProvider.java index 342a7abd2..7d7859c49 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/google/GoogleSheetProvider.java +++ b/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/SheetProvider.java @@ -1,4 +1,4 @@ -package mineplex.core.common.google; +package mineplex.googlesheets; import java.io.File; import java.io.FileInputStream; @@ -6,7 +6,12 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; + +import org.json.JSONArray; +import org.json.JSONObject; import com.google.api.client.auth.oauth2.Credential; import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp; @@ -20,24 +25,17 @@ import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.client.util.store.FileDataStoreFactory; import com.google.api.services.sheets.v4.Sheets; import com.google.api.services.sheets.v4.SheetsScopes; -import com.google.api.services.sheets.v4.model.AddSheetRequest; -import com.google.api.services.sheets.v4.model.BatchUpdateSpreadsheetRequest; -import com.google.api.services.sheets.v4.model.GridProperties; -import com.google.api.services.sheets.v4.model.GridRange; -import com.google.api.services.sheets.v4.model.MergeCellsRequest; -import com.google.api.services.sheets.v4.model.Request; -import com.google.api.services.sheets.v4.model.SheetProperties; +import com.google.api.services.sheets.v4.model.Sheet; import com.google.api.services.sheets.v4.model.Spreadsheet; -import com.google.api.services.sheets.v4.model.ValueRange; -public class GoogleSheetProvider +public class SheetProvider { /** Application name. */ private static final String APPLICATION_NAME = "Mineplex Google Sheets"; /** Directory to store user credentials for this application. */ - private static final File DATA_STORE_DIR = new java.io.File(".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "files"); + private static final File DATA_STORE_DIR = new File(".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "files"); /** Global instance of the {@link FileDataStoreFactory}. */ private static FileDataStoreFactory DATA_STORE_FACTORY; @@ -52,26 +50,28 @@ public class GoogleSheetProvider private Sheets _service; private Credential _credential; - + static { try { HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR); - } catch (Throwable t) + } + catch (Throwable t) { t.printStackTrace(); } } - public GoogleSheetProvider() + public SheetProvider() { try { _credential = authorize(); _service = getSheetsService(); - } catch (IOException e) + } + catch (IOException e) { e.printStackTrace(); } @@ -106,67 +106,55 @@ public class GoogleSheetProvider return new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, _credential).setApplicationName(APPLICATION_NAME).build(); } - public void create(String spreadsheetID, String name, int id, int maxColumn, int maxRow) throws IOException + public JSONObject asJSONObject(SpreadsheetType spreadsheet) { - BatchUpdateSpreadsheetRequest spreadsheetRequest = new BatchUpdateSpreadsheetRequest(); - Request request = new Request(); - AddSheetRequest addSheetRequest = new AddSheetRequest(); - SheetProperties sheetProperties = new SheetProperties(); - GridProperties gridProperties = new GridProperties(); + JSONObject parent = new JSONObject(); + JSONArray array = new JSONArray(); + Map>> valuesMap = get(spreadsheet); + + for (String sheetName : valuesMap.keySet()) + { + List> values = valuesMap.get(sheetName); + + JSONObject object = new JSONObject(); + + object.put("name", sheetName); + object.put("values", values); + + array.put(object); + } + + parent.put("data", array); + return parent; + } + + public Map>> get(SpreadsheetType spreadsheet) + { + try + { + Spreadsheet googleSpreadsheet = _service.spreadsheets().get(spreadsheet.getID()).execute(); + Map>> valuesMap = new HashMap<>(googleSpreadsheet.getSheets().size() - 1); - gridProperties.setColumnCount(maxColumn); - gridProperties.setRowCount(maxRow); + for (Sheet sheet : googleSpreadsheet.getSheets()) + { + String name = sheet.getProperties().getTitle(); - sheetProperties.setGridProperties(gridProperties); - sheetProperties.setTitle(name); - sheetProperties.setSheetId(id); + valuesMap.put(name, get(spreadsheet, name)); + } - addSheetRequest.setProperties(sheetProperties); + return valuesMap; + } + catch (IOException e) + { + e.printStackTrace(); + } - request.setAddSheet(addSheetRequest); - - spreadsheetRequest.setRequests(Arrays.asList(request)); - _service.spreadsheets().batchUpdate(spreadsheetID, spreadsheetRequest).execute(); + return null; } - public void write(String spreadsheetID, String sheetName, String range, List> values) throws IOException + public List> get(SpreadsheetType spreadsheet, String sheetName) throws IOException { - ValueRange valueRange = new ValueRange(); - - valueRange.setValues(values); - - _service.spreadsheets().values().update(spreadsheetID, sheetName + "!" + range, valueRange).setValueInputOption("RAW").execute(); - } - - public void merge(String spreadsheetID, String sheetName, int id, String mergeType, int startRow, int endRow, int startColumn, int endColumn) throws IOException - { - BatchUpdateSpreadsheetRequest spreadsheetRequest = new BatchUpdateSpreadsheetRequest(); - Request request = new Request(); - MergeCellsRequest mergeCellsRequest = new MergeCellsRequest(); - GridRange gridRange = new GridRange(); - - gridRange.setSheetId(id); - - gridRange.setStartRowIndex(startRow); - gridRange.setEndRowIndex(endRow); - - gridRange.setStartColumnIndex(startColumn); - gridRange.setEndColumnIndex(endColumn); - - mergeCellsRequest.setMergeType(mergeType); - mergeCellsRequest.setRange(gridRange); - - request.setMergeCells(mergeCellsRequest); - - spreadsheetRequest.setRequests(Arrays.asList(request)); - _service.spreadsheets().batchUpdate(spreadsheetID, spreadsheetRequest).execute(); - } - - public int getNextSheetID(String spreadsheetID) throws IOException - { - Spreadsheet spreadsheet = _service.spreadsheets().get(spreadsheetID).execute(); - - return spreadsheet.getSheets().size(); + return _service.spreadsheets().values().get(spreadsheet.getID(), sheetName).execute().getValues(); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/google/MineplexGoogleSheet.java b/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/SpreadsheetType.java similarity index 64% rename from Plugins/Mineplex.Core/src/mineplex/core/google/MineplexGoogleSheet.java rename to Plugins/mineplex-google-sheets/src/mineplex/googlesheets/SpreadsheetType.java index 3bc9ea265..854bd31b2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/google/MineplexGoogleSheet.java +++ b/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/SpreadsheetType.java @@ -1,11 +1,9 @@ -package mineplex.core.google; +package mineplex.googlesheets; /** - * An enum containing all the google spreadsheet links relating to Mineplex.
- *
- * This should really be changed to a config. + * An enum containing all the google spreadsheet links relating to Mineplex.
*/ -public enum MineplexGoogleSheet +public enum SpreadsheetType { GEM_HUNTERS_CHESTS("11Noztgbpu_gUKkc5F4evKKfyxS-Jv1coE0IrBToX_gg"), @@ -14,7 +12,7 @@ public enum MineplexGoogleSheet private String _id; - private MineplexGoogleSheet(String id) + private SpreadsheetType(String id) { _id = id; } diff --git a/Plugins/pom.xml b/Plugins/pom.xml index 2efe84ed8..57017c27a 100644 --- a/Plugins/pom.xml +++ b/Plugins/pom.xml @@ -40,6 +40,7 @@ mavericks-review-hub mineplex-game-gemhunters + mineplex-google-sheets From a16acedb144041c678cedfab7cd7c7184be85830 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 20 Jan 2017 20:08:24 +0000 Subject: [PATCH 016/101] Google Sheets v2 finally --- .../core/google/GoogleSheetsManager.java | 53 +---- .../core/google/SheetObjectDeserialiser.java | 8 + .../mineplex/core/itemstack/ItemBuilder.java | 16 +- .../core/twofactor/TwoFactorAuth.java | 2 +- .../gemhunters/economy/EconomyModule.java | 4 +- .../gemhunters/loot/ChestProperties.java | 90 ++++++++ .../mineplex/gemhunters/loot/LootItem.java | 15 +- .../mineplex/gemhunters/loot/LootModule.java | 205 +++++++++--------- .../gemhunters/loot/SpawnedChest.java | 10 +- .../loot/command/UpdateLootCommand.java | 13 +- .../ChestPropertiesDeserialiser.java | 42 ++++ .../deserialisers/LootItemDeserialiser.java | 96 ++++++++ .../supplydrop/SupplyDropModule.java | 2 +- 13 files changed, 369 insertions(+), 187 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/google/SheetObjectDeserialiser.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/ChestProperties.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/ChestPropertiesDeserialiser.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/LootItemDeserialiser.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java b/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java index 383884f9f..634ea5e65 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java @@ -3,16 +3,11 @@ package mineplex.core.google; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; -import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; - -import org.bukkit.Bukkit; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -33,39 +28,36 @@ public class GoogleSheetsManager extends MiniPlugin super("Google Sheets"); } - public Map> getSheetData(String name, Class clazz) + public Map>> getSheetData(String name) { - return getSheetData(new File(DATA_STORE_DIR + File.separator + name + ".json"), clazz); + return getSheetData(new File(DATA_STORE_DIR + File.separator + name + ".json")); } - public Map> getSheetData(File file, Class clazz) + public Map>> getSheetData(File file) { if (!file.exists()) { - Bukkit.broadcastMessage("No file"); return null; } - Map> valuesMap = new HashMap<>(); + Map>> valuesMap = new HashMap<>(); try { JsonParser parser = new JsonParser(); JsonElement data = parser.parse(new FileReader(file)); JsonArray parent = data.getAsJsonObject().getAsJsonArray("data"); - - Bukkit.broadcastMessage("p=" + parent.size()); for (int i = 0; i < parent.size(); i++) { JsonObject sheet = parent.get(i).getAsJsonObject(); String name = sheet.get("name").getAsString(); JsonArray values = sheet.getAsJsonArray("values"); - List> valuesList = new ArrayList<>(values.size()); + List> valuesList = new ArrayList<>(values.size()); for (int j = 0; j < values.size(); j++) { - List list = new ArrayList<>(); + List list = new ArrayList<>(); Iterator iterator = values.get(j).getAsJsonArray().iterator(); while (iterator.hasNext()) @@ -77,44 +69,13 @@ public class GoogleSheetsManager extends MiniPlugin valuesList.add(list); } - valuesMap.put(name, toSet(valuesList, clazz)); + valuesMap.put(name, valuesList); } } catch (FileNotFoundException e) { - e.printStackTrace(); - } - - for (String key : valuesMap.keySet()) - { - Set set = valuesMap.get(key); - - for (T t : set) - { - Bukkit.broadcastMessage(t.toString()); - } } return valuesMap; } - - public Set toSet(List> values, Class clazz) - { - Set result = new HashSet<>(); - Constructor constructor = clazz.getConstructors()[0]; - - for (List objects : values) - { - try - { - result.add(clazz.cast(constructor.newInstance(objects))); - } - catch (Exception e) - { - continue; - } - } - - return result; - } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/google/SheetObjectDeserialiser.java b/Plugins/Mineplex.Core/src/mineplex/core/google/SheetObjectDeserialiser.java new file mode 100644 index 000000000..d254f7cf0 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/google/SheetObjectDeserialiser.java @@ -0,0 +1,8 @@ +package mineplex.core.google; + +public interface SheetObjectDeserialiser +{ + + public T deserialise(String[] values) throws ArrayIndexOutOfBoundsException; + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java index f506bfe18..14af0f28d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java @@ -53,6 +53,7 @@ public class ItemBuilder private int _amount; private Color _color; private short _data; + private short _durability; private final HashMap _enchants = new HashMap(); private final List _lore = new ArrayList(); private Material _mat; @@ -90,6 +91,7 @@ public class ItemBuilder _itemFlags.addAll(meta.getItemFlags()); _unbreakable = meta.spigot().isUnbreakable(); + _durability = item.getDurability(); } } @@ -108,6 +110,7 @@ public class ItemBuilder _mat = mat; _amount = amount; _data = data; + _durability = 0; } public ItemBuilder(Material mat, short data) @@ -115,6 +118,13 @@ public class ItemBuilder this(mat, 1, data); } + public ItemBuilder setDurability(short durability) + { + _durability = durability; + + return this; + } + public HashSet getItemFlags() { return _itemFlags; @@ -278,7 +288,8 @@ public class ItemBuilder item.addUnsafeEnchantments(_enchants); if (_glow) item.addEnchantment(UtilInv.getDullEnchantment(), 1); - + if (_durability != 0) item.setDurability(_durability); + return item; } @@ -298,7 +309,8 @@ public class ItemBuilder newBuilder.setColor(_color); // newBuilder.potion = potion; - + newBuilder.setDurability(_durability); + return newBuilder; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/twofactor/TwoFactorAuth.java b/Plugins/Mineplex.Core/src/mineplex/core/twofactor/TwoFactorAuth.java index 4b3245cee..55e3a82c5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/twofactor/TwoFactorAuth.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/twofactor/TwoFactorAuth.java @@ -172,7 +172,7 @@ public class TwoFactorAuth extends MiniClientPlugin player.sendMessage(F.main("2FA", "Setting up two-factor authentication.")); } - @EventHandler + //@EventHandler public void onJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java index 8e9f733fd..f6bd1021f 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -17,7 +17,6 @@ import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.F; import mineplex.core.google.GoogleSheetsManager; -import mineplex.gemhunters.loot.LootItem; @ReflectivelyCreateMiniPlugin public class EconomyModule extends MiniPlugin @@ -87,8 +86,7 @@ public class EconomyModule extends MiniPlugin { event.setCancelled(true); - require(GoogleSheetsManager.class).getSheetData("GEM_HUNTERS_CHESTS", LootItem.class); - //addToStore(event.getPlayer(), "Testing", 100); + addToStore(event.getPlayer(), "Testing", 100); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/ChestProperties.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/ChestProperties.java new file mode 100644 index 000000000..a808fce23 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/ChestProperties.java @@ -0,0 +1,90 @@ +package mineplex.gemhunters.loot; + +import org.bukkit.Material; + +public class ChestProperties +{ + + private final String _name; + private final Material _blockMaterial; + private final String _dataKey; + private final int _minAmount; + private final int _maxAmount; + private final int _spawnRate; + private final int _expireRate; + private final int _spawnRadius; + private final double _percentile; + + private long _lastSpawn; + + public ChestProperties(String name, Material blockMaterial, String dataKey, int minAmount, int maxAmount, int spawnRate, int expireRate, int spawnRadius, double percentile) + { + _name = name; + _blockMaterial = blockMaterial; + _dataKey = dataKey; + _minAmount = minAmount; + _maxAmount = maxAmount; + _spawnRate = spawnRate; + _expireRate = expireRate; + _spawnRadius = spawnRadius; + _percentile = percentile; + + setLastSpawn(); + } + + public final String getName() + { + return _name; + } + + public final Material getBlockMaterial() + { + return _blockMaterial; + } + + public final String getDataKey() + { + return _dataKey; + } + + public final int getMinAmount() + { + return _minAmount; + } + + public final int getMaxAmount() + { + return _maxAmount; + } + + public final int getSpawnRate() + { + return _spawnRate; + } + + public final int getExpireRate() + { + return _expireRate; + } + + public final int getSpawnRadius() + { + return _spawnRadius; + } + + public final double getPercentile() + { + return _percentile; + } + + public void setLastSpawn() + { + _lastSpawn = System.currentTimeMillis(); + } + + public long getLastSpawn() + { + return _lastSpawn; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java index 176420ef8..b2a4744d6 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java @@ -13,16 +13,11 @@ import mineplex.core.common.util.UtilMath; public class LootItem { - private ItemStack _itemStack; - private int _minAmount; - private int _maxAmount; - private double _probability; - private String _metadata; - - public LootItem(String... strings) - { - - } + private final ItemStack _itemStack; + private final int _minAmount; + private final int _maxAmount; + private final double _probability; + private final String _metadata; public LootItem(ItemStack itemStack, int minAmount, int maxAmount, double probability, String metadata) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index abdc1691e..74efe819d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -1,6 +1,7 @@ package mineplex.gemhunters.loot; -import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -19,7 +20,6 @@ import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.Chest; import org.bukkit.block.DoubleChest; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.inventory.InventoryClickEvent; @@ -32,41 +32,49 @@ import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilFirework; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilWorld; import mineplex.core.google.GoogleSheetsManager; -import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.slack.SlackAPI; +import mineplex.core.slack.SlackMessage; +import mineplex.core.slack.SlackTeam; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.economy.PlayerCashOutCompleteEvent; import mineplex.gemhunters.loot.command.UpdateLootCommand; +import mineplex.gemhunters.loot.deserialisers.ChestPropertiesDeserialiser; +import mineplex.gemhunters.loot.deserialisers.LootItemDeserialiser; import mineplex.gemhunters.loot.rewards.LootItemReward; import mineplex.gemhunters.loot.rewards.LootRankReward; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.world.WorldDataModule; -import net.md_5.bungee.api.ChatColor; @ReflectivelyCreateMiniPlugin public class LootModule extends MiniPlugin { + private static final String SHEET_FILE_NAME = "GEM_HUNTERS_CHESTS"; + private static final String CHEST_MASTER_SHEET_NAME = "CHEST_MASTER"; private static final int MINIMUM_CHEST_ITEMS = 3; private static final int MAXIMUM_CHEST_ITEMS = 6; private static final long CHEST_DESPAWN_TIME_OPENED = TimeUnit.SECONDS.toMillis(15); - private static final long CHEST_DESPAWN_TIME_NATURAL = TimeUnit.MINUTES.toMillis(30); private static final String[] IGNORED_COLOURS = { "RED" }; - private static final float MAX_CHESTS_FACTOR = 0.25F; private static final int MAX_SEARCH_ATTEMPTS = 40; private static final int MAX_CHEST_PLACEMENT_RANGE = 10; private static final int MAX_CHEST_CHECK_DISTANCE_SQUARED = 4; - + private static final LootItemDeserialiser DESERIALISER = new LootItemDeserialiser(); + private static final ChestPropertiesDeserialiser CHEST_DESERIALISER = new ChestPropertiesDeserialiser(); + 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 final GoogleSheetsManager _sheets; private final SafezoneModule _safezone; private final WorldDataModule _worldData; private final Map> _chestLoot; + private final Map _chestProperties; private final List _spawnedChest; private final Map> _spawnedIndexes; private final Set _itemRewards; @@ -79,11 +87,12 @@ public class LootModule extends MiniPlugin _safezone = require(SafezoneModule.class); _worldData = require(WorldDataModule.class); _chestLoot = new HashMap<>(); + _chestProperties = new HashMap<>(); _spawnedChest = new ArrayList<>(200); _spawnedIndexes = new HashMap<>(15); _itemRewards = new HashSet<>(); - //updateChestLoot(); + runSyncLater(() -> updateChestLoot(), 20); } @Override @@ -95,7 +104,7 @@ public class LootModule extends MiniPlugin @EventHandler public void updateSpawnChests(UpdateEvent event) { - if (event.getType() != UpdateType.SLOWER) + if (event.getType() != UpdateType.SEC) { return; } @@ -106,12 +115,13 @@ public class LootModule extends MiniPlugin while (iterator.hasNext()) { SpawnedChest chest = iterator.next(); + ChestProperties properties = chest.getProperties(); - if (chest.isOpened() && UtilTime.elapsed(chest.getOpenedAt(), CHEST_DESPAWN_TIME_OPENED) || UtilTime.elapsed(chest.getSpawnedAt(), CHEST_DESPAWN_TIME_NATURAL)) + if (chest.isOpened() && UtilTime.elapsed(chest.getOpenedAt(), CHEST_DESPAWN_TIME_OPENED) || UtilTime.elapsed(chest.getSpawnedAt(), properties.getExpireRate())) { if (chest.getID() != -1) { - _spawnedIndexes.get(chest.getColour()).remove(chest.getID()); + _spawnedIndexes.get(properties.getDataKey()).remove(chest.getID()); } Block block = chest.getLocation().getBlock(); @@ -128,7 +138,7 @@ public class LootModule extends MiniPlugin } // Spawn new chests - dataPointLoop: for (String key : _worldData.getAllDataLocations().keySet()) + dataPointLoop: for (String key : _chestProperties.keySet()) { // Some data points are ignored like the chest loot related to // supply drops. @@ -141,24 +151,26 @@ public class LootModule extends MiniPlugin } List locations = _worldData.getDataLocation(key); + ChestProperties properties = _chestProperties.get(key); // Only spawn more chests if we need to - int max = (int) (locations.size() * MAX_CHESTS_FACTOR); + int max = (int) (_spawnedChest.size() * properties.getPercentile()); int spawned = 0; for (SpawnedChest chest : _spawnedChest) { - if (chest.getColour().equals(key)) + if (chest.getProperties().getDataKey().equals(key)) { spawned++; } } + // TODO fix this // If there are too many chests of this type we can ignore it - if (spawned > max) - { - continue; - } + // if (spawned > max) + // { + // continue; + // } Set usedIndexes = _spawnedIndexes.get(key); @@ -209,9 +221,8 @@ public class LootModule extends MiniPlugin continue; } - //TODO remove debug message - Bukkit.broadcastMessage("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index); - _spawnedChest.add(new SpawnedChest(chestToPlace, key, index)); + Bukkit.broadcastMessage("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index + " and max=" + max); + _spawnedChest.add(new SpawnedChest(chestToPlace, properties, index)); block.setType(Material.CHEST); } } @@ -231,108 +242,75 @@ public class LootModule extends MiniPlugin public void updateChestLoot() { - Map>> map = null; + log("Updating chest loot"); + Map>> map = _sheets.getSheetData(SHEET_FILE_NAME); for (String key : map.keySet()) { - Set items = new HashSet<>(); - List> grid = map.get(key); - int index = 0; - - try + if (key.equals(CHEST_MASTER_SHEET_NAME)) { - for (List values : grid) + int row = 0; + + for (List rows : map.get(key)) { - if (index++ < 2) - { - continue; - } - - Material material = Material.valueOf(String.valueOf(values.get(0))); - byte data = Byte.parseByte(String.valueOf(values.get(1))); - int minAmount = 1; - int maxAmount = 1; - + row++; try { - String[] numbers = String.valueOf(values.get(2)).split("-"); - - if (numbers.length < 2) - { - minAmount = Integer.parseInt(String.valueOf(values.get(2))); - maxAmount = minAmount; - } - else - { - minAmount = Integer.parseInt(numbers[0]); - maxAmount = Integer.parseInt(numbers[1]); - } + ChestProperties properties = CHEST_DESERIALISER.deserialise(rows.toArray(new String[0])); + _chestProperties.put(properties.getDataKey(), properties); } - catch (NumberFormatException e) + catch (Exception e) { + if (row != 1) + { + reportParsingError(e, key, row); + } + continue; } - - ItemBuilder builder = new ItemBuilder(material, data); - - String title = ChatColor.translateAlternateColorCodes('&', String.valueOf(values.get(3))); - String[] lore = String.valueOf(values.get(4)).split(":"); - String[] colouredLore = new String[lore.length]; - - int loreIndex = 0; - for (String line : lore) - { - colouredLore[loreIndex++] = ChatColor.translateAlternateColorCodes('&', line); - } - - builder.setTitle(title); - builder.setLore(colouredLore); - - String[] enchants = String.valueOf(values.get(5)).split(","); - - for (String enchant : enchants) - { - String[] enchantData = enchant.split(":"); - - if (enchantData.length < 2) - { - continue; - } - - builder.addEnchantment(Enchantment.getByName(enchantData[0]), Integer.parseInt(enchantData[1])); - } - - double probability = Double.parseDouble(String.valueOf(values.get(6))); - String metadata = null; - - if (values.size() > 7) - { - metadata = String.valueOf(values.get(7)); - } - items.add(new LootItem(builder.build(), minAmount, maxAmount, probability, metadata)); } - _chestLoot.put(key, items); - } - catch (Exception e) - { - // TODO send slack message? - e.printStackTrace(); - log("An error occured while parsing spreadsheet data! " + key); continue; } + + Set items = new HashSet<>(); + + int row = 0; + + for (List rows : map.get(key)) + { + row++; + try + { + items.add(DESERIALISER.deserialise(rows.toArray(new String[0]))); + } + catch (Exception e) + { + if (row != 1) + { + reportParsingError(e, key, row); + } + + continue; + } + } + + _chestLoot.put(key, items); } + + log("Finished updating chest loot"); } public void addSpawnedChest(Location location, String colour) { - _spawnedChest.add(new SpawnedChest(location, colour, -1)); + _spawnedChest.add(new SpawnedChest(location, _chestProperties.get(colour), -1)); } public void fillChest(Player player, Block block, String key) { Set used = new HashSet<>(); Set items = _chestLoot.get(key); + ChestProperties properties = _chestProperties.get(key); int sizeMultiplier = 1; BlockState state = block.getState(); @@ -348,16 +326,17 @@ public class LootModule extends MiniPlugin inventory.clear(); - for (int i = 0; i < (MINIMUM_CHEST_ITEMS + UtilMath.r(MAXIMUM_CHEST_ITEMS - MINIMUM_CHEST_ITEMS + 1)) * sizeMultiplier; i++) + for (int i = 0; i < UtilMath.rRange(properties.getMinAmount(), properties.getMaxAmount()) * sizeMultiplier; i++) { LootItem lootItem = getRandomItem(items); ItemStack itemStack = lootItem.getItemStack(); int index = getFreeIndex(inventory.getSize(), used); - if (lootItem.getMetadata() != null) - { - UtilFirework.playFirework(block.getLocation().add(0.5, 1, 0.5), UtilFirework.getRandomFireworkEffect(false, 2, 1)); - } + // if (lootItem.getMetadata() != null) + // { + // UtilFirework.playFirework(block.getLocation().add(0.5, 1, 0.5), + // UtilFirework.getRandomFireworkEffect(false, 2, 1)); + // } inventory.setItem(index, itemStack); } @@ -455,7 +434,7 @@ public class LootModule extends MiniPlugin { if (UtilMath.offset(chest.getLocation(), block.getLocation()) < MAX_CHEST_CHECK_DISTANCE_SQUARED) { - key = chest.getColour(); + key = chest.getProperties().getDataKey(); chest.setOpened(); break; } @@ -495,10 +474,10 @@ public class LootModule extends MiniPlugin { return; } - + handleRewardItem(event.getPlayer(), event.getItem().getItemStack()); } - + public void handleRewardItem(Player player, ItemStack itemStack) { LootItem lootItem = fromItemStack(itemStack); @@ -507,7 +486,7 @@ public class LootModule extends MiniPlugin { return; } - + LootItemReward reward = null; for (LootItemReward storedReward : _itemRewards) @@ -553,4 +532,16 @@ public class LootModule extends MiniPlugin } } } + + private final void reportParsingError(Exception exception, String sheetName, int row) + { + try + { + SlackAPI.getInstance().sendMessage(SlackTeam.DEVELOPER, SLACK_CHANNEL_NAME, new SlackMessage(SLACK_USERNAME, new URL(SLACK_ICON), "A parsing error has occured on sheet *" + sheetName + "* at row *" + row + "*.\n Details: " + exception.getMessage()), true); + } + catch (MalformedURLException e) + { + e.printStackTrace(); + } + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/SpawnedChest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/SpawnedChest.java index 4294a9473..f0a8ae9dc 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/SpawnedChest.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/SpawnedChest.java @@ -6,16 +6,16 @@ public class SpawnedChest { private Location _location; - private String _colour; + private ChestProperties _properties; private int _id; private long _spawnedAt; private long _openedAt; - public SpawnedChest(Location location, String colour, int id) + public SpawnedChest(Location location, ChestProperties properties, int id) { _location = location; - _colour = colour; + _properties =properties; _id = id; _spawnedAt = System.currentTimeMillis(); _openedAt = 0; @@ -31,9 +31,9 @@ public class SpawnedChest return _location; } - public String getColour() + public ChestProperties getProperties() { - return _colour; + return _properties; } public int getID() diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java index f454e62c2..687fe92a2 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java @@ -2,12 +2,10 @@ package mineplex.gemhunters.loot.command; import org.bukkit.entity.Player; -import mineplex.core.Managers; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.F; import mineplex.gemhunters.loot.LootModule; -import mineplex.gemhunters.shop.ShopModule; /** * An ADMIN command that allows users to retrieve the latest data from the @@ -31,16 +29,7 @@ public class UpdateLootCommand extends CommandBase // TODO send redis message } - caller.sendMessage(F.main(Plugin.getName(), "Updating loot tables asynchronusly...")); - - final ShopModule shop = Managers.require(ShopModule.class); - - Plugin.runAsync(() -> { - Plugin.updateChestLoot(); - shop.updateVillagerLoot(); - }); - - caller.sendMessage(F.main(Plugin.getName(), "Finished!")); + caller.sendMessage(F.main(Plugin.getName(), "This command is currently disabled due to development issues.")); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/ChestPropertiesDeserialiser.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/ChestPropertiesDeserialiser.java new file mode 100644 index 000000000..464b14469 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/ChestPropertiesDeserialiser.java @@ -0,0 +1,42 @@ +package mineplex.gemhunters.loot.deserialisers; + +import org.bukkit.Material; + +import mineplex.core.google.SheetObjectDeserialiser; +import mineplex.gemhunters.loot.ChestProperties; + +public class ChestPropertiesDeserialiser implements SheetObjectDeserialiser +{ + + @Override + public ChestProperties deserialise(String[] values) throws ArrayIndexOutOfBoundsException + { + String name = values[0]; + Material blockMaterial = Material.valueOf(values[1]); + String dataKey = values[2]; + + int minAmount = 1; + int maxAmount = 1; + + String[] numbers = values[3].split("-"); + + if (numbers.length != 2) + { + minAmount = Integer.parseInt(String.valueOf(values[3])); + maxAmount = minAmount; + } + else + { + minAmount = Integer.parseInt(numbers[0]); + maxAmount = Integer.parseInt(numbers[1]); + } + + int spawnRate = Integer.parseInt(values[4]); + int expireRate = Integer.parseInt(values[5]); + int spawnRadius = Integer.parseInt(values[6]); + double percentile = (double) Integer.parseInt(values.length > 7 ? values[7] : "0") / 100; + + return new ChestProperties(name, blockMaterial, dataKey, minAmount, maxAmount, spawnRate, expireRate, spawnRadius, percentile); + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/LootItemDeserialiser.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/LootItemDeserialiser.java new file mode 100644 index 000000000..0fcbec32d --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/LootItemDeserialiser.java @@ -0,0 +1,96 @@ +package mineplex.gemhunters.loot.deserialisers; + +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; + +import mineplex.core.google.SheetObjectDeserialiser; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.gemhunters.loot.LootItem; +import net.md_5.bungee.api.ChatColor; + +/** + * This is a {@link LootItem} deserialiser for Google Sheet interpretation.
+ *
+ * Arguments should follow the form:
+ *
    + *
  • Material
  • + *
  • Material Data
  • + *
  • Max Durability
  • + *
  • Amount
  • + *
  • Item Name (optional)
  • + *
  • Item Lore (optional) each line separated by colons
  • + *
  • Enchantments (optional) Has a NAME:LEVEL format with multiple + * enchantments being separated by commas
  • + *
  • Probability
  • + *
  • Metadata (optional)
  • + *
+ * Thus derserialise is guaranteed to have at least 8 strings passed in.
+ * If an illegal argument is passed in, derserialise will throw an exception, + * these should be handled by the caller. + * + * @see SheetObjectDeserialiser + */ +public class LootItemDeserialiser implements SheetObjectDeserialiser +{ + + @Override + public LootItem deserialise(String[] values) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, NumberFormatException + { + Material material = Material.valueOf(values[0]); + byte data = values[1].equals("") ? 0 : Byte.parseByte(values[1]); + int minAmount = 1; + int maxAmount = 1; + short durability = values[2].equals("") ? 0 : Short.valueOf(values[3]); + + + String[] numbers = values[3].split("-"); + + if (numbers.length != 2) + { + minAmount = Integer.parseInt(values[3].equals("") ? "1" : values[3]); + maxAmount = minAmount; + } + else + { + minAmount = Integer.parseInt(numbers[0]); + maxAmount = Integer.parseInt(numbers[1]); + } + + ItemBuilder builder = new ItemBuilder(material, data); + + builder.setDurability(durability); + + String title = ChatColor.translateAlternateColorCodes('&', values[4]); + String[] lore = values[5].split(":"); + String[] colouredLore = new String[lore.length]; + + int loreIndex = 0; + for (String line : lore) + { + colouredLore[loreIndex++] = ChatColor.translateAlternateColorCodes('&', line); + } + + builder.setTitle(title); + builder.setLore(colouredLore); + + String[] enchants = String.valueOf(values[6]).split(","); + + for (String enchant : enchants) + { + String[] enchantData = enchant.split(":"); + + if (enchantData.length < 2) + { + continue; + } + + builder.addEnchantment(Enchantment.getByName(enchantData[0]), Integer.parseInt(enchantData[1])); + } + + double proability = Double.parseDouble(values[7]); + String metadata = values.length > 8 ? values[8] : null; + + return new LootItem(builder.build(), minAmount, maxAmount, proability, metadata); + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java index 5cd4030d7..0ce71a3f5 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java @@ -192,7 +192,7 @@ public class SupplyDropModule extends MiniPlugin } } - _locationKeys = supplyDropKeys.toArray(new String[supplyDropKeys.size()]); + _locationKeys = supplyDropKeys.toArray(new String[0]); } return _locationKeys; From f5e86f4bc10db2a7941cb5d66d29b548c78c8f3e Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 21 Jan 2017 14:21:00 +0000 Subject: [PATCH 017/101] Update Villager trading and Events --- .../gemhunters/economy/EconomyModule.java | 6 +- .../mineplex/gemhunters/loot/LootModule.java | 46 ++--- .../gemhunters/safezone/SafezoneModule.java | 9 +- .../scoreboard/GemHuntersScoreboard.java | 4 +- .../mineplex/gemhunters/shop/ShopModule.java | 165 +++++++----------- .../gemhunters/shop/TradeableItem.java | 21 ++- .../mineplex/gemhunters/shop/TraderNPC.java | 20 +-- .../gemhunters/spawn/SpawnModule.java | 11 +- .../gemhunters/util/SlackSheetsBot.java | 30 ++++ .../worldevent/WorldEventModule.java | 26 +-- .../worldevent/WorldEventPriority.java | 8 + .../gemhunters/worldevent/WorldEventType.java | 26 +-- .../worldevent/giant/CustomGiant.java | 26 ++- .../worldevent/giant/GiantWorldEvent.java | 4 +- .../googlesheets/GoogleSheetController.java | 2 +- .../googlesheets/SpreadsheetType.java | 2 +- 16 files changed, 205 insertions(+), 201 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SlackSheetsBot.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventPriority.java diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java index f6bd1021f..34f5b03b5 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -16,7 +16,6 @@ import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.F; -import mineplex.core.google.GoogleSheetsManager; @ReflectivelyCreateMiniPlugin public class EconomyModule extends MiniPlugin @@ -74,6 +73,11 @@ public class EconomyModule extends MiniPlugin } } + public void removeFromStore(Player player, int gems) + { + _storedGems.put(player.getUniqueId(), _storedGems.get(player.getUniqueId()) - gems); + } + public int getGems(Player player) { return _storedGems.get(player.getUniqueId()); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 74efe819d..2fe0c1f3d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -1,7 +1,5 @@ package mineplex.gemhunters.loot; -import java.net.MalformedURLException; -import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -22,6 +20,7 @@ import org.bukkit.block.Chest; import org.bukkit.block.DoubleChest; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerPickupItemEvent; @@ -32,13 +31,12 @@ import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilWorld; +import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.google.GoogleSheetsManager; -import mineplex.core.slack.SlackAPI; -import mineplex.core.slack.SlackMessage; -import mineplex.core.slack.SlackTeam; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.economy.PlayerCashOutCompleteEvent; @@ -48,6 +46,7 @@ import mineplex.gemhunters.loot.deserialisers.LootItemDeserialiser; import mineplex.gemhunters.loot.rewards.LootItemReward; import mineplex.gemhunters.loot.rewards.LootRankReward; import mineplex.gemhunters.safezone.SafezoneModule; +import mineplex.gemhunters.util.SlackSheetsBot; import mineplex.gemhunters.world.WorldDataModule; @ReflectivelyCreateMiniPlugin @@ -56,8 +55,6 @@ public class LootModule extends MiniPlugin private static final String SHEET_FILE_NAME = "GEM_HUNTERS_CHESTS"; private static final String CHEST_MASTER_SHEET_NAME = "CHEST_MASTER"; - private static final int MINIMUM_CHEST_ITEMS = 3; - private static final int MAXIMUM_CHEST_ITEMS = 6; private static final long CHEST_DESPAWN_TIME_OPENED = TimeUnit.SECONDS.toMillis(15); private static final String[] IGNORED_COLOURS = { "RED" }; private static final int MAX_SEARCH_ATTEMPTS = 40; @@ -65,9 +62,6 @@ public class LootModule extends MiniPlugin private static final int MAX_CHEST_CHECK_DISTANCE_SQUARED = 4; private static final LootItemDeserialiser DESERIALISER = new LootItemDeserialiser(); private static final ChestPropertiesDeserialiser CHEST_DESERIALISER = new ChestPropertiesDeserialiser(); - 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 final GoogleSheetsManager _sheets; private final SafezoneModule _safezone; @@ -153,6 +147,13 @@ public class LootModule extends MiniPlugin List locations = _worldData.getDataLocation(key); ChestProperties properties = _chestProperties.get(key); + if (!UtilTime.elapsed(properties.getLastSpawn(), properties.getSpawnRate())) + { + continue; + } + + properties.setLastSpawn(); + // Only spawn more chests if we need to int max = (int) (_spawnedChest.size() * properties.getPercentile()); int spawned = 0; @@ -223,7 +224,7 @@ public class LootModule extends MiniPlugin Bukkit.broadcastMessage("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index + " and max=" + max); _spawnedChest.add(new SpawnedChest(chestToPlace, properties, index)); - block.setType(Material.CHEST); + block.setType(properties.getBlockMaterial()); } } @@ -232,7 +233,7 @@ public class LootModule extends MiniPlugin Block up = block.getRelative(BlockFace.UP); Block down = block.getRelative(BlockFace.DOWN); - if (block.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block) || _safezone.getSafezone(block.getLocation()) != null) + if (block.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block) || _safezone.isInSafeZone(block.getLocation())) { return false; } @@ -263,7 +264,7 @@ public class LootModule extends MiniPlugin { if (row != 1) { - reportParsingError(e, key, row); + SlackSheetsBot.reportParsingError(e, "Chest Loot", key, row); } continue; @@ -274,7 +275,6 @@ public class LootModule extends MiniPlugin } Set items = new HashSet<>(); - int row = 0; for (List rows : map.get(key)) @@ -288,7 +288,7 @@ public class LootModule extends MiniPlugin { if (row != 1) { - reportParsingError(e, key, row); + SlackSheetsBot.reportParsingError(e, "Chest Loot", key, row); } continue; @@ -342,7 +342,7 @@ public class LootModule extends MiniPlugin } } - private LootItem getRandomItem(Set items) + public LootItem getRandomItem(Set items) { double totalWeight = 0; @@ -410,7 +410,7 @@ public class LootModule extends MiniPlugin @EventHandler public void chestOpen(PlayerInteractEvent event) { - if (event.isCancelled()) + if (event.isCancelled() || !UtilEvent.isAction(event, ActionType.R_BLOCK)) { return; } @@ -532,16 +532,4 @@ public class LootModule extends MiniPlugin } } } - - private final void reportParsingError(Exception exception, String sheetName, int row) - { - try - { - SlackAPI.getInstance().sendMessage(SlackTeam.DEVELOPER, SLACK_CHANNEL_NAME, new SlackMessage(SLACK_USERNAME, new URL(SLACK_ICON), "A parsing error has occured on sheet *" + sheetName + "* at row *" + row + "*.\n Details: " + exception.getMessage()), true); - } - catch (MalformedURLException e) - { - e.printStackTrace(); - } - } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java index 29a039970..ddd19b1d4 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java @@ -97,7 +97,7 @@ public class SafezoneModule extends MiniPlugin Player player = (Player) event.getEntity(); - if (getSafezone(player.getLocation()) != null) + if (isInSafeZone(player.getLocation())) { event.setCancelled(true); } @@ -113,12 +113,17 @@ public class SafezoneModule extends MiniPlugin Player player = (Player) event.getDamager(); - if (getSafezone(player.getLocation()) != null) + if (isInSafeZone(player.getLocation())) { event.setCancelled(true); } } + public boolean isInSafeZone(Location location) + { + return getSafezone(location) != null; + } + public boolean isInSafeZone(Location location, String safezone) { if (safezone == null) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java index e118c7121..e7bb5c153 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java @@ -28,14 +28,14 @@ public class GemHuntersScoreboard extends WritableMineplexScoreboard { writeNewLine(); - write(C.cGreenB + "Gems"); + write(C.cGreenB + "Gems Earned"); write(String.valueOf(_economy.getGems(player))); writeNewLine(); write(C.cYellowB + "World Event"); - if (!_worldEvent.isMajorEventActive()) + if (!_worldEvent.isEventActive()) { write(UtilTime.MakeStr(_worldEvent.getLastEventComplete() + _worldEvent.getEventTimer() - System.currentTimeMillis())); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java index 2dcb2045b..7428c26bf 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java @@ -7,30 +7,45 @@ import java.util.Map; import java.util.Set; import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Villager; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; -import com.google.common.collect.Sets; - import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilMath; import mineplex.core.google.GoogleSheetsManager; -import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.google.SheetObjectDeserialiser; +import mineplex.gemhunters.loot.deserialisers.LootItemDeserialiser; +import mineplex.gemhunters.safezone.SafezoneModule; +import mineplex.gemhunters.util.SlackSheetsBot; import mineplex.gemhunters.world.WorldDataModule; -import net.md_5.bungee.api.ChatColor; @ReflectivelyCreateMiniPlugin public class ShopModule extends MiniPlugin { + private static final String SHEET_FILE_NAME = "GEM_HUNTERS_SHOP"; + private static final LootItemDeserialiser DESERIALISER = new LootItemDeserialiser(); + private static final SheetObjectDeserialiser COST_DESERIALISER = new SheetObjectDeserialiser() + { + + @Override + public Integer deserialise(String[] values) throws ArrayIndexOutOfBoundsException, NumberFormatException + { + return Integer.parseInt(values[10]); + } + + }; + private static final int MINIMUM_ITEMS = 1; + private static final int MAXIMUM_ITEMS = 5; + private final GoogleSheetsManager _sheets; + private final SafezoneModule _safezone; private final WorldDataModule _worldData; - private final Map> _tradeItems; + private final Map> _trades; private boolean _npcsSpawned; @@ -39,110 +54,47 @@ public class ShopModule extends MiniPlugin super("Shop"); _sheets = require(GoogleSheetsManager.class); + _safezone = require(SafezoneModule.class); _worldData = require(WorldDataModule.class); - _tradeItems = new HashMap<>(); + _trades = new HashMap<>(); - //updateVillagerLoot(); + runSyncLater(() -> updateVillagerTrades(), 20); } - public void updateVillagerLoot() + public void updateVillagerTrades() { - Map>> map = null; + log("Updating villager trades"); + Map>> map = _sheets.getSheetData(SHEET_FILE_NAME); for (String key : map.keySet()) { Set items = new HashSet<>(); - List> grid = map.get(key); - int index = 0; + int row = 0; - try + for (List rows : map.get(key)) { - for (List values : grid) + row++; + try { - if (index++ < 2) - { - continue; - } - - log("Size = " + values.size()); - - Material material = Material.valueOf(String.valueOf(values.get(0))); - byte data = Byte.parseByte(String.valueOf(values.get(1))); - int minAmount = 1; - int maxAmount = 1; - - try - { - String[] numbers = String.valueOf(values.get(2)).split("-"); - - if (numbers.length < 2) - { - minAmount = Integer.parseInt(String.valueOf(values.get(2))); - maxAmount = minAmount; - } - else - { - minAmount = Integer.parseInt(numbers[0]); - maxAmount = Integer.parseInt(numbers[1]); - } - } - catch (NumberFormatException e) - { - continue; - } - - ItemBuilder builder = new ItemBuilder(material, data); - - String title = ChatColor.translateAlternateColorCodes('&', String.valueOf(values.get(3))); - String[] lore = String.valueOf(values.get(4)).split(":"); - String[] colouredLore = new String[lore.length]; - - int loreIndex = 0; - for (String line : lore) - { - colouredLore[loreIndex++] = ChatColor.translateAlternateColorCodes('&', line); - } - - builder.setTitle(title); - builder.setLore(colouredLore); - - String[] enchants = String.valueOf(values.get(5)).split(","); - - for (String enchant : enchants) - { - String[] enchantData = enchant.split(":"); - - if (enchantData.length < 2) - { - continue; - } - - builder.addEnchantment(Enchantment.getByName(enchantData[0]), Integer.parseInt(enchantData[1])); - } - - double probability = Double.parseDouble(String.valueOf(values.get(6))); - String metadata = null; - int cost = Integer.parseInt(String.valueOf(values.get(7))); - - if (values.size() > 8) - { - metadata = String.valueOf(values.get(8)); - } - - items.add(new TradeableItem(builder.build(), minAmount, maxAmount, probability, metadata, cost)); + String[] values = rows.toArray(new String[0]); + items.add(new TradeableItem(DESERIALISER.deserialise(values), COST_DESERIALISER.deserialise(values))); } + catch (Exception e) + { + if (row != 1) + { + SlackSheetsBot.reportParsingError(e, "Villager Trades", key, row); + } - _tradeItems.put(key, items); - } - catch (Exception e) - { - // TODO send slack message? - e.printStackTrace(); - log("An error occured while parsing spreadsheet data! " + key); - continue; + continue; + } } + + _trades.put(key, items); } + + log("Finished updating villager trades"); } @EventHandler @@ -155,18 +107,29 @@ public class ShopModule extends MiniPlugin _npcsSpawned = true; - for (String key : _worldData.getAllSpawnLocations().keySet()) + for (String key : _trades.keySet()) { - if (!_tradeItems.containsKey(key)) - { - continue; - } - for (Location location : _worldData.getSpawnLocation(key)) { - new TraderNPC(_plugin, location, Villager.class, "Bob", true, Sets.newHashSet(UtilAlg.Random(_tradeItems.get(key)))); + boolean vegetated = _safezone.isInSafeZone(location); + Set items = getRandomItemSet(_trades.get(key)); + + new TraderNPC(_plugin, location, Villager.class, "Sam", vegetated, items); } } } + + public Set getRandomItemSet(Set items) + { + int size = UtilMath.rRange(MINIMUM_ITEMS, MAXIMUM_ITEMS); + Set items2 = new HashSet<>(size); + + for (int i = 0; i < size; i++) + { + items2.add(UtilAlg.Random(items)); + } + + return items2; + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TradeableItem.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TradeableItem.java index 9af2d72c6..a43ab565c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TradeableItem.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TradeableItem.java @@ -1,21 +1,24 @@ package mineplex.gemhunters.shop; -import org.bukkit.inventory.ItemStack; - import mineplex.gemhunters.loot.LootItem; -public class TradeableItem extends LootItem +public class TradeableItem { - private int _cost; - - public TradeableItem(ItemStack itemStack, int minAmount, int maxAmount, double probability, String metadata, int cost) + private final LootItem _item; + private final int _cost; + + public TradeableItem(LootItem item, int cost) { - super(itemStack, minAmount, maxAmount, probability, metadata); - + _item = item; _cost = cost; } - + + public LootItem getLootItem() + { + return _item; + } + public int getCost() { return _cost; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java index cac169faa..05f42fef6 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java @@ -14,16 +14,13 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.Managers; -import mineplex.core.common.Pair; -import mineplex.core.common.currency.GlobalCurrency; -import mineplex.core.donation.DonationManager; -import mineplex.core.donation.Donor; +import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.util.SimpleNPC; public class TraderNPC extends SimpleNPC { - private final DonationManager _donation; + private final EconomyModule _economy; private final Set _selling; private final Inventory _inv; @@ -32,16 +29,16 @@ public class TraderNPC extends SimpleNPC { super(plugin, spawn, type, name, null, vegetated); - _donation = Managers.require(DonationManager.class); + _economy = Managers.require(EconomyModule.class); _selling = selling; _inv = plugin.getServer().createInventory(null, 9, name); int index = 1; - for (TradeableItem item : selling) + for (TradeableItem item : _selling) { - _inv.setItem(index++, item.getItemStack()); + _inv.setItem(index++, item.getLootItem().getItemStack()); } } @@ -78,8 +75,7 @@ public class TraderNPC extends SimpleNPC } Player player = (Player) event.getWhoClicked(); - Donor donor = _donation.Get(player); - int gems = donor.getBalance(GlobalCurrency.GEM); + int gems = _economy.getGems(player); int cost = fromItemStack(itemStack); if (cost == 0) @@ -95,7 +91,7 @@ public class TraderNPC extends SimpleNPC return; } - donor.addBalance(GlobalCurrency.GEM, -cost); + _economy.removeFromStore(player, cost); player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 1.2F); player.getInventory().addItem(itemStack); @@ -106,7 +102,7 @@ public class TraderNPC extends SimpleNPC { for (TradeableItem item : _selling) { - if (item.getItemStack().isSimilar(itemStack)) + if (item.getLootItem().getItemStack().isSimilar(itemStack)) { return item.getCost(); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index 8ad4004ee..f36eb8831 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -20,7 +20,6 @@ import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilEnt; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.util.ColouredTextAnimation; import mineplex.gemhunters.util.SimpleNPC; @@ -52,7 +51,7 @@ public class SpawnModule extends MiniPlugin { if (_spawn == null || _center == null) { - _spawn = _worldData.getSpawnLocation("Yellow").get(0); + _spawn = _worldData.getCustomLocation("PLAYER_SPAWN").get(0); _center = _worldData.getCustomLocation("CENTER").get(0); } @@ -70,9 +69,9 @@ public class SpawnModule extends MiniPlugin _npcsSpawned = true; - Location location = _worldData.getSpawnLocation("Purple").get(0); + Location location = _worldData.getCustomLocation("TELEPORT_NPC").get(0); - location.setYaw(UtilAlg.GetYaw(location.toVector())); + location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, _spawn))); new SimpleNPC(_plugin, location, Villager.class, C.cDRed + "! " + C.cRedB + "Enter The World" + C.cDRed + " !", new Callback() { @@ -99,7 +98,7 @@ public class SpawnModule extends MiniPlugin @Override public void run() - { + { if (animation.displayAsTitle(data)) { cancel(); @@ -115,7 +114,7 @@ public class SpawnModule extends MiniPlugin Block up = block.getRelative(BlockFace.UP); Block down = block.getRelative(BlockFace.DOWN); - if (block.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block) || _safezone.getSafezone(block.getLocation()) != null) + if (block.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block) || _safezone.isInSafeZone(block.getLocation())) { return false; } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SlackSheetsBot.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SlackSheetsBot.java new file mode 100644 index 000000000..7774a3003 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SlackSheetsBot.java @@ -0,0 +1,30 @@ +package mineplex.gemhunters.util; + +import java.net.MalformedURLException; +import java.net.URL; + +import mineplex.core.slack.SlackAPI; +import mineplex.core.slack.SlackMessage; +import mineplex.core.slack.SlackTeam; + +public class SlackSheetsBot +{ + + 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"; + + public static final void reportParsingError(Exception exception, String spreadsheetName, String sheetName, int row) + { + try + { + SlackAPI.getInstance().sendMessage(SlackTeam.DEVELOPER, SLACK_CHANNEL_NAME, new SlackMessage(SLACK_USERNAME, new URL(SLACK_ICON), "A parsing error has occured on spreadsheet *" + spreadsheetName + "* sheet *" + sheetName + "* at row *" + row + "*.\n Details: " + exception.getMessage()), + true); + } + catch (MalformedURLException e) + { + e.printStackTrace(); + } + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java index 8c091f2b1..eae2508b4 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java @@ -21,12 +21,12 @@ import mineplex.gemhunters.worldevent.command.WorldEventCommand; public class WorldEventModule extends MiniPlugin { - private static final long EVENT_TIMER = TimeUnit.MINUTES.toMillis(15); + private static final long EVENT_TIMER = TimeUnit.MINUTES.toMillis(30); + private static final long EVENT_COOLDOWN_TIMER = TimeUnit.MINUTES.toMillis(40); private static final long COMPLETE_TIMER = TimeUnit.SECONDS.toMillis(30); private final List _events; private long _lastEventComplete; - private int _lastEventId; private WorldEventModule() { @@ -47,7 +47,6 @@ public class WorldEventModule extends MiniPlugin WorldEvent event = eventType.createInstance(); _events.add(event); - _lastEventId = eventType.ordinal(); event.setEventState(WorldEventState.WARMUP); } @@ -60,7 +59,7 @@ public class WorldEventModule extends MiniPlugin for (WorldEventType eventType : eventTypes) { - if (_lastEventId == eventType.ordinal() || eventType.isMajor() || eventType.isTriggerable()) + if (UtilTime.elapsed(eventType.getLast(), EVENT_COOLDOWN_TIMER)) { continue; } @@ -92,31 +91,32 @@ public class WorldEventModule extends MiniPlugin if (worldEvent.getEventState() == WorldEventState.COMPLETE && UtilTime.elapsed(worldEvent.getCompleteTime(), COMPLETE_TIMER)) { - if (!worldEvent.getEventType().isTriggerable()) - { - _lastEventComplete = System.currentTimeMillis(); - } - iterator.remove(); } if (worldEvent.getEventState() == WorldEventState.LIVE && worldEvent.checkToEnd()) { + _lastEventComplete = System.currentTimeMillis(); worldEvent.setEventState(WorldEventState.COMPLETE); } } - if (UtilTime.elapsed(_lastEventComplete, EVENT_TIMER)) + if (!isEventActive() && UtilTime.elapsed(_lastEventComplete, EVENT_TIMER)) { startRandomEvent(); } } - public boolean isMajorEventActive() - { + public boolean isEventActive() + { + return !_events.isEmpty(); + } + + public boolean isGlboalEventActive() + { for (WorldEvent event : _events) { - if (event.getEventType().isMajor()) + if (event.getEventType().getPriority() == WorldEventPriority.GLOBAL) { return true; } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventPriority.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventPriority.java new file mode 100644 index 000000000..cfc826987 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventPriority.java @@ -0,0 +1,8 @@ +package mineplex.gemhunters.worldevent; + +public enum WorldEventPriority +{ + + GLOBAL, ISOLATED + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java index 4e7b1fe18..8188dc114 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java @@ -5,24 +5,18 @@ import mineplex.gemhunters.worldevent.giant.GiantWorldEvent; public enum WorldEventType { - GIANT("Zombie Awakening", GiantWorldEvent.class, true, false); + GIANT("Zombie Awakening", GiantWorldEvent.class, WorldEventPriority.GLOBAL); private String _name; private Class _clazz; - private boolean _major, _triggerable; + private WorldEventPriority _priority; private long _last; - private WorldEventType(String name, Class clazz) - { - this(name, clazz, false, false); - } - - private WorldEventType(String name, Class clazz, boolean major, boolean triggerable) + private WorldEventType(String name, Class clazz, WorldEventPriority priority) { _name = name; _clazz = clazz; - _major = major; - _triggerable = triggerable; + _priority = priority; _last = 0; } @@ -47,19 +41,13 @@ public enum WorldEventType return _name; } - public boolean isMajor() + public WorldEventPriority getPriority() { - return _major; + return _priority; } - - public boolean isTriggerable() - { - return _triggerable; - } - + public long getLast() { return _last; } - } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/CustomGiant.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/CustomGiant.java index 104cf9c46..27a864de3 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/CustomGiant.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/CustomGiant.java @@ -37,6 +37,7 @@ public class CustomGiant implements Listener private static final float DESTORY_FALLING_BLOCK_CHANCE = 0.04F; private static final float MOVE_FACTOR = 0.3F; private static final int MAX_SEARCH_DISTANCE_SQUARED = 2500; + private static final int TOO_CLOSE_DISTANCE_SQUARED = 625; private final SafezoneModule _safezone; @@ -54,9 +55,11 @@ public class CustomGiant implements Listener _giant.setMaxHealth(GIANT_HEALTH); _giant.setHealth(_giant.getMaxHealth()); _giant.setRemoveWhenFarAway(false); - - UtilEnt.vegetate(_giant); + UtilEnt.vegetate(_giant); + UtilEnt.ghost(_giant, true, false); + UtilEnt.setFakeHead(_giant, true); + _fallback = Managers.get(WorldDataModule.class).getCustomLocation("CENTER").get(0); } @@ -78,6 +81,16 @@ public class CustomGiant implements Listener return; } + if (_target.equals(_fallback) && UtilMath.offsetSquared(_giant.getLocation(), _fallback) < TOO_CLOSE_DISTANCE_SQUARED) + { + return; + } + + if (_safezone.isInSafeZone(_giant.getLocation())) + { + _target = _fallback; + } + Vector direction = UtilAlg.getTrajectory2d(_giant.getLocation(), _target).multiply(MOVE_FACTOR); Location toTeleport = _giant.getLocation().add(direction); @@ -97,6 +110,11 @@ public class CustomGiant implements Listener for (Block block : UtilBlock.getInBoundingBox(_giant.getLocation().subtract(GIANT_WIDTH, 0, GIANT_WIDTH), _giant.getLocation().add(GIANT_WIDTH, GIANT_HEIGHT, GIANT_WIDTH))) { + if (_safezone.isInSafeZone(block.getLocation())) + { + continue; + } + if (Math.random() < DESTORY_FALLING_BLOCK_CHANCE) { FallingBlock fallingBlock = block.getWorld().spawnFallingBlock(block.getLocation(), block.getType(), block.getData()); @@ -125,7 +143,7 @@ public class CustomGiant implements Listener for (Player player : UtilServer.getPlayers()) { - if (UtilPlayer.isSpectator(player) || _safezone.getSafezone(player.getLocation()) != null) + if (UtilPlayer.isSpectator(player) || _safezone.isInSafeZone(player.getLocation())) { ignore.add(player); } @@ -137,7 +155,7 @@ public class CustomGiant implements Listener { return _fallback; } - + return UtilMath.offsetSquared(_giant, player) > MAX_SEARCH_DISTANCE_SQUARED ? _fallback : player.getLocation(); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/GiantWorldEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/GiantWorldEvent.java index bfd803be9..2b059fa3b 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/GiantWorldEvent.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/GiantWorldEvent.java @@ -1,5 +1,7 @@ package mineplex.gemhunters.worldevent.giant; +import java.util.concurrent.TimeUnit; + import org.bukkit.entity.Entity; import org.bukkit.entity.Zombie; import org.bukkit.event.EventHandler; @@ -20,7 +22,7 @@ public class GiantWorldEvent extends WorldEvent private static final int MINI_ZOMBIES = 10; private static final int MINI_ZOMBIES_MAX_DISTANCE_SQUARED = 900; - private static final int MAX_TIME = 180000; + private static final long MAX_TIME = TimeUnit.MINUTES.toMillis(6); private CustomGiant _giant; diff --git a/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/GoogleSheetController.java b/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/GoogleSheetController.java index 0a1c0d213..f6244df65 100644 --- a/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/GoogleSheetController.java +++ b/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/GoogleSheetController.java @@ -9,7 +9,7 @@ import org.json.JSONObject; public class GoogleSheetController { - private static final int SLEEP_TIME = 2000; + private static final int SLEEP_TIME = 1000; private static final String DATA_STORE_DIR = ".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "files"; public static void main(String[] args) throws InterruptedException diff --git a/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/SpreadsheetType.java b/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/SpreadsheetType.java index 854bd31b2..af2acf11c 100644 --- a/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/SpreadsheetType.java +++ b/Plugins/mineplex-google-sheets/src/mineplex/googlesheets/SpreadsheetType.java @@ -7,7 +7,7 @@ public enum SpreadsheetType { GEM_HUNTERS_CHESTS("11Noztgbpu_gUKkc5F4evKKfyxS-Jv1coE0IrBToX_gg"), - GEM_HUNTERS_VILLAGERS("1OcYktxVZaW6Fm29Zh6w4Lb-UVyuN8r1x-TFb_3USYYI"), + GEM_HUNTERS_SHOP("1OcYktxVZaW6Fm29Zh6w4Lb-UVyuN8r1x-TFb_3USYYI"), ; private String _id; From 490d1d86f2db354e153155216a6778955920ff49 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 21 Jan 2017 14:24:04 +0000 Subject: [PATCH 018/101] Give players their earnt gems --- .../src/mineplex/gemhunters/economy/EconomyModule.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java index 34f5b03b5..66ee6ae94 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -56,6 +56,11 @@ public class EconomyModule extends MiniPlugin addToStore(killerPlayer, "Killing " + F.name(player.getName()), gems); } + @EventHandler + public void cashOut(PlayerCashOutCompleteEvent event) + { + event.incrementGems(_storedGems.get(event.getPlayer().getUniqueId())); + } @EventHandler public void quit(PlayerQuitEvent event) From 24d71e09fed06edf9cd55d87c302cb7acf2eaffb Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 21 Jan 2017 14:45:58 +0000 Subject: [PATCH 019/101] Teleport dead people --- .../src/mineplex/gemhunters/death/DeathModule.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java index 249597e9c..a4d5c3605 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java @@ -14,7 +14,7 @@ import com.google.common.collect.Sets; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.UtilAction; -import mineplex.gemhunters.world.WorldDataModule; +import mineplex.gemhunters.spawn.SpawnModule; /** * This module handles anything to do with a players death @@ -28,13 +28,13 @@ public class DeathModule extends MiniPlugin // Some items like the cash out item (and for some reason players drop bones?) don't need to be dropped to avoid duplication. private static final Set DISALLOWED_DROPS = Sets.newHashSet(Material.EMERALD, Material.BONE); - private final WorldDataModule _worldData; + private final SpawnModule _spawn; private DeathModule() { super("Death"); - _worldData = require(WorldDataModule.class); + _spawn = require(SpawnModule.class); } @EventHandler @@ -45,7 +45,7 @@ public class DeathModule extends MiniPlugin // Stop the player dieing player.setHealth(20); UtilAction.zeroVelocity(player); - player.teleport(_worldData.getSpawnLocation("Yellow").get(0)); + _spawn.teleportToSpawn(player); Iterator iterator = event.getDrops().iterator(); From 0827ea2da003cf0651f6d14d0525a4e90de685bd Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 21 Jan 2017 14:46:05 +0000 Subject: [PATCH 020/101] World Listeners --- .../src/mineplex/gemhunters/GemHunters.java | 3 ++ .../gemhunters/world/WorldListeners.java | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 0bce76706..96c733f8b 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -59,6 +59,7 @@ import mineplex.gemhunters.scoreboard.ScoreboardModule; import mineplex.gemhunters.shop.ShopModule; import mineplex.gemhunters.spawn.SpawnModule; import mineplex.gemhunters.supplydrop.SupplyDropModule; +import mineplex.gemhunters.world.WorldListeners; import mineplex.gemhunters.worldevent.WorldEventModule; import mineplex.minecraft.game.core.combat.CombatManager; import mineplex.minecraft.game.core.condition.ConditionManager; @@ -218,6 +219,8 @@ public class GemHunters extends JavaPlugin require(SupplyDropModule.class); require(WorldEventModule.class); + new WorldListeners(this); + // UpdateEvent!!! new Updater(this); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java new file mode 100644 index 000000000..c4511d7b9 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -0,0 +1,42 @@ +package mineplex.gemhunters.world; + +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.plugin.java.JavaPlugin; + +public class WorldListeners implements Listener +{ + + public WorldListeners(JavaPlugin plugin) + { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @EventHandler + public void blockBreak(BlockBreakEvent event) + { + if (shouldBlock(event.getPlayer())) + { + event.setCancelled(true); + } + } + + @EventHandler + public void blockPlace(BlockPlaceEvent event) + { + if (shouldBlock(event.getPlayer())) + { + event.setCancelled(true); + } + } + + public boolean shouldBlock(Player player) + { + return player.getGameMode() != GameMode.CREATIVE; + } + +} From c7c7b4448f2fd4f572e92b946f1664a78c9b9511 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 21 Jan 2017 14:46:18 +0000 Subject: [PATCH 021/101] Use File.separator --- .../src/mineplex/gemhunters/spawn/SpawnModule.java | 5 +++++ .../src/mineplex/gemhunters/supplydrop/SupplyDrop.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index f36eb8831..acfd9ed4e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -109,6 +109,11 @@ public class SpawnModule extends MiniPlugin }); } + public void teleportToSpawn(Player player) + { + player.teleport(_spawn); + } + public boolean isSuitable(Block block) { Block up = block.getRelative(BlockFace.UP); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java index 6478f2fca..846760c53 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java @@ -40,7 +40,7 @@ import mineplex.core.common.util.UtilShapes; public class SupplyDrop { - private static final String SCHEMATIC_PATH = "../../update/files/Helicopter.schematic"; + private static final String SCHEMATIC_PATH = ".." + File.separator + ".." + File.separator + "update" + File.separator + "files" + File.separator + "Helicopter.schematic"; private static final int BLADE_LENGTH = 7; private Location _destination; From 8102ba2e4b8d888beb736e52f19e04889797a24b Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 21 Jan 2017 20:45:22 +0000 Subject: [PATCH 022/101] Lots of stuff --- .../src/mineplex/gemhunters/GemHunters.java | 2 + .../gemhunters/death/DeathModule.java | 2 + .../gemhunters/economy/EconomyModule.java | 7 +- .../gemhunters/loot/InventoryModule.java | 138 ++++++++++++++++++ .../mineplex/gemhunters/loot/LootModule.java | 5 +- .../gemhunters/worldevent/WorldEventType.java | 5 +- .../worldevent/pumpkinking/PhaseOne.java | 85 +++++++++++ .../pumpkinking/PumpkinKingWorldEvent.java | 32 ++++ .../worldevent/pumpkinking/PumpkingKing.java | 82 +++++++++++ 9 files changed, 351 insertions(+), 7 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PhaseOne.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PumpkinKingWorldEvent.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PumpkingKing.java diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 96c733f8b..afe84c650 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -53,6 +53,7 @@ import mineplex.gemhunters.chat.ChatModule; import mineplex.gemhunters.death.DeathModule; import mineplex.gemhunters.economy.CashOutModule; import mineplex.gemhunters.economy.EconomyModule; +import mineplex.gemhunters.loot.InventoryModule; import mineplex.gemhunters.loot.LootModule; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.scoreboard.ScoreboardModule; @@ -211,6 +212,7 @@ public class GemHunters extends JavaPlugin require(ChatModule.class); require(DeathModule.class); require(EconomyModule.class); + require(InventoryModule.class); require(LootModule.class); require(SafezoneModule.class); require(ScoreboardModule.class); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java index a4d5c3605..50bd02ab2 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java @@ -44,6 +44,8 @@ public class DeathModule extends MiniPlugin // Stop the player dieing player.setHealth(20); + player.setSaturation(20); + player.setExhaustion(0); UtilAction.zeroVelocity(player); _spawn.teleportToSpawn(player); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java index 66ee6ae94..2c68e86fc 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -51,9 +51,11 @@ public class EconomyModule extends MiniPlugin Player killerPlayer = (Player) killer; - int gems = (int) (_storedGems.get(player.getUniqueId()) * GEM_KILL_FACTOR); + int oldGems = _storedGems.get(player.getUniqueId()); + int newGems = (int) (oldGems * GEM_KILL_FACTOR); - addToStore(killerPlayer, "Killing " + F.name(player.getName()), gems); + addToStore(killerPlayer, "Killing " + F.name(player.getName()), newGems); + removeFromStore(player, oldGems); } @EventHandler @@ -94,7 +96,6 @@ public class EconomyModule extends MiniPlugin if (event.getMessage().startsWith("/test")) { event.setCancelled(true); - addToStore(event.getPlayer(), "Testing", 100); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java new file mode 100644 index 000000000..09905b4fd --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java @@ -0,0 +1,138 @@ +package mineplex.gemhunters.loot; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilInv; +import mineplex.core.itemstack.ItemBuilder; + +@ReflectivelyCreateMiniPlugin +public class InventoryModule extends MiniPlugin +{ + + private static final int START_INDEX = 9; + private static final ItemStack LOCKED = new ItemBuilder(Material.STAINED_GLASS_PANE, (byte) 15).setTitle(C.cGray + "Locked").build(); + + private final Map _rowsUnlocked; + + private InventoryModule() + { + super("Unlocker"); + + _rowsUnlocked = new HashMap<>(); + } + + @EventHandler + public void join(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + Inventory inv = player.getInventory(); + + _rowsUnlocked.put(player.getUniqueId(), 0); + + for (int i = START_INDEX; i < inv.getSize(); i++) + { + inv.setItem(i, LOCKED); + } + } + + @EventHandler + public void quit(PlayerQuitEvent event) + { + _rowsUnlocked.remove(event.getPlayer().getUniqueId()); + } + + @EventHandler + public void inventoryClick(InventoryClickEvent event) + { + Player player = (Player) event.getWhoClicked(); + + if (event.getClickedInventory() == null || event.getCurrentItem() == null) + { + return; + } + + if (event.getCurrentItem().isSimilar(LOCKED)) + { + event.setCancelled(true); + player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0.6F); + } + } + + @EventHandler + public void interact(PlayerInteractEvent event) + { + if (event.isCancelled()) + { + return; + } + + if (!UtilEvent.isAction(event, ActionType.R)) + { + return; + } + + Player player = event.getPlayer(); + ItemStack itemStack = event.getItem(); + + if (itemStack == null) + { + return; + } + + Material material = itemStack.getType(); + + if (material == Material.CHEST || material == Material.ENDER_CHEST) + { + UtilInv.remove(player, material, (byte) 0, 1); + unlockRows(player, material == Material.CHEST ? 1 : 2); + } + } + + public void unlockRows(Player player, int rows) + { + Inventory inv = player.getInventory(); + UUID key = player.getUniqueId(); + + _rowsUnlocked.put(key, _rowsUnlocked.get(key) + rows); + int start = START_INDEX * _rowsUnlocked.get(key); + int end = Math.min(inv.getSize(), start + rows * 9); + int delta = end - start; + + for (int i = start; i < end; i++) + { + inv.setItem(i, null); + } + + player.sendMessage(F.main(_moduleName, "You unlocked an additional " + F.count(String.valueOf(delta)) + " slots of your inventory!")); + } + + @EventHandler + public void test(PlayerCommandPreprocessEvent event) + { + if (event.getMessage().startsWith("/ur")) + { + event.setCancelled(true); + unlockRows(event.getPlayer(), Integer.parseInt(event.getMessage().split(" ")[1])); + } + } +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 2fe0c1f3d..943e17c43 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -20,7 +20,6 @@ import org.bukkit.block.Chest; import org.bukkit.block.DoubleChest; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.block.Action; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerPickupItemEvent; @@ -32,10 +31,10 @@ import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilWorld; -import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.google.GoogleSheetsManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -418,7 +417,7 @@ public class LootModule extends MiniPlugin Player player = event.getPlayer(); Block block = event.getClickedBlock(); - if (block == null || block.getType() != Material.CHEST) + if (block == null || block.getType() != Material.CHEST && block.getType() != Material.ENDER_CHEST) { return; } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java index 8188dc114..c3a3036a9 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java @@ -1,11 +1,14 @@ package mineplex.gemhunters.worldevent; import mineplex.gemhunters.worldevent.giant.GiantWorldEvent; +import mineplex.gemhunters.worldevent.pumpkinking.PumpkinKingWorldEvent; public enum WorldEventType { - GIANT("Zombie Awakening", GiantWorldEvent.class, WorldEventPriority.GLOBAL); + GIANT("Zombie Awakening", GiantWorldEvent.class, WorldEventPriority.GLOBAL), + PUMPKIN_KING("Pumpkin King", PumpkinKingWorldEvent.class, WorldEventPriority.ISOLATED) + ; private String _name; private Class _clazz; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PhaseOne.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PhaseOne.java new file mode 100644 index 000000000..708888dbd --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PhaseOne.java @@ -0,0 +1,85 @@ +package mineplex.gemhunters.worldevent.pumpkinking; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.scheduler.BukkitRunnable; + +import mineplex.core.common.util.MapUtil; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilServer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class PhaseOne implements Listener +{ + + private static final int SHIELD_RADIUS = 4; + + private final PumpkingKing _pumpkingKing; + private final Set _sheildBlocks; + + private boolean _shieldActive; + + public PhaseOne(PumpkingKing pumpkingKing) + { + _pumpkingKing = pumpkingKing; + _sheildBlocks = new HashSet<>(); + } + + @EventHandler + public void shieldActive(UpdateEvent event) + { + if (event.getType() != UpdateType.FASTER) + { + return; + } + + if (!_shieldActive) + { + _shieldActive = true; + createShield(); + } + } + + public void createShield() + { + Map blocks = UtilBlock.getInRadius(_pumpkingKing.getSpawn().getBlock(), SHIELD_RADIUS); + + new BukkitRunnable() + { + + int y = _pumpkingKing.getSpawn().clone().subtract(0, SHIELD_RADIUS, 0).getBlockY(); + int yGoal = y + SHIELD_RADIUS * 2; + + @Override + public void run() + { + if (y > yGoal) + { + cancel(); + return; + } + + for (Block block : blocks.keySet()) + { + if (blocks.get(block) > 0.3 || block.getLocation().getY() > y) + { + continue; + } + + _sheildBlocks.add(block); + MapUtil.QuickChangeBlockAt(block.getLocation(), Material.STAINED_GLASS, (byte) 10); + } + + y += 1; + } + }.runTaskTimer(UtilServer.getPlugin(), 0, 10); + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PumpkinKingWorldEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PumpkinKingWorldEvent.java new file mode 100644 index 000000000..6b2b59106 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PumpkinKingWorldEvent.java @@ -0,0 +1,32 @@ +package mineplex.gemhunters.worldevent.pumpkinking; + +import mineplex.gemhunters.worldevent.WorldEvent; +import mineplex.gemhunters.worldevent.WorldEventType; + +public class PumpkinKingWorldEvent extends WorldEvent +{ + + public PumpkinKingWorldEvent(WorldEventType eventType) + { + super(eventType); + } + + @Override + public void onStart() + { + new PumpkingKing(); + } + + @Override + public boolean checkToEnd() + { + return false; + } + + @Override + public void onEnd() + { + + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PumpkingKing.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PumpkingKing.java new file mode 100644 index 000000000..f964d5e51 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PumpkingKing.java @@ -0,0 +1,82 @@ +package mineplex.gemhunters.worldevent.pumpkinking; + +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Skeleton; +import org.bukkit.event.Listener; + +import mineplex.core.Managers; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilServer; +import mineplex.core.utils.UtilVariant; +import mineplex.gemhunters.world.WorldDataModule; + +public class PumpkingKing +{ + + private final WorldDataModule _worldData; + + private final World _world; + private final Skeleton _entity; + private final Object[] _phases; + + private int _phase; + + public PumpkingKing() + { + _worldData = Managers.require(WorldDataModule.class); + + _world = _worldData.World; + _entity = UtilVariant.spawnWitherSkeleton(getSpawn()); + + _entity.setRemoveWhenFarAway(false); + _entity.setCustomName(C.cDRedB + "Pumpking King"); + _entity.setCustomNameVisible(true); + + UtilEnt.vegetate(_entity, true); + UtilEnt.ghost(_entity, true, false); + UtilEnt.setFakeHead(_entity, true); + + _phases = new Object[] { new PhaseOne(this) }; + + _phase = -1; + nextPhase(); + + //plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + public void nextPhase() + { + if (_phase != -1) + { + UtilServer.Unregister((Listener) _phases[_phase]); + } + + _phase++; + UtilServer.RegisterEvents((Listener) _phases[_phase]); + } + + public Location getSpawn() + { + return getLocation("Spawn"); + } + + public Location getLocation(String id) + { + return _worldData.getCustomLocation("PK " + id).get(0); + } + + public List getLocations(String id) + { + return _worldData.getCustomLocation("PK " + id); + } + + public Skeleton getEntity() + { + return _entity; + } + +} From 2c8b8d4fb0a9be4efaf1706658cf41db728498f7 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 23 Jan 2017 19:56:00 +0000 Subject: [PATCH 023/101] Add max chests --- .../gemhunters/loot/ChestProperties.java | 12 +++---- .../mineplex/gemhunters/loot/LootModule.java | 33 ++++++------------- .../ChestPropertiesDeserialiser.java | 4 +-- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/ChestProperties.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/ChestProperties.java index a808fce23..06d50b758 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/ChestProperties.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/ChestProperties.java @@ -13,11 +13,11 @@ public class ChestProperties private final int _spawnRate; private final int _expireRate; private final int _spawnRadius; - private final double _percentile; + private final int _maxActive; private long _lastSpawn; - public ChestProperties(String name, Material blockMaterial, String dataKey, int minAmount, int maxAmount, int spawnRate, int expireRate, int spawnRadius, double percentile) + public ChestProperties(String name, Material blockMaterial, String dataKey, int minAmount, int maxAmount, int spawnRate, int expireRate, int spawnRadius, int maxActive) { _name = name; _blockMaterial = blockMaterial; @@ -27,7 +27,7 @@ public class ChestProperties _spawnRate = spawnRate; _expireRate = expireRate; _spawnRadius = spawnRadius; - _percentile = percentile; + _maxActive = maxActive; setLastSpawn(); } @@ -72,11 +72,11 @@ public class ChestProperties return _spawnRadius; } - public final double getPercentile() + public final int getMaxActive() { - return _percentile; + return _maxActive; } - + public void setLastSpawn() { _lastSpawn = System.currentTimeMillis(); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 943e17c43..9d62617a5 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -1,6 +1,5 @@ package mineplex.gemhunters.loot; -import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -55,9 +54,7 @@ public class LootModule extends MiniPlugin private static final String SHEET_FILE_NAME = "GEM_HUNTERS_CHESTS"; private static final String CHEST_MASTER_SHEET_NAME = "CHEST_MASTER"; private static final long CHEST_DESPAWN_TIME_OPENED = TimeUnit.SECONDS.toMillis(15); - private static final String[] IGNORED_COLOURS = { "RED" }; private static final int MAX_SEARCH_ATTEMPTS = 40; - private static final int MAX_CHEST_PLACEMENT_RANGE = 10; private static final int MAX_CHEST_CHECK_DISTANCE_SQUARED = 4; private static final LootItemDeserialiser DESERIALISER = new LootItemDeserialiser(); private static final ChestPropertiesDeserialiser CHEST_DESERIALISER = new ChestPropertiesDeserialiser(); @@ -68,7 +65,7 @@ public class LootModule extends MiniPlugin private final Map> _chestLoot; private final Map _chestProperties; - private final List _spawnedChest; + private final Set _spawnedChest; private final Map> _spawnedIndexes; private final Set _itemRewards; @@ -81,7 +78,7 @@ public class LootModule extends MiniPlugin _worldData = require(WorldDataModule.class); _chestLoot = new HashMap<>(); _chestProperties = new HashMap<>(); - _spawnedChest = new ArrayList<>(200); + _spawnedChest = new HashSet<>(200); _spawnedIndexes = new HashMap<>(15); _itemRewards = new HashSet<>(); @@ -131,18 +128,8 @@ public class LootModule extends MiniPlugin } // Spawn new chests - dataPointLoop: for (String key : _chestProperties.keySet()) + for (String key : _chestProperties.keySet()) { - // Some data points are ignored like the chest loot related to - // supply drops. - for (String ignore : IGNORED_COLOURS) - { - if (key.equals(ignore)) - { - continue dataPointLoop; - } - } - List locations = _worldData.getDataLocation(key); ChestProperties properties = _chestProperties.get(key); @@ -154,7 +141,7 @@ public class LootModule extends MiniPlugin properties.setLastSpawn(); // Only spawn more chests if we need to - int max = (int) (_spawnedChest.size() * properties.getPercentile()); + int max = properties.getMaxActive(); int spawned = 0; for (SpawnedChest chest : _spawnedChest) @@ -165,12 +152,11 @@ public class LootModule extends MiniPlugin } } - // TODO fix this // If there are too many chests of this type we can ignore it - // if (spawned > max) - // { - // continue; - // } + if (spawned > max) + { + continue; + } Set usedIndexes = _spawnedIndexes.get(key); @@ -204,7 +190,8 @@ public class LootModule extends MiniPlugin usedIndexes.add(index); randomLocation = locations.get(index); - Location chestToPlace = UtilAlg.getRandomLocation(randomLocation, MAX_CHEST_PLACEMENT_RANGE, 0, MAX_CHEST_PLACEMENT_RANGE); + int placeRadius = properties.getSpawnRadius(); + Location chestToPlace = UtilAlg.getRandomLocation(randomLocation, placeRadius, 0, placeRadius); Block block = chestToPlace.getBlock(); attempts = 0; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/ChestPropertiesDeserialiser.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/ChestPropertiesDeserialiser.java index 464b14469..7d5a63e9c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/ChestPropertiesDeserialiser.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/ChestPropertiesDeserialiser.java @@ -34,9 +34,9 @@ public class ChestPropertiesDeserialiser implements SheetObjectDeserialiser 7 ? values[7] : "0") / 100; + int maxActive = Integer.parseInt(values[7]); - return new ChestProperties(name, blockMaterial, dataKey, minAmount, maxAmount, spawnRate, expireRate, spawnRadius, percentile); + return new ChestProperties(name, blockMaterial, dataKey, minAmount, maxAmount, spawnRate, expireRate, spawnRadius, maxActive); } } From fb35f19c3d5e13533f57c80fe86131ea36651c8f Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 30 Jan 2017 19:09:07 +0000 Subject: [PATCH 024/101] Add Villager Properties support --- .../mineplex/gemhunters/shop/ShopModule.java | 131 +++++++++++++++--- .../mineplex/gemhunters/shop/TraderNPC.java | 53 ++++--- .../gemhunters/shop/VillagerProperties.java | 59 ++++++++ .../VillagerPropertiesDeserialiser.java | 23 +++ 4 files changed, 227 insertions(+), 39 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/VillagerProperties.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/deserialisers/VillagerPropertiesDeserialiser.java diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java index 7428c26bf..fb36a9a75 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java @@ -1,24 +1,30 @@ package mineplex.gemhunters.shop; +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 org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Villager; import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerJoinEvent; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilWorld; import mineplex.core.google.GoogleSheetsManager; import mineplex.core.google.SheetObjectDeserialiser; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.loot.deserialisers.LootItemDeserialiser; import mineplex.gemhunters.safezone.SafezoneModule; +import mineplex.gemhunters.shop.deserialisers.VillagerPropertiesDeserialiser; import mineplex.gemhunters.util.SlackSheetsBot; import mineplex.gemhunters.world.WorldDataModule; @@ -27,6 +33,8 @@ public class ShopModule extends MiniPlugin { private static final String SHEET_FILE_NAME = "GEM_HUNTERS_SHOP"; + private static final String VILLAGER_MASTER_SHEET_NAME = "VILLAGER_MASTER"; + private static final VillagerPropertiesDeserialiser VILLAGER_PROPERTIES_DESERIALISER = new VillagerPropertiesDeserialiser(); private static final LootItemDeserialiser DESERIALISER = new LootItemDeserialiser(); private static final SheetObjectDeserialiser COST_DESERIALISER = new SheetObjectDeserialiser() { @@ -36,18 +44,26 @@ public class ShopModule extends MiniPlugin { return Integer.parseInt(values[10]); } - + }; + private static final int MINIMUM_ITEMS = 1; private static final int MAXIMUM_ITEMS = 5; + private static final int MAX_SEARCH_ATTEMPTS = 40; + + private static final String[] NAMES = { + + }; private final GoogleSheetsManager _sheets; private final SafezoneModule _safezone; private final WorldDataModule _worldData; private final Map> _trades; + private final Map _properties; - private boolean _npcsSpawned; + private final List _npcs; + private final Map> _spawnedIndexes; private ShopModule() { @@ -58,6 +74,10 @@ public class ShopModule extends MiniPlugin _worldData = require(WorldDataModule.class); _trades = new HashMap<>(); + _properties = new HashMap<>(); + + _npcs = new ArrayList<>(); + _spawnedIndexes = new HashMap<>(); runSyncLater(() -> updateVillagerTrades(), 20); } @@ -69,6 +89,32 @@ public class ShopModule extends MiniPlugin for (String key : map.keySet()) { + if (key.equals(VILLAGER_MASTER_SHEET_NAME)) + { + int row = 0; + + for (List rows : map.get(key)) + { + row++; + try + { + VillagerProperties properties = VILLAGER_PROPERTIES_DESERIALISER.deserialise(rows.toArray(new String[0])); + _properties.put(properties.getDataKey(), properties); + } + catch (Exception e) + { + if (row != 1) + { + SlackSheetsBot.reportParsingError(e, "Villager Trades", key, row); + } + + continue; + } + + continue; + } + } + Set items = new HashSet<>(); int row = 0; @@ -98,37 +144,90 @@ public class ShopModule extends MiniPlugin } @EventHandler - public void playerJoin(PlayerJoinEvent event) + public void updateSpawnedVillagers(UpdateEvent event) { - if (_npcsSpawned) + if (event.getType() != UpdateType.SEC) { return; } - _npcsSpawned = true; - - for (String key : _trades.keySet()) + for (String key : _properties.keySet()) { - for (Location location : _worldData.getSpawnLocation(key)) + List locations = _worldData.getDataLocation(key); + VillagerProperties properties = _properties.get(key); + + if (!UtilTime.elapsed(properties.getLastSpawn(), properties.getSpawnRate())) { - boolean vegetated = _safezone.isInSafeZone(location); - Set items = getRandomItemSet(_trades.get(key)); - - new TraderNPC(_plugin, location, Villager.class, "Sam", vegetated, items); + continue; } + + properties.setLastSpawn(); + + // Only spawn more chests if we need to + int max = properties.getMax(); + int spawned = 0; + + for (TraderNPC npc : _npcs) + { + if (npc.getProperties().getDataKey().equals(key)) + { + spawned++; + } + } + + // If there are too many chests of this type we can ignore it + if (spawned > max) + { + continue; + } + + Set usedIndexes = _spawnedIndexes.get(key); + + if (usedIndexes == null) + { + _spawnedIndexes.put(key, new HashSet<>()); + usedIndexes = _spawnedIndexes.get(key); + } + + if (locations.size() == usedIndexes.size()) + { + return; + } + + Location randomLocation = null; + int attempts = 0; + int index = -1; + + while (index == -1 || usedIndexes.contains(index) && attempts < MAX_SEARCH_ATTEMPTS) + { + index = UtilMath.r(locations.size()); + + attempts++; + } + + if (index == -1) + { + continue; + } + + usedIndexes.add(index); + randomLocation = locations.get(index); + + Bukkit.broadcastMessage("Trader at " + UtilWorld.locToStrClean(randomLocation) + " with key=" + key + " and index=" + index + " and max=" + max); + _npcs.add(new TraderNPC(_plugin, randomLocation, Villager.class, NAMES[UtilMath.r(NAMES.length)], _safezone.isInSafeZone(randomLocation), properties, getRandomItemSet(_trades.get(key)))); } } - + public Set getRandomItemSet(Set items) { int size = UtilMath.rRange(MINIMUM_ITEMS, MAXIMUM_ITEMS); Set items2 = new HashSet<>(size); - + for (int i = 0; i < size; i++) { items2.add(UtilAlg.Random(items)); } - + return items2; } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java index 05f42fef6..7d0f7845b 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java @@ -19,41 +19,43 @@ import mineplex.gemhunters.util.SimpleNPC; public class TraderNPC extends SimpleNPC { - + private final EconomyModule _economy; - + + private final VillagerProperties _properties; private final Set _selling; private final Inventory _inv; - - public TraderNPC(JavaPlugin plugin, Location spawn, Class type, String name, boolean vegetated, Set selling) + + public TraderNPC(JavaPlugin plugin, Location spawn, Class type, String name, boolean vegetated, VillagerProperties properties, Set selling) { super(plugin, spawn, type, name, null, vegetated); - + _economy = Managers.require(EconomyModule.class); - + + _properties = properties; _selling = selling; _inv = plugin.getServer().createInventory(null, 9, name); - + int index = 1; - + for (TradeableItem item : _selling) { _inv.setItem(index++, item.getLootItem().getItemStack()); } } - + @Override @EventHandler public void npcClick(PlayerInteractEntityEvent event) { super.npcClick(event); - + if (event.getRightClicked().equals(_entity)) { event.getPlayer().openInventory(_inv); } } - + @EventHandler public void inventoryClick(InventoryClickEvent event) { @@ -61,43 +63,43 @@ public class TraderNPC extends SimpleNPC { return; } - + if (!event.getInventory().equals(_inv)) { return; } - + ItemStack itemStack = event.getCurrentItem(); - + if (itemStack == null) { return; } - + Player player = (Player) event.getWhoClicked(); int gems = _economy.getGems(player); int cost = fromItemStack(itemStack); - + if (cost == 0) { return; } - + event.setCancelled(true); - + if (cost > gems) { player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0.6F); return; } - + _economy.removeFromStore(player, cost); - + player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 1.2F); player.getInventory().addItem(itemStack); player.closeInventory(); } - + public int fromItemStack(ItemStack itemStack) { for (TradeableItem item : _selling) @@ -107,8 +109,13 @@ public class TraderNPC extends SimpleNPC return item.getCost(); } } - + return 0; } - + + public final VillagerProperties getProperties() + { + return _properties; + } + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/VillagerProperties.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/VillagerProperties.java new file mode 100644 index 000000000..bb94751ea --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/VillagerProperties.java @@ -0,0 +1,59 @@ +package mineplex.gemhunters.shop; + +public class VillagerProperties +{ + + private final String _name; + private final String _dataKey; + private final int _spawnRate; + private final int _expireRate; + private final int _max; + + private long _lastSpawn; + + public VillagerProperties(String name, String dataKey, int spawnRate, int expireRate, int max) + { + _name = name; + _dataKey = dataKey; + _spawnRate = spawnRate; + _expireRate = expireRate; + _max = max; + + setLastSpawn(); + } + + public final String getName() + { + return _name; + } + + public final String getDataKey() + { + return _dataKey; + } + + public final int getSpawnRate() + { + return _spawnRate; + } + + public final int getExpireRate() + { + return _expireRate; + } + + public final int getMax() + { + return _max; + } + + public void setLastSpawn() + { + _lastSpawn = System.currentTimeMillis(); + } + + public long getLastSpawn() + { + return _lastSpawn; + } +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/deserialisers/VillagerPropertiesDeserialiser.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/deserialisers/VillagerPropertiesDeserialiser.java new file mode 100644 index 000000000..683564b1e --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/deserialisers/VillagerPropertiesDeserialiser.java @@ -0,0 +1,23 @@ +package mineplex.gemhunters.shop.deserialisers; + +import mineplex.core.google.SheetObjectDeserialiser; +import mineplex.gemhunters.shop.VillagerProperties; + +public class VillagerPropertiesDeserialiser implements SheetObjectDeserialiser +{ + + @Override + public VillagerProperties deserialise(String[] values) throws ArrayIndexOutOfBoundsException + { + String name = values[0]; + String dataKey = values[1]; + + int spawnRate = Integer.parseInt(values[2]); + int expireRate = Integer.parseInt(values[3]); + + int max = Integer.parseInt(values[4]); + + return new VillagerProperties(name, dataKey, spawnRate, expireRate, max); + } + +} From c6bb850bc3e6902d8c6df2b022a21d701b49a7ac Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 30 Jan 2017 23:28:55 +0000 Subject: [PATCH 025/101] Lots of stuff --- .../core/sponsorbranding/BrandingManager.java | 49 +++++++++-- .../core/sponsorbranding/BrandingPost.java | 3 + .../Mineplex.Hub/src/mineplex/hub/Hub.java | 2 +- .../hub/modules/BillboardManager.java | 3 - .../nautilus/game/arcade/ArcadeManager.java | 2 +- .../src/mineplex/gemhunters/GemHunters.java | 2 + .../gemhunters/bounties/BountyModule.java | 46 ++++++++++ .../gemhunters/economy/CashOutModule.java | 4 +- .../gemhunters/economy/CashOutSession.java | 1 - .../scoreboard/GemHuntersScoreboard.java | 6 +- .../scoreboard/ScoreboardModule.java | 10 ++- .../mineplex/gemhunters/shop/ShopModule.java | 2 +- .../gemhunters/util/SlackSheetsBot.java | 25 ++---- .../gemhunters/world/WorldListeners.java | 26 +++++- .../gemhunters/worldevent/WorldEventType.java | 2 - .../worldevent/pumpkinking/PhaseOne.java | 85 ------------------- .../pumpkinking/PumpkinKingWorldEvent.java | 32 ------- .../worldevent/pumpkinking/PumpkingKing.java | 82 ------------------ 18 files changed, 145 insertions(+), 237 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/bounties/BountyModule.java delete mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PhaseOne.java delete mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PumpkinKingWorldEvent.java delete mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PumpkingKing.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/sponsorbranding/BrandingManager.java b/Plugins/Mineplex.Core/src/mineplex/core/sponsorbranding/BrandingManager.java index 944be5f58..883975960 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/sponsorbranding/BrandingManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/sponsorbranding/BrandingManager.java @@ -3,28 +3,29 @@ package mineplex.core.sponsorbranding; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.net.URL; import java.util.concurrent.ConcurrentHashMap; import javax.imageio.ImageIO; -import mineplex.core.MiniPlugin; - import org.bukkit.Location; import org.bukkit.block.BlockFace; -import org.bukkit.plugin.java.JavaPlugin; +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; /** * * Manager for creating billboards with branding logos */ +@ReflectivelyCreateMiniPlugin public class BrandingManager extends MiniPlugin { private ConcurrentHashMap _posts = new ConcurrentHashMap(); private ConcurrentHashMap _imgCache = new ConcurrentHashMap(); - public BrandingManager(JavaPlugin plugin) + private BrandingManager() { - super("Branding Manager", plugin); + super("Branding Manager"); } private BufferedImage getImage(String fileName) @@ -56,6 +57,28 @@ public class BrandingManager extends MiniPlugin return image; } + private BufferedImage getImage(URL url) + { + if (_imgCache.containsKey(url.toString())) + { + return _imgCache.get(url.toString()); + } + + BufferedImage image = null; + + try + { + image = ImageIO.read(url); + _imgCache.put(url.toString(), image); + } + catch (IOException e) + { + e.printStackTrace(); + } + + return image; + } + /** * Generates a billboard with a stored logo * @param location The center of the billboard @@ -75,6 +98,22 @@ public class BrandingManager extends MiniPlugin _posts.put(_posts.size(), bp); } + public void createPost(Location location, BlockFace facing, URL url) + { + BufferedImage image = getImage(url); + + if (image == null) + { + System.out.println("ERROR! Invalid image url!"); + return; + } + + BrandingPost brandingPost = new BrandingPost(location, facing, image); + brandingPost.spawn(); + // Umm why not use a List? + _posts.put(_posts.size(), brandingPost); + } + /** * Clears away all existing billboards */ diff --git a/Plugins/Mineplex.Core/src/mineplex/core/sponsorbranding/BrandingPost.java b/Plugins/Mineplex.Core/src/mineplex/core/sponsorbranding/BrandingPost.java index 49039ff4d..54f469646 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/sponsorbranding/BrandingPost.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/sponsorbranding/BrandingPost.java @@ -68,6 +68,8 @@ public class BrandingPost int width = (int) Math.ceil(_img.getWidth() / 128); int height = (int) Math.ceil(_img.getHeight() / 128); + Bukkit.broadcastMessage("width=" + width + " height=" + height); + switch (_facing) { case EAST: @@ -160,6 +162,7 @@ public class BrandingPost ItemStack item = getMapItem(x, y, _img); i.setItem(item); + Bukkit.broadcastMessage(x + " <- X Y -> " + y); _ents.add(i); } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 0a31bcb05..4b8fa70d5 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -228,7 +228,7 @@ public class Hub extends JavaPlugin implements IRelation //Updates getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1); - BrandingManager brandingManager = new BrandingManager(this); + BrandingManager brandingManager = require(BrandingManager.class); new BillboardManager(this, brandingManager); require(TrackManager.class); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/BillboardManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/BillboardManager.java index adfa01b62..d1dd5df72 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/BillboardManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/BillboardManager.java @@ -4,9 +4,6 @@ import mineplex.core.MiniPlugin; import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.sponsorbranding.BrandingManager; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.block.BlockFace; import org.bukkit.entity.ItemFrame; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageEvent; 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 bf853ef6e..9acf03c42 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -288,7 +288,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation _conditionManager = new SkillConditionManager(plugin); - _brandingManager = new BrandingManager(plugin); + _brandingManager = require(BrandingManager.class); _boosterManager = boosterManager; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index afe84c650..71ed8606b 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -49,6 +49,7 @@ import mineplex.core.teleport.Teleport; import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; import mineplex.core.visibility.VisibilityManager; +import mineplex.gemhunters.bounties.BountyModule; import mineplex.gemhunters.chat.ChatModule; import mineplex.gemhunters.death.DeathModule; import mineplex.gemhunters.economy.CashOutModule; @@ -208,6 +209,7 @@ public class GemHunters extends JavaPlugin new HologramManager(this, packetHandler); // Now we finally get to enable the Gem Hunters modules + require(BountyModule.class); require(CashOutModule.class); require(ChatModule.class); require(DeathModule.class); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/bounties/BountyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/bounties/BountyModule.java new file mode 100644 index 000000000..7a7ea109f --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/bounties/BountyModule.java @@ -0,0 +1,46 @@ +package mineplex.gemhunters.bounties; + +import java.net.MalformedURLException; +import java.net.URL; + +import org.bukkit.block.BlockFace; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.sponsorbranding.BrandingManager; + +@ReflectivelyCreateMiniPlugin +public class BountyModule extends MiniPlugin +{ + + private final BrandingManager _brandingManager; + + private BountyModule() + { + super("Bounty"); + + _brandingManager = require(BrandingManager.class); + } + + @EventHandler + public void test(PlayerCommandPreprocessEvent event) + { + if (!event.getMessage().startsWith("/want")) + { + return; + } + + try + { + event.setCancelled(true); + _brandingManager.createPost(event.getPlayer().getLocation(), BlockFace.SOUTH, new URL("http://minotar.net/helm/Moppletop.png")); + } + catch (MalformedURLException e) + { + e.printStackTrace(); + } + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java index ee6a10ede..605fdc029 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -165,8 +165,8 @@ public class CashOutModule extends MiniPlugin session.endSession(); iterator.remove(); - player.sendMessage(C.cGreen + "Imagine you are being sent to the Lobby."); - // Portal.getInstance().sendToHub(player, "You cashed out!"); + player.kickPlayer(C.cGreen + "Imagine you are being sent to the Lobby."); + // Portal.getInstance().sendToHub(player, null); } } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutSession.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutSession.java index 41a2ac0fc..b996183bf 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutSession.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutSession.java @@ -18,7 +18,6 @@ public class CashOutSession _max = max; _stand = player.getWorld().spawn(player.getLocation().add(0, 0.5, 0), ArmorStand.class); - _stand.setCustomName("Cashing Out"); _stand.setCustomNameVisible(true); _stand.setVisible(false); _stand.setGravity(false); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java index e7bb5c153..4ee1fc741 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java @@ -54,5 +54,9 @@ public class GemHuntersScoreboard extends WritableMineplexScoreboard { return C.cGray + " " + perspective.getName(); } - + + public int getUndernameScore(Player player) + { + return _economy.getGems(player); + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java index f1e2abb89..4b12e985d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java @@ -8,6 +8,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; @@ -97,15 +99,19 @@ public class ScoreboardModule extends MiniPlugin { Player otherPlayer = other.getOwner(); Team team = handle.registerNewTeam(otherPlayer.getName()); - + team.setPrefix(_clientManager.Get(otherPlayer).GetRank().getTag(true, true) + C.Reset + " "); team.setSuffix(scoreboard.getSuffix(player, otherPlayer)); team.addEntry(otherPlayer.getName()); - + if (player.equals(otherPlayer)) { continue; } + + Objective gemCounter = handle.registerNewObjective("gems", "Gems"); + gemCounter.setDisplaySlot(DisplaySlot.BELOW_NAME); + gemCounter.getScore(otherPlayer.getName()).setScore(scoreboard.getUndernameScore(otherPlayer)); Scoreboard otherHandle = other.getHandle(); Team otherTeam = otherHandle.registerNewTeam(player.getName()); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java index fb36a9a75..82013eb3f 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java @@ -52,7 +52,7 @@ public class ShopModule extends MiniPlugin private static final int MAX_SEARCH_ATTEMPTS = 40; private static final String[] NAMES = { - + "Andrew", "Jon", "Bob", "Sam", "Ronan", "Alex", "Joe", "Emma", "Giovani", "Dean", "Josh", "Geoffrey", "Parker", "Spencer", "Luke" }; private final GoogleSheetsManager _sheets; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SlackSheetsBot.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SlackSheetsBot.java index 7774a3003..7e356d085 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SlackSheetsBot.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SlackSheetsBot.java @@ -1,12 +1,5 @@ package mineplex.gemhunters.util; -import java.net.MalformedURLException; -import java.net.URL; - -import mineplex.core.slack.SlackAPI; -import mineplex.core.slack.SlackMessage; -import mineplex.core.slack.SlackTeam; - public class SlackSheetsBot { @@ -16,15 +9,15 @@ public class SlackSheetsBot public static final void reportParsingError(Exception exception, String spreadsheetName, String sheetName, int row) { - try - { - SlackAPI.getInstance().sendMessage(SlackTeam.DEVELOPER, SLACK_CHANNEL_NAME, new SlackMessage(SLACK_USERNAME, new URL(SLACK_ICON), "A parsing error has occured on spreadsheet *" + spreadsheetName + "* sheet *" + sheetName + "* at row *" + row + "*.\n Details: " + exception.getMessage()), - true); - } - catch (MalformedURLException e) - { - e.printStackTrace(); - } +// try +// { +// SlackAPI.getInstance().sendMessage(SlackTeam.DEVELOPER, SLACK_CHANNEL_NAME, new SlackMessage(SLACK_USERNAME, new URL(SLACK_ICON), "A parsing error has occured on spreadsheet *" + spreadsheetName + "* sheet *" + sheetName + "* at row *" + row + "*.\n Details: " + exception.getMessage()), +// true); +// } +// catch (MalformedURLException e) +// { +// e.printStackTrace(); +// } } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java index c4511d7b9..4b9a4c645 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -6,6 +6,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.player.PlayerArmorStandManipulateEvent; +import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.plugin.java.JavaPlugin; public class WorldListeners implements Listener @@ -15,7 +17,7 @@ public class WorldListeners implements Listener { plugin.getServer().getPluginManager().registerEvents(this, plugin); } - + @EventHandler public void blockBreak(BlockBreakEvent event) { @@ -24,7 +26,7 @@ public class WorldListeners implements Listener event.setCancelled(true); } } - + @EventHandler public void blockPlace(BlockPlaceEvent event) { @@ -33,10 +35,28 @@ public class WorldListeners implements Listener event.setCancelled(true); } } + + @EventHandler + public void armorStandEdit(PlayerArmorStandManipulateEvent event) + { + if (shouldBlock(event.getPlayer())) + { + event.setCancelled(true); + } + } + @EventHandler + public void armorStandDestory(PlayerInteractAtEntityEvent event) + { + if (shouldBlock(event.getPlayer())) + { + event.setCancelled(true); + } + } + public boolean shouldBlock(Player player) { return player.getGameMode() != GameMode.CREATIVE; } - + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java index c3a3036a9..aade4f095 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventType.java @@ -1,13 +1,11 @@ package mineplex.gemhunters.worldevent; import mineplex.gemhunters.worldevent.giant.GiantWorldEvent; -import mineplex.gemhunters.worldevent.pumpkinking.PumpkinKingWorldEvent; public enum WorldEventType { GIANT("Zombie Awakening", GiantWorldEvent.class, WorldEventPriority.GLOBAL), - PUMPKIN_KING("Pumpkin King", PumpkinKingWorldEvent.class, WorldEventPriority.ISOLATED) ; private String _name; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PhaseOne.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PhaseOne.java deleted file mode 100644 index 708888dbd..000000000 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PhaseOne.java +++ /dev/null @@ -1,85 +0,0 @@ -package mineplex.gemhunters.worldevent.pumpkinking; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.scheduler.BukkitRunnable; - -import mineplex.core.common.util.MapUtil; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilServer; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; - -public class PhaseOne implements Listener -{ - - private static final int SHIELD_RADIUS = 4; - - private final PumpkingKing _pumpkingKing; - private final Set _sheildBlocks; - - private boolean _shieldActive; - - public PhaseOne(PumpkingKing pumpkingKing) - { - _pumpkingKing = pumpkingKing; - _sheildBlocks = new HashSet<>(); - } - - @EventHandler - public void shieldActive(UpdateEvent event) - { - if (event.getType() != UpdateType.FASTER) - { - return; - } - - if (!_shieldActive) - { - _shieldActive = true; - createShield(); - } - } - - public void createShield() - { - Map blocks = UtilBlock.getInRadius(_pumpkingKing.getSpawn().getBlock(), SHIELD_RADIUS); - - new BukkitRunnable() - { - - int y = _pumpkingKing.getSpawn().clone().subtract(0, SHIELD_RADIUS, 0).getBlockY(); - int yGoal = y + SHIELD_RADIUS * 2; - - @Override - public void run() - { - if (y > yGoal) - { - cancel(); - return; - } - - for (Block block : blocks.keySet()) - { - if (blocks.get(block) > 0.3 || block.getLocation().getY() > y) - { - continue; - } - - _sheildBlocks.add(block); - MapUtil.QuickChangeBlockAt(block.getLocation(), Material.STAINED_GLASS, (byte) 10); - } - - y += 1; - } - }.runTaskTimer(UtilServer.getPlugin(), 0, 10); - } - -} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PumpkinKingWorldEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PumpkinKingWorldEvent.java deleted file mode 100644 index 6b2b59106..000000000 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PumpkinKingWorldEvent.java +++ /dev/null @@ -1,32 +0,0 @@ -package mineplex.gemhunters.worldevent.pumpkinking; - -import mineplex.gemhunters.worldevent.WorldEvent; -import mineplex.gemhunters.worldevent.WorldEventType; - -public class PumpkinKingWorldEvent extends WorldEvent -{ - - public PumpkinKingWorldEvent(WorldEventType eventType) - { - super(eventType); - } - - @Override - public void onStart() - { - new PumpkingKing(); - } - - @Override - public boolean checkToEnd() - { - return false; - } - - @Override - public void onEnd() - { - - } - -} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PumpkingKing.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PumpkingKing.java deleted file mode 100644 index f964d5e51..000000000 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/pumpkinking/PumpkingKing.java +++ /dev/null @@ -1,82 +0,0 @@ -package mineplex.gemhunters.worldevent.pumpkinking; - -import java.util.List; - -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Skeleton; -import org.bukkit.event.Listener; - -import mineplex.core.Managers; -import mineplex.core.common.util.C; -import mineplex.core.common.util.UtilEnt; -import mineplex.core.common.util.UtilServer; -import mineplex.core.utils.UtilVariant; -import mineplex.gemhunters.world.WorldDataModule; - -public class PumpkingKing -{ - - private final WorldDataModule _worldData; - - private final World _world; - private final Skeleton _entity; - private final Object[] _phases; - - private int _phase; - - public PumpkingKing() - { - _worldData = Managers.require(WorldDataModule.class); - - _world = _worldData.World; - _entity = UtilVariant.spawnWitherSkeleton(getSpawn()); - - _entity.setRemoveWhenFarAway(false); - _entity.setCustomName(C.cDRedB + "Pumpking King"); - _entity.setCustomNameVisible(true); - - UtilEnt.vegetate(_entity, true); - UtilEnt.ghost(_entity, true, false); - UtilEnt.setFakeHead(_entity, true); - - _phases = new Object[] { new PhaseOne(this) }; - - _phase = -1; - nextPhase(); - - //plugin.getServer().getPluginManager().registerEvents(this, plugin); - } - - public void nextPhase() - { - if (_phase != -1) - { - UtilServer.Unregister((Listener) _phases[_phase]); - } - - _phase++; - UtilServer.RegisterEvents((Listener) _phases[_phase]); - } - - public Location getSpawn() - { - return getLocation("Spawn"); - } - - public Location getLocation(String id) - { - return _worldData.getCustomLocation("PK " + id).get(0); - } - - public List getLocations(String id) - { - return _worldData.getCustomLocation("PK " + id); - } - - public Skeleton getEntity() - { - return _entity; - } - -} From 0d9deb019b98f138168ae15baed4b4f4551ebeec Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 2 Feb 2017 13:19:23 +0000 Subject: [PATCH 026/101] I do so much I never know what I commit --- .../gemhunters/death/DeathModule.java | 135 ++++++++++++++++-- .../mineplex/gemhunters/loot/LootModule.java | 4 +- .../scoreboard/ScoreboardModule.java | 60 +++++--- .../mineplex/gemhunters/shop/ShopModule.java | 55 +++---- .../mineplex/gemhunters/shop/TraderNPC.java | 18 ++- .../gemhunters/spawn/SpawnModule.java | 8 +- .../mineplex/gemhunters/util/SimpleNPC.java | 5 + .../gemhunters/util/SlackSheetsBot.java | 6 +- .../gemhunters/world/WorldListeners.java | 5 +- 9 files changed, 232 insertions(+), 64 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java index 50bd02ab2..e18e3bff9 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java @@ -1,19 +1,34 @@ package mineplex.gemhunters.death; +import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import java.util.Set; +import java.util.UUID; +import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; import com.google.common.collect.Sets; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; -import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.common.util.UtilTime; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.core.visibility.VisibilityManager; import mineplex.gemhunters.spawn.SpawnModule; /** @@ -25,37 +40,45 @@ import mineplex.gemhunters.spawn.SpawnModule; public class DeathModule extends MiniPlugin { - // Some items like the cash out item (and for some reason players drop bones?) don't need to be dropped to avoid duplication. - private static final Set DISALLOWED_DROPS = Sets.newHashSet(Material.EMERALD, Material.BONE); - + // Some items like the cash out item (and for some reason players drop + // bones?) don't need to be dropped to avoid duplication. + private static final Set DISALLOWED_DROPS = Sets.newHashSet(Material.EMERALD, Material.BONE, Material.STAINED_GLASS_PANE); + private static final int DEATH_ANIMATION_TIME = 7000; + private static final int DEATH_ANIMATION_COUNTDOWN = 2000; + private final SpawnModule _spawn; - + + private final Map _toRemove; + private DeathModule() { super("Death"); - + _spawn = require(SpawnModule.class); + + _toRemove = new HashMap<>(); } - + @EventHandler public void death(PlayerDeathEvent event) { Player player = event.getEntity(); - + // Stop the player dieing player.setHealth(20); player.setSaturation(20); player.setExhaustion(0); - UtilAction.zeroVelocity(player); - _spawn.teleportToSpawn(player); + + startAnimation(player); + _toRemove.put(player.getUniqueId(), System.currentTimeMillis()); Iterator iterator = event.getDrops().iterator(); - + // Iterate through all items and clear any disallowed items while (iterator.hasNext()) { ItemStack itemStack = iterator.next(); - + if (DISALLOWED_DROPS.contains(itemStack.getType())) { iterator.remove(); @@ -63,4 +86,92 @@ public class DeathModule extends MiniPlugin } } + @EventHandler + public void updateAnimations(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + { + return; + } + + Iterator iterator = _toRemove.keySet().iterator(); + + while (iterator.hasNext()) + { + UUID key = iterator.next(); + Player player = UtilPlayer.searchExact(key); + + if (player == null) + { + _toRemove.remove(key); + continue; + } + + long start = _toRemove.get(key); + long end = start + DEATH_ANIMATION_TIME + 1000; + + if (UtilTime.elapsed(start, DEATH_ANIMATION_TIME)) + { + stopAnimation(player); + _toRemove.remove(key); + continue; + } + else if (UtilTime.elapsed(start, DEATH_ANIMATION_COUNTDOWN)) + { + UtilTextMiddle.display(C.cRedB + "YOU DIED", String.valueOf((int) (end - System.currentTimeMillis()) / 1000), 0, 20, 0, player); + } + } + } + + public void startAnimation(Player player) + { + UtilTextMiddle.display(C.cRedB + "YOU DIED", "Respawning shortly", 0, 60, 0, player); + VisibilityManager.Instance.setVisibility(player, false, UtilServer.getPlayers()); + player.setAllowFlight(true); + player.setFlying(true); + player.setGameMode(GameMode.CREATIVE); + } + + public void stopAnimation(Player player) + { + UtilTextMiddle.display(C.cGreenB + "RESPAWNED", "", 0, 20, 20, player); + VisibilityManager.Instance.setVisibility(player, true, UtilServer.getPlayers()); + player.setFlying(false); + player.setAllowFlight(false); + player.setGameMode(GameMode.SURVIVAL); + _spawn.teleportToSpawn(player); + } + + @EventHandler + public void itemPickup(PlayerPickupItemEvent event) + { + if (_toRemove.containsKey(event.getPlayer().getUniqueId())) + { + event.setCancelled(true); + } + } + + @EventHandler + public void blockBreak(BlockBreakEvent event) + { + if (_toRemove.containsKey(event.getPlayer().getUniqueId())) + { + event.setCancelled(true); + } + } + + @EventHandler + public void blockPlace(BlockPlaceEvent event) + { + if (_toRemove.containsKey(event.getPlayer().getUniqueId())) + { + event.setCancelled(true); + } + } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + _toRemove.remove(event.getPlayer().getUniqueId()); + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 9d62617a5..3bb9b50ff 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -168,7 +168,7 @@ public class LootModule extends MiniPlugin if (locations.size() == usedIndexes.size()) { - return; + continue; } Location randomLocation = null; @@ -208,7 +208,7 @@ public class LootModule extends MiniPlugin continue; } - Bukkit.broadcastMessage("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index + " and max=" + max); + Bukkit.broadcastMessage("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); _spawnedChest.add(new SpawnedChest(chestToPlace, properties, index)); block.setType(properties.getBlockMaterial()); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java index 4b12e985d..25d966d6e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java @@ -10,16 +10,18 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Score; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; -import mineplex.core.account.CoreClientManager; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.economy.EconomyModule; @ReflectivelyCreateMiniPlugin public class ScoreboardModule extends MiniPlugin @@ -29,8 +31,8 @@ public class ScoreboardModule extends MiniPlugin private static final String SECONDARY_COLOUR = C.cWhiteB; private static final String TRANSITION_COLOUR = C.cDGreenB; private static final String SCOREBOARD_TITLE = " GEM HUNTERS "; - - private final CoreClientManager _clientManager; + + private final EconomyModule _economy; private final Map _scoreboards; @@ -41,7 +43,7 @@ public class ScoreboardModule extends MiniPlugin { super("Scoreboard"); - _clientManager = require(CoreClientManager.class); + _economy = require(EconomyModule.class); _scoreboards = new HashMap<>(); } @@ -84,8 +86,35 @@ public class ScoreboardModule extends MiniPlugin _scoreboards.remove(player.getUniqueId()); } - public void createPlayerScoreboard(Player player) + @EventHandler + public void updateGemsCounter(UpdateEvent event) { + if (event.getType() != UpdateType.SEC_08) + { + return; + } + + for (Player player : UtilServer.getPlayers()) + { + int gems = _economy.getGems(player); + + for (GemHuntersScoreboard scoreboard : _scoreboards.values()) + { + Objective objective = scoreboard.getHandle().getObjective(DisplaySlot.BELOW_NAME); + Score score = objective.getScore(player.getName()); + + if (score.getScore() == gems) + { + continue; + } + + score.setScore(gems); + } + } + } + + public void createPlayerScoreboard(Player player) + { if (!_scoreboards.containsKey(player.getUniqueId())) { GemHuntersScoreboard scoreboard = new GemHuntersScoreboard(player); @@ -93,30 +122,30 @@ public class ScoreboardModule extends MiniPlugin _scoreboards.put(player.getUniqueId(), scoreboard); - String tag = _clientManager.Get(player).GetRank().getTag(true, true); + // Gem Counter Undername + Objective gemCounter = handle.registerNewObjective("Gems", "Gems"); + gemCounter.setDisplaySlot(DisplaySlot.BELOW_NAME); for (GemHuntersScoreboard other : _scoreboards.values()) { + // Set the other player's name tag for the player joining Player otherPlayer = other.getOwner(); Team team = handle.registerNewTeam(otherPlayer.getName()); - - team.setPrefix(_clientManager.Get(otherPlayer).GetRank().getTag(true, true) + C.Reset + " "); + + team.setPrefix(C.cYellow); team.setSuffix(scoreboard.getSuffix(player, otherPlayer)); team.addEntry(otherPlayer.getName()); - + if (player.equals(otherPlayer)) { continue; } - - Objective gemCounter = handle.registerNewObjective("gems", "Gems"); - gemCounter.setDisplaySlot(DisplaySlot.BELOW_NAME); - gemCounter.getScore(otherPlayer.getName()).setScore(scoreboard.getUndernameScore(otherPlayer)); + // Set the player that is joining Scoreboard otherHandle = other.getHandle(); Team otherTeam = otherHandle.registerNewTeam(player.getName()); - otherTeam.setPrefix(tag + C.Reset + " "); + otherTeam.setPrefix(C.cYellow); otherTeam.setSuffix(other.getSuffix(other.getOwner(), player)); otherTeam.addEntry(player.getName()); } @@ -163,7 +192,7 @@ public class ScoreboardModule extends MiniPlugin { scoreboard.setSidebarName(out); } - + _shineIndex++; if (_shineIndex == SCOREBOARD_TITLE.length() * 2) @@ -172,5 +201,4 @@ public class ScoreboardModule extends MiniPlugin _shineDirection = !_shineDirection; } } - } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java index 82013eb3f..e2f46a809 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java @@ -3,6 +3,7 @@ package mineplex.gemhunters.shop; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -49,10 +50,9 @@ public class ShopModule extends MiniPlugin private static final int MINIMUM_ITEMS = 1; private static final int MAXIMUM_ITEMS = 5; - private static final int MAX_SEARCH_ATTEMPTS = 40; private static final String[] NAMES = { - "Andrew", "Jon", "Bob", "Sam", "Ronan", "Alex", "Joe", "Emma", "Giovani", "Dean", "Josh", "Geoffrey", "Parker", "Spencer", "Luke" + "Andrew", "Jon", "Bob", "Sam", "Ronan", "Alex", "Joe", "Emma", "Giovani", "Dean", "Josh", "Geoffrey", "Parker", "Spencer", "Luke", "Peter", "William", "Connor" }; private final GoogleSheetsManager _sheets; @@ -110,9 +110,8 @@ public class ShopModule extends MiniPlugin continue; } - - continue; } + continue; } Set items = new HashSet<>(); @@ -151,9 +150,23 @@ public class ShopModule extends MiniPlugin return; } + Iterator iterator = _npcs.iterator(); + + while (iterator.hasNext()) + { + TraderNPC npc = iterator.next(); + int expireTime = npc.getProperties().getExpireRate(); + + if (expireTime > 0 && UtilTime.elapsed(npc.getSpawnedAt(), expireTime)) + { + npc.getEntity().remove(); + iterator.remove(); + } + } + for (String key : _properties.keySet()) { - List locations = _worldData.getDataLocation(key); + List locations = _worldData.getSpawnLocation(capitalise(key)); VillagerProperties properties = _properties.get(key); if (!UtilTime.elapsed(properties.getLastSpawn(), properties.getSpawnRate())) @@ -190,30 +203,16 @@ public class ShopModule extends MiniPlugin } if (locations.size() == usedIndexes.size()) - { - return; - } - - Location randomLocation = null; - int attempts = 0; - int index = -1; - - while (index == -1 || usedIndexes.contains(index) && attempts < MAX_SEARCH_ATTEMPTS) - { - index = UtilMath.r(locations.size()); - - attempts++; - } - - if (index == -1) { continue; } - usedIndexes.add(index); - randomLocation = locations.get(index); + int index = UtilMath.r(locations.size()); + Location randomLocation = locations.get(index); - Bukkit.broadcastMessage("Trader at " + UtilWorld.locToStrClean(randomLocation) + " with key=" + key + " and index=" + index + " and max=" + max); + usedIndexes.add(index); + + Bukkit.broadcastMessage("Trader at " + UtilWorld.locToStrClean(randomLocation) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); _npcs.add(new TraderNPC(_plugin, randomLocation, Villager.class, NAMES[UtilMath.r(NAMES.length)], _safezone.isInSafeZone(randomLocation), properties, getRandomItemSet(_trades.get(key)))); } } @@ -230,5 +229,13 @@ public class ShopModule extends MiniPlugin return items2; } + + private final String capitalise(String s) + { + String right = s.toLowerCase().substring(1); + char left = Character.toUpperCase(s.charAt(0)); + + return left + right; + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java index 7d0f7845b..23301c7b6 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java @@ -14,18 +14,22 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.Managers; +import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.common.util.F; +import mineplex.core.itemstack.ItemBuilder; import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.util.SimpleNPC; public class TraderNPC extends SimpleNPC { - private final EconomyModule _economy; private final VillagerProperties _properties; private final Set _selling; private final Inventory _inv; + private final long _spawnedAt; + public TraderNPC(JavaPlugin plugin, Location spawn, Class type, String name, boolean vegetated, VillagerProperties properties, Set selling) { super(plugin, spawn, type, name, null, vegetated); @@ -35,12 +39,15 @@ public class TraderNPC extends SimpleNPC _properties = properties; _selling = selling; _inv = plugin.getServer().createInventory(null, 9, name); + _spawnedAt = System.currentTimeMillis(); int index = 1; for (TradeableItem item : _selling) { - _inv.setItem(index++, item.getLootItem().getItemStack()); + ItemStack itemStack = new ItemBuilder(item.getLootItem().getItemStack()).addLore("", "Cost: " + F.currency(GlobalCurrency.GEM, item.getCost())).build(); + + _inv.setItem(index++, itemStack); } } @@ -104,7 +111,7 @@ public class TraderNPC extends SimpleNPC { for (TradeableItem item : _selling) { - if (item.getLootItem().getItemStack().isSimilar(itemStack)) + if (item.getLootItem().getItemStack().getType() == itemStack.getType()) { return item.getCost(); } @@ -118,4 +125,9 @@ public class TraderNPC extends SimpleNPC return _properties; } + public final long getSpawnedAt() + { + return _spawnedAt; + } + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index acfd9ed4e..74753ba1f 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -52,11 +52,13 @@ public class SpawnModule extends MiniPlugin if (_spawn == null || _center == null) { _spawn = _worldData.getCustomLocation("PLAYER_SPAWN").get(0); - _center = _worldData.getCustomLocation("CENTER").get(0); + _center = new Location(_worldData.World, 0, 64, 0); } - event.getPlayer().teleport(_spawn); - + Player player = event.getPlayer(); + + player.teleport(_spawn); + if (_npcsSpawned) { return; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java index 539adbf3c..ee5e7dd94 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java @@ -81,5 +81,10 @@ public class SimpleNPC implements Listener HandlerList.unregisterAll(this); } + + public final LivingEntity getEntity() + { + return _entity; + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SlackSheetsBot.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SlackSheetsBot.java index 7e356d085..4523e1642 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SlackSheetsBot.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SlackSheetsBot.java @@ -9,10 +9,12 @@ public class SlackSheetsBot public static final void reportParsingError(Exception exception, String spreadsheetName, String sheetName, int row) { + String message = "A parsing error has occured on spreadsheet *" + spreadsheetName + "* sheet *" + sheetName + "* at row *" + row + "*.\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), "A parsing error has occured on spreadsheet *" + spreadsheetName + "* sheet *" + sheetName + "* at row *" + row + "*.\n Details: " + exception.getMessage()), -// true); +// SlackAPI.getInstance().sendMessage(SlackTeam.DEVELOPER, SLACK_CHANNEL_NAME, new SlackMessage(SLACK_USERNAME, new URL(SLACK_ICON), message), true); // } // catch (MalformedURLException e) // { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java index 4b9a4c645..5e1605e80 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -3,6 +3,7 @@ package mineplex.gemhunters.world; import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; @@ -18,7 +19,7 @@ public class WorldListeners implements Listener plugin.getServer().getPluginManager().registerEvents(this, plugin); } - @EventHandler + @EventHandler(priority=EventPriority.LOWEST) public void blockBreak(BlockBreakEvent event) { if (shouldBlock(event.getPlayer())) @@ -27,7 +28,7 @@ public class WorldListeners implements Listener } } - @EventHandler + @EventHandler(priority=EventPriority.LOWEST) public void blockPlace(BlockPlaceEvent event) { if (shouldBlock(event.getPlayer())) From bc510e5ad5c5b054ded666cff8fb3811cb563c8b Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 5 Feb 2017 22:24:10 +0000 Subject: [PATCH 027/101] QA fixes --- .../src/mineplex/gemhunters/GemHunters.java | 2 + .../gemhunters/death/DeathModule.java | 25 +++- .../events/PlayerCustomRespawnEvent.java | 27 +++++ .../gemhunters/economy/CashOutModule.java | 3 +- .../gemhunters/economy/EconomyModule.java | 4 +- .../gemhunters/loot/InventoryModule.java | 4 +- .../mineplex/gemhunters/loot/LootModule.java | 28 ++--- .../mineplex/gemhunters/shop/TraderNPC.java | 1 + .../gemhunters/spawn/SpawnModule.java | 107 ++++++++++++------ .../mineplex/gemhunters/util/SimpleNPC.java | 1 + .../mineplex/gemhunters/world/TimeCycle.java | 93 +++++++++++++++ .../gemhunters/world/WorldListeners.java | 13 ++- .../worldevent/giant/CustomGiant.java | 4 +- 13 files changed, 250 insertions(+), 62 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/events/PlayerCustomRespawnEvent.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 71ed8606b..6ac87f015 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -61,6 +61,7 @@ import mineplex.gemhunters.scoreboard.ScoreboardModule; import mineplex.gemhunters.shop.ShopModule; import mineplex.gemhunters.spawn.SpawnModule; import mineplex.gemhunters.supplydrop.SupplyDropModule; +import mineplex.gemhunters.world.TimeCycle; import mineplex.gemhunters.world.WorldListeners; import mineplex.gemhunters.worldevent.WorldEventModule; import mineplex.minecraft.game.core.combat.CombatManager; @@ -224,6 +225,7 @@ public class GemHunters extends JavaPlugin require(WorldEventModule.class); new WorldListeners(this); + new TimeCycle(this); // UpdateEvent!!! new Updater(this); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java index e18e3bff9..b57961ebd 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java @@ -8,11 +8,13 @@ import java.util.UUID; import org.bukkit.GameMode; import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; @@ -29,6 +31,7 @@ import mineplex.core.common.util.UtilTime; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.core.visibility.VisibilityManager; +import mineplex.gemhunters.death.events.PlayerCustomRespawnEvent; import mineplex.gemhunters.spawn.SpawnModule; /** @@ -59,6 +62,14 @@ public class DeathModule extends MiniPlugin _toRemove = new HashMap<>(); } + @EventHandler + public void join(PlayerJoinEvent event) + { + PlayerCustomRespawnEvent event2 = new PlayerCustomRespawnEvent(event.getPlayer()); + + UtilServer.CallEvent(event2); + } + @EventHandler public void death(PlayerDeathEvent event) { @@ -71,7 +82,7 @@ public class DeathModule extends MiniPlugin startAnimation(player); _toRemove.put(player.getUniqueId(), System.currentTimeMillis()); - + Iterator iterator = event.getDrops().iterator(); // Iterate through all items and clear any disallowed items @@ -109,7 +120,7 @@ public class DeathModule extends MiniPlugin long start = _toRemove.get(key); long end = start + DEATH_ANIMATION_TIME + 1000; - + if (UtilTime.elapsed(start, DEATH_ANIMATION_TIME)) { stopAnimation(player); @@ -127,6 +138,7 @@ public class DeathModule extends MiniPlugin { UtilTextMiddle.display(C.cRedB + "YOU DIED", "Respawning shortly", 0, 60, 0, player); VisibilityManager.Instance.setVisibility(player, false, UtilServer.getPlayers()); + ((CraftPlayer) player).getHandle().spectating = true; player.setAllowFlight(true); player.setFlying(true); player.setGameMode(GameMode.CREATIVE); @@ -136,10 +148,15 @@ public class DeathModule extends MiniPlugin { UtilTextMiddle.display(C.cGreenB + "RESPAWNED", "", 0, 20, 20, player); VisibilityManager.Instance.setVisibility(player, true, UtilServer.getPlayers()); + ((CraftPlayer) player).getHandle().spectating = false; player.setFlying(false); player.setAllowFlight(false); player.setGameMode(GameMode.SURVIVAL); _spawn.teleportToSpawn(player); + + PlayerCustomRespawnEvent event = new PlayerCustomRespawnEvent(player); + + UtilServer.CallEvent(event); } @EventHandler @@ -150,7 +167,7 @@ public class DeathModule extends MiniPlugin event.setCancelled(true); } } - + @EventHandler public void blockBreak(BlockBreakEvent event) { @@ -159,7 +176,7 @@ public class DeathModule extends MiniPlugin event.setCancelled(true); } } - + @EventHandler public void blockPlace(BlockPlaceEvent event) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/events/PlayerCustomRespawnEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/events/PlayerCustomRespawnEvent.java new file mode 100644 index 000000000..6b2db56a6 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/events/PlayerCustomRespawnEvent.java @@ -0,0 +1,27 @@ +package mineplex.gemhunters.death.events; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +public class PlayerCustomRespawnEvent extends PlayerEvent +{ + + private static final HandlerList HANDLERS = new HandlerList(); + + public PlayerCustomRespawnEvent(Player who) + { + super(who); + } + + public HandlerList getHandlers() + { + return HANDLERS; + } + + public static HandlerList getHandlerList() + { + return HANDLERS; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java index 605fdc029..99fbf52e7 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -35,6 +35,7 @@ import mineplex.core.itemstack.ItemBuilder; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.death.events.PlayerCustomRespawnEvent; @ReflectivelyCreateMiniPlugin public class CashOutModule extends MiniPlugin @@ -111,7 +112,7 @@ public class CashOutModule extends MiniPlugin } @EventHandler - public void playerJoin(PlayerJoinEvent event) + public void respawn(PlayerCustomRespawnEvent event) { Player player = event.getPlayer(); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java index 2c68e86fc..c53bfb47d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -9,13 +9,13 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.F; +import mineplex.gemhunters.death.events.PlayerCustomRespawnEvent; @ReflectivelyCreateMiniPlugin public class EconomyModule extends MiniPlugin @@ -33,7 +33,7 @@ public class EconomyModule extends MiniPlugin } @EventHandler - public void join(PlayerJoinEvent event) + public void respawn(PlayerCustomRespawnEvent event) { _storedGems.put(event.getPlayer().getUniqueId(), 0); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java index 09905b4fd..e1a026e61 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java @@ -11,7 +11,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -24,6 +23,7 @@ import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilInv; import mineplex.core.itemstack.ItemBuilder; +import mineplex.gemhunters.death.events.PlayerCustomRespawnEvent; @ReflectivelyCreateMiniPlugin public class InventoryModule extends MiniPlugin @@ -42,7 +42,7 @@ public class InventoryModule extends MiniPlugin } @EventHandler - public void join(PlayerJoinEvent event) + public void respawn(PlayerCustomRespawnEvent event) { Player player = event.getPlayer(); Inventory inv = player.getInventory(); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 3bb9b50ff..617fdd5da 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -16,7 +16,6 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.Chest; -import org.bukkit.block.DoubleChest; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.inventory.InventoryClickEvent; @@ -137,9 +136,9 @@ public class LootModule extends MiniPlugin { continue; } - + properties.setLastSpawn(); - + // Only spawn more chests if we need to int max = properties.getMaxActive(); int spawned = 0; @@ -298,21 +297,22 @@ public class LootModule extends MiniPlugin Set items = _chestLoot.get(key); ChestProperties properties = _chestProperties.get(key); - int sizeMultiplier = 1; - BlockState state = block.getState(); - - // TODO fix double chests - if (state instanceof DoubleChest) + Inventory inventory = null; + + if (block.getType() == Material.ENDER_CHEST) { - sizeMultiplier = 2; + inventory = player.getEnderChest(); + } + else + { + BlockState state = block.getState(); + Chest chest = (Chest) state; + inventory = chest.getBlockInventory(); } - - Chest chest = (Chest) state; - Inventory inventory = chest.getBlockInventory(); inventory.clear(); - for (int i = 0; i < UtilMath.rRange(properties.getMinAmount(), properties.getMaxAmount()) * sizeMultiplier; i++) + for (int i = 0; i < UtilMath.rRange(properties.getMinAmount(), properties.getMaxAmount()); i++) { LootItem lootItem = getRandomItem(items); ItemStack itemStack = lootItem.getItemStack(); @@ -404,7 +404,7 @@ public class LootModule extends MiniPlugin Player player = event.getPlayer(); Block block = event.getClickedBlock(); - if (block == null || block.getType() != Material.CHEST && block.getType() != Material.ENDER_CHEST) + if (block.getType() != Material.CHEST && block.getType() != Material.ENDER_CHEST) { return; } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java index 23301c7b6..eecdd6302 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java @@ -59,6 +59,7 @@ public class TraderNPC extends SimpleNPC if (event.getRightClicked().equals(_entity)) { + event.setCancelled(true); event.getPlayer().openInventory(_inv); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index 74753ba1f..bf03abafa 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -5,6 +5,7 @@ import org.bukkit.Material; import org.bukkit.WorldBorder; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.entity.Creeper; import org.bukkit.entity.Player; import org.bukkit.entity.Villager; import org.bukkit.event.EventHandler; @@ -20,6 +21,8 @@ import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; +import mineplex.core.portal.Intent; +import mineplex.core.portal.Portal; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.util.ColouredTextAnimation; import mineplex.gemhunters.util.SimpleNPC; @@ -29,7 +32,7 @@ import mineplex.gemhunters.world.WorldDataModule; public class SpawnModule extends MiniPlugin { - private static final int WORLD_BORDER_RADIUS = 300; + private static final int WORLD_BORDER_RADIUS = 900; private final SafezoneModule _safezone; private final WorldDataModule _worldData; @@ -56,9 +59,9 @@ public class SpawnModule extends MiniPlugin } Player player = event.getPlayer(); - + player.teleport(_spawn); - + if (_npcsSpawned) { return; @@ -71,51 +74,82 @@ public class SpawnModule extends MiniPlugin _npcsSpawned = true; - Location location = _worldData.getCustomLocation("TELEPORT_NPC").get(0); - - location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, _spawn))); - - new SimpleNPC(_plugin, location, Villager.class, C.cDRed + "! " + C.cRedB + "Enter The World" + C.cDRed + " !", new Callback() { + Location location = _worldData.getCustomLocation("TELEPORT_NPC").get(0); - @Override - public void run(Player data) + location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, _spawn))); + + new SimpleNPC(_plugin, location, Villager.class, C.cDRed + "! " + C.cRedB + "Enter The World" + C.cDRed + " !", new Callback() { - Location location = getRandomLocation(); - if (location == null) + @Override + public void run(Player data) { - data.sendMessage(F.main(_moduleName, "A suitable teleport location could not be found. Please try again in a few seconds.")); - return; - } + Location location = getRandomLocation(); - data.teleport(location); - data.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 4 * 20, 9)); - data.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 4 * 20, 9)); - - ColouredTextAnimation animation = new ColouredTextAnimation("GEM HUNTERS", C.cGoldB + "M ", C.cGoldB + " M", new String[] { C.cDGreenB, C.cGreenB, C.cWhiteB }); - - runSyncTimer(new BukkitRunnable() - { - - @Override - public void run() + if (location == null) { - if (animation.displayAsTitle(data)) - { - cancel(); - } + data.sendMessage(F.main(_moduleName, "A suitable teleport location could not be found. Please try again in a few seconds.")); + return; } - }, 10, 4); - } - }); + + data.teleport(location); + data.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 4 * 20, 9)); + data.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 4 * 20, 9)); + + ColouredTextAnimation animation = new ColouredTextAnimation("GEM HUNTERS", C.cGoldB + "M ", C.cGoldB + " M", new String[] { C.cDGreenB, C.cGreenB, C.cWhiteB }); + + runSyncTimer(new BukkitRunnable() + { + + @Override + public void run() + { + if (animation.displayAsTitle(data)) + { + cancel(); + } + } + }, 10, 4); + } + }); + } + { + Location location = _worldData.getCustomLocation("RETURN_TO_HUB").get(0); + + location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, _spawn))); + + new SimpleNPC(_plugin, location, Villager.class, C.cGoldB + "Return To Hub", new Callback() + { + + @Override + public void run(Player data) + { + Portal.getInstance().sendToHub(data, null, Intent.PLAYER_REQUEST); + } + }); + } + { + Location location = _worldData.getCustomLocation("CARL").get(0); + + location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, _spawn))); + + new SimpleNPC(_plugin, location, Creeper.class, C.cGreenB + "Carl", new Callback() + { + + @Override + public void run(Player data) + { + } + }); + } } public void teleportToSpawn(Player player) { player.teleport(_spawn); } - + public boolean isSuitable(Block block) { Block up = block.getRelative(BlockFace.UP); @@ -149,4 +183,9 @@ public class SpawnModule extends MiniPlugin return null; } + public Location getCenter() + { + return _center; + } + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java index ee5e7dd94..e3c4e908a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java @@ -28,6 +28,7 @@ public class SimpleNPC implements Listener public SimpleNPC(JavaPlugin plugin, Location spawn, Class type, String name, Callback clickEvent, boolean vegetated) { + spawn.getWorld().loadChunk(spawn.getChunk()); _entity = spawn.getWorld().spawn(spawn, type); _entity.setRemoveWhenFarAway(false); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java new file mode 100644 index 000000000..b088867ae --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java @@ -0,0 +1,93 @@ +package mineplex.gemhunters.world; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.Managers; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class TimeCycle implements Listener +{ + + private static final int TICKS_DAY = 1; + private static final int TICKS_NIGHT = 2; + + private final WorldDataModule _worldData; + private World _world; + + private boolean _night; + + public TimeCycle(JavaPlugin plugin) + { + //plugin.getServer().getPluginManager().registerEvents(this, plugin); + + _worldData = Managers.get(WorldDataModule.class); + } + + public void setStreetLights() + { + Bukkit.broadcastMessage("Set " + _night + " " + _worldData.getCustomLocation("123").size()); + for (Location location : _worldData.getCustomLocation("123")) + { + Block block = location.getBlock().getRelative(BlockFace.UP); + + Bukkit.broadcastMessage("set"); + block.setType(_night ? Material.REDSTONE_BLOCK : Material.STONE_SLAB2); + } + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + if (_world == null) + { + _world = _worldData.World; + return; + } + + if (!_night && _world.getTime() > 12000) + { + _night = true; + setStreetLights(); + } + + if (_world.getTime() >= 23900) + { + _world.setTime(0); + _night = false; + setStreetLights(); + } + + _world.setTime(_world.getTime() + (isNight() ? TICKS_NIGHT : TICKS_DAY)); + } + + @EventHandler + public void test(PlayerCommandPreprocessEvent event) { + if (event.getMessage().startsWith("/lamp")) + { + event.setCancelled(true); + event.getPlayer().getLocation().getBlock().setType(Material.REDSTONE_LAMP_ON); + } + } + + public boolean isNight() + { + return _world.getTime() > 12000; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java index 5e1605e80..4c1519c84 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -9,6 +9,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; +import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.plugin.java.JavaPlugin; public class WorldListeners implements Listener @@ -19,7 +20,7 @@ public class WorldListeners implements Listener plugin.getServer().getPluginManager().registerEvents(this, plugin); } - @EventHandler(priority=EventPriority.LOWEST) + @EventHandler(priority = EventPriority.LOWEST) public void blockBreak(BlockBreakEvent event) { if (shouldBlock(event.getPlayer())) @@ -28,7 +29,7 @@ public class WorldListeners implements Listener } } - @EventHandler(priority=EventPriority.LOWEST) + @EventHandler(priority = EventPriority.LOWEST) public void blockPlace(BlockPlaceEvent event) { if (shouldBlock(event.getPlayer())) @@ -45,7 +46,7 @@ public class WorldListeners implements Listener event.setCancelled(true); } } - + @EventHandler public void armorStandDestory(PlayerInteractAtEntityEvent event) { @@ -55,6 +56,12 @@ public class WorldListeners implements Listener } } + @EventHandler + public void chunkUnload(ChunkUnloadEvent event) + { + event.setCancelled(true); + } + public boolean shouldBlock(Player player) { return player.getGameMode() != GameMode.CREATIVE; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/CustomGiant.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/CustomGiant.java index 27a864de3..f5ffdc10f 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/CustomGiant.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/CustomGiant.java @@ -26,7 +26,7 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.safezone.SafezoneModule; -import mineplex.gemhunters.world.WorldDataModule; +import mineplex.gemhunters.spawn.SpawnModule; public class CustomGiant implements Listener { @@ -60,7 +60,7 @@ public class CustomGiant implements Listener UtilEnt.ghost(_giant, true, false); UtilEnt.setFakeHead(_giant, true); - _fallback = Managers.get(WorldDataModule.class).getCustomLocation("CENTER").get(0); + _fallback = Managers.get(SpawnModule.class).getCenter(); } @EventHandler From 7452712107d06ce388a310af5d7479620697bd83 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 7 Feb 2017 00:12:51 +0000 Subject: [PATCH 028/101] Fix Constants --- Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 4b8fa70d5..a804d80f1 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -21,6 +21,7 @@ import mineplex.core.chatsnap.SnapshotManager; import mineplex.core.chatsnap.SnapshotPlugin; import mineplex.core.chatsnap.SnapshotRepository; import mineplex.core.command.CommandCenter; +import mineplex.core.common.Constants; import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.creature.Creature; import mineplex.core.customdata.CustomDataManager; @@ -89,20 +90,16 @@ import static mineplex.core.Managers.require; public class Hub extends JavaPlugin implements IRelation { - private String WEB_CONFIG = "webServer"; - private NpcManager _npcManager; @Override public void onEnable() { Bukkit.setSpawnRadius(0); - getConfig().addDefault(WEB_CONFIG, "http://accounts.mineplex.com/"); - getConfig().set(WEB_CONFIG, getConfig().getString(WEB_CONFIG)); + getConfig().addDefault(Constants.WEB_CONFIG_KEY, Constants.WEB_ADDRESS); + getConfig().set(Constants.WEB_CONFIG_KEY, getConfig().getString(Constants.WEB_CONFIG_KEY)); saveConfig(); - String webServerAddress = getConfig().getString(WEB_CONFIG); - //Logger.initialize(this); //Velocity Fix From 44d4fb9d6009cb66d95851285108b21ba6d39e30 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 7 Feb 2017 00:12:59 +0000 Subject: [PATCH 029/101] Fix /ignore not working --- .../src/mineplex/gemhunters/chat/ChatModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java index 31fd7a80a..f0fddd285 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java @@ -54,7 +54,7 @@ public class ChatModule extends MiniPlugin // We will handle the broadcast event.setCancelled(true); - for (Player other : Bukkit.getOnlinePlayers()) + for (Player other : event.getRecipients()) { other.sendMessage(message); } From e76ce9dce2adc7ed66e9c467446c3785a3c2f8ec Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 7 Feb 2017 00:17:26 +0000 Subject: [PATCH 030/101] Add a treat for samczsun --- .../src/mineplex/gemhunters/world/WorldListeners.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java index 4c1519c84..5aa7a40e1 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -59,6 +59,7 @@ public class WorldListeners implements Listener @EventHandler public void chunkUnload(ChunkUnloadEvent event) { + // Sam don't you dare look here, I understand the implications of this but entities, can I just save by UUID? or does not doing this have bigger complications?. event.setCancelled(true); } From e8b5c180eef13140573bc1dbf69e90e1479fd32f Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 9 Feb 2017 23:47:17 +0000 Subject: [PATCH 031/101] QA Testing fixes --- .../mineplex/gemhunters/chat/ChatModule.java | 1 - .../gemhunters/death/DeathModule.java | 13 +++- .../gemhunters/economy/CashOutModule.java | 24 ++---- .../gemhunters/economy/EconomyModule.java | 47 +++++++----- .../mineplex/gemhunters/loot/LootModule.java | 3 +- .../loot/rewards/LootItemReward.java | 3 +- .../scoreboard/ScoreboardModule.java | 4 +- .../mineplex/gemhunters/shop/ShopModule.java | 28 ++++++- .../mineplex/gemhunters/shop/TraderNPC.java | 12 ++- .../gemhunters/spawn/SpawnModule.java | 27 ++++--- .../mineplex/gemhunters/util/UtilDebug.java | 27 +++++++ .../gemhunters/world/WorldDataModule.java | 2 +- .../gemhunters/world/WorldListeners.java | 75 ++++++++++++++++++- 13 files changed, 200 insertions(+), 66 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/UtilDebug.java diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java index f0fddd285..91ed17ab0 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java @@ -1,6 +1,5 @@ package mineplex.gemhunters.chat; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java index b57961ebd..63377ec29 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java @@ -14,6 +14,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -77,6 +78,7 @@ public class DeathModule extends MiniPlugin // Stop the player dieing player.setHealth(20); + player.setFoodLevel(20); player.setSaturation(20); player.setExhaustion(0); @@ -114,7 +116,7 @@ public class DeathModule extends MiniPlugin if (player == null) { - _toRemove.remove(key); + iterator.remove(); continue; } @@ -185,6 +187,15 @@ public class DeathModule extends MiniPlugin event.setCancelled(true); } } + + @EventHandler + public void inventory(InventoryClickEvent event) + { + if (_toRemove.containsKey(event.getWhoClicked().getUniqueId())) + { + event.setCancelled(true); + } + } @EventHandler public void playerQuit(PlayerQuitEvent event) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java index 99fbf52e7..9d606393b 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -15,7 +15,6 @@ import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -27,22 +26,21 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; -import mineplex.core.donation.DonationManager; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.donation.DonationManager; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.gemhunters.death.events.PlayerCustomRespawnEvent; @ReflectivelyCreateMiniPlugin public class CashOutModule extends MiniPlugin { private static final DecimalFormat ARMOUR_STAND_FORMAT = new DecimalFormat("0.0"); - private static final ItemStack CASH_OUT_ITEM = new ItemBuilder(Material.EMERALD).setTitle(C.cGreen + "Cash Out").addLore("", C.cGray + "Click to begin the process to cash out.", C.cGray + "Cashing out saves your current loot.").build(); + public static final ItemStack CASH_OUT_ITEM = new ItemBuilder(Material.EMERALD).setTitle(C.cGreen + "Cash Out").addLore("", C.cGray + "Click to begin the process to cash out.", C.cGray + "Cashing out saves your current loot.").build(); private static final int CASH_OUT_COOLDOWN = 10000; private static final int CASH_OUT_MAX_MOVE_DISTANCE_SQUARED = 4; @@ -89,7 +87,7 @@ public class CashOutModule extends MiniPlugin { if (event.getItemDrop().getItemStack().isSimilar(CASH_OUT_ITEM)) { - event.getPlayer().sendMessage(F.main("Game", "You cannnot drop the " + F.item("Cash Out Item") + ".")); + event.getPlayer().sendMessage(F.main("Game", "You cannot drop the " + F.item("Cash Out Item") + ".")); event.setCancelled(true); } } @@ -112,18 +110,8 @@ public class CashOutModule extends MiniPlugin } @EventHandler - public void respawn(PlayerCustomRespawnEvent event) - { - Player player = event.getPlayer(); - - player.getInventory().setItem(8, CASH_OUT_ITEM); - } - - // TODO this probably - // @EventHandler public void playerQuit(PlayerQuitEvent event) { - attemptCashOut(event.getPlayer()); } @EventHandler @@ -143,7 +131,7 @@ public class CashOutModule extends MiniPlugin CashOutSession session = _sessions.get(key); double current = session.getCurrent(); ArmorStand stand = session.getArmourStand(); - String standName = ARMOUR_STAND_FORMAT.format(current) + " seconds"; + String standName = ARMOUR_STAND_FORMAT.format(current); if (player == null) { @@ -152,8 +140,8 @@ public class CashOutModule extends MiniPlugin continue; } - UtilTextMiddle.display("", UtilTextMiddle.progress((float) (1 - current / session.getMax())), 0, 10, 0, player); - stand.setCustomName(standName); + UtilTextMiddle.display(C.cGreen + standName, UtilTextMiddle.progress((float) (1 - current / session.getMax())), 0, 10, 0, player); + stand.setCustomName(standName + " seconds"); session.setCurrent(current - 0.05); if (session.getCurrent() <= 0) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java index c53bfb47d..075655a3d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -22,69 +22,76 @@ public class EconomyModule extends MiniPlugin { private static final float GEM_KILL_FACTOR = 0.5F; - + private Map _storedGems; - + public EconomyModule() { super("Economy"); - + _storedGems = new HashMap<>(); } - + @EventHandler public void respawn(PlayerCustomRespawnEvent event) { - _storedGems.put(event.getPlayer().getUniqueId(), 0); + addToStore(event.getPlayer(), null, 100); } - + @EventHandler public void death(PlayerDeathEvent event) { Player player = event.getEntity(); Entity killer = event.getEntity().getKiller(); - + if (!(killer instanceof Player)) { return; } - + Player killerPlayer = (Player) killer; - + int oldGems = _storedGems.get(player.getUniqueId()); int newGems = (int) (oldGems * GEM_KILL_FACTOR); - + addToStore(killerPlayer, "Killing " + F.name(player.getName()), newGems); removeFromStore(player, oldGems); } - + @EventHandler public void cashOut(PlayerCashOutCompleteEvent event) { - event.incrementGems(_storedGems.get(event.getPlayer().getUniqueId())); + event.incrementGems(getGems(event.getPlayer())); } - + @EventHandler public void quit(PlayerQuitEvent event) { _storedGems.remove(event.getPlayer().getUniqueId()); } - + public void addToStore(Player player, String reason, int gems) { - _storedGems.put(player.getUniqueId(), _storedGems.get(player.getUniqueId()) + gems); - + UUID key = player.getUniqueId(); + + if (!_storedGems.containsKey(key)) + { + _storedGems.put(key, 0); + } + + _storedGems.put(key, _storedGems.get(key) + gems); + if (reason != null) { player.sendMessage(F.main(_moduleName, "+" + F.currency(GlobalCurrency.GEM, gems) + " (" + reason + ").")); } } - + public void removeFromStore(Player player, int gems) { - _storedGems.put(player.getUniqueId(), _storedGems.get(player.getUniqueId()) - gems); + addToStore(player, null, -gems); } - + public int getGems(Player player) { return _storedGems.get(player.getUniqueId()); @@ -99,5 +106,5 @@ public class EconomyModule extends MiniPlugin addToStore(event.getPlayer(), "Testing", 100); } } - + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 617fdd5da..8e3b1c07f 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -44,6 +44,7 @@ import mineplex.gemhunters.loot.rewards.LootItemReward; import mineplex.gemhunters.loot.rewards.LootRankReward; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.util.SlackSheetsBot; +import mineplex.gemhunters.util.UtilDebug; import mineplex.gemhunters.world.WorldDataModule; @ReflectivelyCreateMiniPlugin @@ -207,7 +208,7 @@ public class LootModule extends MiniPlugin continue; } - Bukkit.broadcastMessage("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); + UtilDebug.d("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); _spawnedChest.add(new SpawnedChest(chestToPlace, properties, index)); block.setType(properties.getBlockMaterial()); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java index d12bc52b9..b9777ef77 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java @@ -11,6 +11,7 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; import mineplex.core.recharge.Recharge; +import mineplex.gemhunters.util.UtilDebug; public abstract class LootItemReward { @@ -69,7 +70,7 @@ public abstract class LootItemReward public final void success() { - Bukkit.broadcastMessage("Success"); + UtilDebug.d("Success"); onSuccessful(); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java index 25d966d6e..54e93ddf3 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java @@ -133,7 +133,7 @@ public class ScoreboardModule extends MiniPlugin Team team = handle.registerNewTeam(otherPlayer.getName()); team.setPrefix(C.cYellow); - team.setSuffix(scoreboard.getSuffix(player, otherPlayer)); + //team.setSuffix(scoreboard.getSuffix(player, otherPlayer)); team.addEntry(otherPlayer.getName()); if (player.equals(otherPlayer)) @@ -146,7 +146,7 @@ public class ScoreboardModule extends MiniPlugin Team otherTeam = otherHandle.registerNewTeam(player.getName()); otherTeam.setPrefix(C.cYellow); - otherTeam.setSuffix(other.getSuffix(other.getOwner(), player)); + //otherTeam.setSuffix(other.getSuffix(other.getOwner(), player)); otherTeam.addEntry(player.getName()); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java index e2f46a809..3ca326bce 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Villager; import org.bukkit.event.EventHandler; @@ -27,6 +26,7 @@ import mineplex.gemhunters.loot.deserialisers.LootItemDeserialiser; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.shop.deserialisers.VillagerPropertiesDeserialiser; import mineplex.gemhunters.util.SlackSheetsBot; +import mineplex.gemhunters.util.UtilDebug; import mineplex.gemhunters.world.WorldDataModule; @ReflectivelyCreateMiniPlugin @@ -207,17 +207,37 @@ public class ShopModule extends MiniPlugin continue; } - int index = UtilMath.r(locations.size()); + int index = getFreeIndex(locations.size(), usedIndexes); + + if (index == -1) + { + return; + } + Location randomLocation = locations.get(index); usedIndexes.add(index); - Bukkit.broadcastMessage("Trader at " + UtilWorld.locToStrClean(randomLocation) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); + UtilDebug.d("Trader at " + UtilWorld.locToStrClean(randomLocation) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); _npcs.add(new TraderNPC(_plugin, randomLocation, Villager.class, NAMES[UtilMath.r(NAMES.length)], _safezone.isInSafeZone(randomLocation), properties, getRandomItemSet(_trades.get(key)))); } } - public Set getRandomItemSet(Set items) + private int getFreeIndex(int endIndex, Set used) + { + int index = -1; + + while (index == -1 || used.contains(index)) + { + index = UtilMath.r(endIndex); + } + + used.add(index); + + return index; + } + + private Set getRandomItemSet(Set items) { int size = UtilMath.rRange(MINIMUM_ITEMS, MAXIMUM_ITEMS); Set items2 = new HashSet<>(size); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java index eecdd6302..707ce5057 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java @@ -16,7 +16,9 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.Managers; import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilItem; import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.itemstack.ItemStackFactory; import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.util.SimpleNPC; @@ -45,7 +47,7 @@ public class TraderNPC extends SimpleNPC for (TradeableItem item : _selling) { - ItemStack itemStack = new ItemBuilder(item.getLootItem().getItemStack()).addLore("", "Cost: " + F.currency(GlobalCurrency.GEM, item.getCost())).build(); + ItemStack itemStack = new ItemBuilder(item.getLootItem().getItemStack()).addLore("Cost: " + F.currency(GlobalCurrency.GEM, item.getCost())).build(); _inv.setItem(index++, itemStack); } @@ -77,6 +79,8 @@ public class TraderNPC extends SimpleNPC return; } + event.setCancelled(true); + ItemStack itemStack = event.getCurrentItem(); if (itemStack == null) @@ -93,16 +97,18 @@ public class TraderNPC extends SimpleNPC return; } - event.setCancelled(true); - if (cost > gems) { + player.sendMessage(F.main(_entity.getCustomName(), "I'm sorry you don't have enough gems to purchase this.")); player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0.6F); return; } _economy.removeFromStore(player, cost); + String itemName = ItemStackFactory.Instance.GetName(itemStack, true); + + player.sendMessage(F.main(_entity.getCustomName(), "Purchased " + F.elem(itemName) + "!")); player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 1.2F); player.getInventory().addItem(itemStack); player.closeInventory(); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index bf03abafa..b6bbc038c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -5,7 +5,6 @@ import org.bukkit.Material; import org.bukkit.WorldBorder; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.entity.Creeper; import org.bukkit.entity.Player; import org.bukkit.entity.Villager; import org.bukkit.event.EventHandler; @@ -23,6 +22,7 @@ import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; import mineplex.core.portal.Intent; import mineplex.core.portal.Portal; +import mineplex.gemhunters.economy.CashOutModule; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.util.ColouredTextAnimation; import mineplex.gemhunters.util.SimpleNPC; @@ -32,8 +32,9 @@ import mineplex.gemhunters.world.WorldDataModule; public class SpawnModule extends MiniPlugin { - private static final int WORLD_BORDER_RADIUS = 900; - + private static final int WORLD_BORDER_RADIUS = 750; + private static final int MAX_SPAWNING_Y = 73; + private final SafezoneModule _safezone; private final WorldDataModule _worldData; @@ -83,20 +84,22 @@ public class SpawnModule extends MiniPlugin { @Override - public void run(Player data) + public void run(Player player) { Location location = getRandomLocation(); if (location == null) { - data.sendMessage(F.main(_moduleName, "A suitable teleport location could not be found. Please try again in a few seconds.")); + player.sendMessage(F.main(_moduleName, "A suitable teleport location could not be found. Please try again in a few seconds.")); return; } - data.teleport(location); - data.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 4 * 20, 9)); - data.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 4 * 20, 9)); + player.teleport(location); + player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 4 * 20, 9)); + player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 4 * 20, 9)); + player.getInventory().setItem(8, CashOutModule.CASH_OUT_ITEM); + ColouredTextAnimation animation = new ColouredTextAnimation("GEM HUNTERS", C.cGoldB + "M ", C.cGoldB + " M", new String[] { C.cDGreenB, C.cGreenB, C.cWhiteB }); runSyncTimer(new BukkitRunnable() @@ -105,7 +108,7 @@ public class SpawnModule extends MiniPlugin @Override public void run() { - if (animation.displayAsTitle(data)) + if (animation.displayAsTitle(player)) { cancel(); } @@ -130,11 +133,11 @@ public class SpawnModule extends MiniPlugin }); } { - Location location = _worldData.getCustomLocation("CARL").get(0); + Location location = _worldData.getCustomLocation("TUTORIAL").get(0); location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, _spawn))); - new SimpleNPC(_plugin, location, Creeper.class, C.cGreenB + "Carl", new Callback() + new SimpleNPC(_plugin, location, Villager.class, C.cGoldB + "Tutorial", new Callback() { @Override @@ -155,7 +158,7 @@ public class SpawnModule extends MiniPlugin Block up = block.getRelative(BlockFace.UP); Block down = block.getRelative(BlockFace.DOWN); - if (block.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block) || _safezone.isInSafeZone(block.getLocation())) + if (block.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block) || _safezone.isInSafeZone(block.getLocation()) || block.getLocation().getBlockY() > MAX_SPAWNING_Y) { return false; } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/UtilDebug.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/UtilDebug.java new file mode 100644 index 000000000..2c95a9b84 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/UtilDebug.java @@ -0,0 +1,27 @@ +package mineplex.gemhunters.util; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +public class UtilDebug +{ + + public static final void d(String message) + { + for (Player player : Bukkit.getOnlinePlayers()) + { + if (player.getItemInHand() == null || player.getItemInHand().getType() != Material.SPONGE) + { + continue; + } + + if (player.getName().equals("Moppletop")) + { + player.sendMessage(message); + return; + } + } + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java index a3b7111ef..7f9b23ff2 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java @@ -69,7 +69,7 @@ public class WorldDataModule extends MiniPlugin TimingManager.stop("WorldData loading world."); - World.setDifficulty(Difficulty.HARD); + World.setDifficulty(Difficulty.EASY); World.setGameRuleValue("showDeathMessages", "false"); TimingManager.start("WorldData loading WorldConfig."); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java index 5aa7a40e1..4fc9d54c3 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -1,23 +1,50 @@ package mineplex.gemhunters.world; +import org.bukkit.Bukkit; import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockBurnEvent; +import org.bukkit.event.block.BlockFadeEvent; +import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.hanging.HangingBreakEvent; +import org.bukkit.event.hanging.HangingEvent; +import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.world.ChunkUnloadEvent; +import org.bukkit.inventory.BrewerInventory; import org.bukkit.plugin.java.JavaPlugin; +import org.spigotmc.SpigotConfig; public class WorldListeners implements Listener { + private static final int VIEW_DISTANCE = 10; + public WorldListeners(JavaPlugin plugin) { plugin.getServer().getPluginManager().registerEvents(this, plugin); + + plugin.getServer().getScheduler().runTaskLater(plugin, () -> { + + for (World world : plugin.getServer().getWorlds()) + { + SpigotConfig.config.set("world-settings.world.view-distance", VIEW_DISTANCE); + ((CraftWorld) world).getHandle().spigotConfig.viewDistance = VIEW_DISTANCE; + Bukkit.broadcastMessage(((CraftWorld) world).getHandle().spigotConfig.viewDistance + " chunks"); + } + + }, 20); } @EventHandler(priority = EventPriority.LOWEST) @@ -32,7 +59,7 @@ public class WorldListeners implements Listener @EventHandler(priority = EventPriority.LOWEST) public void blockPlace(BlockPlaceEvent event) { - if (shouldBlock(event.getPlayer())) + if (event.getBlockPlaced().getType() != Material.CAKE_BLOCK && shouldBlock(event.getPlayer())) { event.setCancelled(true); } @@ -56,10 +83,54 @@ public class WorldListeners implements Listener } } + @EventHandler + public void armorStandDamage(EntityDamageEvent event) + { + if (event.getEntity() instanceof ArmorStand) + { + event.setCancelled(true); + } + } + + @EventHandler + public void paintings(HangingBreakEvent event) + { + event.setCancelled(true); + } + + @EventHandler + public void inventoryOpen(InventoryOpenEvent event) + { + if (event.getInventory() instanceof BrewerInventory) + { + event.setCancelled(true); + } + } + @EventHandler public void chunkUnload(ChunkUnloadEvent event) { - // Sam don't you dare look here, I understand the implications of this but entities, can I just save by UUID? or does not doing this have bigger complications?. + // Sam don't you dare look here, I understand the implications of this + // but entities, can I just save by UUID? or does not doing this have + // bigger complications?. + event.setCancelled(true); + } + + @EventHandler + public void fireSpread(BlockIgniteEvent event) + { + event.setCancelled(true); + } + + @EventHandler + public void fireSpread(BlockBurnEvent event) + { + event.setCancelled(true); + } + + @EventHandler + public void blockDecay(BlockFadeEvent event) + { event.setCancelled(true); } From 16773521b94000e8498f1adcfccdae0263c61193 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 11 Feb 2017 17:18:39 +0000 Subject: [PATCH 032/101] Lots of fixes --- .../core/google/GoogleSheetsManager.java | 2 +- .../src/mineplex/gemhunters/GemHunters.java | 2 + .../gemhunters/economy/CashOutModule.java | 2 +- .../gemhunters/economy/EconomyModule.java | 16 +- .../gemhunters/loot/ChestProperties.java | 21 +- .../gemhunters/loot/InventoryModule.java | 32 +-- .../mineplex/gemhunters/loot/LootModule.java | 203 ++++++++++-------- .../loot/command/SpawnChestCommand.java | 47 ++++ .../ChestPropertiesDeserialiser.java | 11 +- .../deserialisers/LootItemDeserialiser.java | 26 ++- .../loot/rewards/LootItemReward.java | 5 +- .../gemhunters/safezone/SafezoneModule.java | 31 ++- .../mineplex/gemhunters/shop/ShopModule.java | 6 +- .../mineplex/gemhunters/shop/TraderNPC.java | 1 - .../supplydrop/SupplyDropModule.java | 16 +- .../{commands => command}/EndCommand.java | 2 +- .../{commands => command}/StartCommand.java | 11 +- .../SupplyDropCommand.java | 2 +- .../mineplex/gemhunters/util/UtilDebug.java | 27 --- .../mineplex/gemhunters/world/TimeCycle.java | 1 - .../gemhunters/world/WorldDataModule.java | 60 +----- .../gemhunters/world/WorldListeners.java | 74 ++++++- 22 files changed, 365 insertions(+), 233 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/SpawnChestCommand.java rename Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/{commands => command}/EndCommand.java (93%) rename Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/{commands => command}/StartCommand.java (91%) rename Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/{commands => command}/SupplyDropCommand.java (94%) delete mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/UtilDebug.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java b/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java index 634ea5e65..12be686f9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java @@ -23,7 +23,7 @@ public class GoogleSheetsManager extends MiniPlugin private static final File DATA_STORE_DIR = new File(".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "files"); - public GoogleSheetsManager() + private GoogleSheetsManager() { super("Google Sheets"); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 6ac87f015..ee852603a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -52,6 +52,7 @@ import mineplex.core.visibility.VisibilityManager; import mineplex.gemhunters.bounties.BountyModule; import mineplex.gemhunters.chat.ChatModule; import mineplex.gemhunters.death.DeathModule; +import mineplex.gemhunters.debug.DebugModule; import mineplex.gemhunters.economy.CashOutModule; import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.loot.InventoryModule; @@ -210,6 +211,7 @@ public class GemHunters extends JavaPlugin new HologramManager(this, packetHandler); // Now we finally get to enable the Gem Hunters modules + require(DebugModule.class); require(BountyModule.class); require(CashOutModule.class); require(ChatModule.class); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java index 9d606393b..b9295969e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -60,7 +60,7 @@ public class CashOutModule extends MiniPlugin @EventHandler public void playerInteract(PlayerInteractEvent event) - { + { if (!UtilEvent.isAction(event, ActionType.R)) { return; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java index 075655a3d..893293ab0 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -44,17 +44,17 @@ public class EconomyModule extends MiniPlugin Player player = event.getEntity(); Entity killer = event.getEntity().getKiller(); - if (!(killer instanceof Player)) + int oldGems = getGems(player); + + if (killer instanceof Player) { + Player killerPlayer = (Player) killer; + int newGems = (int) (oldGems * GEM_KILL_FACTOR); + + addToStore(killerPlayer, "Killing " + F.name(player.getName()), newGems); return; } - - Player killerPlayer = (Player) killer; - - int oldGems = _storedGems.get(player.getUniqueId()); - int newGems = (int) (oldGems * GEM_KILL_FACTOR); - - addToStore(killerPlayer, "Killing " + F.name(player.getName()), newGems); + removeFromStore(player, oldGems); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/ChestProperties.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/ChestProperties.java index 06d50b758..fe2ff3aa2 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/ChestProperties.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/ChestProperties.java @@ -1,5 +1,8 @@ package mineplex.gemhunters.loot; +import java.util.HashMap; +import java.util.Map; + import org.bukkit.Material; public class ChestProperties @@ -10,25 +13,29 @@ public class ChestProperties private final String _dataKey; private final int _minAmount; private final int _maxAmount; + private final int _maxChestPerLoc; private final int _spawnRate; private final int _expireRate; private final int _spawnRadius; private final int _maxActive; + private final Map _spawnedIndexes; private long _lastSpawn; - public ChestProperties(String name, Material blockMaterial, String dataKey, int minAmount, int maxAmount, int spawnRate, int expireRate, int spawnRadius, int maxActive) + public ChestProperties(String name, Material blockMaterial, String dataKey, int minAmount, int maxAmount, int maxChestPerLoc, int spawnRate, int expireRate, int spawnRadius, int maxActive) { _name = name; _blockMaterial = blockMaterial; _dataKey = dataKey; _minAmount = minAmount; _maxAmount = maxAmount; + _maxChestPerLoc = maxChestPerLoc; _spawnRate = spawnRate; _expireRate = expireRate; _spawnRadius = spawnRadius; _maxActive = maxActive; + _spawnedIndexes = new HashMap<>(); setLastSpawn(); } @@ -57,6 +64,11 @@ public class ChestProperties return _maxAmount; } + public final int getMaxChestPerLocation() + { + return _maxChestPerLoc; + } + public final int getSpawnRate() { return _spawnRate; @@ -76,7 +88,12 @@ public class ChestProperties { return _maxActive; } - + + public final Map getSpawnIndexes() + { + return _spawnedIndexes; + } + public void setLastSpawn() { _lastSpawn = System.currentTimeMillis(); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java index e1a026e61..95a0ee616 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java @@ -9,7 +9,6 @@ import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.Inventory; @@ -24,6 +23,7 @@ import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilInv; import mineplex.core.itemstack.ItemBuilder; import mineplex.gemhunters.death.events.PlayerCustomRespawnEvent; +import mineplex.gemhunters.debug.DebugModule; @ReflectivelyCreateMiniPlugin public class InventoryModule extends MiniPlugin @@ -31,6 +31,9 @@ public class InventoryModule extends MiniPlugin private static final int START_INDEX = 9; private static final ItemStack LOCKED = new ItemBuilder(Material.STAINED_GLASS_PANE, (byte) 15).setTitle(C.cGray + "Locked").build(); + private static final String ITEM_METADATA = "UNLOCKER"; + + private final LootModule _loot; private final Map _rowsUnlocked; @@ -38,6 +41,8 @@ public class InventoryModule extends MiniPlugin { super("Unlocker"); + _loot = require(LootModule.class); + _rowsUnlocked = new HashMap<>(); } @@ -92,15 +97,22 @@ public class InventoryModule extends MiniPlugin } Player player = event.getPlayer(); - ItemStack itemStack = event.getItem(); + ItemStack itemStack = player.getItemInHand(); if (itemStack == null) { return; } + LootItem lootItem = _loot.fromItemStack(itemStack); + + if (lootItem == null || lootItem.getMetadata().equals(ITEM_METADATA)) + { + return; + } + Material material = itemStack.getType(); - + if (material == Material.CHEST || material == Material.ENDER_CHEST) { UtilInv.remove(player, material, (byte) 0, 1); @@ -118,6 +130,10 @@ public class InventoryModule extends MiniPlugin int end = Math.min(inv.getSize(), start + rows * 9); int delta = end - start; + DebugModule.getInstance().d("start=" + start); + DebugModule.getInstance().d("end=" + end); + DebugModule.getInstance().d("delta=" + delta); + for (int i = start; i < end; i++) { inv.setItem(i, null); @@ -125,14 +141,4 @@ public class InventoryModule extends MiniPlugin player.sendMessage(F.main(_moduleName, "You unlocked an additional " + F.count(String.valueOf(delta)) + " slots of your inventory!")); } - - @EventHandler - public void test(PlayerCommandPreprocessEvent event) - { - if (event.getMessage().startsWith("/ur")) - { - event.setCancelled(true); - unlockRows(event.getPlayer(), Integer.parseInt(event.getMessage().split(" ")[1])); - } - } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 8e3b1c07f..9a1f6ef06 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -8,7 +8,6 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; -import org.bukkit.Bukkit; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; @@ -36,7 +35,9 @@ import mineplex.core.common.util.UtilWorld; import mineplex.core.google.GoogleSheetsManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.debug.DebugModule; import mineplex.gemhunters.economy.PlayerCashOutCompleteEvent; +import mineplex.gemhunters.loot.command.SpawnChestCommand; import mineplex.gemhunters.loot.command.UpdateLootCommand; import mineplex.gemhunters.loot.deserialisers.ChestPropertiesDeserialiser; import mineplex.gemhunters.loot.deserialisers.LootItemDeserialiser; @@ -44,7 +45,6 @@ import mineplex.gemhunters.loot.rewards.LootItemReward; import mineplex.gemhunters.loot.rewards.LootRankReward; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.util.SlackSheetsBot; -import mineplex.gemhunters.util.UtilDebug; import mineplex.gemhunters.world.WorldDataModule; @ReflectivelyCreateMiniPlugin @@ -54,6 +54,7 @@ public class LootModule extends MiniPlugin private static final String SHEET_FILE_NAME = "GEM_HUNTERS_CHESTS"; private static final String CHEST_MASTER_SHEET_NAME = "CHEST_MASTER"; private static final long CHEST_DESPAWN_TIME_OPENED = TimeUnit.SECONDS.toMillis(15); + private static final float CHESTS_ON_START_FACTOR = 0.333F; private static final int MAX_SEARCH_ATTEMPTS = 40; private static final int MAX_CHEST_CHECK_DISTANCE_SQUARED = 4; private static final LootItemDeserialiser DESERIALISER = new LootItemDeserialiser(); @@ -66,7 +67,6 @@ public class LootModule extends MiniPlugin private final Map> _chestLoot; private final Map _chestProperties; private final Set _spawnedChest; - private final Map> _spawnedIndexes; private final Set _itemRewards; private LootModule() @@ -79,16 +79,31 @@ public class LootModule extends MiniPlugin _chestLoot = new HashMap<>(); _chestProperties = new HashMap<>(); _spawnedChest = new HashSet<>(200); - _spawnedIndexes = new HashMap<>(15); _itemRewards = new HashSet<>(); - runSyncLater(() -> updateChestLoot(), 20); + runSyncLater(() -> { + + updateChestLoot(); + + // Spawn some chests + for (String key : _chestProperties.keySet()) + { + int max = _chestProperties.get(key).getMaxActive(); + + for (int i = 0; i < max * CHESTS_ON_START_FACTOR; i++) + { + addSpawnedChest(key, true); + } + } + + }, 20); } @Override public void addCommands() { addCommand(new UpdateLootCommand(this)); + addCommand(new SpawnChestCommand(this)); } @EventHandler @@ -111,7 +126,7 @@ public class LootModule extends MiniPlugin { if (chest.getID() != -1) { - _spawnedIndexes.get(properties.getDataKey()).remove(chest.getID()); + properties.getSpawnIndexes().put(chest.getID(), properties.getSpawnIndexes().get(chest.getID()) - 1); } Block block = chest.getLocation().getBlock(); @@ -130,87 +145,7 @@ public class LootModule extends MiniPlugin // Spawn new chests for (String key : _chestProperties.keySet()) { - List locations = _worldData.getDataLocation(key); - ChestProperties properties = _chestProperties.get(key); - - if (!UtilTime.elapsed(properties.getLastSpawn(), properties.getSpawnRate())) - { - continue; - } - - properties.setLastSpawn(); - - // Only spawn more chests if we need to - int max = properties.getMaxActive(); - int spawned = 0; - - for (SpawnedChest chest : _spawnedChest) - { - if (chest.getProperties().getDataKey().equals(key)) - { - spawned++; - } - } - - // If there are too many chests of this type we can ignore it - if (spawned > max) - { - continue; - } - - Set usedIndexes = _spawnedIndexes.get(key); - - if (usedIndexes == null) - { - _spawnedIndexes.put(key, new HashSet<>()); - usedIndexes = _spawnedIndexes.get(key); - } - - if (locations.size() == usedIndexes.size()) - { - continue; - } - - Location randomLocation = null; - int attempts = 0; - int index = -1; - - while (index == -1 || usedIndexes.contains(index) && attempts < MAX_SEARCH_ATTEMPTS) - { - index = UtilMath.r(locations.size()); - - attempts++; - } - - if (index == -1) - { - continue; - } - - usedIndexes.add(index); - randomLocation = locations.get(index); - - int placeRadius = properties.getSpawnRadius(); - Location chestToPlace = UtilAlg.getRandomLocation(randomLocation, placeRadius, 0, placeRadius); - Block block = chestToPlace.getBlock(); - - attempts = 0; - boolean suitable = false; - - while (!suitable && attempts < MAX_SEARCH_ATTEMPTS) - { - suitable = isSuitable(block); - attempts++; - } - - if (!suitable) - { - continue; - } - - UtilDebug.d("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); - _spawnedChest.add(new SpawnedChest(chestToPlace, properties, index)); - block.setType(properties.getBlockMaterial()); + addSpawnedChest(key, false); } } @@ -219,7 +154,7 @@ public class LootModule extends MiniPlugin Block up = block.getRelative(BlockFace.UP); Block down = block.getRelative(BlockFace.DOWN); - if (block.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block) || _safezone.isInSafeZone(block.getLocation())) + if (block.getType() != Material.AIR || up.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block) || _safezone.isInSafeZone(block.getLocation())) { return false; } @@ -287,6 +222,91 @@ public class LootModule extends MiniPlugin log("Finished updating chest loot"); } + public void addSpawnedChest(String key, boolean force) + { + List locations = _worldData.getDataLocation(key); + ChestProperties properties = _chestProperties.get(key); + + if (!force && !UtilTime.elapsed(properties.getLastSpawn(), properties.getSpawnRate())) + { + return; + } + + properties.setLastSpawn(); + + // Only spawn more chests if we need to + int max = properties.getMaxActive(); + int spawned = 0; + + for (SpawnedChest chest : _spawnedChest) + { + if (chest.getProperties().getDataKey().equals(key)) + { + spawned++; + } + } + + // If there are too many chests of this type we can ignore it + if (spawned > max) + { + return; + } + + Map spawnedIndexes = properties.getSpawnIndexes(); + + if (locations.size() == spawnedIndexes.size()) + { + return; + } + + Location randomLocation = null; + boolean found = false; + int attempts = 0; + int index = -1; + + while (index == -1 || !found && attempts < MAX_SEARCH_ATTEMPTS) + { + index = UtilMath.r(locations.size()); + + if (spawnedIndexes.getOrDefault(index, 0) >= properties.getMaxChestPerLocation()) + { + continue; + } + + attempts++; + } + + if (index == -1) + { + return; + } + + spawnedIndexes.put(index, spawnedIndexes.getOrDefault(index, 0) + 1); + randomLocation = locations.get(index); + + int placeRadius = properties.getSpawnRadius(); + Location chestToPlace = UtilAlg.getRandomLocation(randomLocation, placeRadius, 0, placeRadius); + Block block = chestToPlace.getBlock(); + + attempts = 0; + boolean suitable = false; + + while (!suitable && attempts < MAX_SEARCH_ATTEMPTS) + { + suitable = isSuitable(block); + attempts++; + } + + if (!suitable) + { + return; + } + + DebugModule.getInstance().d("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); + _spawnedChest.add(new SpawnedChest(chestToPlace, properties, index)); + block.setType(properties.getBlockMaterial()); + } + public void addSpawnedChest(Location location, String colour) { _spawnedChest.add(new SpawnedChest(location, _chestProperties.get(colour), -1)); @@ -299,7 +319,7 @@ public class LootModule extends MiniPlugin ChestProperties properties = _chestProperties.get(key); Inventory inventory = null; - + if (block.getType() == Material.ENDER_CHEST) { inventory = player.getEnderChest(); @@ -367,6 +387,11 @@ public class LootModule extends MiniPlugin public LootItem fromItemStack(ItemStack itemStack) { + if (itemStack == null) + { + return null; + } + for (Set items : _chestLoot.values()) { for (LootItem item : items) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/SpawnChestCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/SpawnChestCommand.java new file mode 100644 index 000000000..9e0040952 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/SpawnChestCommand.java @@ -0,0 +1,47 @@ +package mineplex.gemhunters.loot.command; + +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.gemhunters.loot.LootModule; + +public class SpawnChestCommand extends CommandBase +{ + + public SpawnChestCommand(LootModule plugin) + { + super(plugin, Rank.ADMIN, "spawnchest"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args.length == 0) + { + caller.sendMessage(F.help("/" + _aliasUsed + " ", "Spawns a chest at your location.", GetRequiredRank())); + return; + } + + String colour = args[0].toUpperCase(); + + try + { + DyeColor.valueOf(colour); + } + catch (IllegalArgumentException e) + { + caller.sendMessage(F.main(Plugin.getName(), "That is not a valid colour.")); + return; + } + + caller.sendMessage(F.main(Plugin.getName(), "Spawned a " + colour + " chest at your location.")); + + caller.getLocation().getBlock().setType(Material.CHEST); + Plugin.addSpawnedChest(caller.getLocation(), colour); + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/ChestPropertiesDeserialiser.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/ChestPropertiesDeserialiser.java index 7d5a63e9c..15898b8fb 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/ChestPropertiesDeserialiser.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/ChestPropertiesDeserialiser.java @@ -14,7 +14,7 @@ public class ChestPropertiesDeserialiser implements SheetObjectDeserialiser int maxAmount = 1; short durability = values[2].equals("") ? 0 : Short.valueOf(values[3]); - String[] numbers = values[3].split("-"); if (numbers.length != 2) @@ -61,17 +60,22 @@ public class LootItemDeserialiser implements SheetObjectDeserialiser builder.setDurability(durability); String title = ChatColor.translateAlternateColorCodes('&', values[4]); - String[] lore = values[5].split(":"); - String[] colouredLore = new String[lore.length]; - - int loreIndex = 0; - for (String line : lore) - { - colouredLore[loreIndex++] = ChatColor.translateAlternateColorCodes('&', line); - } builder.setTitle(title); - builder.setLore(colouredLore); + + if (!values[5].equals("")) + { + String[] lore = values[5].split(":"); + String[] colouredLore = new String[lore.length]; + + int loreIndex = 0; + for (String line : lore) + { + colouredLore[loreIndex++] = ChatColor.translateAlternateColorCodes('&', line); + } + + builder.setLore(colouredLore); + } String[] enchants = String.valueOf(values[6]).split(","); @@ -89,7 +93,7 @@ public class LootItemDeserialiser implements SheetObjectDeserialiser double proability = Double.parseDouble(values[7]); String metadata = values.length > 8 ? values[8] : null; - + return new LootItem(builder.build(), minAmount, maxAmount, proability, metadata); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java index b9777ef77..8a00d0540 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java @@ -1,6 +1,5 @@ package mineplex.gemhunters.loot.rewards; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.inventory.ItemStack; @@ -11,7 +10,7 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; import mineplex.core.recharge.Recharge; -import mineplex.gemhunters.util.UtilDebug; +import mineplex.gemhunters.debug.DebugModule; public abstract class LootItemReward { @@ -70,7 +69,7 @@ public abstract class LootItemReward public final void success() { - UtilDebug.d("Success"); + DebugModule.getInstance().d("Success"); onSuccessful(); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java index ddd19b1d4..194e55e3a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java @@ -6,10 +6,13 @@ import java.util.Map; import java.util.UUID; import org.bukkit.Location; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.player.PlayerQuitEvent; import mineplex.core.MiniPlugin; @@ -89,7 +92,7 @@ public class SafezoneModule extends MiniPlugin @EventHandler public void entityDamage(EntityDamageEvent event) - { + { if (!(event.getEntity() instanceof Player)) { return; @@ -106,6 +109,23 @@ public class SafezoneModule extends MiniPlugin @EventHandler public void entityAttack(EntityDamageByEntityEvent event) { + // Handle people shooting arrows at people outside a safezone + if (event.getDamager() instanceof Projectile) + { + Projectile projectile = (Projectile) event.getDamager(); + + if (projectile.getShooter() instanceof LivingEntity) + { + LivingEntity entity = (LivingEntity) projectile.getShooter(); + + if (isInSafeZone(entity.getLocation())) + { + event.setCancelled(true); + return; + } + } + } + if (!(event.getDamager() instanceof Player)) { return; @@ -119,6 +139,15 @@ public class SafezoneModule extends MiniPlugin } } + @EventHandler + public void hungerChange(FoodLevelChangeEvent event) + { + if (isInSafeZone(event.getEntity().getLocation())) + { + event.setCancelled(true); + } + } + public boolean isInSafeZone(Location location) { return getSafezone(location) != null; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java index 3ca326bce..5bdba8cf0 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java @@ -22,11 +22,11 @@ import mineplex.core.google.GoogleSheetsManager; import mineplex.core.google.SheetObjectDeserialiser; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.debug.DebugModule; import mineplex.gemhunters.loot.deserialisers.LootItemDeserialiser; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.shop.deserialisers.VillagerPropertiesDeserialiser; import mineplex.gemhunters.util.SlackSheetsBot; -import mineplex.gemhunters.util.UtilDebug; import mineplex.gemhunters.world.WorldDataModule; @ReflectivelyCreateMiniPlugin @@ -216,9 +216,11 @@ public class ShopModule extends MiniPlugin Location randomLocation = locations.get(index); + randomLocation.setYaw(UtilMath.r(360)); + usedIndexes.add(index); - UtilDebug.d("Trader at " + UtilWorld.locToStrClean(randomLocation) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); + DebugModule.getInstance().d("Trader at " + UtilWorld.locToStrClean(randomLocation) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); _npcs.add(new TraderNPC(_plugin, randomLocation, Villager.class, NAMES[UtilMath.r(NAMES.length)], _safezone.isInSafeZone(randomLocation), properties, getRandomItemSet(_trades.get(key)))); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java index 707ce5057..59af93f25 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java @@ -16,7 +16,6 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.Managers; import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilItem; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemStackFactory; import mineplex.gemhunters.economy.EconomyModule; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java index 0ce71a3f5..54607303e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java @@ -29,7 +29,7 @@ import mineplex.core.common.util.UtilWorld; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.loot.LootModule; -import mineplex.gemhunters.supplydrop.commands.SupplyDropCommand; +import mineplex.gemhunters.supplydrop.command.SupplyDropCommand; import mineplex.gemhunters.world.WorldDataModule; @ReflectivelyCreateMiniPlugin @@ -183,11 +183,19 @@ public class SupplyDropModule extends MiniPlugin { if (key.startsWith(LOCATION_DATA)) { - String splitKey = key.split(" ")[1]; + String[] split = key.split(" "); + String nameKey = ""; - if (!supplyDropKeys.contains(splitKey)) + for (int i = 1; i < split.length - 1; i++) { - supplyDropKeys.add(splitKey); + nameKey += split[i] + " "; + } + + nameKey = nameKey.trim(); + + if (!supplyDropKeys.contains(nameKey)) + { + supplyDropKeys.add(nameKey); } } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/EndCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/EndCommand.java similarity index 93% rename from Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/EndCommand.java rename to Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/EndCommand.java index 41de1ab1b..3265371b6 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/EndCommand.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/EndCommand.java @@ -1,4 +1,4 @@ -package mineplex.gemhunters.supplydrop.commands; +package mineplex.gemhunters.supplydrop.command; import org.bukkit.entity.Player; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/StartCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/StartCommand.java similarity index 91% rename from Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/StartCommand.java rename to Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/StartCommand.java index 233cefa0e..7887b5237 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/StartCommand.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/StartCommand.java @@ -1,4 +1,4 @@ -package mineplex.gemhunters.supplydrop.commands; +package mineplex.gemhunters.supplydrop.command; import org.bukkit.entity.Player; @@ -48,8 +48,15 @@ public class StartCommand extends CommandBase } else { - String input = args[0]; + String input = ""; + + for (int i = 0; i < args.length; i++) + { + input += args[i]; + } + input = input.trim(); + for (String key : Plugin.getLocationKeys()) { if (input.equalsIgnoreCase(key)) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/SupplyDropCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/SupplyDropCommand.java similarity index 94% rename from Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/SupplyDropCommand.java rename to Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/SupplyDropCommand.java index 65e1c8218..3e0db5ba7 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/SupplyDropCommand.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/SupplyDropCommand.java @@ -1,4 +1,4 @@ -package mineplex.gemhunters.supplydrop.commands; +package mineplex.gemhunters.supplydrop.command; import org.bukkit.entity.Player; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/UtilDebug.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/UtilDebug.java deleted file mode 100644 index 2c95a9b84..000000000 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/UtilDebug.java +++ /dev/null @@ -1,27 +0,0 @@ -package mineplex.gemhunters.util; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -public class UtilDebug -{ - - public static final void d(String message) - { - for (Player player : Bukkit.getOnlinePlayers()) - { - if (player.getItemInHand() == null || player.getItemInHand().getType() != Material.SPONGE) - { - continue; - } - - if (player.getName().equals("Moppletop")) - { - player.sendMessage(message); - return; - } - } - } - -} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java index b088867ae..fbac6850e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java @@ -8,7 +8,6 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.plugin.java.JavaPlugin; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java index 7f9b23ff2..9aafe307d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java @@ -10,26 +10,19 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.bukkit.Bukkit; import org.bukkit.Difficulty; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.WorldCreator; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.timing.TimingManager; -import mineplex.core.common.util.WorldUtil; -import mineplex.core.common.util.ZipUtil; -import mineplex.core.common.util.worldgen.WorldGenCleanRoom; @ReflectivelyCreateMiniPlugin public class WorldDataModule extends MiniPlugin { - private static final String MAP_PATH = "../../update/maps/Gem-Hunters/Test.zip"; - - private String folder = null; - public World World; public int MinX = 0; public int MinZ = 0; @@ -53,55 +46,20 @@ public class WorldDataModule extends MiniPlugin public void initialize() { final WorldDataModule worldData = this; - - runAsync(() -> { - - // Unzip - worldData.unzipWorld(); - // Load world data - runSync(() -> { - TimingManager.start("WorldData loading world."); + World = Bukkit.getWorlds().get(0); - WorldCreator creator = new WorldCreator(getFolder()); - creator.generator(new WorldGenCleanRoom()); - World = WorldUtil.LoadWorld(creator); + World.setDifficulty(Difficulty.EASY); + World.setGameRuleValue("showDeathMessages", "false"); - TimingManager.stop("WorldData loading world."); - - World.setDifficulty(Difficulty.EASY); - World.setGameRuleValue("showDeathMessages", "false"); - - TimingManager.start("WorldData loading WorldConfig."); - // Load World Data - worldData.loadWorldConfig(); - TimingManager.stop("WorldData loading WorldConfig."); - }); - }); + TimingManager.start("WorldData loading WorldConfig."); + worldData.loadWorldConfig(); + TimingManager.stop("WorldData loading WorldConfig."); } public String getFolder() { - if (folder == null) - { - folder = "world"; - } - - return folder; - } - - protected void unzipWorld() - { - TimingManager.start("UnzipWorld creating folders"); - String folder = getFolder(); - new File(folder).mkdir(); - new File(folder + File.separator + "region").mkdir(); - new File(folder + File.separator + "data").mkdir(); - TimingManager.stop("UnzipWorld creating folders"); - - TimingManager.start("UnzipWorld UnzipToDirectory"); - ZipUtil.UnzipToDirectory(MAP_PATH, folder); - TimingManager.stop("UnzipWorld UnzipToDirectory"); + return "world"; } public void loadWorldConfig() @@ -302,7 +260,7 @@ public class WorldDataModule extends MiniPlugin return SPAWN_LOCATIONS.get(colour); } - + public List getDataLocation(String colour) { if (!DATA_LOCATIONS.containsKey(colour)) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java index 4fc9d54c3..ecf179f6d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -1,11 +1,16 @@ package mineplex.gemhunters.world; -import org.bukkit.Bukkit; +import java.io.File; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + import org.bukkit.GameMode; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -16,37 +21,56 @@ import org.bukkit.event.block.BlockFadeEvent; import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.hanging.HangingBreakEvent; -import org.bukkit.event.hanging.HangingEvent; import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.world.ChunkUnloadEvent; +import org.bukkit.inventory.BeaconInventory; import org.bukkit.inventory.BrewerInventory; import org.bukkit.plugin.java.JavaPlugin; -import org.spigotmc.SpigotConfig; + +import mineplex.core.common.util.UtilWorld; +import mineplex.core.recharge.Recharge; +import mineplex.gemhunters.debug.DebugModule; public class WorldListeners implements Listener { private static final int VIEW_DISTANCE = 10; - + private static final long HUNGER_RECHARGE = TimeUnit.SECONDS.toMillis(15); + + private final JavaPlugin _plugin; + public WorldListeners(JavaPlugin plugin) { + _plugin = plugin; + plugin.getServer().getPluginManager().registerEvents(this, plugin); - plugin.getServer().getScheduler().runTaskLater(plugin, () -> { for (World world : plugin.getServer().getWorlds()) { - SpigotConfig.config.set("world-settings.world.view-distance", VIEW_DISTANCE); ((CraftWorld) world).getHandle().spigotConfig.viewDistance = VIEW_DISTANCE; - Bukkit.broadcastMessage(((CraftWorld) world).getHandle().spigotConfig.viewDistance + " chunks"); } }, 20); } + @EventHandler + public void deletePlayerData(PlayerQuitEvent event) + { + _plugin.getServer().getScheduler().runTaskLater(_plugin, () -> { + World world = event.getPlayer().getWorld(); + UUID uuid = event.getPlayer().getUniqueId(); + new File(world.getWorldFolder().getPath() + File.separator + "playerdata" + File.separator + uuid + ".dat").delete(); + new File(world.getWorldFolder().getPath() + File.separator + "stats" + File.separator + uuid + ".json").delete(); + }, 20); + } + @EventHandler(priority = EventPriority.LOWEST) public void blockBreak(BlockBreakEvent event) { @@ -98,10 +122,19 @@ public class WorldListeners implements Listener event.setCancelled(true); } + @EventHandler + public void itemFrames(PlayerInteractEntityEvent event) + { + if (shouldBlock(event.getPlayer()) && event.getRightClicked() instanceof ItemFrame) + { + event.setCancelled(true); + } + } + @EventHandler public void inventoryOpen(InventoryOpenEvent event) { - if (event.getInventory() instanceof BrewerInventory) + if (event.getInventory() instanceof BrewerInventory || event.getInventory() instanceof BeaconInventory) { event.setCancelled(true); } @@ -110,6 +143,11 @@ public class WorldListeners implements Listener @EventHandler public void chunkUnload(ChunkUnloadEvent event) { + if (!UtilWorld.inWorldBorder(new Location(event.getWorld(), event.getChunk().getX(), 0, event.getChunk().getZ()))) + { + return; + } + // Sam don't you dare look here, I understand the implications of this // but entities, can I just save by UUID? or does not doing this have // bigger complications?. @@ -121,7 +159,7 @@ public class WorldListeners implements Listener { event.setCancelled(true); } - + @EventHandler public void fireSpread(BlockBurnEvent event) { @@ -134,6 +172,24 @@ public class WorldListeners implements Listener event.setCancelled(true); } + @EventHandler(priority = EventPriority.HIGHEST) + public void hungerChange(FoodLevelChangeEvent event) + { + if (event.isCancelled()) + { + return; + } + + Player player = (Player) event.getEntity(); + + DebugModule.getInstance().d(player.getName() + " hunger " + player.getFoodLevel() + " -> " + event.getFoodLevel()); + + if (event.getFoodLevel() < player.getFoodLevel() && Recharge.Instance.use((Player) event.getEntity(), "Hunger", HUNGER_RECHARGE, false, false)) + { + event.setCancelled(true); + } + } + public boolean shouldBlock(Player player) { return player.getGameMode() != GameMode.CREATIVE; From bc6cae9b5ee3686b24d810710f0b6c5dd021c552 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 12 Feb 2017 15:23:37 +0000 Subject: [PATCH 033/101] Remove silly "@author" --- .../src/mineplex/gemhunters/chat/ChatModule.java | 2 -- .../src/mineplex/gemhunters/death/DeathModule.java | 2 -- .../src/mineplex/gemhunters/loot/LootItem.java | 2 -- .../src/mineplex/gemhunters/loot/command/UpdateLootCommand.java | 2 -- .../src/mineplex/gemhunters/supplydrop/SupplyDrop.java | 2 -- 5 files changed, 10 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java index 91ed17ab0..7a2a6b8cc 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java @@ -14,8 +14,6 @@ import mineplex.core.common.util.C; /** * This module handles player chat. - * - * @author Sam */ @ReflectivelyCreateMiniPlugin public class ChatModule extends MiniPlugin diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java index 63377ec29..8bb509674 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java @@ -37,8 +37,6 @@ import mineplex.gemhunters.spawn.SpawnModule; /** * This module handles anything to do with a players death - * - * @author Sam */ @ReflectivelyCreateMiniPlugin public class DeathModule extends MiniPlugin diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java index b2a4744d6..74420cb75 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootItem.java @@ -7,8 +7,6 @@ import mineplex.core.common.util.UtilMath; /** * Represents an item that can be contained in a chest inside the Gem Hunters * world. - * - * @author Sam */ public class LootItem { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java index 687fe92a2..c556148a8 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/UpdateLootCommand.java @@ -10,8 +10,6 @@ import mineplex.gemhunters.loot.LootModule; /** * An ADMIN command that allows users to retrieve the latest data from the * google sheet and update all locally cached loot tables. - * - * @author Sam */ public class UpdateLootCommand extends CommandBase { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java index 846760c53..da2dc542e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java @@ -34,8 +34,6 @@ import mineplex.core.common.util.UtilShapes; *
* {@link SupplyDropModule} handles when and where these supply drops will * spawn. - * - * @author Sam */ public class SupplyDrop { From 652d6d0f84cd5503d52ad600ba4bfa4eab483364 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 12 Feb 2017 15:23:50 +0000 Subject: [PATCH 034/101] Add a GiveGemsCommand --- .../gemhunters/economy/EconomyModule.java | 7 +++ .../economy/command/GiveGemsCommand.java | 47 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/command/GiveGemsCommand.java diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java index 893293ab0..528f2a648 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -16,6 +16,7 @@ import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.F; import mineplex.gemhunters.death.events.PlayerCustomRespawnEvent; +import mineplex.gemhunters.economy.command.GiveGemsCommand; @ReflectivelyCreateMiniPlugin public class EconomyModule extends MiniPlugin @@ -32,6 +33,12 @@ public class EconomyModule extends MiniPlugin _storedGems = new HashMap<>(); } + @Override + public void addCommands() + { + addCommand(new GiveGemsCommand(this)); + } + @EventHandler public void respawn(PlayerCustomRespawnEvent event) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/command/GiveGemsCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/command/GiveGemsCommand.java new file mode 100644 index 000000000..c658546d2 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/command/GiveGemsCommand.java @@ -0,0 +1,47 @@ +package mineplex.gemhunters.economy.command; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.gemhunters.economy.EconomyModule; + +public class GiveGemsCommand extends CommandBase +{ + + public GiveGemsCommand(EconomyModule plugin) + { + super(plugin, Rank.ADMIN, "givegems"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args.length < 2) + { + caller.sendMessage(F.help("/" + _aliasUsed + " ", "Adds an amount of gems to a player's gems earned.", Rank.ADMIN)); + return; + } + + Player target = UtilPlayer.searchOnline(caller, args[0], true); + + if (target == null) + { + return; + } + + try + { + int amount = Integer.parseInt(args[1]); + + Plugin.addToStore(target, "Given by " + F.name(caller.getName()), amount); + } + catch (NumberFormatException e) + { + caller.sendMessage(F.main(Plugin.getName(), "That is not a number.")); + } + } + +} From da28254af02fa96da6d35e61515d6a524d84ffcf Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 13 Feb 2017 18:18:17 +0000 Subject: [PATCH 035/101] Join and Quit messages --- .../src/mineplex/gemhunters/chat/ChatModule.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java index 7a2a6b8cc..8d17a1905 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/chat/ChatModule.java @@ -4,6 +4,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; @@ -11,6 +13,7 @@ import mineplex.core.account.CoreClientManager; import mineplex.core.chat.Chat; import mineplex.core.common.Rank; import mineplex.core.common.util.C; +import mineplex.core.common.util.F; /** * This module handles player chat. @@ -30,6 +33,18 @@ public class ChatModule extends MiniPlugin _chat = require(Chat.class); } + @EventHandler(priority = EventPriority.LOWEST) + public void playerJoin(PlayerJoinEvent event) + { + event.setJoinMessage(F.sys("Join", event.getPlayer().getName())); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void playerQuit(PlayerQuitEvent event) + { + event.setQuitMessage(F.sys("Quit", event.getPlayer().getName())); + } + @EventHandler(priority = EventPriority.HIGHEST) public void chat(AsyncPlayerChatEvent event) { From a879a1dc806b36766bcd45d90be8cf0f40f80307 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 13 Feb 2017 18:18:32 +0000 Subject: [PATCH 036/101] Item Map added --- .../gadget/gadgets/taunts/EternalTaunt.java | 156 --- .../core/gadget/types/TauntGadget.java | 159 --- .../core/particleeffects/LineEffect.java | 54 - .../src/mineplex/gemhunters/GemHunters.java | 17 +- .../gemhunters/map/ItemMapModule.java | 991 ++++++++++++++++++ .../gemhunters/map/ItemMapRenderer.java | 295 ++++++ .../src/mineplex/gemhunters/map/MapInfo.java | 124 +++ .../gemhunters/spawn/SpawnModule.java | 2 +- .../gemhunters/supplydrop/SupplyDrop.java | 6 +- .../supplydrop/SupplyDropModule.java | 7 + .../mineplex/gemhunters/world/TimeCycle.java | 2 +- .../gemhunters/world/WorldListeners.java | 1 + .../gemhunters/worldevent/WorldEvent.java | 8 + .../worldevent/giant/GiantWorldEvent.java | 11 +- 14 files changed, 1453 insertions(+), 380 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapRenderer.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/MapInfo.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/EternalTaunt.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/EternalTaunt.java index d08489b38..53e6a7793 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/EternalTaunt.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/taunts/EternalTaunt.java @@ -1,158 +1,3 @@ -<<<<<<< HEAD -package mineplex.core.gadget.gadgets.taunts; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.Color; -import org.bukkit.FireworkEffect; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.entity.Item; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerPickupItemEvent; -import org.bukkit.util.Vector; - -import mineplex.core.common.Rank; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.LineFormat; -import mineplex.core.common.util.UtilAction; -import mineplex.core.common.util.UtilFirework; -import mineplex.core.common.util.UtilText; -import mineplex.core.disguise.disguises.DisguiseSkeleton; -import mineplex.core.events.EnableArcadeSpawnEvent; -import mineplex.core.gadget.GadgetManager; -import mineplex.core.gadget.gadgets.morph.managers.UtilMorph; -import mineplex.core.gadget.types.TauntGadget; -import mineplex.core.itemstack.ItemStackFactory; -import mineplex.core.recharge.Recharge; -import mineplex.core.updater.UpdateType; - -public class EternalTaunt extends TauntGadget -{ - - private static final int COOLDOWN = 30000; - private static final int PVP_COOLDOWN = 10000; - - private Map> _clocks = new HashMap<>(); - - public EternalTaunt(GadgetManager manager) - { - super(manager, "Eternal Taunt", UtilText.splitLinesToArray(new String[]{C.cGray + "Although the Eternal has been around forever, he waited too long for a worthy opponent and he turned to bones.", - "", - C.cWhite + "Use /taunt in game to show how long you've been waiting.", - C.cRed + "Cannot be used while in PvP!"}, LineFormat.LORE), - -15, Material.WATCH, (byte) 0); - setCanPlayWithPvp(false); - setPvpCooldown(PVP_COOLDOWN); - setShouldPlay(true); - setEventType(UpdateType.FAST); - addDisabledGames(GameType.SMASH, GameType.SMASHTEAMS, GameType.SMASHDOMINATION); - } - - @Override - public void disableCustom(Player player, boolean message) - { - finish(player); - } - - @Override - public void onStart(Player player) - { - if (!Recharge.Instance.use(player, getName(), COOLDOWN, true, false, "Cosmetics")) - return; - UtilFirework.playFirework(player.getLocation(), FireworkEffect.builder().with(FireworkEffect.Type.BALL_LARGE).withColor(Color.fromRGB(255, 175, 175)).withFade(Color.RED).build()); - - _clocks.put(player.getUniqueId(), new ArrayList<>()); - - Bukkit.broadcastMessage(F.main("Taunt", F.name(player.getName()) + " waited so long they turned to bones.")); - - DisguiseSkeleton disguiseSkeleton = new DisguiseSkeleton(player); - UtilMorph.disguise(player, disguiseSkeleton, Manager); - } - - @Override - public void onPlay(Player player) - { - if (!_clocks.containsKey(player.getUniqueId())) - return; - - int i = getPlayerTicks(player); - - EnableArcadeSpawnEvent enableArcadeSpawnEvent = new EnableArcadeSpawnEvent(true); - Bukkit.getPluginManager().callEvent(enableArcadeSpawnEvent); - - Item clock = player.getWorld().dropItem(player.getLocation().add(0.5, 1.5, 0.5), - ItemStackFactory.Instance.CreateStack(Material.WATCH, (byte) 0, 1, " " + i)); - - enableArcadeSpawnEvent = new EnableArcadeSpawnEvent(false); - Bukkit.getPluginManager().callEvent(enableArcadeSpawnEvent); - - Vector vel = new Vector(Math.sin(i * 9/5d), 0, Math.cos(i * 9/5d)); - UtilAction.velocity(clock, vel, Math.abs(Math.sin(i * 12/3000d)), false, 0, 0.2 + Math.abs(Math.cos(i * 12/3000d))*0.6, 1, false); - - _clocks.get(player.getUniqueId()).add(clock); - - if (_clocks.get(player.getUniqueId()).size() >= 5) - { - _clocks.get(player.getUniqueId()).get(0).remove(); - _clocks.get(player.getUniqueId()).remove(0); - } - - if (i % 2 == 0) - player.playSound(player.getLocation(), Sound.CLICK, 1f, 1f); - else - player.playSound(player.getLocation(), Sound.CLICK, 0.5f, 0.5f); - - if (i >= 15) - { - finish(player); - } - } - - @Override - public void onFinish(Player player) - { - UtilMorph.undisguise(player, Manager.getDisguiseManager()); - if (_clocks.containsKey(player.getUniqueId())) - { - _clocks.get(player.getUniqueId()).forEach(c -> c.remove()); - _clocks.get(player.getUniqueId()).clear(); - _clocks.remove(player.getUniqueId()); - } - } - - @EventHandler - public void titanOwner(PlayerJoinEvent event) - { - if (Manager.getClientManager().Get(event.getPlayer()).GetRank().has(Rank.ETERNAL)) - { - Manager.getDonationManager().Get(event.getPlayer()).addOwnedUnknownSalesPackage(getName()); - } - } - - @EventHandler - public void onClockPickup(PlayerPickupItemEvent event) - { - for (List clocks : _clocks.values()) - { - for (Item item : clocks) - { - if (event.getItem().equals(item)) - event.setCancelled(true); - } - } - } - -} -======= package mineplex.core.gadget.gadgets.taunts; import java.util.ArrayList; @@ -300,4 +145,3 @@ public class EternalTaunt extends TauntGadget } } ->>>>>>> refs/remotes/origin/develop diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/TauntGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/TauntGadget.java index 75429b46f..9326a4cdb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/TauntGadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/TauntGadget.java @@ -1,161 +1,3 @@ -<<<<<<< HEAD -package mineplex.core.gadget.types; - -import java.time.YearMonth; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; - -import mineplex.core.gadget.GadgetManager; -import mineplex.core.gadget.gadgets.taunts.GameType; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; - -/** - * Handles Taunts - */ -public abstract class TauntGadget extends Gadget -{ - - /** Sets if this specific taunt can be used while in PvP */ - private boolean _canPlayWithPvp = false; - /** Sets the cooldown for pvp */ - private long _pvpCooldown = 0; - /** Sets if this taunt needs to run on updates */ - private boolean _shouldPlay = false; - /** Sets when the taunt will run, if set above */ - private UpdateType _updateType = UpdateType.TICK; - /** List of games where this item is disabled */ - private List _disabledGames = new ArrayList<>(); - /** The ticks that passed since the player started the effect */ - private Map _ticksPerPlayer = new HashMap<>(); - - /** - * @param manager The normal GadgetManager - * @param name The name of the item - * @param desc The lore/description of the item - * @param cost The cost of the item - * @param mat The display material of the item - * @param data The display data of the item - * @param alternativeSalesPackageNames Possible alternative names for this package - */ - public TauntGadget(GadgetManager manager, String name, String[] desc, int cost, Material mat, byte data, - String... alternativeSalesPackageNames) - { - super(manager, GadgetType.TAUNT, name, desc, cost, mat, data, 1, alternativeSalesPackageNames); - } - - /** - * @param manager The normal GadgetManager - * @param name The name of the item - * @param desc The lore/description of the item - * @param cost The cost of the item - * @param mat The display material of the item - * @param data The display data of the item - * @param yearMonth The year and month of this item, if it is a PPC item - * @param alternativeSalesPackageNames Possible alternative names for this package - */ - public TauntGadget(GadgetManager manager, String name, String[] desc, int cost, Material mat, byte data, - YearMonth yearMonth, String... alternativeSalesPackageNames) - { - super(manager, GadgetType.TAUNT, name, desc, cost, mat, data, yearMonth, 1, alternativeSalesPackageNames); - } - - public void start(Player player) - { - onStart(player); - _ticksPerPlayer.put(player.getUniqueId(), 0); - } - - public abstract void onStart(Player player); - - public void play(Player player) - { - onPlay(player); - int ticks = getPlayerTicks(player) + 1; - _ticksPerPlayer.put(player.getUniqueId(), ticks); - } - - public abstract void onPlay(Player player); - - public void finish(Player player) - { - onFinish(player); - _ticksPerPlayer.remove(player.getUniqueId()); - } - - public abstract void onFinish(Player player); - - public void setCanPlayWithPvp(boolean canPlayWithPvp) - { - _canPlayWithPvp = canPlayWithPvp; - } - - public void setPvpCooldown(long pvpCooldown) - { - _pvpCooldown = pvpCooldown; - } - - public void setShouldPlay(boolean shouldPlay) - { - _shouldPlay = shouldPlay; - } - - public void setEventType(UpdateType updateType) - { - _updateType = updateType; - } - - public void addDisabledGames(GameType... disabledGames) - { - _disabledGames.addAll(Arrays.asList(disabledGames)); - } - - public boolean canPlayWithPvp() - { - return _canPlayWithPvp; - } - - public boolean isGameDisabled(GameType gameType) - { - return _disabledGames.contains(gameType); - } - - public long getPvpCooldown() - { - return _pvpCooldown; - } - - public int getPlayerTicks(Player player) - { - return (_ticksPerPlayer.containsKey(player.getUniqueId())) ? _ticksPerPlayer.get(player.getUniqueId()) : -1; - } - - @EventHandler - public void onUpdate(UpdateEvent event) - { - if (!_shouldPlay) - return; - - if (event.getType() != _updateType) - return; - - for (Player player : getActive()) - { - if (_ticksPerPlayer.containsKey(player.getUniqueId())) - play(player); - } - } - -} -======= package mineplex.core.gadget.types; import java.time.YearMonth; @@ -318,4 +160,3 @@ public abstract class TauntGadget extends Gadget } } ->>>>>>> refs/remotes/origin/develop diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/LineEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/LineEffect.java index 4cf41d963..15a55f406 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/LineEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/LineEffect.java @@ -1,56 +1,3 @@ -<<<<<<< HEAD -package mineplex.core.particleeffects; - -import org.bukkit.Color; -import org.bukkit.Location; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; - -import mineplex.core.common.util.UtilParticle; -import mineplex.core.common.util.particles.ColoredParticle; -import mineplex.core.common.util.particles.DustSpellColor; - -public class LineEffect extends Effect -{ - - private int _particles = 100; - private Color _color; - private int _count = 0; - private Vector _vector; - private Location _fixedLoc; - - public LineEffect(JavaPlugin plugin, Location location, Location target, Color color) - { - super(-1, new EffectLocation(location), plugin); - setTargetLocation(new EffectLocation(target)); - _color = color; - } - - @Override - public void runEffect() - { - Location location = _effectLocation.getFixedLocation().clone().add(0, 1, 0); - if (_vector == null) - { - Location targetLoc = getTargetLocation().getFixedLocation().clone(); - Vector link = targetLoc.toVector().subtract(location.toVector()); - float length = (float) link.length(); - link.normalize(); - Vector vector = link.multiply(length / _particles); - _vector = vector; - _fixedLoc = location.clone().subtract(_vector); - } - ColoredParticle coloredParticle = new ColoredParticle(UtilParticle.ParticleType.RED_DUST, - new DustSpellColor(_color), _effectLocation.getLocation().clone()); - _fixedLoc.add(_vector); - if (_count == _particles) - { - stop(); - } - } - -} -======= package mineplex.core.particleeffects; import java.awt.Color; @@ -103,4 +50,3 @@ public class LineEffect extends Effect } } ->>>>>>> refs/remotes/origin/develop diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index ee852603a..5367faef4 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -19,6 +19,7 @@ import mineplex.core.chat.Chat; import mineplex.core.command.CommandCenter; import mineplex.core.common.Constants; import mineplex.core.common.events.ServerShutdownEvent; +import mineplex.core.communities.CommunityManager; import mineplex.core.creature.Creature; import mineplex.core.delayedtask.DelayedTask; import mineplex.core.disguise.DisguiseManager; @@ -30,7 +31,6 @@ import mineplex.core.give.Give; import mineplex.core.hologram.HologramManager; import mineplex.core.ignore.IgnoreManager; import mineplex.core.incognito.IncognitoManager; -import mineplex.core.inventory.InventoryManager; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.memory.MemoryFix; import mineplex.core.message.MessageManager; @@ -57,12 +57,12 @@ import mineplex.gemhunters.economy.CashOutModule; import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.loot.InventoryModule; import mineplex.gemhunters.loot.LootModule; +import mineplex.gemhunters.map.ItemMapModule; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.scoreboard.ScoreboardModule; import mineplex.gemhunters.shop.ShopModule; import mineplex.gemhunters.spawn.SpawnModule; import mineplex.gemhunters.supplydrop.SupplyDropModule; -import mineplex.gemhunters.world.TimeCycle; import mineplex.gemhunters.world.WorldListeners; import mineplex.gemhunters.worldevent.WorldEventModule; import mineplex.minecraft.game.core.combat.CombatManager; @@ -158,7 +158,7 @@ public class GemHunters extends JavaPlugin new DamageManager(this, new CombatManager(this), new NpcManager(this, creature), disguiseManager, new ConditionManager(this)); // GWEN - // require(AntiHack.class); + //require(AntiHack.class); // Block Restore BlockRestore blockRestore = require(BlockRestore.class); @@ -182,6 +182,9 @@ public class GemHunters extends JavaPlugin // Parties new PartyManager(); + // Communities + new CommunityManager(this, clientManager); + // Fixes new MemoryFix(this); new FoodDupeFix(this); @@ -193,8 +196,8 @@ public class GemHunters extends JavaPlugin explosion.SetTemporaryDebris(false); // Inventories - new InventoryManager(this, clientManager); - + //new InventoryManager(this, clientManager); + // Reports // SnapshotManager snapshotManager = new SnapshotManager(this, new // SnapshotRepository(serverStatusManager.getCurrentServerName(), @@ -219,6 +222,7 @@ public class GemHunters extends JavaPlugin require(EconomyModule.class); require(InventoryModule.class); require(LootModule.class); + require(ItemMapModule.class); require(SafezoneModule.class); require(ScoreboardModule.class); require(SpawnModule.class); @@ -226,8 +230,9 @@ public class GemHunters extends JavaPlugin require(SupplyDropModule.class); require(WorldEventModule.class); + // An arbitrary collection of world listeners such as block place/break, interact events etc... new WorldListeners(this); - new TimeCycle(this); + //new TimeCycle(this); // UpdateEvent!!! new Updater(this); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java new file mode 100644 index 000000000..57225f4d2 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java @@ -0,0 +1,991 @@ +package mineplex.gemhunters.map; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.Field; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map.Entry; + +import org.apache.commons.io.FileUtils; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_8_R3.CraftChunk; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_8_R3.util.LongHash; +import org.bukkit.craftbukkit.v1_8_R3.util.LongObjectHashMap; +import org.bukkit.entity.ItemFrame; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerItemHeldEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.world.ChunkLoadEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.map.MapRenderer; +import org.bukkit.map.MapView; + +import com.google.common.collect.HashMultiset; +import com.google.common.collect.Iterables; +import com.google.common.collect.Multisets; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilItem; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextBottom; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTime.TimeUnit; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.portal.events.ServerTransferEvent; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.death.events.PlayerCustomRespawnEvent; +import mineplex.gemhunters.spawn.SpawnModule; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.Blocks; +import net.minecraft.server.v1_8_R3.Chunk; +import net.minecraft.server.v1_8_R3.ChunkProviderServer; +import net.minecraft.server.v1_8_R3.ChunkRegionLoader; +import net.minecraft.server.v1_8_R3.IBlockData; +import net.minecraft.server.v1_8_R3.MaterialMapColor; +import net.minecraft.server.v1_8_R3.PersistentCollection; +import net.minecraft.server.v1_8_R3.WorldServer; + +/** + * All item map code was adapted from Clans.
+ */ +@ReflectivelyCreateMiniPlugin +public class ItemMapModule extends MiniPlugin +{ + // Every BLOCK_SCAN_INTERVAL we add as a new region to scan + private static final int BLOCK_SCAN_INTERVAL = 16 * 3; + // 1536 is the width of the entire world from one borderland to the other + private static final int HALF_WORLD_SIZE = SpawnModule.WORLD_BORDER_RADIUS; + // This slot is where the Clans Map will go by default + private static final int CLANS_MAP_SLOT = 8; + + private static final String[] ZOOM_INFO; + + static + { + ZOOM_INFO = new String[4]; + for (int zoomLevel = 0; zoomLevel <= 3; zoomLevel++) + { + StringBuilder progressBar = new StringBuilder(C.cBlue); + + boolean colorChange = false; + for (int i = 2; i >= 0; i--) + { + if (!colorChange && i < zoomLevel) + { + progressBar.append(C.cGray); + colorChange = true; + } + char c; + switch (i) + { + case 0: + c = '█'; + break; + case 1: + c = '▆'; + break; + default: + c = '▄'; + break; + } + for (int a = 0; a < 4; a++) + { + progressBar.append(c); + } + + if (i > 0) + { + progressBar.append(" "); + } + } + ZOOM_INFO[zoomLevel] = progressBar.toString(); + } + } + + private Comparator> _comparator; + private int[][] _heightMap = new int[(HALF_WORLD_SIZE * 2) + 16][]; + private HashMap _map = new HashMap(); + private short _mapId = -1; + private HashMap _mapInfo = new HashMap(); + private HashMap _scale = new HashMap(); + // Use LinkedList because operations are either add(Entry) which is O(1) and remove(0) which is O(1) on LinkedList but O(n) on ArrayList + private LinkedList> _scanList = new LinkedList>(); + private World _world; + private WorldServer _nmsWorld; + private ChunkProviderServer _chunkProviderServer; + private ChunkRegionLoader _chunkRegionLoader; + + private ItemMapModule() + { + super("ItemMapManager"); + + _comparator = (o1, o2) -> + { + // Render the places outside the map first to speed up visual errors fixing + int outsideMap = Boolean.compare(o1.getValue() < -HALF_WORLD_SIZE, o2.getValue() < -HALF_WORLD_SIZE); + + if (outsideMap != 0) + { + return -outsideMap; + } + + double dist1 = 0; + double dist2 = 0; + + for (Player player : UtilServer.getPlayers()) + { + dist1 += getDistance(o1, player.getLocation().getX(), player.getLocation().getZ()); + dist2 += getDistance(o2, player.getLocation().getX(), player.getLocation().getZ()); + } + + if (dist1 != dist2) + { + return Double.compare(dist1, dist2); + } + + dist1 = getDistance(o1, 0, 0); + dist2 = getDistance(o2, 0, 0); + + return Double.compare(dist1, dist2); + + }; + + _scale.put(0, 1); + // _scale.put(1, 2); + _scale.put(1, 4); + _scale.put(2, 8); + _scale.put(3, 13); + // _scale.put(5, 16); + + for (Entry entry : _scale.entrySet()) + { + int size = (HALF_WORLD_SIZE * 2) / entry.getValue(); + Byte[][] bytes = new Byte[size][]; + + for (int i = 0; i < size; i++) + { + bytes[i] = new Byte[size]; + } + + _map.put(entry.getKey(), bytes); + } + + for (int i = 0; i < _heightMap.length; i++) + { + _heightMap[i] = new int[_heightMap.length]; + } + + _world = Bukkit.getWorld("world"); + + try + { + Field chunkLoader = ChunkProviderServer.class.getDeclaredField("chunkLoader"); + chunkLoader.setAccessible(true); + _nmsWorld = ((CraftWorld) _world).getHandle(); + _chunkProviderServer = _nmsWorld.chunkProviderServer; + _chunkRegionLoader = (ChunkRegionLoader) chunkLoader.get(_chunkProviderServer); + if (_chunkRegionLoader == null) + { + throw new RuntimeException("Did not expect null chunkLoader"); + } + } + catch (ReflectiveOperationException e) + { + throw new RuntimeException("Could not reflectively access ChunkRegionLoader", e); + } + + try + { + File file = new File("world/gem_hunters_map_id"); + File foundFile = null; + + for (File f : new File("world/data").listFiles()) + { + if (f.getName().startsWith("map_")) + { + foundFile = f; + break; + } + } + + if (foundFile == null) + { + PersistentCollection collection = ((CraftWorld) _world).getHandle().worldMaps; + Field f = collection.getClass().getDeclaredField("d"); + f.setAccessible(true); + ((HashMap) f.get(collection)).put("map", (short) 0); + } + + if (file.exists()) + { + BufferedReader br = new BufferedReader(new FileReader(file)); + _mapId = Short.parseShort(br.readLine()); + br.close(); + + if (foundFile == null) + { + _mapId = -1; + file.delete(); + } + else + { + for (int i = _mapId; i <= _mapId + 100; i++) + { + File file1 = new File("world/data/map_" + i + ".dat"); + + if (!file1.exists()) + { + FileUtils.copyFile(foundFile, file1); + } + + setupRenderer(Bukkit.getMap((short) i)); + } + } + } + + if (_mapId < 0) + { + MapView view = Bukkit.createMap(_world); + _mapId = view.getId(); + setupRenderer(view); + + for (int i = 0; i < 100; i++) + { + setupRenderer(Bukkit.createMap(_world));// Ensures the following 100 maps are unused + } + + file.createNewFile(); + + PrintWriter writer = new PrintWriter(file, "UTF-8"); + writer.print(_mapId); + writer.close(); + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + rebuildScan(); + initialScan(); + } + + private void initialScan() + { + System.out.println("Beginning initial scan. There are " + _scanList.size() + " regions to scan"); + + // How many regions before logging an update (Currently set to every 20%) + int logPer = _scanList.size() / 5; + + while (!_scanList.isEmpty()) + { + Entry entry = _scanList.remove(0); + if (_scanList.size() % logPer == 0) + { + System.out.println("Running initial render... " + _scanList.size() + " sections to go"); + } + + int startingX = entry.getKey(); + int startingZ = entry.getValue(); + + boolean outsideMap = startingZ < -HALF_WORLD_SIZE; + + scanWorldMap(startingX, startingZ, !outsideMap, true); + + if (outsideMap) + { + continue; + } + + for (int scale = 1; scale < _scale.size(); scale++) + { + if (scale == 3) + continue; + + drawWorldScale(scale, startingX, startingZ); + colorWorldHeight(scale, startingX, startingZ); + } + + colorWorldHeight(0, startingX, startingZ); + } + + for (int x = -HALF_WORLD_SIZE; x < HALF_WORLD_SIZE; x += BLOCK_SCAN_INTERVAL) + { + for (int z = -HALF_WORLD_SIZE; z < HALF_WORLD_SIZE; z += BLOCK_SCAN_INTERVAL) + { + drawWorldScale(3, x, z); + colorWorldHeight(3, x, z); + } + } + + System.out.println("Finished first map scan and render"); + } + + private void setupRenderer(MapView view) + { + for (MapRenderer renderer : view.getRenderers()) + { + view.removeRenderer(renderer); + } + + view.addRenderer(new ItemMapRenderer()); + } + + @EventHandler + public void preventMapInItemFrame(PlayerInteractEntityEvent event) + { + if (!(event.getRightClicked() instanceof ItemFrame)) + return; + + if (!isItemClansMap(event.getPlayer().getItemInHand())) + return; + + event.setCancelled(true); + } + + /** + * Get the center of the map. + */ + public int calcMapCenter(int zoom, int cord) + { + int mapSize = HALF_WORLD_SIZE / zoom; // This is how large the map is in pixels + + int mapCord = cord / zoom; // This is pixels from true center of map, not held map + + int fDiff = mapSize - -mapCord; + int sDiff = mapSize - mapCord; + + double chunkBlock = cord & 0xF; + cord -= chunkBlock; + chunkBlock /= zoom; + + /*if ((fDiff < 64 || sDiff < 64) && (Math.abs(fDiff - sDiff) > 1)) + { + cord += (fDiff > sDiff ? Math.floor(chunkBlock) : Math.ceil(chunkBlock)); + } + else*/ + { + cord += (int) Math.floor(chunkBlock) * zoom; + } + + while ((fDiff < 64 || sDiff < 64) && (Math.abs(fDiff - sDiff) > 1)) + { + int change = (fDiff > sDiff ? -zoom : zoom); + cord += change; + + mapCord = cord / zoom; + + fDiff = mapSize - -mapCord; + sDiff = mapSize - mapCord; + } + + return cord; + } + + private void colorWorldHeight(int scale, int startingX, int startingZ) + { + Byte[][] map = _map.get(scale); + int zoom = getZoom(scale); + + for (int x = startingX; x < startingX + BLOCK_SCAN_INTERVAL; x += zoom) + { + double d0 = 0; + + // Prevents ugly lines for the first line of Z + + for (int addX = 0; addX < zoom; addX++) + { + for (int addZ = 0; addZ < zoom; addZ++) + { + int hX = x + addX + HALF_WORLD_SIZE; + int hZ = (startingZ - zoom) + addZ + HALF_WORLD_SIZE; + + if (hX >= HALF_WORLD_SIZE * 2 || hZ >= HALF_WORLD_SIZE * 2) + { + continue; + } + + d0 += _heightMap[hX + 16][hZ + 16] / (zoom * zoom); + } + } + + for (int z = startingZ; z < startingZ + BLOCK_SCAN_INTERVAL; z += zoom) + { + // Water depth colors not included + double d1 = 0; + + for (int addX = 0; addX < zoom; addX++) + { + for (int addZ = 0; addZ < zoom; addZ++) + { + int hX = x + addX + HALF_WORLD_SIZE; + int hZ = z + addZ + HALF_WORLD_SIZE; + + if (hX >= HALF_WORLD_SIZE * 2 || hZ >= HALF_WORLD_SIZE * 2) + { + continue; + } + + d1 += _heightMap[hX + 16][hZ + 16] / (zoom * zoom); + } + } + + double d2 = (d1 - d0) * 4.0D / (zoom + 4) + ((x + z & 0x1) - 0.5D) * 0.4D; + byte b0 = 1; + + d0 = d1; + + if (d2 > 0.6D) + { + b0 = 2; + } + else if (d2 > 1.2D) + { + b0 = 3; + } + else if (d2 < -0.6D) + { + b0 = 0; + } + + int origColor = map[(x + HALF_WORLD_SIZE) / zoom][(z + HALF_WORLD_SIZE) / zoom] - 1; + + /*if (color < 4) + { + d2 = waterDepth * 0.1D + (k1 + j2 & 0x1) * 0.2D; + b0 = 1; + if (d2 < 0.5D) + { + b0 = 2; + } + + if (d2 > 0.9D) + { + b0 = 0; + } + }*/ + + byte color = (byte) (origColor + b0); + if((color <= -113 || color >= 0) && color <= 127) + { + map[(x + HALF_WORLD_SIZE) / zoom][(z + HALF_WORLD_SIZE) / zoom] = color; + } + else + { +// System.out.println(String.format("Tried to set color to %s in colorWorldHeight scale: %s, sx: %s, sz: %s, x: %s, z: %s, zoom: %s", +// color, scale, startingX, startingZ, x, z, zoom)); + } + } + } + } + + private void drawWorldScale(int scale, int startingX, int startingZ) + { + Byte[][] first = _map.get(0); + Byte[][] second = _map.get(scale); + int zoom = getZoom(scale); + + for (int x = startingX; x < startingX + BLOCK_SCAN_INTERVAL; x += zoom) + { + for (int z = startingZ; z < startingZ + BLOCK_SCAN_INTERVAL; z += zoom) + { + HashMultiset hashmultiset = HashMultiset.create(); + + for (int addX = 0; addX < zoom; addX++) + { + for (int addZ = 0; addZ < zoom; addZ++) + { + int pX = x + addX + HALF_WORLD_SIZE; + int pZ = z + addZ + HALF_WORLD_SIZE; + + if (pX >= first.length || pZ >= first.length) + { + continue; + } + + Byte b = first[pX][pZ]; + + hashmultiset.add(b); + } + } + + Byte color; + try + { + color = Iterables.getFirst(Multisets.copyHighestCountFirst(hashmultiset), (byte) 0); + } + catch (Exception e) + { + color = (byte) 0; + } + second[(x + HALF_WORLD_SIZE) / zoom][(z + HALF_WORLD_SIZE) / zoom] = color; + } + } + } + + @EventHandler + public void dropItem(ItemSpawnEvent event) + { + if (isItemClansMap(event.getEntity().getItemStack())) + event.getEntity().remove(); + } + + public void removeMap(Player player) + { + for (int slot = 0; slot < player.getInventory().getSize(); slot++) + { + if (isItemClansMap(player.getInventory().getItem(slot))) + player.getInventory().setItem(slot, null); + } + } + + private double getDistance(double x1, double z1, double x2, double z2) + { + x1 = (x1 - x2); + z1 = (z1 - z2); + + return (x1 * x1) + (z1 * z1); + } + + private double getDistance(Entry entry, double x1, double z1) + { + return getDistance(x1, z1, entry.getKey() + (BLOCK_SCAN_INTERVAL / 2), entry.getValue() + (BLOCK_SCAN_INTERVAL / 2)); + } + + public Byte[][] getMap(int scale) + { + return _map.get(scale); + } + + public MapInfo getMap(Player player) + { + return _mapInfo.get(player.getName()); + } + + public int getMapSize() + { + return HALF_WORLD_SIZE; + } + + public int getZoom(int scale) + { + return _scale.get(scale); + } + + //fixme So what appears to happen is that after you die, if your map is is the same then the map is frozen + @EventHandler + public void onDeath(PlayerDeathEvent event) + { + MapInfo info = getMap(event.getEntity()); + + info.setMap(Math.min(_mapId + 100, info.getMap() + 1)); + } + + @EventHandler + public void onHotbarMove(PlayerItemHeldEvent event) + { + Player player = event.getPlayer(); + + if (!isItemClansMap(player.getInventory().getItem(event.getNewSlot()))) + return; + + showZoom(player, getMap(player)); + } + + @EventHandler + public void onInteract(PlayerInteractEvent event) + { + if (event.getAction() == Action.PHYSICAL) + return; + + if (!isItemClansMap(event.getItem())) + return; + + event.setCancelled(true); + + Player player = event.getPlayer(); + + MapInfo info = getMap(player); + + boolean zoomIn = UtilEvent.isAction(event, ActionType.L); + + if (!_scale.containsKey(info.getScale() + (zoomIn ? -1 : 1))) + { + return; + } + + if (!info.canZoom()) + { + long remainingTime = (info.getZoomCooldown() + 2500) - System.currentTimeMillis(); + + UtilPlayer.message( + player, + F.main("Recharge", + "You cannot use " + F.skill("Map Zoom") + " for " + + F.time(UtilTime.convertString((remainingTime), 1, TimeUnit.FIT)) + ".")); + return; + } + + info.addZoom(); + + if (zoomIn) + { + int newScale = info.getScale() - 1; + Location loc = player.getLocation(); + + int zoom = getZoom(newScale); + + info.setInfo(newScale, calcMapCenter(zoom, loc.getBlockX()), calcMapCenter(zoom, loc.getBlockZ())); + } + else + { + int newScale = info.getScale() + 1; + Location loc = player.getLocation(); + + int zoom = getZoom(newScale); + + info.setInfo(newScale, calcMapCenter(zoom, loc.getBlockX()), calcMapCenter(zoom, loc.getBlockZ())); + } + + showZoom(player, info); + } + + @EventHandler + public void respawn(PlayerCustomRespawnEvent event) + { + MapInfo info = new MapInfo(_mapId); + + Player player = event.getPlayer(); + Location loc = player.getLocation(); + + int zoom = getZoom(1); + + info.setInfo(1, calcMapCenter(zoom, loc.getBlockX()), calcMapCenter(zoom, loc.getBlockZ())); + _mapInfo.put(player.getName(), info); + setMap(player); + } + + @EventHandler + public void onWorldChange(PlayerTeleportEvent event) + { + if (event.getFrom().getWorld() != event.getTo().getWorld() && event.getTo().getWorld().equals("world")) + { + runSyncLater(new Runnable() + { + @Override + public void run() + { + setMap(event.getPlayer()); + } + }, 20); + } + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) + { + _mapInfo.remove(event.getPlayer().getName()); + } + + @EventHandler + public void onServerTransfer(ServerTransferEvent event) + { + Player p = event.getPlayer(); + + p.sendMessage(C.cDRed + C.Bold + "WARNING!"); + p.sendMessage(C.cYellow + "There's a bug where switching servers will freeze the Clans Map!"); + p.sendMessage(C.cYellow + "If you want to play on Clans again, rejoin the Mineplex server!"); + } + + private void rebuildScan() + { + for (int x = -HALF_WORLD_SIZE; x < HALF_WORLD_SIZE; x += BLOCK_SCAN_INTERVAL) + { + for (int z = -HALF_WORLD_SIZE - 16; z < HALF_WORLD_SIZE; z += (z < -HALF_WORLD_SIZE ? 16 : BLOCK_SCAN_INTERVAL)) + { + _scanList.add(new HashMap.SimpleEntry<>(x, z)); + } + } + + Collections.sort(_scanList, _comparator); + } + + @EventHandler + public void recenterMap(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + { + return; + } + + for (Player player : Bukkit.getOnlinePlayers()) + { + MapInfo info = getMap(player); + + if (info.getScale() >= 3) + { + continue; + } + + Location l = player.getLocation(); + int zoom = getZoom(info.getScale()); + + double mapX = (l.getX() - info.getX()) / zoom; + double mapZ = (l.getZ() - info.getZ()) / zoom; + + if (Math.abs(mapX) > 22 || Math.abs(mapZ) > 22) + { + int newX = calcMapCenter(zoom, l.getBlockX()); + int newZ = calcMapCenter(zoom, l.getBlockZ()); + + if (Math.abs(mapX) > 22 ? newX != info.getX() : newZ != info.getZ()) + { + info.setInfo(newX, newZ); + } + } + } + } + + @EventHandler + public void renderMap(UpdateEvent event) + { + if (event.getType() != UpdateType.FAST) + return; + + if (_scanList.isEmpty() && UtilServer.getPlayers().length > 0) + { + rebuildScan(); + } + + if (_scanList.size() % 20 == 0) + { + Collections.sort(_scanList, _comparator); + } + + if (_scanList.isEmpty()) + { + return; + } + + Entry entry = _scanList.remove(0); + + int startingX = entry.getKey(); + int startingZ = entry.getValue(); + + boolean outsideMap = startingZ < -HALF_WORLD_SIZE; + + scanWorldMap(startingX, startingZ, !outsideMap, false); + + if (outsideMap) + return; + + for (int scale = 1; scale < _scale.size(); scale++) + { + drawWorldScale(scale, startingX, startingZ); + colorWorldHeight(scale, startingX, startingZ); + } + + colorWorldHeight(0, startingX, startingZ); + } + + + // Let's not create hundreds of thousands of BlockPositions + // Single thread = should be thread safe + private BlockPosition.MutableBlockPosition _blockPosition = new BlockPosition.MutableBlockPosition(); + + // Maps the cached chunks which were loaded from disk to save IO operations + private LongObjectHashMap _chunkCache = new LongObjectHashMap<>(); + + /* + * Remove the cached chunks when the real chunks are loaded in + */ + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void LoadChunk(ChunkLoadEvent event) + { + _chunkCache.remove(LongHash.toLong(event.getChunk().getX(), event.getChunk().getZ())); + } + + /* + * Given a particular coordinate, this method will scan up to BLOCK_SCAN_INTERVAL and record the color of ever 16th block + * If a chunk has not been loaded, the following steps will be taken: + * * Attempt to load the chunk from disk. + * * If the chunk could not be loaded, generate it froms scratch + * Otherwise, the loaded chunk will be used + */ + public void scanWorldMap(int startingX, int startingZ, boolean setColors, boolean isFirstScan) + { + Byte[][] map = _map.get(0); + for (int beginX = startingX; beginX < startingX + BLOCK_SCAN_INTERVAL; beginX += 16) + { + for (int beginZ = startingZ - (startingZ > -HALF_WORLD_SIZE ? 16 : 0); beginZ < startingZ + + (setColors ? BLOCK_SCAN_INTERVAL : 16); beginZ += 16) + { + int chunkX = beginX / 16; + int chunkZ = beginZ / 16; + net.minecraft.server.v1_8_R3.Chunk nmsChunk = _chunkProviderServer.getChunkIfLoaded(chunkX, chunkZ); + if (nmsChunk == null) + { + long key = LongHash.toLong(chunkX, chunkZ); + nmsChunk = _chunkCache.get(key); + if (nmsChunk == null) + { + if (!isFirstScan) + { + continue; + } + try + { + Object[] data = _chunkRegionLoader.loadChunk(_nmsWorld, chunkX, chunkZ); + if (data == null) + { + // Something is wrong with the chunk + System.out.println("Chunk is not generated or missing level/block data. Regenerating (" + chunkX + "," + chunkZ + ")"); + nmsChunk = ((CraftChunk) _world.getChunkAt(chunkX, chunkZ)).getHandle(); + } + else + { + nmsChunk = (net.minecraft.server.v1_8_R3.Chunk) data[0]; + } + } + catch (IOException e) + { + throw new RuntimeException("Chunk is corrupt or not readable!", e); + } + _chunkCache.put(key, nmsChunk); + } + } + + if (!nmsChunk.isEmpty()) + { + for (int x = beginX; x < beginX + 16; x++) + { + for (int z = beginZ; z < beginZ + 16; z++) + { + int color = 0; + + int k3 = x & 0xF; + int l3 = z & 0xF; + + int l4 = nmsChunk.b(k3, l3) + 1; + IBlockData iblockdata = Blocks.AIR.getBlockData(); + + if (l4 > 1) + { + do + { + l4--; + _blockPosition.c(k3, l4, l3); + iblockdata = nmsChunk.getBlockData(_blockPosition); + } + while (iblockdata.getBlock().g(iblockdata) == MaterialMapColor.b && (l4 > 0)); + + if ((l4 > 0) && (iblockdata.getBlock().getMaterial().isLiquid())) + { + int j5 = l4 - 1; + Block block1; + do + { + _blockPosition.c(k3, j5--, l3); + block1 = nmsChunk.getType(_blockPosition); + } + while ((j5 > 0) && (block1.getMaterial().isLiquid())); + } + } + + _heightMap[x + HALF_WORLD_SIZE + 16][z + HALF_WORLD_SIZE + 16] = l4; + + if (setColors) + { + //color = block.f(i5).M; + _blockPosition.c(k3, l4, l3); + IBlockData data = nmsChunk.getBlockData(_blockPosition); + color = data.getBlock().g(data).M; + + color = (byte) ((color * 4) + 1); + } + + if (setColors && beginZ >= startingZ) + { + map[x + HALF_WORLD_SIZE][z + HALF_WORLD_SIZE] = (byte) color; + } + } + } + } + } + } + } + + public void setMap(Player player) + { + for (ItemStack item : UtilInv.getItems(player)) + { + if (isItemClansMap(item)) + { + return; + } + } + + ItemStack item = new ItemBuilder(Material.MAP, 1, (short) getMap(player).getMap()).setTitle(C.cGreen + "World Map").build(); + + int slot = CLANS_MAP_SLOT; + + ItemStack mapSlot = player.getInventory().getItem(slot); + if (mapSlot != null && mapSlot.getType() != Material.AIR) + { + slot = player.getInventory().firstEmpty(); + } + + if (slot >= 0) + { + player.getInventory().setItem(slot, item); + } + } + + /* + * Displays the action bar to a player given their zoom level. Implementation may change + */ + private void showZoom(Player player, MapInfo info) + { + UtilTextBottom.display(ZOOM_INFO[info.getScale()], player); + } + + /* + * Check whether an {@link ItemStack} is also a Clans Map + * + * @param itemStack The {@link ItemStack} to check + * @returns Whether the {@link ItemStack} is also a Clans Map + */ + private boolean isItemClansMap(ItemStack itemStack) + { + return UtilItem.matchesMaterial(itemStack, Material.MAP) + && itemStack.getDurability() >= _mapId + && itemStack.getDurability() <= _mapId + 100; + } +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapRenderer.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapRenderer.java new file mode 100644 index 000000000..fa2c37151 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapRenderer.java @@ -0,0 +1,295 @@ +package mineplex.gemhunters.map; + +import java.awt.Color; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.map.MapCanvas; +import org.bukkit.map.MapCursor; +import org.bukkit.map.MapCursorCollection; +import org.bukkit.map.MapPalette; +import org.bukkit.map.MapRenderer; +import org.bukkit.map.MapView; + +import mineplex.core.Managers; +import mineplex.core.common.util.UtilTime; +import mineplex.core.communities.Community; +import mineplex.core.communities.CommunityManager; +import mineplex.core.party.Party; +import mineplex.core.party.PartyManager; +import mineplex.gemhunters.safezone.SafezoneModule; +import mineplex.gemhunters.supplydrop.SupplyDropModule; +import mineplex.gemhunters.worldevent.WorldEvent; +import mineplex.gemhunters.worldevent.WorldEventModule; + +/** + * All item map code was adapted from Clans.
+ */ +public class ItemMapRenderer extends MapRenderer +{ + + private static final int RENDER_COOLDOWN = 10000; + private static final int STANDARD_Y = 70; + + private final ItemMapModule _itemMap; + private final SafezoneModule _safezone; + private final SupplyDropModule _supply; + private final WorldEventModule _worldEvent; + + private final CommunityManager _community; + private final PartyManager _party; + + public ItemMapRenderer() + { + super(true); + + _itemMap = Managers.require(ItemMapModule.class); + _safezone = Managers.require(SafezoneModule.class); + _supply = Managers.require(SupplyDropModule.class); + _worldEvent = Managers.require(WorldEventModule.class); + _community = Managers.require(CommunityManager.class); + _party = Managers.require(PartyManager.class); + } + + @Override + public void render(MapView mapView, MapCanvas canvas, Player player) + { + try + { + renderNormalMap(mapView, canvas, player); + } + catch (Throwable t) + { + System.out.println("Error while rendering map"); + t.printStackTrace(); + } + } + + private void renderNormalMap(MapView mapView, MapCanvas canvas, Player player) + { + MapInfo info = _itemMap.getMap(player); + + if (info == null) + { + return; + } + + int scale = info.getScale(); + int zoom = _itemMap.getZoom(scale); + + Byte[][] map = _itemMap.getMap(scale); + + int centerX = info.getX() / zoom; + int centerZ = info.getZ() / zoom; + + // We have this cooldown to squeeze out every single bit of performance + // from the server. + if (UtilTime.elapsed(info.getLastRendered(), RENDER_COOLDOWN)) + { + info.setLastRendered(); + + for (int mapX = 0; mapX < 128; mapX++) + { + for (int mapZ = 0; mapZ < 128; mapZ++) + { + int blockX = centerX + (mapX - 64); + int blockZ = centerZ + (mapZ - 64); + + int pixelX = blockX + (map.length / 2); + int pixelZ = blockZ + (map.length / 2); + + Byte color; + + if (!(pixelX < 0 || pixelZ < 0 || pixelX >= map.length || pixelZ >= map.length) && map[pixelX][pixelZ] != null) + { + color = map[pixelX][pixelZ]; + + blockX *= zoom; + blockZ *= zoom; + + Location location = new Location(mapView.getWorld(), blockX, STANDARD_Y, blockZ); + + boolean safezone = _safezone.isInSafeZone(location); + boolean supplyDrop = _supply.isNearSupplyDrop(location); + + if (safezone || supplyDrop) + { + boolean colorAll = scale > 0; + Color areaColor = null; + + if (safezone) + { + areaColor = Color.GREEN; + } + else if (supplyDrop) + { + areaColor = Color.YELLOW; + } + + if (areaColor != null) + { + if (!((color <= -113 || color >= 0) && color <= 127)) + { + color = (byte) 0; + System.out.println(String.format("Tried to draw invalid color %s, player: %s, mapX: %s, mapZ: %s", color, player.getName(), mapX, mapZ)); + } + else + { + int chunkBX = blockX & 0xF; + int chunkBZ = blockZ & 0xF; + + // Border + if ( + ((chunkBX == 0 || zoom == 13) && + + _safezone.isInSafeZone(new Location(mapView.getWorld(), blockX - 16, STANDARD_Y, blockZ))) + + || ((chunkBZ == 0 || zoom == 13) && + + _safezone.isInSafeZone(new Location(mapView.getWorld(), blockX, STANDARD_Y, blockZ - 16))) + + || ((chunkBX + zoom > 15 || zoom == 13) && + + _safezone.isInSafeZone(new Location(mapView.getWorld(), blockX + 16, STANDARD_Y, blockZ))) + + || ((chunkBZ + zoom > 15 || zoom == 13) && + + _safezone.isInSafeZone(new Location(mapView.getWorld(), blockX, STANDARD_Y, blockZ + 16)))) + { + Color cColor = MapPalette.getColor(color); + double clans = colorAll ? 1 : 0.8; + double base = 1 - clans; + + int r = (int) ((cColor.getRed() * base) + (areaColor.getRed() * clans)); + int b = (int) ((cColor.getBlue() * base) + (areaColor.getBlue() * clans)); + int g = (int) ((cColor.getGreen() * base) + (areaColor.getGreen() * clans)); + + color = MapPalette.matchColor(r, g, b); + } + + // Inside + else + { + Color cColor = MapPalette.getColor(color); + + double clans = 0.065; + + // Stripes + //boolean checker = (mapX + (mapZ % 4)) % 4 == 0; + double base = 1 - clans; + + int r = (int) ((cColor.getRed() * base) + (areaColor.getRed() * clans)); + int b = (int) ((cColor.getBlue() * base) + (areaColor.getBlue() * clans)); + int g = (int) ((cColor.getGreen() * base) + (areaColor.getGreen() * clans)); + + color = MapPalette.matchColor(r, g, b); + } + } + } + } + } + else + { + color = (byte) 0; + } + + canvas.setPixel(mapX, mapZ, color); + } + } + } + + if (info.isSendMap()) + { + player.sendMap(mapView); + } + + MapCursorCollection cursors = canvas.getCursors(); + + while (cursors.size() > 0) + { + cursors.removeCursor(cursors.getCursor(0)); + } + + for (WorldEvent event : _worldEvent.getActiveEvents()) + { + if (!event.isInProgress()) + { + continue; + } + + Location point = event.getCurrentLocation(); + double mapX = (point.getX() - info.getX()) / zoom; + double mapZ = (point.getZ() - info.getZ()) / zoom; + + // To make these appear at the edges of the map, just change it from + // 64 to something like 128 for double the map size + if (mapX > -64 && mapX < 64 && mapZ > -64 && mapZ < 64) + { + byte b0 = (byte) (int) Math.min(127, (double) (mapX * 2.0F) + 0.5D); + byte b1 = (byte) (int) Math.max(-127, (double) (mapZ * 2.0F) + 0.5D); + + byte cursorType = 4; // http://i.imgur.com/wpH6PT8.png + // Those are byte 5 and 6 + byte rotation = (byte) ((int) Math.floor(System.currentTimeMillis() / 1000D) % 16); + + MapCursor cursor = new MapCursor(b0, b1, rotation, cursorType, true); + + cursors.addCursor(cursor); + } + } + + Party party = _party.getPartyByPlayer(player); + Community[] communities = _community.Get(player).getCommunities(); + + for (Player other : Bukkit.getOnlinePlayers()) + { + if (player.canSee(other) && other.isValid()) + { + Location l = other.getLocation(); + + double mapX = (l.getX() - info.getX()) / zoom; + double mapZ = (l.getZ() - info.getZ()) / zoom; + + if (mapX > -64 && mapX < 64 && mapZ > -64 && mapZ < 64) + { + MapCursor.Type cursorDisplay = null; + + if (player.equals(other)) + { + cursorDisplay = MapCursor.Type.WHITE_POINTER; + } + else if (party != null && party.isMember(other)) + { + cursorDisplay = MapCursor.Type.GREEN_POINTER; + } + else if (communities.length > 0) + { + for (Community community : communities) + { + if (community.getMembers().containsKey(other.getUniqueId())) + { + cursorDisplay = MapCursor.Type.BLUE_POINTER; + break; + } + } + } + + if (cursorDisplay == null) + { + continue; + } + + byte b0 = (byte) (int) Math.min(127, (double) (mapX * 2.0F) + 0.5D); + byte b1 = (byte) (int) Math.max(-127, (double) (mapZ * 2.0F) + 0.5D); + + byte rotation = (byte) (int) ((l.getYaw() * 16D) / 360D); + + MapCursor cursor = new MapCursor(b0, b1, (byte) (rotation & 0xF), cursorDisplay.getValue(), true); + + cursors.addCursor(cursor); + } + } + } + } +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/MapInfo.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/MapInfo.java new file mode 100644 index 000000000..5af724e57 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/MapInfo.java @@ -0,0 +1,124 @@ +package mineplex.gemhunters.map; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import mineplex.core.common.util.UtilTime; + +public class MapInfo +{ + private int _scale; + private int _centerX; + private int _centerZ; + private long _lastRendered; + private boolean _sendMap; + private List _lastZooms = new ArrayList(); + private int _mapId; + + public MapInfo(int newId) + { + _mapId = newId; + } + + public int getMap() + { + return _mapId; + } + + public void setMap(int newId) + { + _mapId = newId; + } + + public boolean canZoom() + { + Iterator itel = _lastZooms.iterator(); + + while (itel.hasNext()) + { + long lastZoomed = itel.next(); + + if (UtilTime.elapsed(lastZoomed, 2500)) + { + itel.remove(); + } + } + + return _lastZooms.size() < 3; + } + + public void addZoom() + { + _lastZooms.add(System.currentTimeMillis()); + } + + public long getZoomCooldown() + { + long cooldown = 0; + + for (long zoomCooldown : _lastZooms) + { + if (cooldown == 0 || zoomCooldown < cooldown) + { + cooldown = zoomCooldown; + } + } + + return cooldown; + } + + public long getLastRendered() + { + return _lastRendered; + } + + public void setLastRendered() + { + _lastRendered = System.currentTimeMillis(); + } + + public void setInfo(int scale, int x, int z) + { + _lastRendered = 0; + _scale = scale; + _centerX = x; + _centerZ = z; + _sendMap = true; + } + + public void setInfo(int x, int z) + { + _lastRendered = 0; + _centerX = x; + _centerZ = z; + _sendMap = true; + } + + public boolean isSendMap() + { + if (_sendMap) + { + _sendMap = false; + return true; + } + + return false; + } + + public int getX() + { + return _centerX; + } + + public int getZ() + { + return _centerZ; + } + + public int getScale() + { + return _scale; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index b6bbc038c..ce51aa10c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -32,7 +32,7 @@ import mineplex.gemhunters.world.WorldDataModule; public class SpawnModule extends MiniPlugin { - private static final int WORLD_BORDER_RADIUS = 750; + public static final int WORLD_BORDER_RADIUS = 768; private static final int MAX_SPAWNING_Y = 73; private final SafezoneModule _safezone; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java index da2dc542e..62874e8d3 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java @@ -205,5 +205,9 @@ public class SupplyDrop UtilFirework.playFirework(fallingBlock.getLocation().add(0.5, 1, 0.5), UtilFirework.getRandomFireworkEffect(false, 2, 1)); } - + + public final Location getChestLocation() + { + return _destination; + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java index 54607303e..734a1cebd 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java @@ -41,6 +41,8 @@ public class SupplyDropModule extends MiniPlugin private static final String CHEST_COLOUR = "RED"; private static final String LOCATION_DATA = "SUPPLY_DROP"; + private static final int SUPPLY_DROP_DISTANCE_SQUARED = 625; + private final BlockRestore _blockRestore; private final LootModule _loot; private final WorldDataModule _worldData; @@ -172,6 +174,11 @@ public class SupplyDropModule extends MiniPlugin { return _current != null; } + + public boolean isNearSupplyDrop(Location location) + { + return isActive() ? UtilMath.offsetSquared(location, _current.getChestLocation()) <= SUPPLY_DROP_DISTANCE_SQUARED : false; + } public String[] getLocationKeys() { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java index fbac6850e..32fc398ad 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java @@ -28,7 +28,7 @@ public class TimeCycle implements Listener public TimeCycle(JavaPlugin plugin) { - //plugin.getServer().getPluginManager().registerEvents(this, plugin); + plugin.getServer().getPluginManager().registerEvents(this, plugin); _worldData = Managers.get(WorldDataModule.class); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java index ecf179f6d..c7f2637d8 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -55,6 +55,7 @@ public class WorldListeners implements Listener for (World world : plugin.getServer().getWorlds()) { ((CraftWorld) world).getHandle().spigotConfig.viewDistance = VIEW_DISTANCE; + ((CraftWorld) world).getHandle().a(VIEW_DISTANCE); } }, 20); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEvent.java index 1b1ecf4ac..c83973f2e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEvent.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEvent.java @@ -4,6 +4,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.event.EventHandler; @@ -50,6 +51,8 @@ public abstract class WorldEvent implements Listener public abstract void onEnd(); + public abstract Location getCurrentLocation(); + public final void start() { onStart(); @@ -117,6 +120,11 @@ public abstract class WorldEvent implements Listener } } + public boolean isInProgress() + { + return _eventState == WorldEventState.WARMUP || _eventState == WorldEventState.LIVE; + } + public WorldEventState getEventState() { return _eventState; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/GiantWorldEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/GiantWorldEvent.java index 2b059fa3b..bbda270b5 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/GiantWorldEvent.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/GiantWorldEvent.java @@ -2,6 +2,7 @@ package mineplex.gemhunters.worldevent.giant; import java.util.concurrent.TimeUnit; +import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Zombie; import org.bukkit.event.EventHandler; @@ -21,8 +22,8 @@ public class GiantWorldEvent extends WorldEvent { private static final int MINI_ZOMBIES = 10; - private static final int MINI_ZOMBIES_MAX_DISTANCE_SQUARED = 900; - private static final long MAX_TIME = TimeUnit.MINUTES.toMillis(6); + private static final int MINI_ZOMBIES_MAX_DISTANCE_SQUARED = 2500; + private static final long MAX_TIME = TimeUnit.MINUTES.toMillis(5); private CustomGiant _giant; @@ -53,6 +54,12 @@ public class GiantWorldEvent extends WorldEvent { } + @Override + public Location getCurrentLocation() + { + return _giant.getGiant().getLocation(); + } + @EventHandler public void zombieCombust(EntityCombustEvent event) { From cf36c83f4b67cf4ee70d7d89db44a1779e4f13ef Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 16 Feb 2017 14:15:56 +0000 Subject: [PATCH 037/101] Use Consumers instead of Callbacks --- .../src/mineplex/gemhunters/util/SimpleNPC.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java index e3c4e908a..b0e9fa6df 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java @@ -1,5 +1,7 @@ package mineplex.gemhunters.util; +import java.util.function.Consumer; + import org.bukkit.Location; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -18,15 +20,15 @@ public class SimpleNPC implements Listener { protected final LivingEntity _entity; - private final Callback _clickEvent; + private final Consumer _clickEvent; private final boolean _vegetated; - public SimpleNPC(JavaPlugin plugin, Location spawn, Class type, String name, Callback clickEvent) + public SimpleNPC(JavaPlugin plugin, Location spawn, Class type, String name, Consumer clickEvent) { this(plugin, spawn, type, name, clickEvent, true); } - public SimpleNPC(JavaPlugin plugin, Location spawn, Class type, String name, Callback clickEvent, boolean vegetated) + public SimpleNPC(JavaPlugin plugin, Location spawn, Class type, String name, Consumer clickEvent, boolean vegetated) { spawn.getWorld().loadChunk(spawn.getChunk()); _entity = spawn.getWorld().spawn(spawn, type); @@ -57,7 +59,7 @@ public class SimpleNPC implements Listener if (_clickEvent != null) { - _clickEvent.run(event.getPlayer()); + _clickEvent.accept(event.getPlayer()); } } From d56cd59df007852e4a124aafe38beaef90b4fd44 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 17 Feb 2017 18:16:17 +0000 Subject: [PATCH 038/101] Quests and a whole host of wacky changes --- .../mineplex/core/common/util/UtilInv.java | 15 ++ .../src/mineplex/gemhunters/GemHunters.java | 32 ++- .../gemhunters/death/DeathModule.java | 2 +- .../PlayerCustomRespawnEvent.java | 2 +- .../gemhunters/economy/CashOutModule.java | 23 +- .../gemhunters/economy/EconomyModule.java | 14 +- .../gemhunters/loot/InventoryModule.java | 4 +- .../mineplex/gemhunters/loot/LootModule.java | 15 +- .../loot/event/PlayerChestOpenEvent.java | 60 +++++ .../gemhunters/map/ItemMapModule.java | 26 +- .../gemhunters/quest/QuestModule.java | 252 ++++++++++++++++++ .../mineplex/gemhunters/quest/QuestNPC.java | 43 +++ .../gemhunters/quest/QuestPlayerData.java | 53 ++++ .../mineplex/gemhunters/quest/QuestUI.java | 61 +++++ .../quest/types/ChestOpenerQuest.java | 56 ++++ .../gemhunters/quest/types/Quest.java | 127 +++++++++ .../mineplex/gemhunters/shop/TraderNPC.java | 1 - .../gemhunters/spawn/SpawnModule.java | 100 ++++--- .../event/PlayerTeleportIntoMapEvent.java | 56 ++++ .../mineplex/gemhunters/util/SimpleNPC.java | 1 - .../mineplex/gemhunters/world/SewerMobs.java | 95 +++++++ .../mineplex/gemhunters/world/TimeCycle.java | 6 +- 22 files changed, 934 insertions(+), 110 deletions(-) rename Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/{events => event}/PlayerCustomRespawnEvent.java (91%) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/event/PlayerChestOpenEvent.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestNPC.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestPlayerData.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestUI.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/Quest.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/event/PlayerTeleportIntoMapEvent.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilInv.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilInv.java index f7b6cbec7..246105fc8 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilInv.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilInv.java @@ -447,6 +447,21 @@ public class UtilInv return false; } + + public static boolean hasSpace(Player player, int slots) + { + int slotsFree = 0; + + for (int slot = 0; slot < player.getInventory().getSize(); slot++) + { + if (player.getInventory().getItem(slot) == null) + { + slotsFree++; + } + } + + return slotsFree >= slots; + } public static void give(Player player, Material material) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 5367faef4..c397b959a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -33,6 +33,7 @@ import mineplex.core.ignore.IgnoreManager; import mineplex.core.incognito.IncognitoManager; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.memory.MemoryFix; +import mineplex.core.menu.MenuManager; import mineplex.core.message.MessageManager; import mineplex.core.monitor.LagMeter; import mineplex.core.npc.NpcManager; @@ -58,11 +59,14 @@ import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.loot.InventoryModule; import mineplex.gemhunters.loot.LootModule; import mineplex.gemhunters.map.ItemMapModule; +import mineplex.gemhunters.quest.QuestModule; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.scoreboard.ScoreboardModule; import mineplex.gemhunters.shop.ShopModule; import mineplex.gemhunters.spawn.SpawnModule; import mineplex.gemhunters.supplydrop.SupplyDropModule; +import mineplex.gemhunters.world.SewerMobs; +import mineplex.gemhunters.world.TimeCycle; import mineplex.gemhunters.world.WorldListeners; import mineplex.gemhunters.worldevent.WorldEventModule; import mineplex.minecraft.game.core.combat.CombatManager; @@ -158,7 +162,7 @@ public class GemHunters extends JavaPlugin new DamageManager(this, new CombatManager(this), new NpcManager(this, creature), disguiseManager, new ConditionManager(this)); // GWEN - //require(AntiHack.class); + // require(AntiHack.class); // Block Restore BlockRestore blockRestore = require(BlockRestore.class); @@ -181,10 +185,10 @@ public class GemHunters extends JavaPlugin // Parties new PartyManager(); - + // Communities new CommunityManager(this, clientManager); - + // Fixes new MemoryFix(this); new FoodDupeFix(this); @@ -194,10 +198,10 @@ public class GemHunters extends JavaPlugin explosion.SetDebris(true); explosion.SetTemporaryDebris(false); - + // Inventories - //new InventoryManager(this, clientManager); - + // new InventoryManager(this, clientManager); + // Reports // SnapshotManager snapshotManager = new SnapshotManager(this, new // SnapshotRepository(serverStatusManager.getCurrentServerName(), @@ -213,7 +217,12 @@ public class GemHunters extends JavaPlugin // Holograms new HologramManager(this, packetHandler); + // Menus + new MenuManager(this); + // Now we finally get to enable the Gem Hunters modules + // Though if any other module needs one of these it will be generated in + // order, however they are all here just for good measure. require(DebugModule.class); require(BountyModule.class); require(CashOutModule.class); @@ -223,6 +232,7 @@ public class GemHunters extends JavaPlugin require(InventoryModule.class); require(LootModule.class); require(ItemMapModule.class); + require(QuestModule.class); require(SafezoneModule.class); require(ScoreboardModule.class); require(SpawnModule.class); @@ -230,10 +240,12 @@ public class GemHunters extends JavaPlugin require(SupplyDropModule.class); require(WorldEventModule.class); - // An arbitrary collection of world listeners such as block place/break, interact events etc... + // An arbitrary collection of world listeners such as block place/break, + // interact events etc... new WorldListeners(this); - //new TimeCycle(this); - + new TimeCycle(this); + new SewerMobs(this); + // UpdateEvent!!! new Updater(this); @@ -262,7 +274,7 @@ public class GemHunters extends JavaPlugin { continue; } - + entity.remove(); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java index 8bb509674..d83761810 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java @@ -32,7 +32,7 @@ import mineplex.core.common.util.UtilTime; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.core.visibility.VisibilityManager; -import mineplex.gemhunters.death.events.PlayerCustomRespawnEvent; +import mineplex.gemhunters.death.event.PlayerCustomRespawnEvent; import mineplex.gemhunters.spawn.SpawnModule; /** diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/events/PlayerCustomRespawnEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/event/PlayerCustomRespawnEvent.java similarity index 91% rename from Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/events/PlayerCustomRespawnEvent.java rename to Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/event/PlayerCustomRespawnEvent.java index 6b2db56a6..e588841cf 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/events/PlayerCustomRespawnEvent.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/event/PlayerCustomRespawnEvent.java @@ -1,4 +1,4 @@ -package mineplex.gemhunters.death.events; +package mineplex.gemhunters.death.event; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java index b9295969e..fa731b801 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -34,13 +34,14 @@ import mineplex.core.itemstack.ItemBuilder; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.spawn.event.PlayerTeleportIntoMapEvent; @ReflectivelyCreateMiniPlugin public class CashOutModule extends MiniPlugin { private static final DecimalFormat ARMOUR_STAND_FORMAT = new DecimalFormat("0.0"); - public static final ItemStack CASH_OUT_ITEM = new ItemBuilder(Material.EMERALD).setTitle(C.cGreen + "Cash Out").addLore("", C.cGray + "Click to begin the process to cash out.", C.cGray + "Cashing out saves your current loot.").build(); + private static final ItemStack CASH_OUT_ITEM = new ItemBuilder(Material.EMERALD).setTitle(C.cGreen + "Cash Out").addLore("", C.cGray + "Click to begin the process to cash out.", C.cGray + "Cashing out saves your current loot.").build(); private static final int CASH_OUT_COOLDOWN = 10000; private static final int CASH_OUT_MAX_MOVE_DISTANCE_SQUARED = 4; @@ -58,6 +59,17 @@ public class CashOutModule extends MiniPlugin _sessions = new HashMap<>(); } + @EventHandler + public void teleportIn(PlayerTeleportIntoMapEvent event) + { + if (event.isCancelled()) + { + return; + } + + event.getPlayer().getInventory().setItem(7, CASH_OUT_ITEM); + } + @EventHandler public void playerInteract(PlayerInteractEvent event) { @@ -95,7 +107,8 @@ public class CashOutModule extends MiniPlugin @EventHandler public void inventoryClick(InventoryClickEvent event) { - Inventory inv = event.getInventory(); + Player player = (Player) event.getWhoClicked(); + Inventory inv = event.getClickedInventory(); ItemStack itemStack = event.getCurrentItem(); if (inv == null || itemStack == null) @@ -103,10 +116,12 @@ public class CashOutModule extends MiniPlugin return; } - if (itemStack.isSimilar(CASH_OUT_ITEM)) + if (inv.equals(player.getInventory())) { - event.setCancelled(true); + return; } + + event.setCancelled(true); } @EventHandler diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java index 528f2a648..b010714b4 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -8,14 +8,13 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerQuitEvent; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.F; -import mineplex.gemhunters.death.events.PlayerCustomRespawnEvent; +import mineplex.gemhunters.death.event.PlayerCustomRespawnEvent; import mineplex.gemhunters.economy.command.GiveGemsCommand; @ReflectivelyCreateMiniPlugin @@ -103,15 +102,4 @@ public class EconomyModule extends MiniPlugin { return _storedGems.get(player.getUniqueId()); } - - @EventHandler - public void test(PlayerCommandPreprocessEvent event) - { - if (event.getMessage().startsWith("/test")) - { - event.setCancelled(true); - addToStore(event.getPlayer(), "Testing", 100); - } - } - } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java index 95a0ee616..f9552c0d3 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java @@ -22,7 +22,7 @@ import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilInv; import mineplex.core.itemstack.ItemBuilder; -import mineplex.gemhunters.death.events.PlayerCustomRespawnEvent; +import mineplex.gemhunters.death.event.PlayerCustomRespawnEvent; import mineplex.gemhunters.debug.DebugModule; @ReflectivelyCreateMiniPlugin @@ -106,7 +106,7 @@ public class InventoryModule extends MiniPlugin LootItem lootItem = _loot.fromItemStack(itemStack); - if (lootItem == null || lootItem.getMetadata().equals(ITEM_METADATA)) + if (lootItem == null || lootItem.getMetadata() == null || !lootItem.getMetadata().equals(ITEM_METADATA)) { return; } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 9a1f6ef06..519b52154 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -30,6 +30,7 @@ import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilWorld; import mineplex.core.google.GoogleSheetsManager; @@ -41,6 +42,7 @@ import mineplex.gemhunters.loot.command.SpawnChestCommand; import mineplex.gemhunters.loot.command.UpdateLootCommand; import mineplex.gemhunters.loot.deserialisers.ChestPropertiesDeserialiser; import mineplex.gemhunters.loot.deserialisers.LootItemDeserialiser; +import mineplex.gemhunters.loot.event.PlayerChestOpenEvent; import mineplex.gemhunters.loot.rewards.LootItemReward; import mineplex.gemhunters.loot.rewards.LootRankReward; import mineplex.gemhunters.safezone.SafezoneModule; @@ -410,7 +412,7 @@ public class LootModule extends MiniPlugin { for (SpawnedChest chest : _spawnedChest) { - if (chest.getLocation().distanceSquared(location) < 4 && chest.isOpened()) + if (chest.getLocation().distanceSquared(location) < MAX_CHEST_CHECK_DISTANCE_SQUARED && chest.isOpened()) { return true; } @@ -444,7 +446,7 @@ public class LootModule extends MiniPlugin for (SpawnedChest chest : _spawnedChest) { - if (UtilMath.offset(chest.getLocation(), block.getLocation()) < MAX_CHEST_CHECK_DISTANCE_SQUARED) + if (UtilMath.offsetSquared(chest.getLocation(), block.getLocation()) < MAX_CHEST_CHECK_DISTANCE_SQUARED) { key = chest.getProperties().getDataKey(); chest.setOpened(); @@ -458,6 +460,15 @@ public class LootModule extends MiniPlugin return; } + PlayerChestOpenEvent openEvent = new PlayerChestOpenEvent(player, block, _chestProperties.get(key)); + UtilServer.CallEvent(openEvent); + + if (openEvent.isCancelled()) + { + event.setCancelled(true); + return; + } + fillChest(player, block, key); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/event/PlayerChestOpenEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/event/PlayerChestOpenEvent.java new file mode 100644 index 000000000..fb7d40583 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/event/PlayerChestOpenEvent.java @@ -0,0 +1,60 @@ +package mineplex.gemhunters.loot.event; + +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +import mineplex.gemhunters.loot.ChestProperties; + +public class PlayerChestOpenEvent extends PlayerEvent implements Cancellable +{ + + private static final HandlerList HANDLERS = new HandlerList(); + + private boolean _cancel; + private final Block _block; + private final ChestProperties _properties; + + public PlayerChestOpenEvent(Player who, Block block, ChestProperties properties) + { + super(who); + + _block = block; + _properties = properties; + } + + public Block getChest() + { + return _block; + } + + public ChestProperties getProperties() + { + return _properties; + } + + public HandlerList getHandlers() + { + return HANDLERS; + } + + public static HandlerList getHandlerList() + { + return HANDLERS; + } + + @Override + public boolean isCancelled() + { + return _cancel; + } + + @Override + public void setCancelled(boolean cancel) + { + _cancel = cancel; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java index 57225f4d2..73fc579d1 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java @@ -21,14 +21,12 @@ import org.bukkit.craftbukkit.v1_8_R3.CraftChunk; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.craftbukkit.v1_8_R3.util.LongHash; import org.bukkit.craftbukkit.v1_8_R3.util.LongObjectHashMap; -import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.Action; import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -59,8 +57,8 @@ import mineplex.core.itemstack.ItemBuilder; import mineplex.core.portal.events.ServerTransferEvent; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.gemhunters.death.events.PlayerCustomRespawnEvent; import mineplex.gemhunters.spawn.SpawnModule; +import mineplex.gemhunters.spawn.event.PlayerTeleportIntoMapEvent; import net.minecraft.server.v1_8_R3.Block; import net.minecraft.server.v1_8_R3.BlockPosition; import net.minecraft.server.v1_8_R3.Blocks; @@ -357,19 +355,7 @@ public class ItemMapModule extends MiniPlugin view.addRenderer(new ItemMapRenderer()); } - - @EventHandler - public void preventMapInItemFrame(PlayerInteractEntityEvent event) - { - if (!(event.getRightClicked() instanceof ItemFrame)) - return; - - if (!isItemClansMap(event.getPlayer().getItemInHand())) - return; - - event.setCancelled(true); - } - + /** * Get the center of the map. */ @@ -678,7 +664,7 @@ public class ItemMapModule extends MiniPlugin } @EventHandler - public void respawn(PlayerCustomRespawnEvent event) + public void teleportIn(PlayerTeleportIntoMapEvent event) { MapInfo info = new MapInfo(_mapId); @@ -714,7 +700,7 @@ public class ItemMapModule extends MiniPlugin _mapInfo.remove(event.getPlayer().getName()); } - @EventHandler + //@EventHandler public void onServerTransfer(ServerTransferEvent event) { Player p = event.getPlayer(); @@ -748,8 +734,8 @@ public class ItemMapModule extends MiniPlugin for (Player player : Bukkit.getOnlinePlayers()) { MapInfo info = getMap(player); - - if (info.getScale() >= 3) + + if (info == null || info.getScale() >= 3) { continue; } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java new file mode 100644 index 000000000..433f7d3f2 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java @@ -0,0 +1,252 @@ +package mineplex.gemhunters.quest; + +import java.util.List; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.MiniClientPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilItem; +import mineplex.core.common.util.UtilItem.ItemAttribute; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.common.util.UtilTime; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.menu.Menu; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.quest.types.ChestOpenerQuest; +import mineplex.gemhunters.quest.types.Quest; +import mineplex.gemhunters.world.WorldDataModule; + +@ReflectivelyCreateMiniPlugin +public class QuestModule extends MiniClientPlugin +{ + + private static final int MAX_QUESTS = 5; + private static final long RESET_QUESTS_TIME = TimeUnit.MINUTES.toMillis(15); + + private final Quest[] _quests = { new ChestOpenerQuest(0, "Chest Opener", 100, 250, 5), new ChestOpenerQuest(1, "Grand Chest Opener", 200, 500, 20), new ChestOpenerQuest(2, "Superior Chest Opener", 500, 750, 40) }; + + private final WorldDataModule _worldData; + + private QuestModule() + { + super("Quest"); + + _worldData = require(WorldDataModule.class); + + Menu menu = new QuestUI(this); + + runSyncLater(() -> { + + for (Location location : _worldData.getCustomLocation("QUEST_NPC")) + { + new QuestNPC(this, location, menu); + } + + }, 20); + } + + @Override + protected QuestPlayerData addPlayer(UUID uuid) + { + return new QuestPlayerData(); + } + + @EventHandler + public void playerJoin(PlayerJoinEvent event) + { + updateQuests(event.getPlayer()); + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.SLOW) + { + return; + } + + for (Player player : Bukkit.getOnlinePlayers()) + { + QuestPlayerData playerData = Get(player); + + if (!UtilTime.elapsed(playerData.getLastClear(), RESET_QUESTS_TIME)) + { + continue; + } + + player.sendMessage(F.main(C.cYellowB + "Quest Master", "I have " + F.count(String.valueOf(MAX_QUESTS)) + " new quests for you! Come and see me to start them!")); + + playerData.clear(); + updateQuests(player); + } + } + + public void updateQuests(Player player) + { + QuestPlayerData playerData = Get(player); + List quests = playerData.getPossibleQuests(); + + for (int i = 0; i < MAX_QUESTS; i++) + { + Quest quest = getRandomQuest(playerData, player); + + if (quest == null) + { + player.sendMessage(F.main(_moduleName, "It seems that there was some trouble finding you a new quest. Please try again later.")); + return; + } + + quests.add(quest.getId()); + } + } + + public void startQuest(Quest quest, Player player) + { + if (isActive(quest, player)) + { + player.sendMessage(F.main(_moduleName, "You have already accepted that quest.")); + return; + } + else if (isComplete(quest, player)) + { + player.sendMessage(F.main(_moduleName, "You have already completed that quest.")); + return; + } + + player.sendMessage(F.main(_moduleName, "Started " + F.name(quest.getName()) + ".")); + + QuestPlayerData playerData = Get(player); + playerData.getActiveQuests().add(quest.getId()); + + updateQuestItem(quest, player); + } + + public void completeQuest(Quest quest, Player player) + { + if (!isActive(quest, player)) + { + player.sendMessage(F.main(_moduleName, "This quest is not active for you.")); + return; + } + + QuestPlayerData playerData = Get(player); + playerData.getActiveQuests().remove(Integer.valueOf(quest.getId())); + playerData.getCompletedQuests().add(quest.getId()); + + updateQuestItem(quest, player); + } + + public Quest getRandomQuest(QuestPlayerData playerData, Player player) + { + int attempts = 0; + + while (attempts < _quests.length * 2) + { + attempts++; + + int index = UtilMath.r(_quests.length); + Quest quest = _quests[index]; + + if (isActive(quest, player) || playerData.getPossibleQuests().contains(quest.getId())) + { + continue; + } + + return quest; + } + + return null; + } + + public ItemStack getItemStack(Quest quest, Player player, boolean npc, boolean hasSpace) + { + ItemBuilder builder = new ItemBuilder(Material.PAPER); + + builder.setTitle(C.cGreen + quest.getName()); + builder.addLore(C.blankLine, quest.getDescription(), C.blankLine); + + boolean active = isActive(quest, player); + boolean complete = isComplete(quest, player); + + if (npc) + { + if (active) + { + builder.setGlow(true); + builder.addLore(C.cRed + "You have already started this quest!"); + } + else if (complete) + { + builder.addLore(C.cRed + "You have already completed this quest!"); + } + else if (hasSpace) + { + builder.addLore(C.cGreen + "Click to start this quest!"); + } + else + { + builder.addLore(C.cRed + "You do not have enough space in your inventory!"); + } + } + else + { + builder.addLore(UtilTextMiddle.progress(quest.getProgress(player)) + C.mBody + " [" + C.cGreen + quest.get(player) + C.mBody + "/" + C.cGreen + quest.getGoal() + C.mBody + "]"); + } + + return builder.build(); + } + + public void updateQuestItem(Quest quest, Player player) + { + ItemStack itemStack = getItemStack(quest, player, false, true); + + for (ItemStack items : player.getInventory().getContents()) + { + if (UtilItem.isSimilar(itemStack, items, ItemAttribute.MATERIAL, ItemAttribute.NAME, ItemAttribute.DATA)) + { + player.getInventory().remove(items); + } + } + + if (isActive(quest, player)) + { + player.getInventory().addItem(itemStack); + } + } + + public boolean isActive(Quest quest, Player player) + { + return Get(player).getActiveQuests().contains(quest.getId()); + } + + public boolean isComplete(Quest quest, Player player) + { + return Get(player).getCompletedQuests().contains(quest.getId()); + } + + public Quest getFromId(int id) + { + for (Quest quest : _quests) + { + if (quest.getId() == id) + { + return quest; + } + } + + return null; + } +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestNPC.java new file mode 100644 index 000000000..609f873bb --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestNPC.java @@ -0,0 +1,43 @@ +package mineplex.gemhunters.quest; + +import org.bukkit.Location; +import org.bukkit.entity.Villager; +import org.bukkit.entity.Villager.Profession; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEntityEvent; + +import mineplex.core.common.util.C; +import mineplex.core.menu.Menu; +import mineplex.gemhunters.util.SimpleNPC; + +public class QuestNPC extends SimpleNPC +{ + + private Menu _questMenu; + + public QuestNPC(QuestModule quest, Location spawn, Menu menu) + { + super(quest.getPlugin(), spawn, Villager.class, C.cYellowB + "Quest Master", null); + + _questMenu = menu; + + Villager villager = (Villager) _entity; + + villager.setProfession(Profession.LIBRARIAN); + } + + @Override + @EventHandler + public void npcClick(PlayerInteractEntityEvent event) + { + if (!event.getRightClicked().equals(_entity)) + { + return; + } + + event.setCancelled(true); + + _questMenu.open(event.getPlayer()); + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestPlayerData.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestPlayerData.java new file mode 100644 index 000000000..dbfce2d62 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestPlayerData.java @@ -0,0 +1,53 @@ +package mineplex.gemhunters.quest; + +import java.util.ArrayList; +import java.util.List; + +public class QuestPlayerData +{ + + private final List _possibleQuests; + private final List _activeQuests; + private final List _completedQuests; + + private long _lastClear; + + public QuestPlayerData() + { + _possibleQuests = new ArrayList<>(); + _activeQuests = new ArrayList<>(); + _completedQuests = new ArrayList<>(); + + _lastClear = System.currentTimeMillis(); + } + + public void clear() + { + _possibleQuests.clear(); + _activeQuests.clear(); + _completedQuests.clear(); + + _lastClear = System.currentTimeMillis(); + } + + public List getPossibleQuests() + { + return _possibleQuests; + } + + public List getActiveQuests() + { + return _activeQuests; + } + + public List getCompletedQuests() + { + return _completedQuests; + } + + public long getLastClear() + { + return _lastClear; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestUI.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestUI.java new file mode 100644 index 000000000..1fac094f5 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestUI.java @@ -0,0 +1,61 @@ +package mineplex.gemhunters.quest; + +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilUI; +import mineplex.core.menu.Button; +import mineplex.core.menu.Menu; +import mineplex.gemhunters.quest.types.Quest; + +public class QuestUI extends Menu +{ + + public QuestUI(QuestModule plugin) + { + super("Quest Master", plugin); + } + + @Override + protected Button[] setUp(Player player) + { + Button[] buttons = new Button[21]; + QuestPlayerData playerData = getPlugin().Get(player); + + int i = 0; + int[] slots = UtilUI.getIndicesFor(playerData.getPossibleQuests().size(), 1); + for (Integer id : playerData.getPossibleQuests()) + { + Quest quest = getPlugin().getFromId(id); + ItemStack itemStack = getPlugin().getItemStack(quest, player, true, UtilInv.hasSpace(player, 1)); + + buttons[slots[i++]] = new QuestSelectButton(getPlugin(), itemStack, quest); + } + + return buttons; + } + + public class QuestSelectButton extends Button + { + + private final Quest _quest; + + public QuestSelectButton(QuestModule plugin, ItemStack itemStack, Quest quest) + { + super(itemStack, plugin); + + _quest = quest; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + getPlugin().startQuest(_quest, player); + resetAndUpdate(); + } + + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java new file mode 100644 index 000000000..8a8514b80 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java @@ -0,0 +1,56 @@ +package mineplex.gemhunters.quest.types; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import mineplex.core.common.util.F; +import mineplex.gemhunters.debug.DebugModule; +import mineplex.gemhunters.loot.event.PlayerChestOpenEvent; + +public class ChestOpenerQuest extends Quest +{ + + private final int _goal; + + public ChestOpenerQuest(int id, String name, int startCost, int completeReward, int goal) + { + super(id, name, "Open " + F.count(String.valueOf(goal)) + " Chests.", startCost, completeReward); + + _goal = goal; + } + + @Override + public float getProgress(Player player) + { + return (float) get(player) / (float) _goal; + } + + @Override + public int getGoal() + { + return _goal; + } + + @EventHandler + public void chestOpen(PlayerChestOpenEvent event) + { + DebugModule.getInstance().d(event.getEventName()); + Player player = event.getPlayer(); + + if (!isActive(player)) + { + DebugModule.getInstance().d("Not active."); + return; + } + + int amount = getAndIncrement(player, 1); + + DebugModule.getInstance().d("amount = " + amount); + + if (amount >= _goal) + { + onReward(player); + } + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/Quest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/Quest.java new file mode 100644 index 000000000..47a56ae0c --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/Quest.java @@ -0,0 +1,127 @@ +package mineplex.gemhunters.quest.types; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +import mineplex.core.Managers; +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilServer; +import mineplex.core.donation.DonationManager; +import mineplex.gemhunters.economy.EconomyModule; +import mineplex.gemhunters.quest.QuestModule; + +public abstract class Quest implements Listener +{ + + private final int _id; + private final String _name; + private final String _description; + private final int _startCost; + private final int _completeReward; + + protected final QuestModule _quest; + protected final CoreClientManager _clientManager; + protected final DonationManager _donation; + protected final EconomyModule _economy; + + private final Map _counter; + + public Quest(int id, String name, String description, int startCost, int completeReward) + { + _id = id; + _name = name; + _description = description; + _startCost = startCost; + _completeReward = completeReward; + + _quest = Managers.require(QuestModule.class); + _clientManager = Managers.require(CoreClientManager.class); + _donation = Managers.require(DonationManager.class); + _economy = Managers.require(EconomyModule.class); + + _counter = new HashMap<>(); + + UtilServer.getServer().getPluginManager().registerEvents(this, UtilServer.getPlugin()); + } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + remove(event.getPlayer()); + } + + public int get(Player player) + { + return _counter.getOrDefault(player.getUniqueId(), 0); + } + + public int getAndIncrement(Player player, int amount) + { + int newAmount = get(player) + amount; + _counter.put(player.getUniqueId(), newAmount); + _quest.updateQuestItem(this, player); + + return newAmount; + } + + public int remove(Player player) + { + return _counter.remove(player.getUniqueId()); + } + + public void onStart(Player player) + { + _economy.removeFromStore(player, _startCost); + } + + public void onReward(Player player) + { + _economy.addToStore(player, "Completing " + F.elem(_name), _completeReward); + remove(player); + _quest.completeQuest(this, player); + } + + public boolean isActive(Player player) + { + return _quest.isActive(this, player); + } + + public abstract float getProgress(Player player); + + public int getGoal() + { + return 1; + } + + public final int getId() + { + return _id; + } + + public final String getName() + { + return _name; + } + + public final String getDescription() + { + return _description; + } + + public final int getStartCost() + { + return _startCost; + } + + public final int getCompleteReward() + { + return _completeReward; + } +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java index 59af93f25..47576c345 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java @@ -110,7 +110,6 @@ public class TraderNPC extends SimpleNPC player.sendMessage(F.main(_entity.getCustomName(), "Purchased " + F.elem(itemName) + "!")); player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 1.2F); player.getInventory().addItem(itemStack); - player.closeInventory(); } public int fromItemStack(ItemStack itemStack) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index ce51aa10c..e910bcfdf 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -16,14 +16,14 @@ import org.bukkit.scheduler.BukkitRunnable; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.C; -import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilServer; import mineplex.core.portal.Intent; import mineplex.core.portal.Portal; -import mineplex.gemhunters.economy.CashOutModule; import mineplex.gemhunters.safezone.SafezoneModule; +import mineplex.gemhunters.spawn.event.PlayerTeleportIntoMapEvent; import mineplex.gemhunters.util.ColouredTextAnimation; import mineplex.gemhunters.util.SimpleNPC; import mineplex.gemhunters.world.WorldDataModule; @@ -34,7 +34,7 @@ public class SpawnModule extends MiniPlugin public static final int WORLD_BORDER_RADIUS = 768; private static final int MAX_SPAWNING_Y = 73; - + private final SafezoneModule _safezone; private final WorldDataModule _worldData; @@ -80,70 +80,66 @@ public class SpawnModule extends MiniPlugin location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, _spawn))); - new SimpleNPC(_plugin, location, Villager.class, C.cDRed + "! " + C.cRedB + "Enter The World" + C.cDRed + " !", new Callback() - { + new SimpleNPC(_plugin, location, Villager.class, C.cDRed + "! " + C.cRedB + "Enter The World" + C.cDRed + " !", clicker -> { - @Override - public void run(Player player) + Location toTeleport = getRandomLocation(); + + if (toTeleport == null) { - Location location = getRandomLocation(); - - if (location == null) - { - player.sendMessage(F.main(_moduleName, "A suitable teleport location could not be found. Please try again in a few seconds.")); - return; - } - - player.teleport(location); - player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 4 * 20, 9)); - player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 4 * 20, 9)); - - player.getInventory().setItem(8, CashOutModule.CASH_OUT_ITEM); - - ColouredTextAnimation animation = new ColouredTextAnimation("GEM HUNTERS", C.cGoldB + "M ", C.cGoldB + " M", new String[] { C.cDGreenB, C.cGreenB, C.cWhiteB }); - - runSyncTimer(new BukkitRunnable() - { - - @Override - public void run() - { - if (animation.displayAsTitle(player)) - { - cancel(); - } - } - }, 10, 4); + clicker.sendMessage(F.main(_moduleName, "A suitable teleport location could not be found. Please try again in a few seconds.")); + return; } + + PlayerTeleportIntoMapEvent teleportEvent = new PlayerTeleportIntoMapEvent(player, toTeleport); + + UtilServer.CallEvent(teleportEvent); + + if (teleportEvent.isCancelled()) + { + clicker.sendMessage(F.main(_moduleName, "Something went wrong there, sorry. Please try again in a few seconds.")); + return; + } + + clicker.teleport(toTeleport); + clicker.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 4 * 20, 9)); + clicker.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 4 * 20, 9)); + + ColouredTextAnimation animation = new ColouredTextAnimation("GEM HUNTERS", C.cGoldB + "M ", C.cGoldB + " M", new String[] { C.cDGreenB, C.cGreenB, C.cWhiteB }); + + runSyncTimer(new BukkitRunnable() + { + + @Override + public void run() + { + if (animation.displayAsTitle(player)) + { + cancel(); + } + } + }, 10, 4); }); } { Location location = _worldData.getCustomLocation("RETURN_TO_HUB").get(0); location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, _spawn))); - - new SimpleNPC(_plugin, location, Villager.class, C.cGoldB + "Return To Hub", new Callback() - { - - @Override - public void run(Player data) - { - Portal.getInstance().sendToHub(data, null, Intent.PLAYER_REQUEST); - } + + new SimpleNPC(_plugin, location, Villager.class, C.cGoldB + "Return To Hub", clicker -> { + + Portal.getInstance().sendToHub(clicker, null, Intent.PLAYER_REQUEST); + }); } { Location location = _worldData.getCustomLocation("TUTORIAL").get(0); location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, _spawn))); - - new SimpleNPC(_plugin, location, Villager.class, C.cGoldB + "Tutorial", new Callback() - { - - @Override - public void run(Player data) - { - } + + new SimpleNPC(_plugin, location, Villager.class, C.cGoldB + "Tutorial", clicker -> { + + clicker.sendMessage(F.main(_moduleName, "A tutorial will be coming soon.")); + }); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/event/PlayerTeleportIntoMapEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/event/PlayerTeleportIntoMapEvent.java new file mode 100644 index 000000000..51b6e6d6f --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/event/PlayerTeleportIntoMapEvent.java @@ -0,0 +1,56 @@ +package mineplex.gemhunters.spawn.event; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +public class PlayerTeleportIntoMapEvent extends PlayerEvent implements Cancellable +{ + + private static final HandlerList HANDLERS = new HandlerList(); + + private boolean _cancel; + private Location _to; + + public PlayerTeleportIntoMapEvent(Player who, Location to) + { + super(who); + + _to = to; + } + + public void setTo(Location to) + { + _to = to; + } + + public Location getTo() + { + return _to; + } + + public HandlerList getHandlers() + { + return HANDLERS; + } + + public static HandlerList getHandlerList() + { + return HANDLERS; + } + + @Override + public boolean isCancelled() + { + return _cancel; + } + + @Override + public void setCancelled(boolean cancel) + { + _cancel = cancel; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java index b0e9fa6df..5e265998e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/SimpleNPC.java @@ -13,7 +13,6 @@ import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.plugin.java.JavaPlugin; -import mineplex.core.common.util.Callback; import mineplex.core.common.util.UtilEnt; public class SimpleNPC implements Listener diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java new file mode 100644 index 000000000..b9e363f43 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java @@ -0,0 +1,95 @@ +package mineplex.gemhunters.world; + +import java.util.HashSet; +import java.util.Random; +import java.util.Set; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilMath; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.spawn.SpawnModule; + +public class SewerMobs implements Listener +{ + + private static final int MAX_MOBS = 100; + + private final Set _entities; + + public SewerMobs(JavaPlugin plugin) + { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + + _entities = new HashSet<>(); + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.SLOWEST) + { + return; + } + + World world = Bukkit.getWorlds().get(0); + + for (int i = 0; i < MAX_MOBS / 4; i++) + { + if (_entities.size() >= MAX_MOBS) + { + break; + } + + EntityType type = UtilMath.random.nextBoolean() ? EntityType.ZOMBIE : EntityType.SKELETON; + + _entities.add(world.spawnEntity(getRandomLocation(world), type)); + } + } + + public Location getRandomLocation(World world) + { + int attempts = 0; + + while (attempts < 40) + { + Location location = new Location(world, UtilMath.r(SpawnModule.WORLD_BORDER_RADIUS * 2) - SpawnModule.WORLD_BORDER_RADIUS, 46, UtilMath.r(SpawnModule.WORLD_BORDER_RADIUS * 2) - SpawnModule.WORLD_BORDER_RADIUS); + + if (!isSuitable(location.getBlock())) + { + continue; + } + + attempts++; + } + + return null; + } + + public boolean isSuitable(Block block) + { + Block up = block.getRelative(BlockFace.UP); + Block down = block.getRelative(BlockFace.DOWN); + + if (block.getType() != Material.AIR || up.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block)) + { + return false; + } + + return true; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java index 32fc398ad..a3a61a617 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java @@ -62,20 +62,20 @@ public class TimeCycle implements Listener if (!_night && _world.getTime() > 12000) { _night = true; - setStreetLights(); + //setStreetLights(); } if (_world.getTime() >= 23900) { _world.setTime(0); _night = false; - setStreetLights(); + //setStreetLights(); } _world.setTime(_world.getTime() + (isNight() ? TICKS_NIGHT : TICKS_DAY)); } - @EventHandler + //@EventHandler public void test(PlayerCommandPreprocessEvent event) { if (event.getMessage().startsWith("/lamp")) { From 5fbbae1493298bb8b2464a38362f4a4a441aa79e Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 17 Feb 2017 18:55:38 +0000 Subject: [PATCH 039/101] The SamitoD quest --- .../gemhunters/quest/QuestModule.java | 17 +++- .../quest/types/ChestOpenerQuest.java | 3 - .../gemhunters/quest/types/Quest.java | 9 ++- .../gemhunters/quest/types/SamitoDQuest.java | 80 +++++++++++++++++++ .../mineplex/gemhunters/world/SewerMobs.java | 12 ++- 5 files changed, 109 insertions(+), 12 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java index 433f7d3f2..72ae6680c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java @@ -23,10 +23,12 @@ import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.menu.Menu; +import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.quest.types.ChestOpenerQuest; import mineplex.gemhunters.quest.types.Quest; +import mineplex.gemhunters.quest.types.SamitoDQuest; import mineplex.gemhunters.world.WorldDataModule; @ReflectivelyCreateMiniPlugin @@ -36,7 +38,13 @@ public class QuestModule extends MiniClientPlugin private static final int MAX_QUESTS = 5; private static final long RESET_QUESTS_TIME = TimeUnit.MINUTES.toMillis(15); - private final Quest[] _quests = { new ChestOpenerQuest(0, "Chest Opener", 100, 250, 5), new ChestOpenerQuest(1, "Grand Chest Opener", 200, 500, 20), new ChestOpenerQuest(2, "Superior Chest Opener", 500, 750, 40) }; + private final Quest[] _quests = { + new ChestOpenerQuest(0, "Chest Opener", 100, 250, 5), + new ChestOpenerQuest(1, "Grand Chest Opener", 200, 500, 20), + new ChestOpenerQuest(2, "Superior Chest Opener", 500, 750, 40), + + new SamitoDQuest(3, "Give to the Homeless", "Donate " + F.count(String.valueOf(10)) + " gems to the Hobo.", 100, 300, 10) + }; private final WorldDataModule _worldData; @@ -95,7 +103,7 @@ public class QuestModule extends MiniClientPlugin } public void updateQuests(Player player) - { + { QuestPlayerData playerData = Get(player); List quests = playerData.getPossibleQuests(); @@ -211,6 +219,11 @@ public class QuestModule extends MiniClientPlugin public void updateQuestItem(Quest quest, Player player) { + if (!Recharge.Instance.use(player, "Quest Update Item", 1000, false, false)) + { + return; + } + ItemStack itemStack = getItemStack(quest, player, false, true); for (ItemStack items : player.getInventory().getContents()) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java index 8a8514b80..3ab14a3b1 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java @@ -39,13 +39,10 @@ public class ChestOpenerQuest extends Quest if (!isActive(player)) { - DebugModule.getInstance().d("Not active."); return; } int amount = getAndIncrement(player, 1); - - DebugModule.getInstance().d("amount = " + amount); if (amount >= _goal) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/Quest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/Quest.java index 47a56ae0c..96d50c705 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/Quest.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/Quest.java @@ -16,6 +16,7 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.donation.DonationManager; import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.quest.QuestModule; +import mineplex.gemhunters.world.WorldDataModule; public abstract class Quest implements Listener { @@ -30,6 +31,7 @@ public abstract class Quest implements Listener protected final CoreClientManager _clientManager; protected final DonationManager _donation; protected final EconomyModule _economy; + protected final WorldDataModule _worldData; private final Map _counter; @@ -45,7 +47,8 @@ public abstract class Quest implements Listener _clientManager = Managers.require(CoreClientManager.class); _donation = Managers.require(DonationManager.class); _economy = Managers.require(EconomyModule.class); - + _worldData = Managers.require(WorldDataModule.class); + _counter = new HashMap<>(); UtilServer.getServer().getPluginManager().registerEvents(this, UtilServer.getPlugin()); @@ -71,9 +74,9 @@ public abstract class Quest implements Listener return newAmount; } - public int remove(Player player) + public void remove(Player player) { - return _counter.remove(player.getUniqueId()); + _counter.remove(player.getUniqueId()); } public void onStart(Player player) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java new file mode 100644 index 000000000..215defd3c --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java @@ -0,0 +1,80 @@ +package mineplex.gemhunters.quest.types; + +import org.bukkit.FireworkEffect.Type; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEvent; + +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilFirework; +import mineplex.core.common.util.UtilMath; +import mineplex.gemhunters.debug.DebugModule; + +public class SamitoDQuest extends Quest +{ + + private static final String NPC_NAME = "Hobo"; + private static final String[] REACTIONS = { + "Well hello there folks and welcome... to... my... youtube channel", + "WILLIAMMMMMMM", + "ALEXXXXXXXXXX", + }; + + private final Location _pot; + private final int _gemsToDonate; + + public SamitoDQuest(int id, String name, String description, int startCost, int completeReward, int gemsToDonate) + { + super(id, name, description, startCost, completeReward); + + _pot = _worldData.getCustomLocation("QUEST_SAM").get(0); + _pot.getBlock().setType(Material.FLOWER_POT); + + _gemsToDonate = gemsToDonate; + } + + @Override + public float getProgress(Player player) + { + return 0; + } + + @EventHandler + public void onInteract(PlayerInteractEvent event) + { + Player player = event.getPlayer(); + + if (event.isCancelled() || !isActive(player)) + { + return; + } + + DebugModule.getInstance().d(event.getEventName()); + + Block block = event.getClickedBlock(); + + if (block == null) + { + return; + } + + if (UtilMath.offsetSquared(block.getLocation(), _pot) < 4) + { + if (_economy.getGems(player) < _gemsToDonate) + { + player.sendMessage(F.main(NPC_NAME, "Awww come on man, even alex has more gems than you.")); + return; + } + + player.sendMessage(F.main(NPC_NAME, REACTIONS[UtilMath.random.nextInt(REACTIONS.length)])); + _economy.removeFromStore(player, _gemsToDonate); + UtilFirework.playFirework(_pot, Type.BURST, Color.GREEN, true, false); + onReward(player); + } + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java index b9e363f43..f26fb895c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java @@ -1,7 +1,6 @@ package mineplex.gemhunters.world; import java.util.HashSet; -import java.util.Random; import java.util.Set; import org.bukkit.Bukkit; @@ -16,7 +15,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; -import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilMath; import mineplex.core.updater.UpdateType; @@ -55,8 +53,14 @@ public class SewerMobs implements Listener } EntityType type = UtilMath.random.nextBoolean() ? EntityType.ZOMBIE : EntityType.SKELETON; + Location location = getRandomLocation(world); - _entities.add(world.spawnEntity(getRandomLocation(world), type)); + if (location == null) + { + continue; + } + + _entities.add(world.spawnEntity(location, type)); } } @@ -66,7 +70,7 @@ public class SewerMobs implements Listener while (attempts < 40) { - Location location = new Location(world, UtilMath.r(SpawnModule.WORLD_BORDER_RADIUS * 2) - SpawnModule.WORLD_BORDER_RADIUS, 46, UtilMath.r(SpawnModule.WORLD_BORDER_RADIUS * 2) - SpawnModule.WORLD_BORDER_RADIUS); + Location location = new Location(world, UtilMath.r(SpawnModule.WORLD_BORDER_RADIUS * 2) - SpawnModule.WORLD_BORDER_RADIUS, 51, UtilMath.r(SpawnModule.WORLD_BORDER_RADIUS * 2) - SpawnModule.WORLD_BORDER_RADIUS); if (!isSuitable(location.getBlock())) { From 9db3ddc2d9a3d0b0e52e196a5129cf777a72d06c Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 17 Feb 2017 19:04:08 +0000 Subject: [PATCH 040/101] Remove debug message --- .../src/mineplex/gemhunters/quest/types/SamitoDQuest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java index 215defd3c..553a399f3 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java @@ -53,8 +53,6 @@ public class SamitoDQuest extends Quest return; } - DebugModule.getInstance().d(event.getEventName()); - Block block = event.getClickedBlock(); if (block == null) From 52bcd01e27a0e5eeaad6fd479b6140b03d700e64 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 17 Feb 2017 19:04:16 +0000 Subject: [PATCH 041/101] Remove give item cooldown --- .../src/mineplex/gemhunters/quest/QuestModule.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java index 72ae6680c..4af8759bf 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java @@ -219,11 +219,6 @@ public class QuestModule extends MiniClientPlugin public void updateQuestItem(Quest quest, Player player) { - if (!Recharge.Instance.use(player, "Quest Update Item", 1000, false, false)) - { - return; - } - ItemStack itemStack = getItemStack(quest, player, false, true); for (ItemStack items : player.getInventory().getContents()) From be2963cf799557f61c494ab4a131fb3a04c2b24f Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 17 Feb 2017 19:41:48 +0000 Subject: [PATCH 042/101] More Sam Quotes --- .../src/mineplex/gemhunters/quest/QuestModule.java | 1 - .../src/mineplex/gemhunters/quest/types/SamitoDQuest.java | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java index 4af8759bf..0ad0ac6f9 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java @@ -23,7 +23,6 @@ import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.menu.Menu; -import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.quest.types.ChestOpenerQuest; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java index 553a399f3..30af73b08 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java @@ -1,7 +1,7 @@ package mineplex.gemhunters.quest.types; -import org.bukkit.FireworkEffect.Type; import org.bukkit.Color; +import org.bukkit.FireworkEffect.Type; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -12,7 +12,6 @@ import org.bukkit.event.player.PlayerInteractEvent; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilFirework; import mineplex.core.common.util.UtilMath; -import mineplex.gemhunters.debug.DebugModule; public class SamitoDQuest extends Quest { @@ -22,6 +21,10 @@ public class SamitoDQuest extends Quest "Well hello there folks and welcome... to... my... youtube channel", "WILLIAMMMMMMM", "ALEXXXXXXXXXX", + "CHISS", + "Rods and Gaps", + "Hit him with that w-tap", + "You're the one who wanted to bring out bows young man" }; private final Location _pot; From 30d2059e9aff2c88829ef3efd6daceaeb1c4b6a0 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 18 Feb 2017 10:36:05 +0000 Subject: [PATCH 043/101] Use MiniClientPlugin for gem tracking --- .../gemhunters/economy/EconomyModule.java | 35 ++++++------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java index b010714b4..03c1006f9 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -1,16 +1,13 @@ package mineplex.gemhunters.economy; -import java.util.HashMap; -import java.util.Map; import java.util.UUID; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import mineplex.core.MiniPlugin; +import mineplex.core.MiniClientPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.F; @@ -18,18 +15,14 @@ import mineplex.gemhunters.death.event.PlayerCustomRespawnEvent; import mineplex.gemhunters.economy.command.GiveGemsCommand; @ReflectivelyCreateMiniPlugin -public class EconomyModule extends MiniPlugin +public class EconomyModule extends MiniClientPlugin { private static final float GEM_KILL_FACTOR = 0.5F; - private Map _storedGems; - public EconomyModule() { super("Economy"); - - _storedGems = new HashMap<>(); } @Override @@ -58,7 +51,6 @@ public class EconomyModule extends MiniPlugin int newGems = (int) (oldGems * GEM_KILL_FACTOR); addToStore(killerPlayer, "Killing " + F.name(player.getName()), newGems); - return; } removeFromStore(player, oldGems); @@ -70,22 +62,9 @@ public class EconomyModule extends MiniPlugin event.incrementGems(getGems(event.getPlayer())); } - @EventHandler - public void quit(PlayerQuitEvent event) - { - _storedGems.remove(event.getPlayer().getUniqueId()); - } - public void addToStore(Player player, String reason, int gems) { - UUID key = player.getUniqueId(); - - if (!_storedGems.containsKey(key)) - { - _storedGems.put(key, 0); - } - - _storedGems.put(key, _storedGems.get(key) + gems); + Set(player, Get(player) + gems); if (reason != null) { @@ -100,6 +79,12 @@ public class EconomyModule extends MiniPlugin public int getGems(Player player) { - return _storedGems.get(player.getUniqueId()); + return Get(player); + } + + @Override + protected Integer addPlayer(UUID uuid) + { + return 0; } } From 4cb4f944e7d11e2f705e72bb162608cd98f0691a Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 18 Feb 2017 10:36:23 +0000 Subject: [PATCH 044/101] Fix the map not working when players relog --- .../src/mineplex/gemhunters/map/ItemMapModule.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java index 73fc579d1..7de836fac 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java @@ -57,8 +57,8 @@ import mineplex.core.itemstack.ItemBuilder; import mineplex.core.portal.events.ServerTransferEvent; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.death.event.PlayerCustomRespawnEvent; import mineplex.gemhunters.spawn.SpawnModule; -import mineplex.gemhunters.spawn.event.PlayerTeleportIntoMapEvent; import net.minecraft.server.v1_8_R3.Block; import net.minecraft.server.v1_8_R3.BlockPosition; import net.minecraft.server.v1_8_R3.Blocks; @@ -664,7 +664,7 @@ public class ItemMapModule extends MiniPlugin } @EventHandler - public void teleportIn(PlayerTeleportIntoMapEvent event) + public void teleportIn(PlayerCustomRespawnEvent event) { MapInfo info = new MapInfo(_mapId); From 074c786c35c14638019591332a2001f87c5a7c1c Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 18 Feb 2017 10:36:38 +0000 Subject: [PATCH 045/101] Don't allow purchase if inv if full --- .../mineplex/gemhunters/shop/TraderNPC.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java index 47576c345..4db8482fe 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java @@ -1,5 +1,6 @@ package mineplex.gemhunters.shop; +import java.util.List; import java.util.Set; import org.bukkit.Location; @@ -16,6 +17,7 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.Managers; import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilInv; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemStackFactory; import mineplex.gemhunters.economy.EconomyModule; @@ -102,9 +104,25 @@ public class TraderNPC extends SimpleNPC player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0.6F); return; } + + if (!UtilInv.HasSpace(player, itemStack.getType(), itemStack.getAmount())) + { + player.sendMessage(F.main(_entity.getCustomName(), "I'm sorry you don't have enough space to hold that.")); + player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0.6F); + return; + } _economy.removeFromStore(player, cost); + // Remove cost lore + ItemBuilder builder = new ItemBuilder(itemStack); + + List lore = builder.getLore(); + lore.remove(lore.size() - 1); + builder.setLore(lore.toArray(new String[0])); + + itemStack = builder.build(); + String itemName = ItemStackFactory.Instance.GetName(itemStack, true); player.sendMessage(F.main(_entity.getCustomName(), "Purchased " + F.elem(itemName) + "!")); From 0fa0d88aac3ba27313f222c61d829e78133e6ef2 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 18 Feb 2017 10:36:50 +0000 Subject: [PATCH 046/101] Clean up sewer mobs --- .../src/mineplex/gemhunters/world/SewerMobs.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java index f26fb895c..b10278c4b 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java @@ -1,6 +1,7 @@ package mineplex.gemhunters.world; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import org.bukkit.Bukkit; @@ -44,6 +45,17 @@ public class SewerMobs implements Listener } World world = Bukkit.getWorlds().get(0); + Iterator iterator= _entities.iterator(); + + while (iterator.hasNext()) + { + Entity entity = iterator.next(); + + if (entity.isDead() || !entity.isValid()) + { + iterator.remove(); + } + } for (int i = 0; i < MAX_MOBS / 4; i++) { From af29135026fdd4bef39a4ce97f515a03a9d89206 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 18 Feb 2017 10:37:03 +0000 Subject: [PATCH 047/101] ItemFrames and Leaves --- .../gemhunters/world/WorldListeners.java | 48 +++++++++---------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java index c7f2637d8..12d296638 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -8,7 +8,6 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; @@ -20,6 +19,7 @@ import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockFadeEvent; import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.LeavesDecayEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.hanging.HangingBreakEvent; @@ -40,28 +40,18 @@ import mineplex.gemhunters.debug.DebugModule; public class WorldListeners implements Listener { - private static final int VIEW_DISTANCE = 10; private static final long HUNGER_RECHARGE = TimeUnit.SECONDS.toMillis(15); - + private final JavaPlugin _plugin; - + public WorldListeners(JavaPlugin plugin) { _plugin = plugin; - + plugin.getServer().getPluginManager().registerEvents(this, plugin); - plugin.getServer().getScheduler().runTaskLater(plugin, () -> { - - for (World world : plugin.getServer().getWorlds()) - { - ((CraftWorld) world).getHandle().spigotConfig.viewDistance = VIEW_DISTANCE; - ((CraftWorld) world).getHandle().a(VIEW_DISTANCE); - } - - }, 20); } - @EventHandler + //@EventHandler public void deletePlayerData(PlayerQuitEvent event) { _plugin.getServer().getScheduler().runTaskLater(_plugin, () -> { @@ -71,7 +61,7 @@ public class WorldListeners implements Listener new File(world.getWorldFolder().getPath() + File.separator + "stats" + File.separator + uuid + ".json").delete(); }, 20); } - + @EventHandler(priority = EventPriority.LOWEST) public void blockBreak(BlockBreakEvent event) { @@ -100,7 +90,7 @@ public class WorldListeners implements Listener } @EventHandler - public void armorStandDestory(PlayerInteractAtEntityEvent event) + public void entityDestory(PlayerInteractAtEntityEvent event) { if (shouldBlock(event.getPlayer())) { @@ -109,9 +99,9 @@ public class WorldListeners implements Listener } @EventHandler - public void armorStandDamage(EntityDamageEvent event) + public void entityDamage(EntityDamageEvent event) { - if (event.getEntity() instanceof ArmorStand) + if (event.getEntity() instanceof ArmorStand || event.getEntity() instanceof ItemFrame) { event.setCancelled(true); } @@ -122,11 +112,11 @@ public class WorldListeners implements Listener { event.setCancelled(true); } - + @EventHandler public void itemFrames(PlayerInteractEntityEvent event) { - if (shouldBlock(event.getPlayer()) && event.getRightClicked() instanceof ItemFrame) + if (event.getRightClicked() instanceof ItemFrame) { event.setCancelled(true); } @@ -148,7 +138,7 @@ public class WorldListeners implements Listener { return; } - + // Sam don't you dare look here, I understand the implications of this // but entities, can I just save by UUID? or does not doing this have // bigger complications?. @@ -172,6 +162,12 @@ public class WorldListeners implements Listener { event.setCancelled(true); } + + @EventHandler + public void leavesDecay(LeavesDecayEvent event) + { + event.setCancelled(true); + } @EventHandler(priority = EventPriority.HIGHEST) public void hungerChange(FoodLevelChangeEvent event) @@ -180,11 +176,11 @@ public class WorldListeners implements Listener { return; } - + Player player = (Player) event.getEntity(); - - DebugModule.getInstance().d(player.getName() + " hunger " + player.getFoodLevel() + " -> " + event.getFoodLevel()); - + + DebugModule.getInstance().d(player.getName() + " hunger " + player.getFoodLevel() + " -> " + event.getFoodLevel()); + if (event.getFoodLevel() < player.getFoodLevel() && Recharge.Instance.use((Player) event.getEntity(), "Hunger", HUNGER_RECHARGE, false, false)) { event.setCancelled(true); From 15395d13917a4d204d45b23bb3dc2852c0cc61ef Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 18 Feb 2017 10:37:26 +0000 Subject: [PATCH 048/101] Fix item giving and animations going to the wrong player --- .../src/mineplex/gemhunters/spawn/SpawnModule.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index e910bcfdf..6bfc84d53 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -62,6 +62,8 @@ public class SpawnModule extends MiniPlugin Player player = event.getPlayer(); player.teleport(_spawn); + player.setFoodLevel(20); + player.setExhaustion(0); if (_npcsSpawned) { @@ -90,7 +92,7 @@ public class SpawnModule extends MiniPlugin return; } - PlayerTeleportIntoMapEvent teleportEvent = new PlayerTeleportIntoMapEvent(player, toTeleport); + PlayerTeleportIntoMapEvent teleportEvent = new PlayerTeleportIntoMapEvent(clicker, toTeleport); UtilServer.CallEvent(teleportEvent); @@ -112,7 +114,7 @@ public class SpawnModule extends MiniPlugin @Override public void run() { - if (animation.displayAsTitle(player)) + if (animation.displayAsTitle(clicker)) { cancel(); } From 77dfc2a7c7ba5c98978d1750c28269d26ed30615 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 18 Feb 2017 10:37:40 +0000 Subject: [PATCH 049/101] No need for UtilServer --- .../src/mineplex/gemhunters/scoreboard/ScoreboardModule.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java index 54e93ddf3..42efc4a01 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/ScoreboardModule.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; @@ -18,7 +19,6 @@ import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.economy.EconomyModule; @@ -94,7 +94,7 @@ public class ScoreboardModule extends MiniPlugin return; } - for (Player player : UtilServer.getPlayers()) + for (Player player : Bukkit.getOnlinePlayers()) { int gems = _economy.getGems(player); From 4fc991dd242521da271a824b15d4a5788dc99790 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 20 Feb 2017 21:02:49 +0000 Subject: [PATCH 050/101] Add sewer mobs --- .../mineplex/gemhunters/world/SewerMobs.java | 111 ------------------ .../gemhunters/world/UndergroundMobs.java | 89 ++++++++++++++ 2 files changed, 89 insertions(+), 111 deletions(-) delete mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/UndergroundMobs.java diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java deleted file mode 100644 index b10278c4b..000000000 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/SewerMobs.java +++ /dev/null @@ -1,111 +0,0 @@ -package mineplex.gemhunters.world; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.plugin.java.JavaPlugin; - -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilMath; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.gemhunters.spawn.SpawnModule; - -public class SewerMobs implements Listener -{ - - private static final int MAX_MOBS = 100; - - private final Set _entities; - - public SewerMobs(JavaPlugin plugin) - { - plugin.getServer().getPluginManager().registerEvents(this, plugin); - - _entities = new HashSet<>(); - } - - @EventHandler - public void update(UpdateEvent event) - { - if (event.getType() != UpdateType.SLOWEST) - { - return; - } - - World world = Bukkit.getWorlds().get(0); - Iterator iterator= _entities.iterator(); - - while (iterator.hasNext()) - { - Entity entity = iterator.next(); - - if (entity.isDead() || !entity.isValid()) - { - iterator.remove(); - } - } - - for (int i = 0; i < MAX_MOBS / 4; i++) - { - if (_entities.size() >= MAX_MOBS) - { - break; - } - - EntityType type = UtilMath.random.nextBoolean() ? EntityType.ZOMBIE : EntityType.SKELETON; - Location location = getRandomLocation(world); - - if (location == null) - { - continue; - } - - _entities.add(world.spawnEntity(location, type)); - } - } - - public Location getRandomLocation(World world) - { - int attempts = 0; - - while (attempts < 40) - { - Location location = new Location(world, UtilMath.r(SpawnModule.WORLD_BORDER_RADIUS * 2) - SpawnModule.WORLD_BORDER_RADIUS, 51, UtilMath.r(SpawnModule.WORLD_BORDER_RADIUS * 2) - SpawnModule.WORLD_BORDER_RADIUS); - - if (!isSuitable(location.getBlock())) - { - continue; - } - - attempts++; - } - - return null; - } - - public boolean isSuitable(Block block) - { - Block up = block.getRelative(BlockFace.UP); - Block down = block.getRelative(BlockFace.DOWN); - - if (block.getType() != Material.AIR || up.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block)) - { - return false; - } - - return true; - } - -} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/UndergroundMobs.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/UndergroundMobs.java new file mode 100644 index 000000000..334e5cb1f --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/UndergroundMobs.java @@ -0,0 +1,89 @@ +package mineplex.gemhunters.world; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Skeleton; +import org.bukkit.entity.Spider; +import org.bukkit.entity.Zombie; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.Managers; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilMath; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class UndergroundMobs implements Listener +{ + + private static final int MAX_MOBS = 100; + private static final String SEWER_KEY = "SEWER_MOB"; + private static final String SUBWAY_KEY = "SUBWAY_MOBS"; + + private final WorldDataModule _worldData; + + private final World _world; + private final Set _entities; + + public UndergroundMobs(JavaPlugin plugin) + { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + + _worldData = Managers.require(WorldDataModule.class); + + _world = Bukkit.getWorlds().get(0); + _entities = new HashSet<>(); + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC_20) + { + return; + } + + Iterator iterator = _entities.iterator(); + + while (iterator.hasNext()) + { + Entity entity = iterator.next(); + + if (entity.isDead() || !entity.isValid()) + { + entity.remove(); + iterator.remove(); + } + } + + for (int i = 0; i < 10; i++) + { + if (_entities.size() >= MAX_MOBS) + { + break; + } + + { + Location location = UtilAlg.Random(_worldData.getCustomLocation(SEWER_KEY)); + Class clazz = UtilMath.random.nextBoolean() ? Zombie.class : Skeleton.class; + Entity entity = _world.spawn(location, clazz); + _entities.add(entity); + } + { + Location location = UtilAlg.Random(_worldData.getCustomLocation(SUBWAY_KEY)); + Class clazz = Spider.class; + Entity entity = _world.spawn(location, clazz); + _entities.add(entity); + } + } + } + +} From 1b2c384afe16cb1a079e052b769937c147c1b1f5 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 21 Feb 2017 09:56:08 +0000 Subject: [PATCH 051/101] Mounts base --- .../mineplex/core/gadget/GadgetManager.java | 8 ++ .../gamemodifiers/GameModifierType.java | 6 +- .../gemhunters/GameModifierMount.java | 23 ++++ .../gamemodifiers/gemhunters/MountType.java | 53 ++++++++ .../src/mineplex/gemhunters/GemHunters.java | 18 ++- .../gemhunters/economy/CashOutModule.java | 6 +- .../mineplex/gemhunters/mount/MountData.java | 37 ++++++ .../gemhunters/mount/MountModule.java | 119 ++++++++++++++++++ .../mount/event/MountSpawnEvent.java | 6 + .../gemhunters/quest/QuestPlayerData.java | 1 - 10 files changed, 267 insertions(+), 10 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/gemhunters/GameModifierMount.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/gemhunters/MountType.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/MountData.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/MountModule.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/event/MountSpawnEvent.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java index b326e71e5..6b971d8e1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java @@ -86,6 +86,8 @@ import mineplex.core.gadget.gadgets.doublejump.titan.DoubleJumpTitan; import mineplex.core.gadget.gadgets.doublejump.vampire.DoubleJumpBlood; import mineplex.core.gadget.gadgets.doublejump.wisdom.DoubleJumpEnchant; import mineplex.core.gadget.gadgets.gamemodifiers.GameModifierType; +import mineplex.core.gadget.gadgets.gamemodifiers.gemhunters.GameModifierMount; +import mineplex.core.gadget.gadgets.gamemodifiers.gemhunters.MountType; import mineplex.core.gadget.gadgets.gamemodifiers.kits.KitGameModifier; import mineplex.core.gadget.gadgets.gamemodifiers.kits.KitModifier; import mineplex.core.gadget.gadgets.gamemodifiers.kits.KitModifierType; @@ -558,6 +560,12 @@ public class GadgetManager extends MiniPlugin addGadget(new EternalTaunt(this)); addGadget(new BlowAKissTaunt(this)); + // Gem Hunters Mounts + for (MountType mount : MountType.values()) + { + addGadget(new GameModifierMount(this, mount)); + } + for (GadgetType gadgetType : GadgetType.values()) { if (!_gadgets.containsKey(gadgetType)) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/GameModifierType.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/GameModifierType.java index 569a71dcf..018092c15 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/GameModifierType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/GameModifierType.java @@ -19,7 +19,11 @@ public enum GameModifierType MineStrike("MineStrike", new String[]{"Apply custom gun models and skin to use ingame"}, Material.TNT, 0), SurvivalGames("Survival Games", new String[]{"Placeholder"}, Material.DIAMOND_SWORD, 0, true), - Bridges("Bridges", new String[]{"Placeholder"}, Material.IRON_PICKAXE, 0, true); + Bridges("Bridges", new String[]{"Placeholder"}, Material.IRON_PICKAXE, 0, true), + + GemHunters("Gem Hunters", new String[] { "" }, Material.EMERALD, 0) + + ; private String _name; private List _desc; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/gemhunters/GameModifierMount.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/gemhunters/GameModifierMount.java new file mode 100644 index 000000000..eb23fea91 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/gemhunters/GameModifierMount.java @@ -0,0 +1,23 @@ +package mineplex.core.gadget.gadgets.gamemodifiers.gemhunters; + +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.gadgets.gamemodifiers.GameModifierType; +import mineplex.core.gadget.types.GameModifierGadget; + +public class GameModifierMount extends GameModifierGadget +{ + + private final MountType _mountType; + + public GameModifierMount(GadgetManager manager, MountType mountType) + { + super(manager, GameModifierType.GemHunters, mountType.getName() + " Mount", mountType.getDescription(), -2, mountType.getMaterial(), mountType.getData(), false); + + _mountType = mountType; + } + + public final MountType getMountType() + { + return _mountType; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/gemhunters/MountType.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/gemhunters/MountType.java new file mode 100644 index 000000000..c1af6c427 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/gamemodifiers/gemhunters/MountType.java @@ -0,0 +1,53 @@ +package mineplex.core.gadget.gadgets.gamemodifiers.gemhunters; + +import org.bukkit.Material; +import org.bukkit.entity.EntityType; + +public enum MountType +{ + + SKELETON(EntityType.HORSE, Material.BONE, (byte) 0, "Skeleton Horse", "Spooky") + + ; + + private final EntityType _entityType; + private final Material _material; + private final byte _data; + private final String _name; + private final String[] _description; + + private MountType(EntityType entityType, Material material, byte data, String name, String... description) + { + _entityType = entityType; + _material = material; + _data = data; + _name = name; + _description = description; + } + + public final EntityType getEntityType() + { + return _entityType; + } + + public final Material getMaterial() + { + return _material; + } + + public byte getData() + { + return _data; + } + + public final String getName() + { + return _name; + } + + public final String[] getDescription() + { + return _description; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index c397b959a..42ab331c2 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -27,20 +27,25 @@ import mineplex.core.donation.DonationManager; import mineplex.core.elo.EloManager; import mineplex.core.explosion.Explosion; import mineplex.core.friend.FriendManager; +import mineplex.core.gadget.GadgetManager; import mineplex.core.give.Give; import mineplex.core.hologram.HologramManager; import mineplex.core.ignore.IgnoreManager; import mineplex.core.incognito.IncognitoManager; +import mineplex.core.inventory.InventoryManager; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.memory.MemoryFix; import mineplex.core.menu.MenuManager; import mineplex.core.message.MessageManager; import mineplex.core.monitor.LagMeter; +import mineplex.core.mount.MountManager; import mineplex.core.npc.NpcManager; import mineplex.core.packethandler.PacketHandler; import mineplex.core.party.PartyManager; +import mineplex.core.pet.PetManager; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; +import mineplex.core.projectile.ProjectileManager; import mineplex.core.punish.Punish; import mineplex.core.recharge.Recharge; import mineplex.core.serverConfig.ServerConfiguration; @@ -59,14 +64,15 @@ import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.loot.InventoryModule; import mineplex.gemhunters.loot.LootModule; import mineplex.gemhunters.map.ItemMapModule; +import mineplex.gemhunters.mount.MountModule; import mineplex.gemhunters.quest.QuestModule; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.scoreboard.ScoreboardModule; import mineplex.gemhunters.shop.ShopModule; import mineplex.gemhunters.spawn.SpawnModule; import mineplex.gemhunters.supplydrop.SupplyDropModule; -import mineplex.gemhunters.world.SewerMobs; import mineplex.gemhunters.world.TimeCycle; +import mineplex.gemhunters.world.UndergroundMobs; import mineplex.gemhunters.world.WorldListeners; import mineplex.gemhunters.worldevent.WorldEventModule; import mineplex.minecraft.game.core.combat.CombatManager; @@ -200,7 +206,7 @@ public class GemHunters extends JavaPlugin explosion.SetTemporaryDebris(false); // Inventories - // new InventoryManager(this, clientManager); + InventoryManager inventoryManager = new InventoryManager(this, clientManager); // Reports // SnapshotManager snapshotManager = new SnapshotManager(this, new @@ -215,11 +221,14 @@ public class GemHunters extends JavaPlugin new CustomTagFix(this, packetHandler); // Holograms - new HologramManager(this, packetHandler); + HologramManager hologramManager = new HologramManager(this, packetHandler); // Menus new MenuManager(this); + // Gadgets, used for mounts, lots of managers for something really small :( + new GadgetManager(this, clientManager, donationManager, inventoryManager, new MountManager(this, clientManager, donationManager, blockRestore, disguiseManager), new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore), preferenceManager, disguiseManager, blockRestore, new ProjectileManager(this), achievementManager, packetHandler, hologramManager, incognito); + // Now we finally get to enable the Gem Hunters modules // Though if any other module needs one of these it will be generated in // order, however they are all here just for good measure. @@ -232,6 +241,7 @@ public class GemHunters extends JavaPlugin require(InventoryModule.class); require(LootModule.class); require(ItemMapModule.class); + require(MountModule.class); require(QuestModule.class); require(SafezoneModule.class); require(ScoreboardModule.class); @@ -244,7 +254,7 @@ public class GemHunters extends JavaPlugin // interact events etc... new WorldListeners(this); new TimeCycle(this); - new SewerMobs(this); + new UndergroundMobs(this); // UpdateEvent!!! new Updater(this); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java index fa731b801..04a892877 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -107,16 +107,14 @@ public class CashOutModule extends MiniPlugin @EventHandler public void inventoryClick(InventoryClickEvent event) { - Player player = (Player) event.getWhoClicked(); - Inventory inv = event.getClickedInventory(); ItemStack itemStack = event.getCurrentItem(); - if (inv == null || itemStack == null) + if (itemStack == null) { return; } - if (inv.equals(player.getInventory())) + if (!itemStack.isSimilar(CASH_OUT_ITEM)) { return; } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/MountData.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/MountData.java new file mode 100644 index 000000000..e8aaa9cc0 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/MountData.java @@ -0,0 +1,37 @@ +package mineplex.gemhunters.mount; + +import org.bukkit.entity.LivingEntity; + +import mineplex.core.gadget.gadgets.gamemodifiers.gemhunters.MountType; + +public class MountData +{ + + private MountType _mountType; + private LivingEntity _entity; + + public MountData() + { + + } + + public void setMountType(MountType mountType) + { + _mountType = mountType; + } + + public MountType getMountType() + { + return _mountType; + } + + public void setEntity(LivingEntity entity) + { + _entity = entity; + } + + public LivingEntity getEntity() + { + return _entity; + } +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/MountModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/MountModule.java new file mode 100644 index 000000000..56cb32950 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/MountModule.java @@ -0,0 +1,119 @@ +package mineplex.gemhunters.mount; + +import java.util.UUID; + +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.MiniClientPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.gadgets.gamemodifiers.GameModifierType; +import mineplex.core.gadget.gadgets.gamemodifiers.gemhunters.GameModifierMount; +import mineplex.core.gadget.gadgets.gamemodifiers.gemhunters.MountType; +import mineplex.core.recharge.Recharge; +import mineplex.gemhunters.loot.LootItem; +import mineplex.gemhunters.loot.LootModule; + +@ReflectivelyCreateMiniPlugin +public class MountModule extends MiniClientPlugin +{ + + private static final String ITEM_METADATA = "UNLOCKER"; + + private final LootModule _loot; + private final GadgetManager _gadget; + + private MountModule() + { + super("Mount"); + + _loot = require(LootModule.class); + _gadget = require(GadgetManager.class); + } + + @Override + protected MountData addPlayer(UUID uuid) + { + return new MountData(); + } + + @EventHandler + public void playerInteract(PlayerInteractEvent event) + { + if (event.isCancelled()) + { + return; + } + + if (!UtilEvent.isAction(event, ActionType.R)) + { + return; + } + + Player player = event.getPlayer(); + ItemStack itemStack = player.getItemInHand(); + + if (itemStack == null) + { + return; + } + + LootItem lootItem = _loot.fromItemStack(itemStack); + + if (lootItem == null || lootItem.getMetadata() == null || !lootItem.getMetadata().startsWith(ITEM_METADATA)) + { + return; + } + + int cooldown = Integer.parseInt(lootItem.getMetadata().split(" ")[1]); + + if (!Recharge.Instance.use(player, _moduleName, cooldown, true, true)) + { + return; + } + + spawnMount(player); + } + + public void spawnMount(Player player) + { + spawnMount(player, ((GameModifierMount) _gadget.getActiveGameModifier(player, GameModifierType.GemHunters, g -> g != null)).getMountType()); + } + + public void spawnMount(Player player, MountType mountType) + { + MountData data = Get(player); + LivingEntity entity = data.getEntity(); + EntityType entityType = mountType.getEntityType(); + + despawnMount(player); + + entity = (LivingEntity) player.getWorld().spawnEntity(player.getLocation().add(0, 1, 0), entityType == null ? EntityType.HORSE : entityType); + + data.setEntity(entity); + data.setMountType(mountType); + } + + public void despawnMount(Player player) + { + MountData data = Get(player); + LivingEntity entity = data.getEntity(); + + if (entity != null) + { + entity.remove(); + } + } + + public boolean isActive(Player player) + { + return Get(player).getEntity() != null; + } +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/event/MountSpawnEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/event/MountSpawnEvent.java new file mode 100644 index 000000000..0414b020f --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/event/MountSpawnEvent.java @@ -0,0 +1,6 @@ +package mineplex.gemhunters.mount.event; + +public class MountSpawnEvent +{ + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestPlayerData.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestPlayerData.java index dbfce2d62..bf8af3e38 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestPlayerData.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestPlayerData.java @@ -24,7 +24,6 @@ public class QuestPlayerData public void clear() { _possibleQuests.clear(); - _activeQuests.clear(); _completedQuests.clear(); _lastClear = System.currentTimeMillis(); From 75f734c5e7e61ab8fffdb8a36c4868777be51ffd Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 21 Feb 2017 10:08:48 +0000 Subject: [PATCH 052/101] Fix where after many hours chests would stop spawning --- .../src/mineplex/gemhunters/loot/LootModule.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 519b52154..0dea6917e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -255,12 +255,6 @@ public class LootModule extends MiniPlugin } Map spawnedIndexes = properties.getSpawnIndexes(); - - if (locations.size() == spawnedIndexes.size()) - { - return; - } - Location randomLocation = null; boolean found = false; int attempts = 0; From bde899212fbf5d03980b96b390baa8ec0aea6a1d Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 21 Feb 2017 12:36:48 +0000 Subject: [PATCH 053/101] Allow other players to pickup quests --- .../gemhunters/quest/{types => }/Quest.java | 28 ++- .../gemhunters/quest/QuestModule.java | 175 ++++++++++++++++-- .../mineplex/gemhunters/quest/QuestUI.java | 1 - .../quest/types/ChestOpenerQuest.java | 1 + .../gemhunters/quest/types/SamitoDQuest.java | 1 + 5 files changed, 185 insertions(+), 21 deletions(-) rename Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/{types => }/Quest.java (87%) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/Quest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/Quest.java similarity index 87% rename from Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/Quest.java rename to Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/Quest.java index 96d50c705..91d6875d5 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/Quest.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/Quest.java @@ -1,4 +1,4 @@ -package mineplex.gemhunters.quest.types; +package mineplex.gemhunters.quest; import java.util.HashMap; import java.util.Map; @@ -15,7 +15,6 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilServer; import mineplex.core.donation.DonationManager; import mineplex.gemhunters.economy.EconomyModule; -import mineplex.gemhunters.quest.QuestModule; import mineplex.gemhunters.world.WorldDataModule; public abstract class Quest implements Listener @@ -48,7 +47,7 @@ public abstract class Quest implements Listener _donation = Managers.require(DonationManager.class); _economy = Managers.require(EconomyModule.class); _worldData = Managers.require(WorldDataModule.class); - + _counter = new HashMap<>(); UtilServer.getServer().getPluginManager().registerEvents(this, UtilServer.getPlugin()); @@ -60,6 +59,23 @@ public abstract class Quest implements Listener remove(event.getPlayer()); } + public void transfer(Player from, Player to) + { + // If the player has already been progressing this quest and is + // further than the other don't bother transferring their data. + if (get(to) >= get(from)) + { + return; + } + + set(to, get(from)); + } + + public void set(Player player, int amount) + { + _counter.put(player.getUniqueId(), amount); + } + public int get(Player player) { return _counter.getOrDefault(player.getUniqueId(), 0); @@ -70,7 +86,7 @@ public abstract class Quest implements Listener int newAmount = get(player) + amount; _counter.put(player.getUniqueId(), newAmount); _quest.updateQuestItem(this, player); - + return newAmount; } @@ -95,7 +111,7 @@ public abstract class Quest implements Listener { return _quest.isActive(this, player); } - + public abstract float getProgress(Player player); public int getGoal() @@ -107,7 +123,7 @@ public abstract class Quest implements Listener { return _id; } - + public final String getName() { return _name; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java index 0ad0ac6f9..3e0fbbf56 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java @@ -7,10 +7,15 @@ import java.util.concurrent.TimeUnit; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.metadata.FixedMetadataValue; import mineplex.core.MiniClientPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; @@ -19,16 +24,18 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilItem.ItemAttribute; import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.menu.Menu; +import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.quest.types.ChestOpenerQuest; -import mineplex.gemhunters.quest.types.Quest; import mineplex.gemhunters.quest.types.SamitoDQuest; import mineplex.gemhunters.world.WorldDataModule; +import net.md_5.bungee.api.ChatColor; @ReflectivelyCreateMiniPlugin public class QuestModule extends MiniClientPlugin @@ -36,17 +43,19 @@ public class QuestModule extends MiniClientPlugin private static final int MAX_QUESTS = 5; private static final long RESET_QUESTS_TIME = TimeUnit.MINUTES.toMillis(15); - - private final Quest[] _quests = { - new ChestOpenerQuest(0, "Chest Opener", 100, 250, 5), + private static final Material MATERIAL = Material.PAPER; + private static final String ITEM_METADATA = "quest"; + + private final Quest[] _quests = { + new ChestOpenerQuest(0, "Chest Opener", 100, 250, 5), new ChestOpenerQuest(1, "Grand Chest Opener", 200, 500, 20), new ChestOpenerQuest(2, "Superior Chest Opener", 500, 750, 40), - - new SamitoDQuest(3, "Give to the Homeless", "Donate " + F.count(String.valueOf(10)) + " gems to the Hobo.", 100, 300, 10) + + new SamitoDQuest(3, "Give to the Homeless", "Donate " + F.count(String.valueOf(10)) + " gems to the Hobo.", 100, 300, 10) }; private final WorldDataModule _worldData; - + private QuestModule() { super("Quest"); @@ -55,7 +64,8 @@ public class QuestModule extends MiniClientPlugin Menu menu = new QuestUI(this); - runSyncLater(() -> { + runSyncLater(() -> + { for (Location location : _worldData.getCustomLocation("QUEST_NPC")) { @@ -101,8 +111,97 @@ public class QuestModule extends MiniClientPlugin } } + @EventHandler + public void pickupItem(PlayerPickupItemEvent event) + { + if (event.isCancelled()) + { + return; + } + + Item item = event.getItem(); + Player player = event.getPlayer(); + Quest quest = fromItemStack(event.getItem().getItemStack()); + + if (quest == null) + { + return; + } + + if (!item.hasMetadata(ITEM_METADATA)) + { + return; + } + + if (!Recharge.Instance.use(event.getPlayer(), "Quest Pickup " + quest.getId(), 2000, false, false)) + { + event.setCancelled(true); + return; + } + + boolean able = startQuest(quest, player); + + if (!able) + { + event.setCancelled(true); + } + else + { + UUID owner = UUID.fromString(item.getMetadata(ITEM_METADATA).get(0).asString()); + Player other = UtilPlayer.searchExact(owner); + + /* + * Noting here that when a player leaves their quest progress is removed. + * However that means that if a new player picks up their quest item we + * run into a problem where that will be null. Thus the progress on that + * quest is lost. + * More complications are added when a player quits out and their NPC is + * there instead until they finally really really quit out. + * This is one massive headache in order to keep quests alive while not + * running into some serious memory leaks. + * Furthermore the time complications of this project mean that there isn't + * enough time right now to implement this (however a enough time for me + * to type this lengthy comment about it). So in true style I'm cutting + * corners and saying that if a player quits out then don't allow other + * players to be able to pickup the quest. + */ + if (other == null) + { + event.setCancelled(true); + return; + } + + + } + } + + @EventHandler + public void dropItem(PlayerDropItemEvent event) + { + if (event.isCancelled()) + { + return; + } + + Player player = event.getPlayer(); + Quest quest = fromItemStack(event.getItemDrop().getItemStack()); + + if (quest == null) + { + return; + } + + cancelQuest(quest, player); + handleDroppedQuest(event.getItemDrop(), player); + } + + public void handleDroppedQuest(Item item, Player player) + { + item.setMetadata(ITEM_METADATA, new FixedMetadataValue(_plugin, player.getUniqueId().toString())); + } + public void updateQuests(Player player) - { + { QuestPlayerData playerData = Get(player); List quests = playerData.getPossibleQuests(); @@ -120,17 +219,17 @@ public class QuestModule extends MiniClientPlugin } } - public void startQuest(Quest quest, Player player) + public boolean startQuest(Quest quest, Player player) { if (isActive(quest, player)) { player.sendMessage(F.main(_moduleName, "You have already accepted that quest.")); - return; + return false; } else if (isComplete(quest, player)) { player.sendMessage(F.main(_moduleName, "You have already completed that quest.")); - return; + return false; } player.sendMessage(F.main(_moduleName, "Started " + F.name(quest.getName()) + ".")); @@ -139,6 +238,8 @@ public class QuestModule extends MiniClientPlugin playerData.getActiveQuests().add(quest.getId()); updateQuestItem(quest, player); + + return true; } public void completeQuest(Quest quest, Player player) @@ -149,6 +250,8 @@ public class QuestModule extends MiniClientPlugin return; } + player.sendMessage(F.main(_moduleName, "Completed " + F.name(quest.getName()) + ".")); + QuestPlayerData playerData = Get(player); playerData.getActiveQuests().remove(Integer.valueOf(quest.getId())); playerData.getCompletedQuests().add(quest.getId()); @@ -156,6 +259,20 @@ public class QuestModule extends MiniClientPlugin updateQuestItem(quest, player); } + public void cancelQuest(Quest quest, Player player) + { + if (!isActive(quest, player)) + { + player.sendMessage(F.main(_moduleName, "This quest is not active for you.")); + return; + } + + player.sendMessage(F.main(_moduleName, "Dropped " + F.name(quest.getName()) + ".")); + + QuestPlayerData playerData = Get(player); + playerData.getActiveQuests().remove(Integer.valueOf(quest.getId())); + } + public Quest getRandomQuest(QuestPlayerData playerData, Player player) { int attempts = 0; @@ -167,7 +284,7 @@ public class QuestModule extends MiniClientPlugin int index = UtilMath.r(_quests.length); Quest quest = _quests[index]; - if (isActive(quest, player) || playerData.getPossibleQuests().contains(quest.getId())) + if (isActive(quest, player) || isPossible(quest, player)) { continue; } @@ -180,7 +297,7 @@ public class QuestModule extends MiniClientPlugin public ItemStack getItemStack(Quest quest, Player player, boolean npc, boolean hasSpace) { - ItemBuilder builder = new ItemBuilder(Material.PAPER); + ItemBuilder builder = new ItemBuilder(MATERIAL); builder.setTitle(C.cGreen + quest.getName()); builder.addLore(C.blankLine, quest.getDescription(), C.blankLine); @@ -216,6 +333,31 @@ public class QuestModule extends MiniClientPlugin return builder.build(); } + public Quest fromItemStack(ItemStack itemStack) + { + Material material = itemStack.getType(); + ItemMeta meta = itemStack.getItemMeta(); + + if (material != MATERIAL || meta == null || !meta.hasLore()) + { + return null; + } + + String name = ChatColor.stripColor(meta.getDisplayName()); + + for (Quest quest : _quests) + { + if (!quest.getName().equals(name)) + { + continue; + } + + return quest; + } + + return null; + } + public void updateQuestItem(Quest quest, Player player) { ItemStack itemStack = getItemStack(quest, player, false, true); @@ -234,6 +376,11 @@ public class QuestModule extends MiniClientPlugin } } + public boolean isPossible(Quest quest, Player player) + { + return Get(player).getPossibleQuests().contains(quest.getId()); + } + public boolean isActive(Quest quest, Player player) { return Get(player).getActiveQuests().contains(quest.getId()); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestUI.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestUI.java index 1fac094f5..59face7bb 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestUI.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestUI.java @@ -8,7 +8,6 @@ import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilUI; import mineplex.core.menu.Button; import mineplex.core.menu.Menu; -import mineplex.gemhunters.quest.types.Quest; public class QuestUI extends Menu { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java index 3ab14a3b1..7af52015d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java @@ -6,6 +6,7 @@ import org.bukkit.event.EventHandler; import mineplex.core.common.util.F; import mineplex.gemhunters.debug.DebugModule; import mineplex.gemhunters.loot.event.PlayerChestOpenEvent; +import mineplex.gemhunters.quest.Quest; public class ChestOpenerQuest extends Quest { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java index 30af73b08..a44a6fabf 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/SamitoDQuest.java @@ -12,6 +12,7 @@ import org.bukkit.event.player.PlayerInteractEvent; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilFirework; import mineplex.core.common.util.UtilMath; +import mineplex.gemhunters.quest.Quest; public class SamitoDQuest extends Quest { From 3d4e64a2082f1259604a61f2f30d027b908ae4b1 Mon Sep 17 00:00:00 2001 From: cnr Date: Wed, 22 Feb 2017 17:41:23 -0600 Subject: [PATCH 054/101] Add Mineplexer support for beta lobbies --- .../bungee/lobbyBalancer/LobbyBalancer.java | 129 +++++++++-------- .../bungee/lobbyBalancer/LobbyType.java | 34 +++++ .../src/mineplex/bungee/motd/MotdManager.java | 130 +++++------------- 3 files changed, 133 insertions(+), 160 deletions(-) create mode 100644 Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyType.java diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java index de8602e07..fca669fba 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java @@ -2,33 +2,34 @@ package mineplex.bungee.lobbyBalancer; import java.io.File; import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.EnumMap; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; -import mineplex.serverdata.Region; -import mineplex.serverdata.data.MinecraftServer; -import mineplex.serverdata.servers.ServerManager; -import mineplex.serverdata.servers.ServerRepository; import net.md_5.bungee.api.event.ServerConnectEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.event.EventHandler; -import com.google.common.collect.Lists; +import mineplex.serverdata.Region; +import mineplex.serverdata.data.MinecraftServer; +import mineplex.serverdata.servers.ServerManager; +import mineplex.serverdata.servers.ServerRepository; public class LobbyBalancer implements Listener, Runnable { private Plugin _plugin; private ServerRepository _repository; - - private List _sortedLobbies = Lists.newArrayList(); - private List _sortedClans = Lists.newArrayList(); - private static Object _serverLock = new Object(); - - private int _lobbyIndex = 0; - private int _clansIndex = 0; + + private final Map> _sortedLobbyMap = new EnumMap<>(LobbyType.class); + private final Map _nextIndexMap = new EnumMap<>(LobbyType.class); + private static final LobbySorter LOBBY_SORTER = new LobbySorter(); + private static final Object _serverLock = new Object(); public LobbyBalancer(Plugin plugin) { @@ -46,45 +47,42 @@ public class LobbyBalancer implements Listener, Runnable @EventHandler public void playerConnect(ServerConnectEvent event) { - if (event.getTarget().getName().equalsIgnoreCase("Lobby")) - { - synchronized (_serverLock) - { - if (_lobbyIndex >= _sortedLobbies.size() || _sortedLobbies.get(_lobbyIndex).getPlayerCount() >= _sortedLobbies.get(_lobbyIndex).getMaxPlayerCount()) - _lobbyIndex = 0; + Arrays.stream(LobbyType.values()) + .filter(type -> type.getConnectName().equalsIgnoreCase(event.getTarget().getName())) + .findFirst() + .ifPresent(lobbyType -> + { + synchronized (_serverLock) + { + List lobbies = _sortedLobbyMap.get(lobbyType); - event.setTarget(_plugin.getProxy().getServerInfo(_sortedLobbies.get(_lobbyIndex).getName())); - _sortedLobbies.get(_lobbyIndex).incrementPlayerCount(1); - System.out.println("Sending " + event.getPlayer().getName() + " to " + _sortedLobbies.get(_lobbyIndex).getName() + "(" + _sortedLobbies.get(_lobbyIndex).getPublicAddress() + ")"); - _lobbyIndex++; - } - } - if (event.getTarget().getName().equalsIgnoreCase("ClansHub")) - { - synchronized (_serverLock) - { - if (_clansIndex >= _sortedClans.size() || _sortedClans.get(_clansIndex).getPlayerCount() >= _sortedClans.get(_clansIndex).getMaxPlayerCount()) - _clansIndex = 0; + int nextIndex = _nextIndexMap.getOrDefault(lobbyType, 0); + if (nextIndex >= lobbies.size()) + { + nextIndex = 0; + } - event.setTarget(_plugin.getProxy().getServerInfo(_sortedClans.get(_clansIndex).getName())); - _sortedClans.get(_clansIndex).incrementPlayerCount(1); - System.out.println("Sending " + event.getPlayer().getName() + " to " + _sortedClans.get(_clansIndex).getName() + "(" + _sortedClans.get(_clansIndex).getPublicAddress() + ")"); - _clansIndex++; - } - } + MinecraftServer server = lobbies.get(nextIndex); + + event.setTarget(_plugin.getProxy().getServerInfo(server.getName())); + server.incrementPlayerCount(1); + System.out.println("Sending " + event.getPlayer().getName() + " to " + server.getName() + "(" + server.getPublicAddress() + ")"); + + _nextIndexMap.put(lobbyType, ++nextIndex); + } + }); } public void run() { loadServers(); - - if (!_plugin.getProxy().getServers().containsKey("ClansHub")) + + for (LobbyType type : LobbyType.values()) { - _plugin.getProxy().getServers().put("ClansHub", _plugin.getProxy().constructServerInfo("ClansHub", new InetSocketAddress("lobby.mineplex.com", 25565), "LobbyBalancer", false)); - } - if (!_plugin.getProxy().getServers().containsKey("Lobby")) - { - _plugin.getProxy().getServers().put("Lobby", _plugin.getProxy().constructServerInfo("Lobby", new InetSocketAddress("lobby.mineplex.com", 25565), "LobbyBalancer", false)); + if (!_plugin.getProxy().getServers().containsKey(type.getConnectName())) + { + _plugin.getProxy().getServers().put(type.getConnectName(), _plugin.getProxy().constructServerInfo(type.getConnectName(), new InetSocketAddress("lobby.mineplex.com", 25565), "LobbyBalancer", false)); + } } } @@ -95,9 +93,12 @@ public class LobbyBalancer implements Listener, Runnable synchronized (_serverLock) { long startTime = System.currentTimeMillis(); - _sortedLobbies.clear(); - _sortedClans.clear(); - + _sortedLobbyMap.clear(); + for (LobbyType type : LobbyType.values()) + { + _sortedLobbyMap.put(type, new ArrayList<>()); + } + for (MinecraftServer server : servers) { if (server.getName() == null) @@ -105,32 +106,26 @@ public class LobbyBalancer implements Listener, Runnable InetSocketAddress socketAddress = new InetSocketAddress(server.getPublicAddress(), server.getPort()); _plugin.getProxy().getServers().put(server.getName(), _plugin.getProxy().constructServerInfo(server.getName(), socketAddress, "LobbyBalancer", false)); - - if (server.getName().toUpperCase().startsWith("LOBBY-")) - { - if (server.getMotd() == null || !server.getMotd().contains("Restarting")) - { - _sortedLobbies.add(server); - } - } - if (server.getName().toUpperCase().startsWith("CLANSHUB-")) - { - if (server.getMotd() == null || !server.getMotd().contains("Restarting")) - { - _sortedClans.add(server); - } - } + + if (server.getMotd() != null && server.getMotd().contains("Restarting")) + { + continue; + } + + Arrays.stream(LobbyType.values()) + .filter(type -> server.getName().toUpperCase().startsWith(type.getUppercasePrefix())) + .findFirst() + .ifPresent(type -> _sortedLobbyMap.get(type).add(server)); } - - Collections.sort(_sortedLobbies, new LobbySorter()); - Collections.sort(_sortedClans, new LobbySorter()); - + + _sortedLobbyMap.values().forEach(lobbies -> Collections.sort(lobbies, LOBBY_SORTER)); + long timeSpentInLock = System.currentTimeMillis() - startTime; if (timeSpentInLock > 50) System.out.println("[==] TIMING [==] Locked loading servers for " + timeSpentInLock + "ms"); - - _lobbyIndex = 0; + + _nextIndexMap.clear(); } } } diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyType.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyType.java new file mode 100644 index 000000000..8b4e4fb5d --- /dev/null +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyType.java @@ -0,0 +1,34 @@ +package mineplex.bungee.lobbyBalancer; + +public enum LobbyType +{ + NORMAL("Lobby", "LOBBY-", "MainMotd"), + CLANS("ClansHub", "CLANSHUB-", "ClansMotd"), + BETA("BetaHub","BETAHUB-", "BetaMotd"), + ; + private final String _connectName; // The name of the server the player is connecting to + private final String _uppercasePrefix; // The (toUpperCase()) prefix given to servers of this lobby type + private final String _redisMotdKey; + + LobbyType(String connectName, String uppercasePrefix, String redisMotdKey) + { + _connectName = connectName; + _uppercasePrefix = uppercasePrefix; + _redisMotdKey = redisMotdKey; + } + + public String getConnectName() + { + return _connectName; + } + + public String getUppercasePrefix() + { + return _uppercasePrefix; + } + + public String getRedisMotdKey() + { + return _redisMotdKey; + } +} diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/motd/MotdManager.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/motd/MotdManager.java index aa2565f27..4b556d2e2 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/motd/MotdManager.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/motd/MotdManager.java @@ -1,138 +1,82 @@ package mineplex.bungee.motd; -import java.io.File; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; +import java.util.EnumMap; +import java.util.Map; +import java.util.Optional; import java.util.Random; import java.util.concurrent.TimeUnit; -import mineplex.serverdata.Region; -import mineplex.serverdata.data.DataRepository; -import mineplex.serverdata.redis.RedisDataRepository; -import mineplex.serverdata.servers.ConnectionData; -import mineplex.serverdata.servers.ConnectionData.ConnectionType; -import mineplex.serverdata.servers.ServerManager; import net.md_5.bungee.api.event.ProxyPingEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.event.EventHandler; +import mineplex.bungee.lobbyBalancer.LobbyType; +import mineplex.serverdata.Region; +import mineplex.serverdata.data.DataRepository; +import mineplex.serverdata.redis.RedisDataRepository; +import mineplex.serverdata.servers.ServerManager; + public class MotdManager implements Listener, Runnable { - private Plugin _plugin; - - private DataRepository _repository; - private DataRepository _secondRepository; - private Region _region; - - private Random _random = new Random(); - private String _firstLine = " §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r"; - private List _motdLines; - private String _firstCLine = " §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r"; - private List _motdCLines; + private static final String DEFAULT_HEADLINE = " §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r"; + + private final DataRepository _repository; + private final Random _random = new Random(); + private final Map motds = new EnumMap<>(LobbyType.class); public MotdManager(Plugin plugin) { - _plugin = plugin; - _region = !new File("eu.dat").exists() ? Region.US : Region.EU; - - _plugin.getProxy().getScheduler().schedule(_plugin, this, 5L, 30L, TimeUnit.SECONDS); - _plugin.getProxy().getPluginManager().registerListener(_plugin, this); + plugin.getProxy().getScheduler().schedule(plugin, this, 5L, 30L, TimeUnit.SECONDS); + plugin.getProxy().getPluginManager().registerListener(plugin, this); _repository = new RedisDataRepository(ServerManager.getConnection(true, ServerManager.SERVER_STATUS_LABEL), ServerManager.getConnection(false, ServerManager.SERVER_STATUS_LABEL), Region.ALL, GlobalMotd.class, "globalMotd"); run(); - - if (new File("updateMOTD.dat").exists()) - { - if (_region == Region.US) - _secondRepository = new RedisDataRepository(new ConnectionData("10.81.1.156", 6379, ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.81.1.156", 6377, ConnectionType.SLAVE, "ServerStatus"), - Region.ALL, GlobalMotd.class, "globalMotd"); - else - _secondRepository = new RedisDataRepository(new ConnectionData("10.33.53.16", 6379, ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.33.53.16", 6377, ConnectionType.SLAVE, "ServerStatus"), - Region.ALL, GlobalMotd.class, "globalMotd"); - - //String motdLine = "§f§l◄ §c§lMaintenance§f§l ►"; - //String motdLine = "§f§l◄ §a§lCarl the Creeper§f§l ►"; -// String motdLine = " §2§l§n M O N S T E R M A Z E B E T A §f"; - String motdLine = " §f> §4§lCLANS BETA §f- §c§lOpen to Everyone §f<"; -// String motdLine = " §f❄ §2§lServer Maintenance §f❄ §2§lBe Back Soon §f❄"; - //String motdLine = " §d§lRank Sale §a§l40% Off"); - //String motdLine = " §f§l◄§c§lMAINTENANCE§f§l►"); - - updateMainMotd(" §f§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§f§m §r", motdLine); - System.out.println("Updated Bungee MOTD"); - } } @EventHandler public void serverPing(ProxyPingEvent event) { + net.md_5.bungee.api.ServerPing serverPing = event.getResponse(); - if (event.getConnection().getListener() != null && event.getConnection().getListener().getDefaultServer().equalsIgnoreCase("ClansHub")) + Optional maybeType = Optional.empty(); + + if (event.getConnection().getListener() != null) { - String motd = _firstCLine; - if (_motdCLines != null && _motdCLines.size() > 0) - { - motd += "\n" + _motdCLines.get(_random.nextInt(_motdCLines.size())); - } - event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), serverPing.getPlayers(), motd, serverPing.getFaviconObject())); + maybeType = Arrays.stream(LobbyType.values()) + .filter(type -> event.getConnection().getListener().getDefaultServer().equalsIgnoreCase(type.getConnectName())) + .findFirst(); } - else + + LobbyType lobbyType = maybeType.orElse(LobbyType.NORMAL); + GlobalMotd globalMotd = motds.get(lobbyType); + + String motd = DEFAULT_HEADLINE; + if (globalMotd != null && globalMotd.getHeadline() != null) { - String motd = _firstLine; - if (_motdLines != null && _motdLines.size() > 0) + motd = globalMotd.getHeadline() == null ? DEFAULT_HEADLINE : globalMotd.getHeadline(); + if (globalMotd.getMotd() != null) { - motd += "\n" + _motdLines.get(_random.nextInt(_motdLines.size())); + motd += "\n" + globalMotd.getMotd().get(_random.nextInt(globalMotd.getMotd().size())); } - event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), serverPing.getPlayers(), motd, serverPing.getFaviconObject())); } + + event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), serverPing.getPlayers(), motd, serverPing.getFaviconObject())); } @Override public void run() { + for (LobbyType type : LobbyType.values()) { - GlobalMotd motd = _repository.getElement("MainMotd"); + GlobalMotd motd = _repository.getElement(type.getRedisMotdKey()); if (motd != null) - { - _motdLines = motd.getMotd(); - _firstLine = motd.getHeadline(); - } - } - { - GlobalMotd motd = _repository.getElement("ClansMotd"); - - if (motd != null) - { - _motdCLines = motd.getMotd(); - _firstCLine = motd.getHeadline(); - } - else { - _repository.addElement(new GlobalMotd("ClansMotd", "§4§lMineplex Clans§r", Arrays.asList("Default MOTD"))); + motds.put(type, motd); } } } - - /** - * Update the main {@link GlobalMotd} determining the MOTD for Bungee instances. - * @param motdLines - the lines to update the MOTD to. - */ - public void updateMainMotd(String headline, String motdLine) - { - List motdLines = new ArrayList(); - - motdLines.add(motdLine); - - _repository.addElement(new GlobalMotd("MainMotd", headline, motdLines)); - _secondRepository.addElement(new GlobalMotd("MainMotd", headline, motdLines)); - } - - public List getMotdLines() - { - return _motdLines; - } } From 5b13a8750055249fc35fcc230a5d52d7dc9f0f87 Mon Sep 17 00:00:00 2001 From: samczsun Date: Fri, 20 Jan 2017 18:04:06 -0500 Subject: [PATCH 055/101] Move api to config file --- .../src/mineplex/core/common/api/ApiHost.java | 81 ++++++++++++++++--- .../api/enderchest/EnderchestWorldLoader.java | 2 +- .../repository/AntiSpamRepository.java | 2 +- .../core/boosters/BoosterRepository.java | 2 +- 4 files changed, 73 insertions(+), 14 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/ApiHost.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/ApiHost.java index a168c3540..a6dd1cbae 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/ApiHost.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/ApiHost.java @@ -1,21 +1,80 @@ package mineplex.core.common.api; -/** - * TODO: Store this in a file instead of being hardcoded - * - * @author Shaun Bennett - */ -public enum ApiHost +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.configuration.file.YamlConfiguration; + +public class ApiHost { - AMPLIFIERS("10.33.53.12", 7979), - ANTISPAM("10.33.53.12", 8181), - ENDERCHEST("10.33.53.10", 8010) - ; + private static final String API_HOST_FILE = "api-config.dat"; + private static final Object LOCK = new Object(); + + private static volatile boolean LOADED = false; + + private static final Map API_HOST_MAP = new HashMap<>(); + + public static ApiHost getAPIHost(String identifier) + { + if (!LOADED) + { + synchronized (LOCK) + { + if (!LOADED) + { + try + { + File configFile = new File(API_HOST_FILE); + YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile); + + for (String key : configuration.getKeys(false)) + { + String ip = configuration.getConfigurationSection(key).getString("ip"); + // Use parseInt to catch non-ints instead of a 0 + int port = Integer.parseInt(configuration.getConfigurationSection(key).getString("port")); + if (ip == null) + { + throw new NullPointerException(); + } + + API_HOST_MAP.put(key, new ApiHost(ip, port)); + } + } + catch (Throwable t) + { + t.printStackTrace(); + } + finally + { + LOADED = true; + } + } + } + } + + return API_HOST_MAP.get(identifier); + } + + public static ApiHost getAmplifierService() + { + return getAPIHost("AMPLIFIERS"); + } + + public static ApiHost getAntispamService() + { + return getAPIHost("ANTISPAM"); + } + + public static ApiHost getEnderchestService() + { + return getAPIHost("ENDERCHEST"); + } private String _host; private int _port; - ApiHost(String host, int port) + private ApiHost(String host, int port) { _host = host; _port = port; diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/enderchest/EnderchestWorldLoader.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/enderchest/EnderchestWorldLoader.java index 0a782d6d7..5a196c26e 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/enderchest/EnderchestWorldLoader.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/enderchest/EnderchestWorldLoader.java @@ -18,7 +18,7 @@ public class EnderchestWorldLoader public EnderchestWorldLoader() { - String url = "http://" + ApiHost.ENDERCHEST.getHost() + ":" + ApiHost.ENDERCHEST.getPort() + "/"; + String url = "http://" + ApiHost.getEnderchestService().getHost() + ":" + ApiHost.getEnderchestService().getPort() + "/"; _webCall = new ApiWebCall(url); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antispam/repository/AntiSpamRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/antispam/repository/AntiSpamRepository.java index 4211d3116..be920e079 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antispam/repository/AntiSpamRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antispam/repository/AntiSpamRepository.java @@ -17,7 +17,7 @@ public class AntiSpamRepository extends ApiEndpoint { public AntiSpamRepository() { - super(ApiHost.ANTISPAM, "/chat"); + super(ApiHost.getAntispamService(), "/chat"); } public AntiSpamApiResponse sendMessage(String source, ChatPayload payload) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterRepository.java index 25e8c2c64..2f42602e9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterRepository.java @@ -24,7 +24,7 @@ public class BoosterRepository extends ApiEndpoint { public BoosterRepository() { - super(ApiHost.AMPLIFIERS, "/booster", new GsonBuilder().setFieldNamingStrategy(new ApiFieldNamingStrategy()) + super(ApiHost.getAmplifierService(), "/booster", new GsonBuilder().setFieldNamingStrategy(new ApiFieldNamingStrategy()) // .registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()) .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX").create()); } From 2b64de8ad14cd6a21013a79399cbddca2e3ff60c Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 23 Feb 2017 14:42:55 +0000 Subject: [PATCH 056/101] Preparation for beta --- .../core/cosmetic/CosmeticManager.java | 5 + .../src/mineplex/gemhunters/GemHunters.java | 38 +++-- .../mineplex/gemhunters/beta/BetaModule.java | 49 +++++++ .../gemhunters/bounties/BountyModule.java | 2 +- .../gemhunters/death/DeathModule.java | 2 +- .../gemhunters/economy/CashOutModule.java | 1 - .../gemhunters/loot/InventoryModule.java | 30 ++-- .../mineplex/gemhunters/loot/LootModule.java | 130 ++++++++++++++++-- .../loot/rewards/LootChestReward.java | 53 +++++++ .../loot/rewards/LootGadgetReward.java | 55 ++++++++ .../loot/rewards/LootRankReward.java | 13 +- .../loot/rewards/LootShardReward.java | 42 ++++++ .../gemhunters/map/ItemMapModule.java | 4 +- .../gemhunters/map/ItemMapRenderer.java | 93 +++++++------ .../gemhunters/mount/MountModule.java | 56 ++++++-- .../mineplex/gemhunters/quest/QuestNPC.java | 4 +- .../scoreboard/GemHuntersScoreboard.java | 22 ++- .../VillagerPropertiesDeserialiser.java | 6 +- .../gemhunters/spawn/SpawnModule.java | 11 +- .../gemhunters/supplydrop/SupplyDrop.java | 14 +- .../supplydrop/SupplyDropModule.java | 20 ++- .../gemhunters/world/UndergroundMobs.java | 9 +- .../gemhunters/world/WorldListeners.java | 32 +++-- .../worldevent/WorldEventModule.java | 2 +- .../worldevent/WorldEventPriority.java | 2 +- 25 files changed, 543 insertions(+), 152 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/beta/BetaModule.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootChestReward.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootGadgetReward.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootShardReward.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/CosmeticManager.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/CosmeticManager.java index 590e814fd..d1ae7b491 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/CosmeticManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/CosmeticManager.java @@ -242,6 +242,11 @@ public class CosmeticManager extends MiniPlugin { return _boosterManager; } + + public void displayUI(Player player) + { + _shop.attemptShopOpen(player); + } public void disableTeamArmor() { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 42ab331c2..50859e2f0 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -4,8 +4,6 @@ import static mineplex.core.Managers.require; import org.bukkit.World; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.spigotmc.SpigotConfig; @@ -15,11 +13,13 @@ import mineplex.core.TimingsFix; import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; import mineplex.core.blockrestore.BlockRestore; +import mineplex.core.boosters.BoosterManager; import mineplex.core.chat.Chat; import mineplex.core.command.CommandCenter; import mineplex.core.common.Constants; import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.communities.CommunityManager; +import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.creature.Creature; import mineplex.core.delayedtask.DelayedTask; import mineplex.core.disguise.DisguiseManager; @@ -52,9 +52,11 @@ import mineplex.core.serverConfig.ServerConfiguration; import mineplex.core.stats.StatsManager; import mineplex.core.status.ServerStatusManager; import mineplex.core.teleport.Teleport; +import mineplex.core.thank.ThankManager; import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; import mineplex.core.visibility.VisibilityManager; +import mineplex.gemhunters.beta.BetaModule; import mineplex.gemhunters.bounties.BountyModule; import mineplex.gemhunters.chat.ChatModule; import mineplex.gemhunters.death.DeathModule; @@ -129,7 +131,7 @@ public class GemHunters extends JavaPlugin Give.Initialize(this); // Server config - new ServerConfiguration(this, clientManager); + ServerConfiguration serverConfig = new ServerConfiguration(this, clientManager); // Teleport new Teleport(this, clientManager); @@ -226,12 +228,22 @@ public class GemHunters extends JavaPlugin // Menus new MenuManager(this); - // Gadgets, used for mounts, lots of managers for something really small :( - new GadgetManager(this, clientManager, donationManager, inventoryManager, new MountManager(this, clientManager, donationManager, blockRestore, disguiseManager), new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore), preferenceManager, disguiseManager, blockRestore, new ProjectileManager(this), achievementManager, packetHandler, hologramManager, incognito); + // Gadgets, used for mounts, lots of managers for something really small + // :( + MountManager mountManager = new MountManager(this, clientManager, donationManager, blockRestore, disguiseManager); + PetManager petManager = new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore); + ProjectileManager projectileManager = new ProjectileManager(this); + GadgetManager gadgetManager = new GadgetManager(this, clientManager, donationManager, inventoryManager, mountManager, petManager, preferenceManager, disguiseManager, blockRestore, projectileManager, achievementManager, packetHandler, hologramManager, incognito); + ThankManager thankManager = new ThankManager(this, clientManager, donationManager); + BoosterManager boosterManager = new BoosterManager(this, null, clientManager, donationManager, inventoryManager, thankManager); + CosmeticManager cosmeticManager = new CosmeticManager(this, clientManager, donationManager, inventoryManager, gadgetManager, mountManager, petManager, null, boosterManager); + cosmeticManager.setActive(false); + // Now we finally get to enable the Gem Hunters modules // Though if any other module needs one of these it will be generated in - // order, however they are all here just for good measure. + // order, however they are all here just for good measure.s + require(BetaModule.class); require(DebugModule.class); require(BountyModule.class); require(CashOutModule.class); @@ -274,20 +286,6 @@ public class GemHunters extends JavaPlugin public void onDisable() { getServer().getPluginManager().callEvent(new ServerShutdownEvent(this)); - - // Cleanup all rouge entities - for (World world : getServer().getWorlds()) - { - for (Entity entity : world.getEntities()) - { - if (entity instanceof Player) - { - continue; - } - - entity.remove(); - } - } } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/beta/BetaModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/beta/BetaModule.java new file mode 100644 index 000000000..ab215deed --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/beta/BetaModule.java @@ -0,0 +1,49 @@ +package mineplex.gemhunters.beta; + +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +@ReflectivelyCreateMiniPlugin +public class BetaModule extends MiniPlugin +{ + + private static final String[] ANNOUCEMENTS = { + "Please remember this game is an early access BETA and all bugs should be reported to a staff member.", + "Thank you for playing Gem Hunters!", + "Many more features are being added over the coming days!", + "Players in your party show up on your map!", + "Safezones are marked as green areas on your map!", + "Players that have super valuable items show up on your map!" + }; + + private int _lastIndex; + + private BetaModule() + { + super("Beta"); + } + + @EventHandler + public void annouce(UpdateEvent event) + { + if (event.getType() != UpdateType.MIN_01) + { + return; + } + + Bukkit.broadcastMessage(F.main(C.cRedB + "BETA", C.cYellow + ANNOUCEMENTS[_lastIndex])); + + if (++_lastIndex == ANNOUCEMENTS.length) + { + _lastIndex = 0; + } + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/bounties/BountyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/bounties/BountyModule.java index 7a7ea109f..771d58997 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/bounties/BountyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/bounties/BountyModule.java @@ -24,7 +24,7 @@ public class BountyModule extends MiniPlugin _brandingManager = require(BrandingManager.class); } - @EventHandler + //@EventHandler public void test(PlayerCommandPreprocessEvent event) { if (!event.getMessage().startsWith("/want")) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java index d83761810..d3376f06f 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java @@ -44,7 +44,7 @@ public class DeathModule extends MiniPlugin // Some items like the cash out item (and for some reason players drop // bones?) don't need to be dropped to avoid duplication. - private static final Set DISALLOWED_DROPS = Sets.newHashSet(Material.EMERALD, Material.BONE, Material.STAINED_GLASS_PANE); + private static final Set DISALLOWED_DROPS = Sets.newHashSet(Material.EMERALD, Material.MAP, Material.BONE, Material.STAINED_GLASS_PANE); private static final int DEATH_ANIMATION_TIME = 7000; private static final int DEATH_ANIMATION_COUNTDOWN = 2000; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java index 04a892877..adf39923a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -16,7 +16,6 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import mineplex.core.MiniPlugin; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java index f9552c0d3..0f72525fd 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java @@ -35,7 +35,7 @@ public class InventoryModule extends MiniPlugin private final LootModule _loot; - private final Map _rowsUnlocked; + private final Map _slotsUnlocked; private InventoryModule() { @@ -43,7 +43,7 @@ public class InventoryModule extends MiniPlugin _loot = require(LootModule.class); - _rowsUnlocked = new HashMap<>(); + _slotsUnlocked = new HashMap<>(); } @EventHandler @@ -52,7 +52,7 @@ public class InventoryModule extends MiniPlugin Player player = event.getPlayer(); Inventory inv = player.getInventory(); - _rowsUnlocked.put(player.getUniqueId(), 0); + _slotsUnlocked.put(player.getUniqueId(), 0); for (int i = START_INDEX; i < inv.getSize(); i++) { @@ -63,7 +63,7 @@ public class InventoryModule extends MiniPlugin @EventHandler public void quit(PlayerQuitEvent event) { - _rowsUnlocked.remove(event.getPlayer().getUniqueId()); + _slotsUnlocked.remove(event.getPlayer().getUniqueId()); } @EventHandler @@ -86,11 +86,6 @@ public class InventoryModule extends MiniPlugin @EventHandler public void interact(PlayerInteractEvent event) { - if (event.isCancelled()) - { - return; - } - if (!UtilEvent.isAction(event, ActionType.R)) { return; @@ -111,23 +106,17 @@ public class InventoryModule extends MiniPlugin return; } - Material material = itemStack.getType(); - - if (material == Material.CHEST || material == Material.ENDER_CHEST) - { - UtilInv.remove(player, material, (byte) 0, 1); - unlockRows(player, material == Material.CHEST ? 1 : 2); - } + player.setItemInHand(UtilInv.decrement(itemStack)); + unlockSlots(player, itemStack.getType() == Material.CHEST ? 9 : 18); } - public void unlockRows(Player player, int rows) + public void unlockSlots(Player player, int slots) { Inventory inv = player.getInventory(); UUID key = player.getUniqueId(); - _rowsUnlocked.put(key, _rowsUnlocked.get(key) + rows); - int start = START_INDEX * _rowsUnlocked.get(key); - int end = Math.min(inv.getSize(), start + rows * 9); + int start = START_INDEX + _slotsUnlocked.get(key); + int end = Math.min(inv.getSize(), start + slots); int delta = end - start; DebugModule.getInstance().d("start=" + start); @@ -140,5 +129,6 @@ public class InventoryModule extends MiniPlugin } player.sendMessage(F.main(_moduleName, "You unlocked an additional " + F.count(String.valueOf(delta)) + " slots of your inventory!")); + _slotsUnlocked.put(key, _slotsUnlocked.get(key) + slots); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 0dea6917e..e82457176 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -6,8 +6,10 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.concurrent.TimeUnit; +import org.bukkit.Bukkit; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; @@ -29,6 +31,8 @@ import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; @@ -37,15 +41,20 @@ import mineplex.core.google.GoogleSheetsManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.debug.DebugModule; +import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.economy.PlayerCashOutCompleteEvent; import mineplex.gemhunters.loot.command.SpawnChestCommand; import mineplex.gemhunters.loot.command.UpdateLootCommand; import mineplex.gemhunters.loot.deserialisers.ChestPropertiesDeserialiser; import mineplex.gemhunters.loot.deserialisers.LootItemDeserialiser; import mineplex.gemhunters.loot.event.PlayerChestOpenEvent; +import mineplex.gemhunters.loot.rewards.LootChestReward; +import mineplex.gemhunters.loot.rewards.LootGadgetReward; import mineplex.gemhunters.loot.rewards.LootItemReward; import mineplex.gemhunters.loot.rewards.LootRankReward; +import mineplex.gemhunters.loot.rewards.LootShardReward; import mineplex.gemhunters.safezone.SafezoneModule; +import mineplex.gemhunters.spawn.event.PlayerTeleportIntoMapEvent; import mineplex.gemhunters.util.SlackSheetsBot; import mineplex.gemhunters.world.WorldDataModule; @@ -61,7 +70,13 @@ public class LootModule extends MiniPlugin private static final int MAX_CHEST_CHECK_DISTANCE_SQUARED = 4; private static final LootItemDeserialiser DESERIALISER = new LootItemDeserialiser(); private static final ChestPropertiesDeserialiser CHEST_DESERIALISER = new ChestPropertiesDeserialiser(); - + private static final ItemStack[] SPAWN_ITEMS = { + new ItemStack(Material.WOOD_SWORD), + new ItemStack(Material.APPLE, 3), + }; + private static final String GEM_METADATA = "GEM"; + + private final EconomyModule _economy; private final GoogleSheetsManager _sheets; private final SafezoneModule _safezone; private final WorldDataModule _worldData; @@ -70,19 +85,22 @@ public class LootModule extends MiniPlugin private final Map _chestProperties; private final Set _spawnedChest; private final Set _itemRewards; - + private final Set _shownPlayers; + private LootModule() { super("Loot"); + _economy = require(EconomyModule.class); _sheets = require(GoogleSheetsManager.class); _safezone = require(SafezoneModule.class); _worldData = require(WorldDataModule.class); _chestLoot = new HashMap<>(); _chestProperties = new HashMap<>(); - _spawnedChest = new HashSet<>(200); + _spawnedChest = new HashSet<>(); _itemRewards = new HashSet<>(); - + _shownPlayers = new HashSet<>(); + runSyncLater(() -> { updateChestLoot(); @@ -233,7 +251,7 @@ public class LootModule extends MiniPlugin { return; } - + properties.setLastSpawn(); // Only spawn more chests if we need to @@ -253,6 +271,11 @@ public class LootModule extends MiniPlugin { return; } + + if (locations.isEmpty()) + { + return; + } Map spawnedIndexes = properties.getSpawnIndexes(); Location randomLocation = null; @@ -262,14 +285,13 @@ public class LootModule extends MiniPlugin while (index == -1 || !found && attempts < MAX_SEARCH_ATTEMPTS) { + attempts++; index = UtilMath.r(locations.size()); if (spawnedIndexes.getOrDefault(index, 0) >= properties.getMaxChestPerLocation()) { continue; } - - attempts++; } if (index == -1) @@ -516,12 +538,36 @@ public class LootModule extends MiniPlugin if (reward == null) { - switch (lootItem.getMetadata()) + String[] metadataSplit = lootItem.getMetadata().split(" "); + String key = metadataSplit[0]; + String[] values = new String[metadataSplit.length - 1]; + + for (int i = 1; i < metadataSplit.length; i++) + { + values[i - 1] = metadataSplit[i]; + } + + switch (key) { case "RANK_UPGRADE": reward = new LootRankReward(itemStack); break; - + case "SHARD": + reward = new LootShardReward(Integer.parseInt(values[0]) * 1000, itemStack, Integer.parseInt(values[1])); + break; + case "CHEST": + reward = new LootChestReward(Integer.parseInt(values[0]) * 1000, itemStack, values[1], Integer.parseInt(values[2])); + break; + case "GADGET": + String gadget = ""; + + for (int i = 1; i < values.length; i++) + { + gadget += values[i] + " "; + } + + reward = new LootGadgetReward(Integer.parseInt(values[0]) * 1000, itemStack, gadget.trim()); + break; default: return; } @@ -531,7 +577,68 @@ public class LootModule extends MiniPlugin reward.collectItem(player); } + + @EventHandler + public void gemClick(PlayerInteractEvent event) + { + if (!UtilEvent.isAction(event, ActionType.R)) + { + return; + } + Player player = event.getPlayer(); + ItemStack itemStack = player.getItemInHand(); + + if (itemStack == null) + { + return; + } + + LootItem lootItem = fromItemStack(itemStack); + + if (lootItem == null || lootItem.getMetadata() == null || !lootItem.getMetadata().startsWith(GEM_METADATA)) + { + return; + } + + player.setItemInHand(UtilInv.decrement(itemStack)); + + int amount = Integer.parseInt(lootItem.getMetadata().split(" ")[1]); + + _economy.addToStore(player, "Gem Item", amount); + } + + @EventHandler + public void mapUpdate(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + { + return; + } + + _shownPlayers.clear(); + + for (Player player : Bukkit.getOnlinePlayers()) + { + UUID key = player.getUniqueId(); + + for (LootItemReward itemReward : _itemRewards) + { + if (itemReward.getPlayer().equals(player)) + { + _shownPlayers.add(key); + break; + } + } + } + } + + @EventHandler + public void mapTeleport(PlayerTeleportIntoMapEvent event) + { + event.getPlayer().getInventory().addItem(SPAWN_ITEMS); + } + @EventHandler public void cashOutComplete(PlayerCashOutCompleteEvent event) { @@ -549,4 +656,9 @@ public class LootModule extends MiniPlugin } } } + + public final Set getShownPlayers() + { + return _shownPlayers; + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootChestReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootChestReward.java new file mode 100644 index 000000000..031e859f6 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootChestReward.java @@ -0,0 +1,53 @@ +package mineplex.gemhunters.loot.rewards; + +import org.bukkit.inventory.ItemStack; + +import mineplex.core.Managers; +import mineplex.core.common.util.Callback; +import mineplex.core.inventory.InventoryManager; +import mineplex.gemhunters.debug.DebugModule; + +public class LootChestReward extends LootItemReward +{ + + private final InventoryManager _inventory; + + private final String _chestName; + private final int _amount; + + public LootChestReward(long cashOutDelay, ItemStack itemStack, String chestName, int amount) + { + super(chestName + " Chest", cashOutDelay, itemStack); + + _inventory = Managers.require(InventoryManager.class); + _chestName = chestName; + _amount = amount; + } + + @Override + public void onCollectItem() + { + + } + + @Override + public void onSuccessful() + { + _inventory.addItemToInventory(new Callback() + { + + @Override + public void run(Boolean success) + { + DebugModule.getInstance().d("Success= " + success); + } + }, _player, _chestName + " Chest", _amount); + } + + @Override + public void onDeath() + { + + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootGadgetReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootGadgetReward.java new file mode 100644 index 000000000..1d8dc728a --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootGadgetReward.java @@ -0,0 +1,55 @@ +package mineplex.gemhunters.loot.rewards; + +import org.bukkit.inventory.ItemStack; + +import mineplex.core.Managers; +import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.donation.DonationManager; +import mineplex.core.donation.Donor; +import mineplex.gemhunters.debug.DebugModule; + +public class LootGadgetReward extends LootItemReward +{ + + private final DonationManager _donation; + + private final String _gadget; + + public LootGadgetReward(long cashOutDelay, ItemStack itemStack, String gadget) + { + super(gadget, cashOutDelay, itemStack); + + _donation = Managers.require(DonationManager.class); + _gadget = gadget; + } + + @Override + public void onCollectItem() + { + + } + + @Override + public void onSuccessful() + { + Donor donor = _donation.Get(_player); + + if (donor.ownsUnknownSalesPackage(_gadget)) + { + DebugModule.getInstance().d("Shard duplicate"); + donor.addBalance(GlobalCurrency.TREASURE_SHARD, (int) (500 + Math.random() * 1000)); + } + else + { + DebugModule.getInstance().d("Adding gadget"); + donor.addOwnedUnknownSalesPackage(_gadget); + } + } + + @Override + public void onDeath() + { + + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java index 56e782511..85ffc4e6d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootRankReward.java @@ -8,19 +8,25 @@ import mineplex.core.Managers; import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClientManager; import mineplex.core.common.Rank; +import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.common.util.F; +import mineplex.core.donation.DonationManager; public class LootRankReward extends LootItemReward { - private static final long CASH_OUT_DELAY = TimeUnit.SECONDS.toMillis(60); - + private static final long CASH_OUT_DELAY = TimeUnit.MINUTES.toMillis(15); + private static final int CONSOLATION_PRICE = 10000; + private final CoreClientManager _clientManager; + private final DonationManager _donation; public LootRankReward(ItemStack itemStack) { super("Rank", CASH_OUT_DELAY, itemStack); _clientManager = Managers.require(CoreClientManager.class); + _donation = Managers.require(DonationManager.class); } @Override @@ -63,7 +69,8 @@ public class LootRankReward extends LootItemReward // A suitable rank could not be found. if (newRank == null) { - // TODO implement shard reward. + _player.sendMessage(F.main("Loot", "Since you already have eternal ( You are lucky :) ). So instead you can have " + CONSOLATION_PRICE + " shards.")); + _donation.Get(_player).addBalance(GlobalCurrency.TREASURE_SHARD, CONSOLATION_PRICE); return; } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootShardReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootShardReward.java new file mode 100644 index 000000000..1faf61dfa --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootShardReward.java @@ -0,0 +1,42 @@ +package mineplex.gemhunters.loot.rewards; + +import org.bukkit.inventory.ItemStack; + +import mineplex.core.Managers; +import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.donation.DonationManager; + +public class LootShardReward extends LootItemReward +{ + + private final DonationManager _donation; + + private final int _amount; + + public LootShardReward(long cashOutDelay, ItemStack itemStack, int amount) + { + super("Shard", cashOutDelay, itemStack); + + _donation = Managers.require(DonationManager.class); + _amount = amount; + } + + @Override + public void onCollectItem() + { + + } + + @Override + public void onSuccessful() + { + _donation.Get(_player).addBalance(GlobalCurrency.TREASURE_SHARD, _amount); + } + + @Override + public void onDeath() + { + + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java index 7de836fac..b92d9fe61 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java @@ -58,7 +58,6 @@ import mineplex.core.portal.events.ServerTransferEvent; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.death.event.PlayerCustomRespawnEvent; -import mineplex.gemhunters.spawn.SpawnModule; import net.minecraft.server.v1_8_R3.Block; import net.minecraft.server.v1_8_R3.BlockPosition; import net.minecraft.server.v1_8_R3.Blocks; @@ -79,7 +78,7 @@ public class ItemMapModule extends MiniPlugin // Every BLOCK_SCAN_INTERVAL we add as a new region to scan private static final int BLOCK_SCAN_INTERVAL = 16 * 3; // 1536 is the width of the entire world from one borderland to the other - private static final int HALF_WORLD_SIZE = SpawnModule.WORLD_BORDER_RADIUS; + private static final int HALF_WORLD_SIZE = 768; // This slot is where the Clans Map will go by default private static final int CLANS_MAP_SLOT = 8; @@ -945,6 +944,7 @@ public class ItemMapModule extends MiniPlugin ItemStack mapSlot = player.getInventory().getItem(slot); if (mapSlot != null && mapSlot.getType() != Material.AIR) { + slot = player.getInventory().firstEmpty(); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapRenderer.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapRenderer.java index fa2c37151..225e4b4b2 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapRenderer.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapRenderer.java @@ -1,6 +1,8 @@ package mineplex.gemhunters.map; import java.awt.Color; +import java.util.Set; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -14,11 +16,11 @@ import org.bukkit.map.MapView; import mineplex.core.Managers; import mineplex.core.common.util.UtilTime; -import mineplex.core.communities.Community; -import mineplex.core.communities.CommunityManager; import mineplex.core.party.Party; import mineplex.core.party.PartyManager; +import mineplex.gemhunters.loot.LootModule; import mineplex.gemhunters.safezone.SafezoneModule; +import mineplex.gemhunters.supplydrop.SupplyDrop; import mineplex.gemhunters.supplydrop.SupplyDropModule; import mineplex.gemhunters.worldevent.WorldEvent; import mineplex.gemhunters.worldevent.WorldEventModule; @@ -33,22 +35,22 @@ public class ItemMapRenderer extends MapRenderer private static final int STANDARD_Y = 70; private final ItemMapModule _itemMap; + private final LootModule _loot; private final SafezoneModule _safezone; private final SupplyDropModule _supply; private final WorldEventModule _worldEvent; - - private final CommunityManager _community; + private final PartyManager _party; - + public ItemMapRenderer() { super(true); _itemMap = Managers.require(ItemMapModule.class); + _loot = Managers.require(LootModule.class); _safezone = Managers.require(SafezoneModule.class); _supply = Managers.require(SupplyDropModule.class); _worldEvent = Managers.require(WorldEventModule.class); - _community = Managers.require(CommunityManager.class); _party = Managers.require(PartyManager.class); } @@ -111,21 +113,11 @@ public class ItemMapRenderer extends MapRenderer Location location = new Location(mapView.getWorld(), blockX, STANDARD_Y, blockZ); boolean safezone = _safezone.isInSafeZone(location); - boolean supplyDrop = _supply.isNearSupplyDrop(location); - if (safezone || supplyDrop) + if (safezone) { boolean colorAll = scale > 0; - Color areaColor = null; - - if (safezone) - { - areaColor = Color.GREEN; - } - else if (supplyDrop) - { - areaColor = Color.YELLOW; - } + Color areaColor = Color.GREEN; if (areaColor != null) { @@ -136,26 +128,15 @@ public class ItemMapRenderer extends MapRenderer } else { - int chunkBX = blockX & 0xF; - int chunkBZ = blockZ & 0xF; +// int chunkBX = blockX & 0xF; +// int chunkBZ = blockZ & 0xF; // Border if ( - ((chunkBX == 0 || zoom == 13) && - - _safezone.isInSafeZone(new Location(mapView.getWorld(), blockX - 16, STANDARD_Y, blockZ))) - - || ((chunkBZ == 0 || zoom == 13) && - - _safezone.isInSafeZone(new Location(mapView.getWorld(), blockX, STANDARD_Y, blockZ - 16))) - - || ((chunkBX + zoom > 15 || zoom == 13) && - - _safezone.isInSafeZone(new Location(mapView.getWorld(), blockX + 16, STANDARD_Y, blockZ))) - - || ((chunkBZ + zoom > 15 || zoom == 13) && - - _safezone.isInSafeZone(new Location(mapView.getWorld(), blockX, STANDARD_Y, blockZ + 16)))) + _safezone.isInSafeZone(new Location(mapView.getWorld(), blockX - 1, STANDARD_Y, blockZ)) || + _safezone.isInSafeZone(new Location(mapView.getWorld(), blockX, STANDARD_Y, blockZ - 1)) || + _safezone.isInSafeZone(new Location(mapView.getWorld(), blockX + 16, STANDARD_Y, blockZ)) || + _safezone.isInSafeZone(new Location(mapView.getWorld(), blockX, STANDARD_Y, blockZ + 1))) { Color cColor = MapPalette.getColor(color); double clans = colorAll ? 1 : 0.8; @@ -222,6 +203,31 @@ public class ItemMapRenderer extends MapRenderer double mapX = (point.getX() - info.getX()) / zoom; double mapZ = (point.getZ() - info.getZ()) / zoom; + // To make these appear at the edges of the map, just change it from + // 64 to something like 128 for double the map size + if (mapX > -64 && mapX < 64 && mapZ > -64 && mapZ < 64) + { + byte b0 = (byte) (int) Math.min(127, (double) (mapX * 2.0F) + 0.5D); + byte b1 = (byte) (int) Math.max(-127, (double) (mapZ * 2.0F) + 0.5D); + + byte cursorType = 5; // http://i.imgur.com/wpH6PT8.png + // Those are byte 5 and 6 + byte rotation = (byte) ((int) Math.floor(System.currentTimeMillis() / 1000D) % 16); + + MapCursor cursor = new MapCursor(b0, b1, rotation, cursorType, true); + + cursors.addCursor(cursor); + } + } + + SupplyDrop supplyDrop = _supply.getActive(); + + if (_supply.isActive()) + { + Location point = supplyDrop.getCurrentLocation(); + double mapX = (point.getX() - info.getX()) / zoom; + double mapZ = (point.getZ() - info.getZ()) / zoom; + // To make these appear at the edges of the map, just change it from // 64 to something like 128 for double the map size if (mapX > -64 && mapX < 64 && mapZ > -64 && mapZ < 64) @@ -240,7 +246,7 @@ public class ItemMapRenderer extends MapRenderer } Party party = _party.getPartyByPlayer(player); - Community[] communities = _community.Get(player).getCommunities(); + Set shownPlayers = _loot.getShownPlayers(); for (Player other : Bukkit.getOnlinePlayers()) { @@ -259,21 +265,14 @@ public class ItemMapRenderer extends MapRenderer { cursorDisplay = MapCursor.Type.WHITE_POINTER; } + else if (shownPlayers.contains(other.getUniqueId())) + { + cursorDisplay = MapCursor.Type.BLUE_POINTER; + } else if (party != null && party.isMember(other)) { cursorDisplay = MapCursor.Type.GREEN_POINTER; } - else if (communities.length > 0) - { - for (Community community : communities) - { - if (community.getMembers().containsKey(other.getUniqueId())) - { - cursorDisplay = MapCursor.Type.BLUE_POINTER; - break; - } - } - } if (cursorDisplay == null) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/MountModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/MountModule.java index 56cb32950..72cc23b13 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/MountModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/MountModule.java @@ -2,9 +2,14 @@ package mineplex.gemhunters.mount; import java.util.UUID; +import org.bukkit.Material; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Horse; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.Tameable; +import org.bukkit.entity.Horse.Color; +import org.bukkit.entity.Horse.Style; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; @@ -25,7 +30,7 @@ import mineplex.gemhunters.loot.LootModule; public class MountModule extends MiniClientPlugin { - private static final String ITEM_METADATA = "UNLOCKER"; + private static final String ITEM_METADATA = "MOUNT"; private final LootModule _loot; private final GadgetManager _gadget; @@ -47,11 +52,6 @@ public class MountModule extends MiniClientPlugin @EventHandler public void playerInteract(PlayerInteractEvent event) { - if (event.isCancelled()) - { - return; - } - if (!UtilEvent.isAction(event, ActionType.R)) { return; @@ -72,7 +72,7 @@ public class MountModule extends MiniClientPlugin return; } - int cooldown = Integer.parseInt(lootItem.getMetadata().split(" ")[1]); + int cooldown = Integer.parseInt(lootItem.getMetadata().split(" ")[1]) * 1000; if (!Recharge.Instance.use(player, _moduleName, cooldown, true, true)) { @@ -84,19 +84,55 @@ public class MountModule extends MiniClientPlugin public void spawnMount(Player player) { - spawnMount(player, ((GameModifierMount) _gadget.getActiveGameModifier(player, GameModifierType.GemHunters, g -> g != null)).getMountType()); + GameModifierMount mount = ((GameModifierMount) _gadget.getActiveGameModifier(player, GameModifierType.GemHunters, g -> g != null)); + MountType mountType = null; + + if (mount != null) + { + mountType = mount.getMountType(); + } + + spawnMount(player, mountType); } public void spawnMount(Player player, MountType mountType) { MountData data = Get(player); LivingEntity entity = data.getEntity(); - EntityType entityType = mountType.getEntityType(); + EntityType entityType = mountType == null ? EntityType.HORSE : mountType.getEntityType(); despawnMount(player); - entity = (LivingEntity) player.getWorld().spawnEntity(player.getLocation().add(0, 1, 0), entityType == null ? EntityType.HORSE : entityType); + entity = (LivingEntity) player.getWorld().spawnEntity(player.getLocation().add(0, 1, 0), entityType); + if (entity instanceof Tameable) + { + Tameable tameable = (Tameable) entity; + + tameable.setOwner(player); + } + + if (entity instanceof Horse) + { + Horse horse = (Horse) entity; + + horse.setAdult(); + horse.setAgeLock(true); + horse.setColor(Color.BROWN); + horse.setStyle(Style.NONE); + horse.setMaxDomestication(1); + horse.setJumpStrength(1); + horse.getInventory().setSaddle(new ItemStack(Material.SADDLE)); + } + + entity.setCustomName(player.getName() + "\'s Mount"); + entity.setCustomNameVisible(true); + entity.setCanPickupItems(false); + entity.setHealth(1); + entity.setMaxHealth(1); + + entity.setPassenger(player); + data.setEntity(entity); data.setMountType(mountType); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestNPC.java index 609f873bb..33d61a47d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestNPC.java @@ -7,6 +7,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerInteractEntityEvent; import mineplex.core.common.util.C; +import mineplex.core.common.util.F; import mineplex.core.menu.Menu; import mineplex.gemhunters.util.SimpleNPC; @@ -37,7 +38,8 @@ public class QuestNPC extends SimpleNPC event.setCancelled(true); - _questMenu.open(event.getPlayer()); + event.getPlayer().sendMessage(F.main("Quest", "The Quest Master is currently disabled but will be avaiable to all players shortly.")); + //_questMenu.open(event.getPlayer());/ } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java index 4ee1fc741..4959f4a78 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/scoreboard/GemHuntersScoreboard.java @@ -4,17 +4,20 @@ import org.bukkit.entity.Player; import mineplex.core.Managers; import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilTime; import mineplex.core.scoreboard.WritableMineplexScoreboard; import mineplex.gemhunters.economy.EconomyModule; +import mineplex.gemhunters.supplydrop.SupplyDropModule; import mineplex.gemhunters.worldevent.WorldEvent; import mineplex.gemhunters.worldevent.WorldEventModule; public class GemHuntersScoreboard extends WritableMineplexScoreboard { - + private final EconomyModule _economy; private final WorldEventModule _worldEvent; + private final SupplyDropModule _supplyDrop; public GemHuntersScoreboard(Player player) { @@ -22,6 +25,7 @@ public class GemHuntersScoreboard extends WritableMineplexScoreboard _economy = Managers.require(EconomyModule.class); _worldEvent = Managers.require(WorldEventModule.class); + _supplyDrop = Managers.require(SupplyDropModule.class); } public void writeContent(Player player) @@ -33,13 +37,25 @@ public class GemHuntersScoreboard extends WritableMineplexScoreboard writeNewLine(); + write(C.cGoldB + "Supply Drop"); + if (_supplyDrop.isActive()) + { + write(_supplyDrop.getActive().getName() + " - " + (int) UtilMath.offset(player.getLocation(), _supplyDrop.getActive().getChestLocation()) + "m"); + } + else + { + write(UtilTime.MakeStr(_supplyDrop.getLastSupplyDrop() + _supplyDrop.getSequenceTimer() - System.currentTimeMillis())); + } + + writeNewLine(); + write(C.cYellowB + "World Event"); if (!_worldEvent.isEventActive()) { write(UtilTime.MakeStr(_worldEvent.getLastEventComplete() + _worldEvent.getEventTimer() - System.currentTimeMillis())); } - else + else { for (WorldEvent event : _worldEvent.getActiveEvents()) { @@ -54,7 +70,7 @@ public class GemHuntersScoreboard extends WritableMineplexScoreboard { return C.cGray + " " + perspective.getName(); } - + public int getUndernameScore(Player player) { return _economy.getGems(player); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/deserialisers/VillagerPropertiesDeserialiser.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/deserialisers/VillagerPropertiesDeserialiser.java index 683564b1e..8d37883a9 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/deserialisers/VillagerPropertiesDeserialiser.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/deserialisers/VillagerPropertiesDeserialiser.java @@ -12,10 +12,10 @@ public class VillagerPropertiesDeserialiser implements SheetObjectDeserialiser _bladeBlocks; private boolean _diagonal; - public SupplyDrop(Location spawn, Location destination, Location despawn) + public SupplyDrop(String name, Location spawn, Location destination, Location despawn) { + _name = name; _destination = destination.clone(); _despawn = despawn.clone(); _current = spawn.clone().add(-2, 0, 0); @@ -206,6 +208,16 @@ public class SupplyDrop UtilFirework.playFirework(fallingBlock.getLocation().add(0.5, 1, 0.5), UtilFirework.getRandomFireworkEffect(false, 2, 1)); } + public final String getName() + { + return _name; + } + + public final Location getCurrentLocation() + { + return _current; + } + public final Location getChestLocation() { return _destination; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java index 734a1cebd..60c07c11a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java @@ -40,8 +40,6 @@ public class SupplyDropModule extends MiniPlugin private static final String CHEST_COLOUR = "RED"; private static final String LOCATION_DATA = "SUPPLY_DROP"; - - private static final int SUPPLY_DROP_DISTANCE_SQUARED = 625; private final BlockRestore _blockRestore; private final LootModule _loot; @@ -108,7 +106,7 @@ public class SupplyDropModule extends MiniPlugin @EventHandler public void fallingBlockChange(EntityChangeBlockEvent event) { - if (event.getEntity() instanceof FallingBlock && event.getTo() == Material.WOOD && isActive()) + if (event.getEntity() instanceof FallingBlock && event.getTo() == Material.WOOD && isActive() && UtilMath.offsetSquared(_current.getChestLocation(), event.getBlock().getLocation()) < 4) { Block block = event.getBlock(); @@ -149,7 +147,7 @@ public class SupplyDropModule extends MiniPlugin UtilServer.broadcast(F.main(_moduleName, "A Supply Drop is spawning at " + F.elem(locationKey) + " - " + C.cYellow + UtilWorld.locToStrClean(destination))); _lastSupplyDrop = System.currentTimeMillis(); - _current = new SupplyDrop(spawn, destination, despawn); + _current = new SupplyDrop(locationKey, spawn, destination, despawn); } public void startSequence() @@ -175,9 +173,19 @@ public class SupplyDropModule extends MiniPlugin return _current != null; } - public boolean isNearSupplyDrop(Location location) + public SupplyDrop getActive() { - return isActive() ? UtilMath.offsetSquared(location, _current.getChestLocation()) <= SUPPLY_DROP_DISTANCE_SQUARED : false; + return _current; + } + + public long getLastSupplyDrop() + { + return _lastSupplyDrop; + } + + public long getSequenceTimer() + { + return SEQUENCE_TIMER; } public String[] getLocationKeys() diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/UndergroundMobs.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/UndergroundMobs.java index 334e5cb1f..f36b5a778 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/UndergroundMobs.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/UndergroundMobs.java @@ -20,11 +20,12 @@ import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilMath; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.debug.DebugModule; public class UndergroundMobs implements Listener { - private static final int MAX_MOBS = 100; + private static final int MAX_MOBS = 300; private static final String SEWER_KEY = "SEWER_MOB"; private static final String SUBWAY_KEY = "SUBWAY_MOBS"; @@ -64,6 +65,8 @@ public class UndergroundMobs implements Listener } } + DebugModule.getInstance().d("Spawning mobs " + _entities.size()); + for (int i = 0; i < 10; i++) { if (_entities.size() >= MAX_MOBS) @@ -72,13 +75,13 @@ public class UndergroundMobs implements Listener } { - Location location = UtilAlg.Random(_worldData.getCustomLocation(SEWER_KEY)); + Location location = UtilAlg.Random(_worldData.getCustomLocation(SEWER_KEY)).clone().add(0, 1, 0); Class clazz = UtilMath.random.nextBoolean() ? Zombie.class : Skeleton.class; Entity entity = _world.spawn(location, clazz); _entities.add(entity); } { - Location location = UtilAlg.Random(_worldData.getCustomLocation(SUBWAY_KEY)); + Location location = UtilAlg.Random(_worldData.getCustomLocation(SUBWAY_KEY)).clone().add(0, 1, 0); Class clazz = Spider.class; Entity entity = _world.spawn(location, clazz); _entities.add(entity); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java index 12d296638..3313ec499 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -2,7 +2,6 @@ package mineplex.gemhunters.world; import java.io.File; import java.util.UUID; -import java.util.concurrent.TimeUnit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -28,20 +27,18 @@ import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.weather.WeatherChangeEvent; import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.inventory.BeaconInventory; import org.bukkit.inventory.BrewerInventory; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.common.util.UtilWorld; -import mineplex.core.recharge.Recharge; import mineplex.gemhunters.debug.DebugModule; public class WorldListeners implements Listener { - private static final long HUNGER_RECHARGE = TimeUnit.SECONDS.toMillis(15); - private final JavaPlugin _plugin; public WorldListeners(JavaPlugin plugin) @@ -139,9 +136,11 @@ public class WorldListeners implements Listener return; } - // Sam don't you dare look here, I understand the implications of this - // but entities, can I just save by UUID? or does not doing this have - // bigger complications?. + if (event.getChunk().getEntities().length == 0) + { + return; + } + event.setCancelled(true); } @@ -169,21 +168,24 @@ public class WorldListeners implements Listener event.setCancelled(true); } - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler public void hungerChange(FoodLevelChangeEvent event) { - if (event.isCancelled()) - { - return; - } - Player player = (Player) event.getEntity(); DebugModule.getInstance().d(player.getName() + " hunger " + player.getFoodLevel() + " -> " + event.getFoodLevel()); - - if (event.getFoodLevel() < player.getFoodLevel() && Recharge.Instance.use((Player) event.getEntity(), "Hunger", HUNGER_RECHARGE, false, false)) + // Some witchcraft from the arcade, seems to make hunger not ridiculous. + player.setSaturation(3.8F); + } + + @EventHandler + public void weather(WeatherChangeEvent event) + { + if (event.toWeatherState()) { + DebugModule.getInstance().d("Cancelling a weather change"); event.setCancelled(true); + event.getWorld().setStorm(false); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java index eae2508b4..521714db6 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventModule.java @@ -22,7 +22,7 @@ public class WorldEventModule extends MiniPlugin { private static final long EVENT_TIMER = TimeUnit.MINUTES.toMillis(30); - private static final long EVENT_COOLDOWN_TIMER = TimeUnit.MINUTES.toMillis(40); + private static final long EVENT_COOLDOWN_TIMER = TimeUnit.MINUTES.toMillis(20); private static final long COMPLETE_TIMER = TimeUnit.SECONDS.toMillis(30); private final List _events; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventPriority.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventPriority.java index cfc826987..8aba307b8 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventPriority.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/WorldEventPriority.java @@ -3,6 +3,6 @@ package mineplex.gemhunters.worldevent; public enum WorldEventPriority { - GLOBAL, ISOLATED + GLOBAL, TRIGGERED } From eb6003a169bdfc5eb6f47bb847576b976a79ffb3 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 24 Feb 2017 01:06:05 +0000 Subject: [PATCH 057/101] Final push --- .../src/mineplex/gemhunters/GemHunters.java | 4 + .../mineplex/gemhunters/beta/BetaModule.java | 2 +- .../gemhunters/death/DeathModule.java | 25 +- .../gemhunters/death/npc/CombatLogNPC.java | 238 ++++++++++++++++ .../gemhunters/death/npc/NPCManager.java | 253 ++++++++++++++++++ .../gemhunters/death/npc/PlayerInfo.java | 94 +++++++ .../mineplex/gemhunters/loot/LootModule.java | 11 +- .../gemhunters/mount/MountModule.java | 4 +- .../gemhunters/quest/QuestModule.java | 2 +- .../mineplex/gemhunters/shop/TraderNPC.java | 4 +- .../gemhunters/spawn/SpawnModule.java | 16 +- .../gemhunters/supplydrop/SupplyDrop.java | 4 +- .../gemhunters/world/UndergroundMobs.java | 13 +- 13 files changed, 639 insertions(+), 31 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/CombatLogNPC.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/NPCManager.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/PlayerInfo.java diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 50859e2f0..e7c6a9b37 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -60,6 +60,7 @@ import mineplex.gemhunters.beta.BetaModule; import mineplex.gemhunters.bounties.BountyModule; import mineplex.gemhunters.chat.ChatModule; import mineplex.gemhunters.death.DeathModule; +import mineplex.gemhunters.death.npc.NPCManager; import mineplex.gemhunters.debug.DebugModule; import mineplex.gemhunters.economy.CashOutModule; import mineplex.gemhunters.economy.EconomyModule; @@ -268,6 +269,9 @@ public class GemHunters extends JavaPlugin new TimeCycle(this); new UndergroundMobs(this); + // Combat npc + new NPCManager(hologramManager); + // UpdateEvent!!! new Updater(this); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/beta/BetaModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/beta/BetaModule.java index ab215deed..537455ba9 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/beta/BetaModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/beta/BetaModule.java @@ -15,7 +15,7 @@ public class BetaModule extends MiniPlugin { private static final String[] ANNOUCEMENTS = { - "Please remember this game is an early access BETA and all bugs should be reported to a staff member.", + "Please remember this game is an early access BETA and all bugs should be reported at mineplex.com/forums/m/11929946/viewforum/8006500 .", "Thank you for playing Gem Hunters!", "Many more features are being added over the coming days!", "Players in your party show up on your map!", diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java index d3376f06f..7ddaf48c0 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java @@ -13,12 +13,12 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.inventory.ItemStack; import com.google.common.collect.Sets; @@ -77,26 +77,21 @@ public class DeathModule extends MiniPlugin // Stop the player dieing player.setHealth(20); player.setFoodLevel(20); - player.setSaturation(20); player.setExhaustion(0); startAnimation(player); _toRemove.put(player.getUniqueId(), System.currentTimeMillis()); - - Iterator iterator = event.getDrops().iterator(); - - // Iterate through all items and clear any disallowed items - while (iterator.hasNext()) - { - ItemStack itemStack = iterator.next(); - - if (DISALLOWED_DROPS.contains(itemStack.getType())) - { - iterator.remove(); - } - } } + @EventHandler + public void itemSpawn(ItemSpawnEvent event) + { + if (DISALLOWED_DROPS.contains(event.getEntity().getItemStack().getType())) + { + event.setCancelled(true); + } + } + @EventHandler public void updateAnimations(UpdateEvent event) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/CombatLogNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/CombatLogNPC.java new file mode 100644 index 000000000..b1337b6bb --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/CombatLogNPC.java @@ -0,0 +1,238 @@ +package mineplex.gemhunters.death.npc; + +import java.io.File; +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Skeleton; +import org.bukkit.metadata.FixedMetadataValue; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTime; +import mineplex.core.disguise.DisguiseManager; +import mineplex.core.disguise.disguises.DisguisePlayer; +import mineplex.core.hologram.Hologram; +import mineplex.core.hologram.HologramManager; + +public class CombatLogNPC +{ + public final static EntityType NPC_TYPE = EntityType.VILLAGER; + + private PlayerInfo _playerInfo; + + private Hologram _hologram; + + private DisguiseManager _disguiseManager; + private long _spawnDate; + private final long _endingTime; + private double _spawnHealth; + + private boolean _creative; + + private LivingEntity _npc; + private ArmorStand _stand; + + private CraftLivingEntity _lastDamager; + + public int getEntityId() + { + return _npc.getEntityId(); + } + + public CombatLogNPC(Player player, DisguiseManager disguiseManager, HologramManager hologramManager, boolean wasCreative) + { + _playerInfo = new PlayerInfo(player); + _creative = wasCreative; + + _disguiseManager = disguiseManager; + _hologram = new Hologram(hologramManager, player.getEyeLocation().add(0, 1, 0), C.cYellow + UtilTime.MakeStr(NPCManager.COMBAT_LOG_DURATION) + C.cWhite + " Seconds left before despawn"); + _spawnDate = 0; + _endingTime = System.currentTimeMillis() + NPCManager.COMBAT_LOG_DURATION; + _spawnHealth = player.getHealth(); + _hologram.start(); + } + + /** + * Called when the {@code _npc} associated with this CombatLogNPC is killed + * and thus drops all the owner's items. + */ + public void onDeath(CraftLivingEntity killer) + { + Location location = _npc.getLocation(); + World world = location.getWorld(); + + File file = new File(world.getWorldFolder(), String.format("playerdata/%s.dat", _playerInfo.getPlayerUuid())); + file.delete(); // Delete the player's .dat file so they will join with + // empty inventory/respawn on next login + if (killer != null) + { + String killerName = "Unknown"; + + if (killer instanceof CraftPlayer) + { + killerName = ((CraftPlayer) killer).getName(); + } + else + { + killerName = UtilEnt.getName(killer); + } + +// try +// { +// DataOutputStream stream = new DataOutputStream(new FileOutputStream(_userDataPath + String.format("DEATH_%s.dat", _playerInfo.getPlayerUuid()))); +// +// stream.writeLong(System.currentTimeMillis()); +// stream.writeInt(killerName.length()); +// stream.writeBytes(killerName); +// +// stream.close(); +// } +// catch (IOException e) +// { +// System.out.println(String.format("FATAL ERROR while trying to create player death lock for %s, meaning %s will not be informed that they died next time they log in.", _playerInfo.getPlayerName(), _playerInfo.getPlayerName())); +// } + + UtilServer.broadcast(F.main("Death", F.elem(_playerInfo.getPlayerName()) + " was killed by " + F.elem(killerName) + " while combat logged.")); + } + + _playerInfo.dropItems(location); + _disguiseManager.undisguise(_npc); + } + + public void update() + { + _hologram.setText("Quitting in " + UtilTime.MakeStr(Math.max(_endingTime - System.currentTimeMillis(), 0))); + } + + /** + * @return true, if the {@code _npc} associated with this CombatLogNPC is + * alive, false otherwise. + */ + public boolean isAlive() + { + return _npc != null && !_npc.isDead(); + } + + /** + * @return the amount of time (in milliseconds) that this npc has been alive + * an spawned in. + */ + public long getAliveDuation() + { + return System.currentTimeMillis() - _spawnDate; + } + + public void spawn() + { + if (_npc != null) despawn(); + + _npc = spawnNpc(getPlayer()); + _spawnDate = System.currentTimeMillis(); + } + + public void despawn() + { + System.out.println("Despawning"); + if (_npc != null) + { + if (_stand != null) + { + _stand.setPassenger(null); + _stand.remove(); + _stand = null; + } + + _npc.remove(); + _npc = null; + _hologram.stop(); + _hologram = null; + } + } + + public void remove() + { + if (_hologram != null) + { + _hologram.stop(); + _hologram = null; + } + } + + public PlayerInfo getPlayerInfo() + { + return _playerInfo; + } + + public Player getPlayer() + { + return _playerInfo.getPlayer(); + } + + public boolean matchesPlayer(Player player) + { + return _playerInfo.getPlayerName().equalsIgnoreCase(player.getName()); + } + + private LivingEntity spawnNpc(Player player) + { + Location spawnLoc = player.getLocation(); + Skeleton skel = player.getWorld().spawn(spawnLoc, Skeleton.class); + skel.setMetadata("CombatLogNPC", new FixedMetadataValue(UtilServer.getPlugin(), player.getUniqueId().toString())); + skel.teleport(spawnLoc); + skel.setHealth(_spawnHealth); + UtilEnt.vegetate(skel); + UtilEnt.silence(skel, true); + + skel.getEquipment().setHelmet(player.getInventory().getHelmet()); + skel.getEquipment().setChestplate(player.getInventory().getChestplate()); + skel.getEquipment().setLeggings(player.getInventory().getLeggings()); + skel.getEquipment().setBoots(player.getInventory().getBoots()); + skel.getEquipment().setItemInHand(player.getItemInHand()); + + // Get in range + List inRange = UtilPlayer.getNearby(spawnLoc, 75d); + + // Disguise + DisguisePlayer disguise = new DisguisePlayer(skel, ((CraftPlayer) player).getHandle().getProfile()); + _disguiseManager.disguise(disguise, attempted -> inRange.contains(attempted)); + + if (!UtilEnt.isGrounded(player)) + { + ArmorStand stand = player.getWorld().spawn(spawnLoc.clone().subtract(0,1,0), ArmorStand.class); + + stand.setVisible(false); + stand.setPassenger(skel); + stand.setGravity(false); + + _stand = stand; + } + + return skel; + } + + public boolean wasCreative() + { + return _creative; + } + + public CraftLivingEntity getLastDamager() + { + return _lastDamager; + } + + public void setLastDamager(CraftLivingEntity damager) + { + _lastDamager = damager; + } +} \ No newline at end of file diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/NPCManager.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/NPCManager.java new file mode 100644 index 000000000..1a9300bc6 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/NPCManager.java @@ -0,0 +1,253 @@ +package mineplex.gemhunters.death.npc; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Sound; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityCombustEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.world.ChunkUnloadEvent; +import org.bukkit.metadata.FixedMetadataValue; + +import mineplex.core.MiniPlugin; +import mineplex.core.disguise.DisguiseManager; +import mineplex.core.hologram.HologramManager; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; + +public class NPCManager extends MiniPlugin +{ + public static final long COMBAT_LOG_DURATION = 30000; + + private static NPCManager _instance; + + public static NPCManager getInstance() + { + return _instance; + } + + private Set _logoutNpcs; + private Set _toKillIds; + + private HologramManager _hologramManager; + + public NPCManager(HologramManager hologramManager) + { + super("NPC Manager"); + + _instance = this; + _logoutNpcs = new HashSet<>(); + _toKillIds = new HashSet<>(); + _hologramManager = hologramManager; + } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + NPCManager.getInstance().spawnLogoutNpc(event.getPlayer()); + } + + @Override + public void disable() + { + log("Killing logout npcs"); + + // Despawn/kill all combat log NPCs on server shutdown + for (CombatLogNPC npc : _logoutNpcs) + { + npc.despawn(); + } + _logoutNpcs.clear(); + } + + public void spawnLogoutNpc(Player player) + { + if (!hasLogoutNpc(player)) + { + CombatLogNPC npc = new CombatLogNPC(player, require(DisguiseManager.class), _hologramManager, player.getGameMode().equals(GameMode.CREATIVE)); + npc.spawn(); + _logoutNpcs.add(npc); + log(String.format("Spawned combat log NPC for %s!", player.getName())); + } + } + + @EventHandler + public void killNpcs(PlayerJoinEvent event) + { + for (LivingEntity entity : Bukkit.getWorlds().get(0).getLivingEntities()) + { + if (entity.hasMetadata("CombatLogNPC") && ((FixedMetadataValue) entity.getMetadata("CombatLogNPC").get(0)).asString().equals(event.getPlayer().getUniqueId().toString())) + { + entity.remove(); + } + } + } + + public void despawnLogoutNpc(Player player) + { + CombatLogNPC npc = getLogoutNpc(player); + + if (npc != null) + { + _toKillIds.add(npc.getEntityId()); + npc.despawn(); + _logoutNpcs.remove(npc); + log(String.format("Despawned combat log NPC for %s!", player.getName())); + } + } + + public boolean hasLogoutNpc(Player player) + { + return getLogoutNpc(player) != null; + } + + public CombatLogNPC getLogoutNpc(Player player) + { + for (CombatLogNPC logoutNpc : _logoutNpcs) + { + if (logoutNpc.matchesPlayer(player)) + { + return logoutNpc; + } + } + + return null; + } + + @EventHandler + public void onChunkUnload(ChunkUnloadEvent event) + { + for (Entity entity : event.getChunk().getEntities()) + { + for (CombatLogNPC npc : _logoutNpcs) + { + if (entity.getEntityId() == npc.getEntityId()) + { + event.setCancelled(true); + + break; + } + } + } + } + + @EventHandler(ignoreCancelled = true) + public void onEntityDeath(EntityDeathEvent event) + { + CombatLogNPC logoutNpc = getLogoutNpc(event.getEntity()); + + if (logoutNpc != null) + { + logoutNpc.onDeath(logoutNpc.getLastDamager()); + event.getDrops().clear(); // Clear the entity's item drops. Manually + // drops combat log items earlier + } + } + + @EventHandler(ignoreCancelled = true) + public void onEntityDamaged(CustomDamageEvent event) + { + CombatLogNPC logoutNpc = getLogoutNpc(event.GetDamageeEntity()); + + if (logoutNpc != null && event.GetDamagerEntity(true) != null) + { + if (logoutNpc.wasCreative()) + { + event.SetCancelled("Cannot hurt creative player"); + return; + } + + if (event.GetDamagerPlayer(true) != null) + { + event.GetDamagerPlayer(true).playSound(event.GetDamagerPlayer(true).getLocation(), Sound.HURT_FLESH, 1, 1); + } + + logoutNpc.setLastDamager(((CraftLivingEntity) event.GetDamagerEntity(true))); + event.SetKnockback(false); + } + } + + @EventHandler + public void onEntityIgnite(EntityCombustEvent event) + { + if (isLogoutNpc(event.getEntity())) + { + event.setCancelled(true); + } + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (event.getType() == UpdateType.FASTER) + { + for (CombatLogNPC npc : _logoutNpcs) + { + npc.update(); + } + } + + if (event.getType() == UpdateType.SEC) + { + Iterator iterator = _logoutNpcs.iterator(); + + while (iterator.hasNext()) + { + CombatLogNPC npc = iterator.next(); + + if (Bukkit.getPlayer(npc.getPlayerInfo().getPlayerName()) != null) + { + System.out.println("{NPCMANAGER} ORIGINAL PLAYER ALIVE AND DESPAWNING"); + npc.despawn(); + iterator.remove(); + } + else if (!npc.isAlive()) + { + System.out.println("{NPCMANAGER} NOT ALIVE AND REMOVING"); + npc.remove(); + iterator.remove(); + } + else if (npc.getAliveDuation() > COMBAT_LOG_DURATION) + { + System.out.println("{NPCMANAGER} DESPAWNING"); + npc.despawn(); + iterator.remove(); + } + } + } + } + + private boolean isLogoutNpc(Entity entity) + { + return getLogoutNpc(entity) != null; + } + + private CombatLogNPC getLogoutNpc(Entity entity) + { + return getLogoutNpc(entity.getEntityId()); + } + + private CombatLogNPC getLogoutNpc(int entityId) + { + for (CombatLogNPC npc : _logoutNpcs) + { + if (npc.getEntityId() == entityId) + { + return npc; + } + } + + return null; + } +} \ No newline at end of file diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/PlayerInfo.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/PlayerInfo.java new file mode 100644 index 000000000..5044751af --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/PlayerInfo.java @@ -0,0 +1,94 @@ +package mineplex.gemhunters.death.npc; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +public class PlayerInfo +{ + private String _playerName; + private UUID _playerUuid; + private ItemStack[] _armor; + private Set _items; + private Location _location; + + public PlayerInfo(Player player) + { + _playerName = player.getName(); + _playerUuid = player.getUniqueId(); + _armor = player.getInventory().getArmorContents(); + _items = fetchItems(player.getInventory()); + _location = player.getLocation(); + } + + public void dropItems(Location location) + { + World world = location.getWorld(); + for (ItemStack item : _items) + { + world.dropItemNaturally(location, item); + } + } + + public void restore() + { + Player player = getPlayer(); + + player.getInventory().setArmorContents(_armor); + player.getInventory().addItem(_items.toArray(new ItemStack[0])); + player.teleport(_location); + } + + public String getPlayerName() + { + return _playerName; + } + + public Set getItems() + { + return _items; + } + + public UUID getUniqueId() + { + return _playerUuid; + } + + public String getPlayerUuid() + { + return _playerUuid.toString(); + } + + public Player getPlayer() + { + return Bukkit.getPlayerExact(_playerName); + } + + private Set fetchItems(PlayerInventory inventory) + { + Set items = new HashSet(); + + addItems(items, inventory.getContents()); + + return items; + } + + private void addItems(Set items, ItemStack[] itemsToAdd) + { + for (ItemStack item : itemsToAdd) + { + if (item != null && item.getType() != Material.AIR) + { + items.add(item); + } + } + } +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index e82457176..421101c7d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -32,7 +32,6 @@ import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilInv; -import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; @@ -178,7 +177,7 @@ public class LootModule extends MiniPlugin { return false; } - + return true; } @@ -311,6 +310,8 @@ public class LootModule extends MiniPlugin while (!suitable && attempts < MAX_SEARCH_ATTEMPTS) { + chestToPlace = UtilAlg.getRandomLocation(randomLocation, placeRadius, 0, placeRadius); + block = chestToPlace.getBlock(); suitable = isSuitable(block); attempts++; } @@ -357,12 +358,6 @@ public class LootModule extends MiniPlugin ItemStack itemStack = lootItem.getItemStack(); int index = getFreeIndex(inventory.getSize(), used); - // if (lootItem.getMetadata() != null) - // { - // UtilFirework.playFirework(block.getLocation().add(0.5, 1, 0.5), - // UtilFirework.getRandomFireworkEffect(false, 2, 1)); - // } - inventory.setItem(index, itemStack); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/MountModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/MountModule.java index 72cc23b13..010dea756 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/MountModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/mount/MountModule.java @@ -16,6 +16,7 @@ import org.bukkit.inventory.ItemStack; import mineplex.core.MiniClientPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.common.util.F; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.gadget.GadgetManager; @@ -92,7 +93,8 @@ public class MountModule extends MiniClientPlugin mountType = mount.getMountType(); } - spawnMount(player, mountType); + player.sendMessage(F.main(_moduleName, "Mounts are currently disabled.")); + //spawnMount(player, mountType); } public void spawnMount(Player player, MountType mountType) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java index 3e0fbbf56..ed4d72bac 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java @@ -87,7 +87,7 @@ public class QuestModule extends MiniClientPlugin updateQuests(event.getPlayer()); } - @EventHandler + //@EventHandler public void update(UpdateEvent event) { if (event.getType() != UpdateType.SLOW) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java index 4db8482fe..a94690840 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java @@ -134,7 +134,9 @@ public class TraderNPC extends SimpleNPC { for (TradeableItem item : _selling) { - if (item.getLootItem().getItemStack().getType() == itemStack.getType()) + ItemStack itemStack2 = item.getLootItem().getItemStack(); + + if (itemStack.getType() == itemStack2.getType()) { return item.getCost(); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index 11b8f6cbd..200761968 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -23,6 +23,9 @@ import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilServer; import mineplex.core.portal.Intent; import mineplex.core.portal.Portal; +import mineplex.gemhunters.death.npc.CombatLogNPC; +import mineplex.gemhunters.death.npc.NPCManager; +import mineplex.gemhunters.death.npc.PlayerInfo; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.spawn.event.PlayerTeleportIntoMapEvent; import mineplex.gemhunters.util.ColouredTextAnimation; @@ -61,12 +64,23 @@ public class SpawnModule extends MiniPlugin } Player player = event.getPlayer(); - + NPCManager npcManager = NPCManager.getInstance(); + + if (npcManager.hasLogoutNpc(player)) + { + CombatLogNPC npc = npcManager.getLogoutNpc(player); + PlayerInfo info = npc.getPlayerInfo(); + + info.restore(); + return; + } + player.teleport(_spawn); player.setFoodLevel(20); player.setExhaustion(0); player.getInventory().clear(); player.getInventory().setArmorContents(null); + player.updateInventory(); if (_npcsSpawned) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java index d41f535c6..8f2ca4203 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java @@ -72,8 +72,6 @@ public class SupplyDrop _lastHelicopter = new HashSet<>(100); _bladeBlocks = new HashSet<>(20); _diagonal = false; - - spawn.getChunk().load(); } public boolean advancePath() @@ -92,6 +90,8 @@ public class SupplyDrop public boolean moveHelicopter() { + _current.getChunk().load(); + for (Block block : _lastHelicopter) { block.setType(Material.AIR); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/UndergroundMobs.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/UndergroundMobs.java index f36b5a778..b1e2ba508 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/UndergroundMobs.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/UndergroundMobs.java @@ -13,6 +13,8 @@ import org.bukkit.entity.Spider; import org.bukkit.entity.Zombie; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.Managers; @@ -25,7 +27,7 @@ import mineplex.gemhunters.debug.DebugModule; public class UndergroundMobs implements Listener { - private static final int MAX_MOBS = 300; + private static final int MAX_MOBS = 500; private static final String SEWER_KEY = "SEWER_MOB"; private static final String SUBWAY_KEY = "SUBWAY_MOBS"; @@ -88,5 +90,14 @@ public class UndergroundMobs implements Listener } } } + + @EventHandler + public void cancelSuffication(EntityDamageEvent event) + { + if (event.getCause() == DamageCause.SUFFOCATION && _entities.contains(event.getEntity())) + { + event.setCancelled(true); + } + } } From 9ece8c99597b296bdb419f30cb83620fc7c33e21 Mon Sep 17 00:00:00 2001 From: cnr Date: Thu, 23 Feb 2017 23:35:31 -0600 Subject: [PATCH 058/101] Add beta whitelist miniplugin --- .../src/mineplex/core/beta/BetaWhitelist.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java b/Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java new file mode 100644 index 000000000..6c47fa235 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java @@ -0,0 +1,69 @@ +package mineplex.core.beta; + +import java.util.Set; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; + +import com.google.common.collect.ImmutableSet; + +import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.bonuses.BonusManager; +import mineplex.core.common.Rank; +import mineplex.core.powerplayclub.PowerPlayClubRepository; + +public class BetaWhitelist extends MiniPlugin +{ + private static final Set EXTRA_PLAYERS = ImmutableSet.builder() + // GI Members + .add(UUID.fromString("8506533f-1da7-4d5c-a835-a483b5a18b54")) // Awquard + .add(UUID.fromString("a8526c97-95be-4cb7-ae58-7df5d3b108a6")) // ASlime + .add(UUID.fromString("ae6d71b7-3d49-429f-b31f-5cf5af136540")) // Cabob + .add(UUID.fromString("ea1f709c-031f-4028-8f7d-2073c5a37d1a")) // CharlieHacks + .add(UUID.fromString("d3c1457a-1084-43e1-846c-addc47393b90")) // Chocobutter + .add(UUID.fromString("6b60782e-f95b-4449-a39e-0ad7fa5fdab0")) // CosmoLink + .add(UUID.fromString("18697323-50d3-47ea-a5c2-e7ac1a0d9fa0")) // Danah + .add(UUID.fromString("1cc18d8d-ab28-4354-8cce-f93fb06423bf")) // Fetch + .add(UUID.fromString("c56e5b96-8dc3-46ca-b682-24cf8467e3a1")) // KingOfWizards + .add(UUID.fromString("ea30fe99-2044-438f-bfd8-97bcc639239e")) // Mauo + .add(UUID.fromString("933b2f93-806a-4f39-88a2-935442418ae5")) // Tier4Global + .add(UUID.fromString("ac239b94-3079-4a8a-a52f-7b81c8a87b4d")) // Paddi + .add(UUID.fromString("3ced328d-f079-45e4-ad71-8c721c4a699b")) // Smaland47 + .add(UUID.fromString("d51fc65b-fce9-4464-9391-b259525dc6ca")) // SnitSays + .add(UUID.fromString("12bbeda2-567a-400a-9d66-f76fab832de0")) // StoneColdKiller + .add(UUID.fromString("2e0c1d88-7f44-44f5-85b4-9ad0b2cfddce")) // Tours + .add(UUID.fromString("32aff2d0-f68c-4eb9-b5d4-139fc48b7ca6")) // Trimzon + .add(UUID.fromString("3dcfe366-fcaa-48f7-abcc-b73fb62616e1")) // gamefish32 + .add(UUID.fromString("6795643a-2b61-41bf-9429-c7549fd128a8")) // umGim + .add(UUID.fromString("47ba454a-4999-42f4-a269-2f4114ceb3c7")) // falconviii + .build(); + private final CoreClientManager _clientManager; + private final PowerPlayClubRepository _powerPlayClubRepository; + + public BetaWhitelist(BonusManager manager) + { + super("Beta Whitelist"); + _clientManager = manager.getClientManager(); + _powerPlayClubRepository = manager.getPowerPlayClubRepository(); + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + Rank rank = _clientManager.Get(player).GetRank(true); + if ((rank != Rank.MAPDEV && rank != Rank.MAPLEAD && rank.has(Rank.TWITCH) // If this player is Twitch+ (and not a builder), + || _powerPlayClubRepository.getCachedData(player).isSubscribed()) // a PPC subscriber, + || EXTRA_PLAYERS.contains(player.getUniqueId())) // or explicitly whitelisted, + { + return; // allow them in + } + + // Otherwise, kick them out + event.getPlayer().kickPlayer("Sorry, you aren't whitelisted on this beta server.\n\nSubscribe to " + ChatColor.GOLD + "Power Play Club " + ChatColor.WHITE + "at " + ChatColor.GREEN + "mineplex.com/shop" + ChatColor.WHITE + "!"); + } +} From af8b5f65224923b8a88cd4bc725898dd89bd25e8 Mon Sep 17 00:00:00 2001 From: cnr Date: Wed, 22 Feb 2017 17:41:23 -0600 Subject: [PATCH 059/101] Add Mineplexer support for beta lobbies --- .../bungee/lobbyBalancer/LobbyBalancer.java | 129 +++++++++-------- .../bungee/lobbyBalancer/LobbyType.java | 34 +++++ .../src/mineplex/bungee/motd/MotdManager.java | 130 +++++------------- 3 files changed, 133 insertions(+), 160 deletions(-) create mode 100644 Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyType.java diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java index de8602e07..fca669fba 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyBalancer.java @@ -2,33 +2,34 @@ package mineplex.bungee.lobbyBalancer; import java.io.File; import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.EnumMap; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; -import mineplex.serverdata.Region; -import mineplex.serverdata.data.MinecraftServer; -import mineplex.serverdata.servers.ServerManager; -import mineplex.serverdata.servers.ServerRepository; import net.md_5.bungee.api.event.ServerConnectEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.event.EventHandler; -import com.google.common.collect.Lists; +import mineplex.serverdata.Region; +import mineplex.serverdata.data.MinecraftServer; +import mineplex.serverdata.servers.ServerManager; +import mineplex.serverdata.servers.ServerRepository; public class LobbyBalancer implements Listener, Runnable { private Plugin _plugin; private ServerRepository _repository; - - private List _sortedLobbies = Lists.newArrayList(); - private List _sortedClans = Lists.newArrayList(); - private static Object _serverLock = new Object(); - - private int _lobbyIndex = 0; - private int _clansIndex = 0; + + private final Map> _sortedLobbyMap = new EnumMap<>(LobbyType.class); + private final Map _nextIndexMap = new EnumMap<>(LobbyType.class); + private static final LobbySorter LOBBY_SORTER = new LobbySorter(); + private static final Object _serverLock = new Object(); public LobbyBalancer(Plugin plugin) { @@ -46,45 +47,42 @@ public class LobbyBalancer implements Listener, Runnable @EventHandler public void playerConnect(ServerConnectEvent event) { - if (event.getTarget().getName().equalsIgnoreCase("Lobby")) - { - synchronized (_serverLock) - { - if (_lobbyIndex >= _sortedLobbies.size() || _sortedLobbies.get(_lobbyIndex).getPlayerCount() >= _sortedLobbies.get(_lobbyIndex).getMaxPlayerCount()) - _lobbyIndex = 0; + Arrays.stream(LobbyType.values()) + .filter(type -> type.getConnectName().equalsIgnoreCase(event.getTarget().getName())) + .findFirst() + .ifPresent(lobbyType -> + { + synchronized (_serverLock) + { + List lobbies = _sortedLobbyMap.get(lobbyType); - event.setTarget(_plugin.getProxy().getServerInfo(_sortedLobbies.get(_lobbyIndex).getName())); - _sortedLobbies.get(_lobbyIndex).incrementPlayerCount(1); - System.out.println("Sending " + event.getPlayer().getName() + " to " + _sortedLobbies.get(_lobbyIndex).getName() + "(" + _sortedLobbies.get(_lobbyIndex).getPublicAddress() + ")"); - _lobbyIndex++; - } - } - if (event.getTarget().getName().equalsIgnoreCase("ClansHub")) - { - synchronized (_serverLock) - { - if (_clansIndex >= _sortedClans.size() || _sortedClans.get(_clansIndex).getPlayerCount() >= _sortedClans.get(_clansIndex).getMaxPlayerCount()) - _clansIndex = 0; + int nextIndex = _nextIndexMap.getOrDefault(lobbyType, 0); + if (nextIndex >= lobbies.size()) + { + nextIndex = 0; + } - event.setTarget(_plugin.getProxy().getServerInfo(_sortedClans.get(_clansIndex).getName())); - _sortedClans.get(_clansIndex).incrementPlayerCount(1); - System.out.println("Sending " + event.getPlayer().getName() + " to " + _sortedClans.get(_clansIndex).getName() + "(" + _sortedClans.get(_clansIndex).getPublicAddress() + ")"); - _clansIndex++; - } - } + MinecraftServer server = lobbies.get(nextIndex); + + event.setTarget(_plugin.getProxy().getServerInfo(server.getName())); + server.incrementPlayerCount(1); + System.out.println("Sending " + event.getPlayer().getName() + " to " + server.getName() + "(" + server.getPublicAddress() + ")"); + + _nextIndexMap.put(lobbyType, ++nextIndex); + } + }); } public void run() { loadServers(); - - if (!_plugin.getProxy().getServers().containsKey("ClansHub")) + + for (LobbyType type : LobbyType.values()) { - _plugin.getProxy().getServers().put("ClansHub", _plugin.getProxy().constructServerInfo("ClansHub", new InetSocketAddress("lobby.mineplex.com", 25565), "LobbyBalancer", false)); - } - if (!_plugin.getProxy().getServers().containsKey("Lobby")) - { - _plugin.getProxy().getServers().put("Lobby", _plugin.getProxy().constructServerInfo("Lobby", new InetSocketAddress("lobby.mineplex.com", 25565), "LobbyBalancer", false)); + if (!_plugin.getProxy().getServers().containsKey(type.getConnectName())) + { + _plugin.getProxy().getServers().put(type.getConnectName(), _plugin.getProxy().constructServerInfo(type.getConnectName(), new InetSocketAddress("lobby.mineplex.com", 25565), "LobbyBalancer", false)); + } } } @@ -95,9 +93,12 @@ public class LobbyBalancer implements Listener, Runnable synchronized (_serverLock) { long startTime = System.currentTimeMillis(); - _sortedLobbies.clear(); - _sortedClans.clear(); - + _sortedLobbyMap.clear(); + for (LobbyType type : LobbyType.values()) + { + _sortedLobbyMap.put(type, new ArrayList<>()); + } + for (MinecraftServer server : servers) { if (server.getName() == null) @@ -105,32 +106,26 @@ public class LobbyBalancer implements Listener, Runnable InetSocketAddress socketAddress = new InetSocketAddress(server.getPublicAddress(), server.getPort()); _plugin.getProxy().getServers().put(server.getName(), _plugin.getProxy().constructServerInfo(server.getName(), socketAddress, "LobbyBalancer", false)); - - if (server.getName().toUpperCase().startsWith("LOBBY-")) - { - if (server.getMotd() == null || !server.getMotd().contains("Restarting")) - { - _sortedLobbies.add(server); - } - } - if (server.getName().toUpperCase().startsWith("CLANSHUB-")) - { - if (server.getMotd() == null || !server.getMotd().contains("Restarting")) - { - _sortedClans.add(server); - } - } + + if (server.getMotd() != null && server.getMotd().contains("Restarting")) + { + continue; + } + + Arrays.stream(LobbyType.values()) + .filter(type -> server.getName().toUpperCase().startsWith(type.getUppercasePrefix())) + .findFirst() + .ifPresent(type -> _sortedLobbyMap.get(type).add(server)); } - - Collections.sort(_sortedLobbies, new LobbySorter()); - Collections.sort(_sortedClans, new LobbySorter()); - + + _sortedLobbyMap.values().forEach(lobbies -> Collections.sort(lobbies, LOBBY_SORTER)); + long timeSpentInLock = System.currentTimeMillis() - startTime; if (timeSpentInLock > 50) System.out.println("[==] TIMING [==] Locked loading servers for " + timeSpentInLock + "ms"); - - _lobbyIndex = 0; + + _nextIndexMap.clear(); } } } diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyType.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyType.java new file mode 100644 index 000000000..8b4e4fb5d --- /dev/null +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/lobbyBalancer/LobbyType.java @@ -0,0 +1,34 @@ +package mineplex.bungee.lobbyBalancer; + +public enum LobbyType +{ + NORMAL("Lobby", "LOBBY-", "MainMotd"), + CLANS("ClansHub", "CLANSHUB-", "ClansMotd"), + BETA("BetaHub","BETAHUB-", "BetaMotd"), + ; + private final String _connectName; // The name of the server the player is connecting to + private final String _uppercasePrefix; // The (toUpperCase()) prefix given to servers of this lobby type + private final String _redisMotdKey; + + LobbyType(String connectName, String uppercasePrefix, String redisMotdKey) + { + _connectName = connectName; + _uppercasePrefix = uppercasePrefix; + _redisMotdKey = redisMotdKey; + } + + public String getConnectName() + { + return _connectName; + } + + public String getUppercasePrefix() + { + return _uppercasePrefix; + } + + public String getRedisMotdKey() + { + return _redisMotdKey; + } +} diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/motd/MotdManager.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/motd/MotdManager.java index aa2565f27..4b556d2e2 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/motd/MotdManager.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/motd/MotdManager.java @@ -1,138 +1,82 @@ package mineplex.bungee.motd; -import java.io.File; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; +import java.util.EnumMap; +import java.util.Map; +import java.util.Optional; import java.util.Random; import java.util.concurrent.TimeUnit; -import mineplex.serverdata.Region; -import mineplex.serverdata.data.DataRepository; -import mineplex.serverdata.redis.RedisDataRepository; -import mineplex.serverdata.servers.ConnectionData; -import mineplex.serverdata.servers.ConnectionData.ConnectionType; -import mineplex.serverdata.servers.ServerManager; import net.md_5.bungee.api.event.ProxyPingEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.event.EventHandler; +import mineplex.bungee.lobbyBalancer.LobbyType; +import mineplex.serverdata.Region; +import mineplex.serverdata.data.DataRepository; +import mineplex.serverdata.redis.RedisDataRepository; +import mineplex.serverdata.servers.ServerManager; + public class MotdManager implements Listener, Runnable { - private Plugin _plugin; - - private DataRepository _repository; - private DataRepository _secondRepository; - private Region _region; - - private Random _random = new Random(); - private String _firstLine = " §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r"; - private List _motdLines; - private String _firstCLine = " §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r"; - private List _motdCLines; + private static final String DEFAULT_HEADLINE = " §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r"; + + private final DataRepository _repository; + private final Random _random = new Random(); + private final Map motds = new EnumMap<>(LobbyType.class); public MotdManager(Plugin plugin) { - _plugin = plugin; - _region = !new File("eu.dat").exists() ? Region.US : Region.EU; - - _plugin.getProxy().getScheduler().schedule(_plugin, this, 5L, 30L, TimeUnit.SECONDS); - _plugin.getProxy().getPluginManager().registerListener(_plugin, this); + plugin.getProxy().getScheduler().schedule(plugin, this, 5L, 30L, TimeUnit.SECONDS); + plugin.getProxy().getPluginManager().registerListener(plugin, this); _repository = new RedisDataRepository(ServerManager.getConnection(true, ServerManager.SERVER_STATUS_LABEL), ServerManager.getConnection(false, ServerManager.SERVER_STATUS_LABEL), Region.ALL, GlobalMotd.class, "globalMotd"); run(); - - if (new File("updateMOTD.dat").exists()) - { - if (_region == Region.US) - _secondRepository = new RedisDataRepository(new ConnectionData("10.81.1.156", 6379, ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.81.1.156", 6377, ConnectionType.SLAVE, "ServerStatus"), - Region.ALL, GlobalMotd.class, "globalMotd"); - else - _secondRepository = new RedisDataRepository(new ConnectionData("10.33.53.16", 6379, ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.33.53.16", 6377, ConnectionType.SLAVE, "ServerStatus"), - Region.ALL, GlobalMotd.class, "globalMotd"); - - //String motdLine = "§f§l◄ §c§lMaintenance§f§l ►"; - //String motdLine = "§f§l◄ §a§lCarl the Creeper§f§l ►"; -// String motdLine = " §2§l§n M O N S T E R M A Z E B E T A §f"; - String motdLine = " §f> §4§lCLANS BETA §f- §c§lOpen to Everyone §f<"; -// String motdLine = " §f❄ §2§lServer Maintenance §f❄ §2§lBe Back Soon §f❄"; - //String motdLine = " §d§lRank Sale §a§l40% Off"); - //String motdLine = " §f§l◄§c§lMAINTENANCE§f§l►"); - - updateMainMotd(" §f§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§f§m §r", motdLine); - System.out.println("Updated Bungee MOTD"); - } } @EventHandler public void serverPing(ProxyPingEvent event) { + net.md_5.bungee.api.ServerPing serverPing = event.getResponse(); - if (event.getConnection().getListener() != null && event.getConnection().getListener().getDefaultServer().equalsIgnoreCase("ClansHub")) + Optional maybeType = Optional.empty(); + + if (event.getConnection().getListener() != null) { - String motd = _firstCLine; - if (_motdCLines != null && _motdCLines.size() > 0) - { - motd += "\n" + _motdCLines.get(_random.nextInt(_motdCLines.size())); - } - event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), serverPing.getPlayers(), motd, serverPing.getFaviconObject())); + maybeType = Arrays.stream(LobbyType.values()) + .filter(type -> event.getConnection().getListener().getDefaultServer().equalsIgnoreCase(type.getConnectName())) + .findFirst(); } - else + + LobbyType lobbyType = maybeType.orElse(LobbyType.NORMAL); + GlobalMotd globalMotd = motds.get(lobbyType); + + String motd = DEFAULT_HEADLINE; + if (globalMotd != null && globalMotd.getHeadline() != null) { - String motd = _firstLine; - if (_motdLines != null && _motdLines.size() > 0) + motd = globalMotd.getHeadline() == null ? DEFAULT_HEADLINE : globalMotd.getHeadline(); + if (globalMotd.getMotd() != null) { - motd += "\n" + _motdLines.get(_random.nextInt(_motdLines.size())); + motd += "\n" + globalMotd.getMotd().get(_random.nextInt(globalMotd.getMotd().size())); } - event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), serverPing.getPlayers(), motd, serverPing.getFaviconObject())); } + + event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), serverPing.getPlayers(), motd, serverPing.getFaviconObject())); } @Override public void run() { + for (LobbyType type : LobbyType.values()) { - GlobalMotd motd = _repository.getElement("MainMotd"); + GlobalMotd motd = _repository.getElement(type.getRedisMotdKey()); if (motd != null) - { - _motdLines = motd.getMotd(); - _firstLine = motd.getHeadline(); - } - } - { - GlobalMotd motd = _repository.getElement("ClansMotd"); - - if (motd != null) - { - _motdCLines = motd.getMotd(); - _firstCLine = motd.getHeadline(); - } - else { - _repository.addElement(new GlobalMotd("ClansMotd", "§4§lMineplex Clans§r", Arrays.asList("Default MOTD"))); + motds.put(type, motd); } } } - - /** - * Update the main {@link GlobalMotd} determining the MOTD for Bungee instances. - * @param motdLines - the lines to update the MOTD to. - */ - public void updateMainMotd(String headline, String motdLine) - { - List motdLines = new ArrayList(); - - motdLines.add(motdLine); - - _repository.addElement(new GlobalMotd("MainMotd", headline, motdLines)); - _secondRepository.addElement(new GlobalMotd("MainMotd", headline, motdLines)); - } - - public List getMotdLines() - { - return _motdLines; - } } From 60d9bd5d210150e87d6f7920b5dbaf79a31bb1be Mon Sep 17 00:00:00 2001 From: samczsun Date: Fri, 20 Jan 2017 18:04:06 -0500 Subject: [PATCH 060/101] Move api to config file --- .../src/mineplex/core/common/api/ApiHost.java | 81 ++++++++++++++++--- .../api/enderchest/EnderchestWorldLoader.java | 2 +- .../repository/AntiSpamRepository.java | 2 +- .../core/boosters/BoosterRepository.java | 2 +- 4 files changed, 73 insertions(+), 14 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/ApiHost.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/ApiHost.java index a168c3540..a6dd1cbae 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/ApiHost.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/ApiHost.java @@ -1,21 +1,80 @@ package mineplex.core.common.api; -/** - * TODO: Store this in a file instead of being hardcoded - * - * @author Shaun Bennett - */ -public enum ApiHost +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.configuration.file.YamlConfiguration; + +public class ApiHost { - AMPLIFIERS("10.33.53.12", 7979), - ANTISPAM("10.33.53.12", 8181), - ENDERCHEST("10.33.53.10", 8010) - ; + private static final String API_HOST_FILE = "api-config.dat"; + private static final Object LOCK = new Object(); + + private static volatile boolean LOADED = false; + + private static final Map API_HOST_MAP = new HashMap<>(); + + public static ApiHost getAPIHost(String identifier) + { + if (!LOADED) + { + synchronized (LOCK) + { + if (!LOADED) + { + try + { + File configFile = new File(API_HOST_FILE); + YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile); + + for (String key : configuration.getKeys(false)) + { + String ip = configuration.getConfigurationSection(key).getString("ip"); + // Use parseInt to catch non-ints instead of a 0 + int port = Integer.parseInt(configuration.getConfigurationSection(key).getString("port")); + if (ip == null) + { + throw new NullPointerException(); + } + + API_HOST_MAP.put(key, new ApiHost(ip, port)); + } + } + catch (Throwable t) + { + t.printStackTrace(); + } + finally + { + LOADED = true; + } + } + } + } + + return API_HOST_MAP.get(identifier); + } + + public static ApiHost getAmplifierService() + { + return getAPIHost("AMPLIFIERS"); + } + + public static ApiHost getAntispamService() + { + return getAPIHost("ANTISPAM"); + } + + public static ApiHost getEnderchestService() + { + return getAPIHost("ENDERCHEST"); + } private String _host; private int _port; - ApiHost(String host, int port) + private ApiHost(String host, int port) { _host = host; _port = port; diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/enderchest/EnderchestWorldLoader.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/enderchest/EnderchestWorldLoader.java index 0a782d6d7..5a196c26e 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/enderchest/EnderchestWorldLoader.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/enderchest/EnderchestWorldLoader.java @@ -18,7 +18,7 @@ public class EnderchestWorldLoader public EnderchestWorldLoader() { - String url = "http://" + ApiHost.ENDERCHEST.getHost() + ":" + ApiHost.ENDERCHEST.getPort() + "/"; + String url = "http://" + ApiHost.getEnderchestService().getHost() + ":" + ApiHost.getEnderchestService().getPort() + "/"; _webCall = new ApiWebCall(url); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antispam/repository/AntiSpamRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/antispam/repository/AntiSpamRepository.java index 4211d3116..be920e079 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antispam/repository/AntiSpamRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antispam/repository/AntiSpamRepository.java @@ -17,7 +17,7 @@ public class AntiSpamRepository extends ApiEndpoint { public AntiSpamRepository() { - super(ApiHost.ANTISPAM, "/chat"); + super(ApiHost.getAntispamService(), "/chat"); } public AntiSpamApiResponse sendMessage(String source, ChatPayload payload) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterRepository.java index 25e8c2c64..2f42602e9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterRepository.java @@ -24,7 +24,7 @@ public class BoosterRepository extends ApiEndpoint { public BoosterRepository() { - super(ApiHost.AMPLIFIERS, "/booster", new GsonBuilder().setFieldNamingStrategy(new ApiFieldNamingStrategy()) + super(ApiHost.getAmplifierService(), "/booster", new GsonBuilder().setFieldNamingStrategy(new ApiFieldNamingStrategy()) // .registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()) .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX").create()); } From fb70c93f918f1e23b96e29d2caf94905468a0097 Mon Sep 17 00:00:00 2001 From: cnr Date: Thu, 23 Feb 2017 23:35:31 -0600 Subject: [PATCH 061/101] Add beta whitelist miniplugin --- .../src/mineplex/core/beta/BetaWhitelist.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java b/Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java new file mode 100644 index 000000000..6c47fa235 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java @@ -0,0 +1,69 @@ +package mineplex.core.beta; + +import java.util.Set; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; + +import com.google.common.collect.ImmutableSet; + +import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.bonuses.BonusManager; +import mineplex.core.common.Rank; +import mineplex.core.powerplayclub.PowerPlayClubRepository; + +public class BetaWhitelist extends MiniPlugin +{ + private static final Set EXTRA_PLAYERS = ImmutableSet.builder() + // GI Members + .add(UUID.fromString("8506533f-1da7-4d5c-a835-a483b5a18b54")) // Awquard + .add(UUID.fromString("a8526c97-95be-4cb7-ae58-7df5d3b108a6")) // ASlime + .add(UUID.fromString("ae6d71b7-3d49-429f-b31f-5cf5af136540")) // Cabob + .add(UUID.fromString("ea1f709c-031f-4028-8f7d-2073c5a37d1a")) // CharlieHacks + .add(UUID.fromString("d3c1457a-1084-43e1-846c-addc47393b90")) // Chocobutter + .add(UUID.fromString("6b60782e-f95b-4449-a39e-0ad7fa5fdab0")) // CosmoLink + .add(UUID.fromString("18697323-50d3-47ea-a5c2-e7ac1a0d9fa0")) // Danah + .add(UUID.fromString("1cc18d8d-ab28-4354-8cce-f93fb06423bf")) // Fetch + .add(UUID.fromString("c56e5b96-8dc3-46ca-b682-24cf8467e3a1")) // KingOfWizards + .add(UUID.fromString("ea30fe99-2044-438f-bfd8-97bcc639239e")) // Mauo + .add(UUID.fromString("933b2f93-806a-4f39-88a2-935442418ae5")) // Tier4Global + .add(UUID.fromString("ac239b94-3079-4a8a-a52f-7b81c8a87b4d")) // Paddi + .add(UUID.fromString("3ced328d-f079-45e4-ad71-8c721c4a699b")) // Smaland47 + .add(UUID.fromString("d51fc65b-fce9-4464-9391-b259525dc6ca")) // SnitSays + .add(UUID.fromString("12bbeda2-567a-400a-9d66-f76fab832de0")) // StoneColdKiller + .add(UUID.fromString("2e0c1d88-7f44-44f5-85b4-9ad0b2cfddce")) // Tours + .add(UUID.fromString("32aff2d0-f68c-4eb9-b5d4-139fc48b7ca6")) // Trimzon + .add(UUID.fromString("3dcfe366-fcaa-48f7-abcc-b73fb62616e1")) // gamefish32 + .add(UUID.fromString("6795643a-2b61-41bf-9429-c7549fd128a8")) // umGim + .add(UUID.fromString("47ba454a-4999-42f4-a269-2f4114ceb3c7")) // falconviii + .build(); + private final CoreClientManager _clientManager; + private final PowerPlayClubRepository _powerPlayClubRepository; + + public BetaWhitelist(BonusManager manager) + { + super("Beta Whitelist"); + _clientManager = manager.getClientManager(); + _powerPlayClubRepository = manager.getPowerPlayClubRepository(); + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + Rank rank = _clientManager.Get(player).GetRank(true); + if ((rank != Rank.MAPDEV && rank != Rank.MAPLEAD && rank.has(Rank.TWITCH) // If this player is Twitch+ (and not a builder), + || _powerPlayClubRepository.getCachedData(player).isSubscribed()) // a PPC subscriber, + || EXTRA_PLAYERS.contains(player.getUniqueId())) // or explicitly whitelisted, + { + return; // allow them in + } + + // Otherwise, kick them out + event.getPlayer().kickPlayer("Sorry, you aren't whitelisted on this beta server.\n\nSubscribe to " + ChatColor.GOLD + "Power Play Club " + ChatColor.WHITE + "at " + ChatColor.GREEN + "mineplex.com/shop" + ChatColor.WHITE + "!"); + } +} From eed784da0406ea0088c797a79e73aaf673f9831d Mon Sep 17 00:00:00 2001 From: cnr Date: Thu, 23 Feb 2017 23:48:24 -0600 Subject: [PATCH 062/101] Add beta whitelist to GemHunters and remove missing debug references --- .../src/mineplex/core/beta/BetaWhitelist.java | 7 +++---- .../src/mineplex/gemhunters/GemHunters.java | 13 +++++++++---- .../mineplex/gemhunters/loot/InventoryModule.java | 7 +++---- .../src/mineplex/gemhunters/loot/LootModule.java | 4 +--- .../gemhunters/loot/rewards/LootChestReward.java | 3 +-- .../gemhunters/loot/rewards/LootGadgetReward.java | 5 ++--- .../gemhunters/loot/rewards/LootItemReward.java | 3 +-- .../gemhunters/quest/types/ChestOpenerQuest.java | 3 +-- .../src/mineplex/gemhunters/shop/ShopModule.java | 4 +--- .../mineplex/gemhunters/world/UndergroundMobs.java | 3 +-- .../mineplex/gemhunters/world/WorldListeners.java | 5 ++--- 11 files changed, 25 insertions(+), 32 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java b/Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java index 6c47fa235..7e1a30617 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java @@ -12,7 +12,6 @@ import com.google.common.collect.ImmutableSet; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; -import mineplex.core.bonuses.BonusManager; import mineplex.core.common.Rank; import mineplex.core.powerplayclub.PowerPlayClubRepository; @@ -44,11 +43,11 @@ public class BetaWhitelist extends MiniPlugin private final CoreClientManager _clientManager; private final PowerPlayClubRepository _powerPlayClubRepository; - public BetaWhitelist(BonusManager manager) + public BetaWhitelist(CoreClientManager clientManager, PowerPlayClubRepository powerPlayRepository) { super("Beta Whitelist"); - _clientManager = manager.getClientManager(); - _powerPlayClubRepository = manager.getPowerPlayClubRepository(); + _clientManager = clientManager; + _powerPlayClubRepository = powerPlayRepository; } @EventHandler diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index e7c6a9b37..9bd47124d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -1,6 +1,6 @@ package mineplex.gemhunters; -import static mineplex.core.Managers.require; +import net.minecraft.server.v1_8_R3.MinecraftServer; import org.bukkit.World; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; @@ -12,6 +12,7 @@ import mineplex.core.FoodDupeFix; import mineplex.core.TimingsFix; import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; +import mineplex.core.beta.BetaWhitelist; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.boosters.BoosterManager; import mineplex.core.chat.Chat; @@ -44,6 +45,7 @@ import mineplex.core.packethandler.PacketHandler; import mineplex.core.party.PartyManager; import mineplex.core.pet.PetManager; import mineplex.core.portal.Portal; +import mineplex.core.powerplayclub.PowerPlayClubRepository; import mineplex.core.preferences.PreferencesManager; import mineplex.core.projectile.ProjectileManager; import mineplex.core.punish.Punish; @@ -61,7 +63,6 @@ import mineplex.gemhunters.bounties.BountyModule; import mineplex.gemhunters.chat.ChatModule; import mineplex.gemhunters.death.DeathModule; import mineplex.gemhunters.death.npc.NPCManager; -import mineplex.gemhunters.debug.DebugModule; import mineplex.gemhunters.economy.CashOutModule; import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.loot.InventoryModule; @@ -81,7 +82,8 @@ import mineplex.gemhunters.worldevent.WorldEventModule; import mineplex.minecraft.game.core.combat.CombatManager; import mineplex.minecraft.game.core.condition.ConditionManager; import mineplex.minecraft.game.core.damage.DamageManager; -import net.minecraft.server.v1_8_R3.MinecraftServer; + +import static mineplex.core.Managers.require; /** * Gem Hunters main class
@@ -245,7 +247,7 @@ public class GemHunters extends JavaPlugin // Though if any other module needs one of these it will be generated in // order, however they are all here just for good measure.s require(BetaModule.class); - require(DebugModule.class); + //require(DebugModule.class); require(BountyModule.class); require(CashOutModule.class); require(ChatModule.class); @@ -284,6 +286,9 @@ public class GemHunters extends JavaPlugin // Turn off the server's debugging MinecraftServer.getServer().getPropertyManager().setProperty("debug", false); SpigotConfig.debug = false; + + // beta whitelist + new BetaWhitelist(clientManager, new PowerPlayClubRepository(this, clientManager, donationManager)); } @Override diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java index 0f72525fd..1ea26c086 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java @@ -23,7 +23,6 @@ import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilInv; import mineplex.core.itemstack.ItemBuilder; import mineplex.gemhunters.death.event.PlayerCustomRespawnEvent; -import mineplex.gemhunters.debug.DebugModule; @ReflectivelyCreateMiniPlugin public class InventoryModule extends MiniPlugin @@ -119,9 +118,9 @@ public class InventoryModule extends MiniPlugin int end = Math.min(inv.getSize(), start + slots); int delta = end - start; - DebugModule.getInstance().d("start=" + start); - DebugModule.getInstance().d("end=" + end); - DebugModule.getInstance().d("delta=" + delta); + //DebugModule.getInstance().d("start=" + start); + //DebugModule.getInstance().d("end=" + end); + //DebugModule.getInstance().d("delta=" + delta); for (int i = start; i < end; i++) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 421101c7d..77cc84abf 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -35,11 +35,9 @@ import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; -import mineplex.core.common.util.UtilWorld; import mineplex.core.google.GoogleSheetsManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.gemhunters.debug.DebugModule; import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.economy.PlayerCashOutCompleteEvent; import mineplex.gemhunters.loot.command.SpawnChestCommand; @@ -321,7 +319,7 @@ public class LootModule extends MiniPlugin return; } - DebugModule.getInstance().d("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); + //DebugModule.getInstance().d("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); _spawnedChest.add(new SpawnedChest(chestToPlace, properties, index)); block.setType(properties.getBlockMaterial()); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootChestReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootChestReward.java index 031e859f6..5ef354ec1 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootChestReward.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootChestReward.java @@ -5,7 +5,6 @@ import org.bukkit.inventory.ItemStack; import mineplex.core.Managers; import mineplex.core.common.util.Callback; import mineplex.core.inventory.InventoryManager; -import mineplex.gemhunters.debug.DebugModule; public class LootChestReward extends LootItemReward { @@ -39,7 +38,7 @@ public class LootChestReward extends LootItemReward @Override public void run(Boolean success) { - DebugModule.getInstance().d("Success= " + success); + //DebugModule.getInstance().d("Success= " + success); } }, _player, _chestName + " Chest", _amount); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootGadgetReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootGadgetReward.java index 1d8dc728a..8fa2e0be7 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootGadgetReward.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootGadgetReward.java @@ -6,7 +6,6 @@ import mineplex.core.Managers; import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.donation.DonationManager; import mineplex.core.donation.Donor; -import mineplex.gemhunters.debug.DebugModule; public class LootGadgetReward extends LootItemReward { @@ -36,12 +35,12 @@ public class LootGadgetReward extends LootItemReward if (donor.ownsUnknownSalesPackage(_gadget)) { - DebugModule.getInstance().d("Shard duplicate"); + //DebugModule.getInstance().d("Shard duplicate"); donor.addBalance(GlobalCurrency.TREASURE_SHARD, (int) (500 + Math.random() * 1000)); } else { - DebugModule.getInstance().d("Adding gadget"); + //DebugModule.getInstance().d("Adding gadget"); donor.addOwnedUnknownSalesPackage(_gadget); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java index 8a00d0540..0ed3b9df2 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java @@ -10,7 +10,6 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; import mineplex.core.recharge.Recharge; -import mineplex.gemhunters.debug.DebugModule; public abstract class LootItemReward { @@ -69,7 +68,7 @@ public abstract class LootItemReward public final void success() { - DebugModule.getInstance().d("Success"); + //DebugModule.getInstance().d("Success"); onSuccessful(); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java index 7af52015d..ed1591623 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/types/ChestOpenerQuest.java @@ -4,7 +4,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import mineplex.core.common.util.F; -import mineplex.gemhunters.debug.DebugModule; import mineplex.gemhunters.loot.event.PlayerChestOpenEvent; import mineplex.gemhunters.quest.Quest; @@ -35,7 +34,7 @@ public class ChestOpenerQuest extends Quest @EventHandler public void chestOpen(PlayerChestOpenEvent event) { - DebugModule.getInstance().d(event.getEventName()); + //DebugModule.getInstance().d(event.getEventName()); Player player = event.getPlayer(); if (!isActive(player)) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java index 5bdba8cf0..96d41d9fa 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java @@ -17,12 +17,10 @@ import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilTime; -import mineplex.core.common.util.UtilWorld; import mineplex.core.google.GoogleSheetsManager; import mineplex.core.google.SheetObjectDeserialiser; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.gemhunters.debug.DebugModule; import mineplex.gemhunters.loot.deserialisers.LootItemDeserialiser; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.shop.deserialisers.VillagerPropertiesDeserialiser; @@ -220,7 +218,7 @@ public class ShopModule extends MiniPlugin usedIndexes.add(index); - DebugModule.getInstance().d("Trader at " + UtilWorld.locToStrClean(randomLocation) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); + //DebugModule.getInstance().d("Trader at " + UtilWorld.locToStrClean(randomLocation) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); _npcs.add(new TraderNPC(_plugin, randomLocation, Villager.class, NAMES[UtilMath.r(NAMES.length)], _safezone.isInSafeZone(randomLocation), properties, getRandomItemSet(_trades.get(key)))); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/UndergroundMobs.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/UndergroundMobs.java index b1e2ba508..2369868f1 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/UndergroundMobs.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/UndergroundMobs.java @@ -22,7 +22,6 @@ import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilMath; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.gemhunters.debug.DebugModule; public class UndergroundMobs implements Listener { @@ -67,7 +66,7 @@ public class UndergroundMobs implements Listener } } - DebugModule.getInstance().d("Spawning mobs " + _entities.size()); + //DebugModule.getInstance().d("Spawning mobs " + _entities.size()); for (int i = 0; i < 10; i++) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java index 3313ec499..82e91f732 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -34,7 +34,6 @@ import org.bukkit.inventory.BrewerInventory; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.common.util.UtilWorld; -import mineplex.gemhunters.debug.DebugModule; public class WorldListeners implements Listener { @@ -173,7 +172,7 @@ public class WorldListeners implements Listener { Player player = (Player) event.getEntity(); - DebugModule.getInstance().d(player.getName() + " hunger " + player.getFoodLevel() + " -> " + event.getFoodLevel()); + //DebugModule.getInstance().d(player.getName() + " hunger " + player.getFoodLevel() + " -> " + event.getFoodLevel()); // Some witchcraft from the arcade, seems to make hunger not ridiculous. player.setSaturation(3.8F); } @@ -183,7 +182,7 @@ public class WorldListeners implements Listener { if (event.toWeatherState()) { - DebugModule.getInstance().d("Cancelling a weather change"); + //DebugModule.getInstance().d("Cancelling a weather change"); event.setCancelled(true); event.getWorld().setStorm(false); } From 162ab602b24804dc91d7845d79d889704e03f0eb Mon Sep 17 00:00:00 2001 From: cnr Date: Fri, 24 Feb 2017 00:08:15 -0600 Subject: [PATCH 063/101] Rename GemHunters output jar --- Plugins/mineplex-game-gemhunters/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/mineplex-game-gemhunters/pom.xml b/Plugins/mineplex-game-gemhunters/pom.xml index 270c67554..16129c057 100644 --- a/Plugins/mineplex-game-gemhunters/pom.xml +++ b/Plugins/mineplex-game-gemhunters/pom.xml @@ -9,7 +9,7 @@ ../plugin.xml - Gem-Hunters + GemHunters mineplex-game-gemhunters From 68f61bbb201e6f06de40f1248f8c6d362f998056 Mon Sep 17 00:00:00 2001 From: cnr Date: Fri, 24 Feb 2017 03:33:26 -0600 Subject: [PATCH 064/101] Send players to beta hubs; add 2fa and anticheat --- .../src/mineplex/core/portal/Commands/SendCommand.java | 2 +- .../src/mineplex/core/portal/Commands/ServerCommand.java | 2 +- .../src/mineplex/core/portal/GenericServer.java | 7 ++++++- Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java | 4 ++-- Plugins/mineplex-game-gemhunters/plugin.yml | 2 +- .../src/mineplex/gemhunters/GemHunters.java | 7 ++++++- .../src/mineplex/gemhunters/economy/CashOutModule.java | 6 ++++-- .../src/mineplex/gemhunters/spawn/SpawnModule.java | 3 ++- 8 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/SendCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/SendCommand.java index f0c7c59bf..40bfe8476 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/SendCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/SendCommand.java @@ -1,4 +1,4 @@ -package mineplex.core.portal.commands; +package mineplex.core.portal.Commands; import org.bukkit.entity.Player; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java index 5511e0105..56ba7b9e7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java @@ -1,4 +1,4 @@ -package mineplex.core.portal.commands; +package mineplex.core.portal.Commands; import org.bukkit.entity.Player; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/GenericServer.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/GenericServer.java index 02cb2da42..94059bbb3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/GenericServer.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/GenericServer.java @@ -12,7 +12,12 @@ public enum GenericServer /** * The Clans Hubs, such as ClansHub-1 */ - CLANS_HUB("ClansHub"); + CLANS_HUB("ClansHub"), + /** + * The Beta Hubs, such as BetaHub-1 + */ + BETA_HUB("BetaHub"), + ; private final String _name; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java index 5d0d5eb88..26cdcf0bd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java @@ -24,8 +24,8 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTabTitle; -import mineplex.core.portal.commands.SendCommand; -import mineplex.core.portal.commands.ServerCommand; +import mineplex.core.portal.Commands.SendCommand; +import mineplex.core.portal.Commands.ServerCommand; import mineplex.core.portal.events.GenericServerTransferEvent; import mineplex.core.portal.events.ServerTransferEvent; import mineplex.serverdata.Region; diff --git a/Plugins/mineplex-game-gemhunters/plugin.yml b/Plugins/mineplex-game-gemhunters/plugin.yml index a0a9f1660..4f013d203 100644 --- a/Plugins/mineplex-game-gemhunters/plugin.yml +++ b/Plugins/mineplex-game-gemhunters/plugin.yml @@ -1,4 +1,4 @@ -name: Gem-Hunters +name: GemHunters main: mineplex.gemhunters.GemHunters version: 0.1 commands: diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 9bd47124d..f52cbaa5a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -12,6 +12,7 @@ import mineplex.core.FoodDupeFix; import mineplex.core.TimingsFix; import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; +import mineplex.core.antihack.AntiHack; import mineplex.core.beta.BetaWhitelist; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.boosters.BoosterManager; @@ -55,6 +56,7 @@ import mineplex.core.stats.StatsManager; import mineplex.core.status.ServerStatusManager; import mineplex.core.teleport.Teleport; import mineplex.core.thank.ThankManager; +import mineplex.core.twofactor.TwoFactorAuth; import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; import mineplex.core.visibility.VisibilityManager; @@ -173,7 +175,7 @@ public class GemHunters extends JavaPlugin new DamageManager(this, new CombatManager(this), new NpcManager(this, creature), disguiseManager, new ConditionManager(this)); // GWEN - // require(AntiHack.class); + require(AntiHack.class); // Block Restore BlockRestore blockRestore = require(BlockRestore.class); @@ -287,6 +289,9 @@ public class GemHunters extends JavaPlugin MinecraftServer.getServer().getPropertyManager().setProperty("debug", false); SpigotConfig.debug = false; + // Two-factor auth + require(TwoFactorAuth.class); + // beta whitelist new BetaWhitelist(clientManager, new PowerPlayClubRepository(this, clientManager, donationManager)); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java index adf39923a..e355c7298 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -30,6 +30,9 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.donation.DonationManager; import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.portal.GenericServer; +import mineplex.core.portal.Intent; +import mineplex.core.portal.Portal; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -166,8 +169,7 @@ public class CashOutModule extends MiniPlugin session.endSession(); iterator.remove(); - player.kickPlayer(C.cGreen + "Imagine you are being sent to the Lobby."); - // Portal.getInstance().sendToHub(player, null); + Portal.getInstance().sendPlayerToGenericServer(player, GenericServer.BETA_HUB, Intent.PLAYER_REQUEST); } } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index 200761968..61b10eaea 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -21,6 +21,7 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilServer; +import mineplex.core.portal.GenericServer; import mineplex.core.portal.Intent; import mineplex.core.portal.Portal; import mineplex.gemhunters.death.npc.CombatLogNPC; @@ -146,7 +147,7 @@ public class SpawnModule extends MiniPlugin new SimpleNPC(_plugin, location, Villager.class, C.cGoldB + "Return To Hub", clicker -> { - Portal.getInstance().sendToHub(clicker, null, Intent.PLAYER_REQUEST); + Portal.getInstance().sendPlayerToGenericServer(clicker, GenericServer.BETA_HUB, Intent.PLAYER_REQUEST); }); } From 385842119455d34dae2704f79d11f894b817f3e0 Mon Sep 17 00:00:00 2001 From: cnr Date: Fri, 24 Feb 2017 05:49:10 -0600 Subject: [PATCH 065/101] Fix combat NPC issues - Cashed out players were treated as combat-logged players - Player inventories were not cleared before returning items, resulting in duplicated items - Players would be given the "locked slot" item - Allow multiple stacks of the same type and amount --- .../gemhunters/death/npc/NPCManager.java | 13 ++++++++-- .../gemhunters/death/npc/PlayerInfo.java | 26 +++++++++---------- .../gemhunters/loot/InventoryModule.java | 2 +- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/NPCManager.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/NPCManager.java index 1a9300bc6..c0a95876a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/NPCManager.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/NPCManager.java @@ -3,6 +3,7 @@ package mineplex.gemhunters.death.npc; import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -24,6 +25,7 @@ import mineplex.core.disguise.DisguiseManager; import mineplex.core.hologram.HologramManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.economy.PlayerCashOutCompleteEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent; public class NPCManager extends MiniPlugin @@ -39,7 +41,8 @@ public class NPCManager extends MiniPlugin private Set _logoutNpcs; private Set _toKillIds; - + private Set _cashedOutPreventNPCs = new HashSet<>(); + private HologramManager _hologramManager; public NPCManager(HologramManager hologramManager) @@ -51,6 +54,12 @@ public class NPCManager extends MiniPlugin _toKillIds = new HashSet<>(); _hologramManager = hologramManager; } + + @EventHandler + public void onCashOut(PlayerCashOutCompleteEvent event) + { + _cashedOutPreventNPCs.add(event.getPlayer().getUniqueId()); + } @EventHandler public void playerQuit(PlayerQuitEvent event) @@ -73,7 +82,7 @@ public class NPCManager extends MiniPlugin public void spawnLogoutNpc(Player player) { - if (!hasLogoutNpc(player)) + if (!_cashedOutPreventNPCs.remove(player.getUniqueId()) && !hasLogoutNpc(player)) { CombatLogNPC npc = new CombatLogNPC(player, require(DisguiseManager.class), _hologramManager, player.getGameMode().equals(GameMode.CREATIVE)); npc.spawn(); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/PlayerInfo.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/PlayerInfo.java index 5044751af..694606cab 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/PlayerInfo.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/npc/PlayerInfo.java @@ -1,7 +1,7 @@ package mineplex.gemhunters.death.npc; -import java.util.HashSet; -import java.util.Set; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import org.bukkit.Bukkit; @@ -12,12 +12,14 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import mineplex.gemhunters.loot.InventoryModule; + public class PlayerInfo { private String _playerName; private UUID _playerUuid; private ItemStack[] _armor; - private Set _items; + private List _items; private Location _location; public PlayerInfo(Player player) @@ -41,7 +43,8 @@ public class PlayerInfo public void restore() { Player player = getPlayer(); - + + player.getInventory().clear(); player.getInventory().setArmorContents(_armor); player.getInventory().addItem(_items.toArray(new ItemStack[0])); player.teleport(_location); @@ -51,12 +54,7 @@ public class PlayerInfo { return _playerName; } - - public Set getItems() - { - return _items; - } - + public UUID getUniqueId() { return _playerUuid; @@ -72,20 +70,20 @@ public class PlayerInfo return Bukkit.getPlayerExact(_playerName); } - private Set fetchItems(PlayerInventory inventory) + private List fetchItems(PlayerInventory inventory) { - Set items = new HashSet(); + List items = new ArrayList<>(); addItems(items, inventory.getContents()); return items; } - private void addItems(Set items, ItemStack[] itemsToAdd) + private void addItems(List items, ItemStack[] itemsToAdd) { for (ItemStack item : itemsToAdd) { - if (item != null && item.getType() != Material.AIR) + if (item != null && item.getType() != Material.AIR && !item.isSimilar(InventoryModule.LOCKED)) { items.add(item); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java index 1ea26c086..f0c7e1e6b 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java @@ -28,8 +28,8 @@ import mineplex.gemhunters.death.event.PlayerCustomRespawnEvent; public class InventoryModule extends MiniPlugin { + public static final ItemStack LOCKED = new ItemBuilder(Material.STAINED_GLASS_PANE, (byte) 15).setTitle(C.cGray + "Locked").build(); private static final int START_INDEX = 9; - private static final ItemStack LOCKED = new ItemBuilder(Material.STAINED_GLASS_PANE, (byte) 15).setTitle(C.cGray + "Locked").build(); private static final String ITEM_METADATA = "UNLOCKER"; private final LootModule _loot; From 76ef632e811872f498a4491fa8c3bd7b9d4d7e5d Mon Sep 17 00:00:00 2001 From: cnr Date: Fri, 24 Feb 2017 06:10:40 -0600 Subject: [PATCH 066/101] Reward gems and shards the correct way --- .../src/mineplex/gemhunters/economy/CashOutModule.java | 4 ++-- .../src/mineplex/gemhunters/loot/rewards/LootShardReward.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java index e355c7298..5809f042b 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -165,8 +165,8 @@ public class CashOutModule extends MiniPlugin UtilServer.CallEvent(completeEvent); - _donation.Get(player).addBalance(GlobalCurrency.GEM, completeEvent.getGems()); - + _donation.rewardCurrencyUntilSuccess(GlobalCurrency.GEM, player, "Earned", completeEvent.getGems()); + session.endSession(); iterator.remove(); Portal.getInstance().sendPlayerToGenericServer(player, GenericServer.BETA_HUB, Intent.PLAYER_REQUEST); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootShardReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootShardReward.java index 1faf61dfa..af1119a73 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootShardReward.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootShardReward.java @@ -30,7 +30,7 @@ public class LootShardReward extends LootItemReward @Override public void onSuccessful() { - _donation.Get(_player).addBalance(GlobalCurrency.TREASURE_SHARD, _amount); + _donation.rewardCurrencyUntilSuccess(GlobalCurrency.TREASURE_SHARD, _player, "Earned", _amount); } @Override From 295f626ec4692d12587d1bf68bf9564894b21f1d Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 24 Feb 2017 20:50:53 +0000 Subject: [PATCH 067/101] Actually remove gems when players join --- .../gemhunters/economy/EconomyModule.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java index 03c1006f9..a004700b6 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -11,18 +11,26 @@ import mineplex.core.MiniClientPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.F; +import mineplex.core.donation.DonationManager; +import mineplex.core.donation.Donor; import mineplex.gemhunters.death.event.PlayerCustomRespawnEvent; import mineplex.gemhunters.economy.command.GiveGemsCommand; +import mineplex.gemhunters.spawn.event.PlayerTeleportIntoMapEvent; @ReflectivelyCreateMiniPlugin public class EconomyModule extends MiniClientPlugin { private static final float GEM_KILL_FACTOR = 0.5F; - + private static final int GEM_START_COST = 100; + + private final DonationManager _donation; + public EconomyModule() { super("Economy"); + + _donation = require(DonationManager.class); } @Override @@ -34,7 +42,19 @@ public class EconomyModule extends MiniClientPlugin @EventHandler public void respawn(PlayerCustomRespawnEvent event) { - addToStore(event.getPlayer(), null, 100); + addToStore(event.getPlayer(), null, GEM_START_COST); + } + + @EventHandler + public void teleportIn(PlayerTeleportIntoMapEvent event) + { + Player player = event.getPlayer(); + Donor donor = _donation.Get(event.getPlayer()); + + if (donor.getBalance(GlobalCurrency.GEM) >= GEM_START_COST) + { + _donation.purchaseUnknownSalesPackage(player, "Gem Hunters Access", GlobalCurrency.GEM, GEM_START_COST, false, null); + } } @EventHandler From 2090d2202ca0b858b98b34194031da85446f56bb Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 24 Feb 2017 20:51:11 +0000 Subject: [PATCH 068/101] Actually give people gadget items --- .../mineplex/gemhunters/loot/rewards/LootGadgetReward.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootGadgetReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootGadgetReward.java index 8fa2e0be7..59f9db30f 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootGadgetReward.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootGadgetReward.java @@ -36,12 +36,12 @@ public class LootGadgetReward extends LootItemReward if (donor.ownsUnknownSalesPackage(_gadget)) { //DebugModule.getInstance().d("Shard duplicate"); - donor.addBalance(GlobalCurrency.TREASURE_SHARD, (int) (500 + Math.random() * 1000)); + _donation.rewardCurrencyUntilSuccess(GlobalCurrency.TREASURE_SHARD, _player, "Earned", (int) (500 + 1000 * Math.random())); } else { //DebugModule.getInstance().d("Adding gadget"); - donor.addOwnedUnknownSalesPackage(_gadget); + _donation.purchaseUnknownSalesPackage(_player, _gadget, GlobalCurrency.TREASURE_SHARD, 0, true, null); } } From 71964b7bcae215c93fe3240fcbcb991b61d7b8c3 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 24 Feb 2017 20:51:26 +0000 Subject: [PATCH 069/101] Fix the no eat bug inside safezones --- .../src/mineplex/gemhunters/safezone/SafezoneModule.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java index 194e55e3a..8c8b13a77 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java @@ -142,8 +142,15 @@ public class SafezoneModule extends MiniPlugin @EventHandler public void hungerChange(FoodLevelChangeEvent event) { - if (isInSafeZone(event.getEntity().getLocation())) + if (isInSafeZone(event.getEntity().getLocation()) && event.getEntity() instanceof Player) { + Player player = (Player) event.getEntity(); + + if (player.getFoodLevel() >= event.getFoodLevel()) + { + return; + } + event.setCancelled(true); } } From 43524465c7b23f4e8b9807f7dd8dcaca82e26691 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 24 Feb 2017 20:51:40 +0000 Subject: [PATCH 070/101] Fix the damageToLevel bug --- .../src/mineplex/gemhunters/world/WorldListeners.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java index 82e91f732..e65c83fb1 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -34,6 +34,7 @@ import org.bukkit.inventory.BrewerInventory; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.common.util.UtilWorld; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; public class WorldListeners implements Listener { @@ -57,6 +58,12 @@ public class WorldListeners implements Listener new File(world.getWorldFolder().getPath() + File.separator + "stats" + File.separator + uuid + ".json").delete(); }, 20); } + + @EventHandler + public void customDamage(CustomDamageEvent event) + { + event.SetDamageToLevel(false); + } @EventHandler(priority = EventPriority.LOWEST) public void blockBreak(BlockBreakEvent event) From a7edc830e02e8b8e07cc92d250309b0bfc062108 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 24 Feb 2017 20:52:54 +0000 Subject: [PATCH 071/101] Fix cashout related problems with cashing out --- .../src/mineplex/gemhunters/economy/CashOutModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java index 5809f042b..1db9db186 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -169,7 +169,7 @@ public class CashOutModule extends MiniPlugin session.endSession(); iterator.remove(); - Portal.getInstance().sendPlayerToGenericServer(player, GenericServer.BETA_HUB, Intent.PLAYER_REQUEST); + Portal.getInstance().sendPlayerToGenericServer(player, GenericServer.BETA_HUB, Intent.FORCE_TRANSFER); } } } From ce272a32884d55e69caaff65d453e8bd263a80aa Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 24 Feb 2017 22:11:17 +0000 Subject: [PATCH 072/101] Fix hunger is safezones for real this time --- .../src/mineplex/gemhunters/safezone/SafezoneModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java index 8c8b13a77..fc9dc2b50 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java @@ -146,7 +146,7 @@ public class SafezoneModule extends MiniPlugin { Player player = (Player) event.getEntity(); - if (player.getFoodLevel() >= event.getFoodLevel()) + if (player.getFoodLevel() < event.getFoodLevel()) { return; } From 7be7b47395dfd276506ba98066681be734504962 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 24 Feb 2017 22:11:27 +0000 Subject: [PATCH 073/101] Debug stuff --- .../core/portal/Commands/SendCommand.java | 2 +- .../core/portal/Commands/ServerCommand.java | 2 +- .../src/mineplex/core/portal/Portal.java | 4 +-- .../src/mineplex/gemhunters/GemHunters.java | 4 ++- .../gemhunters/world/DebugListeners.java | 30 +++++++++++++++++++ 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/DebugListeners.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/SendCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/SendCommand.java index 40bfe8476..f0c7c59bf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/SendCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/SendCommand.java @@ -1,4 +1,4 @@ -package mineplex.core.portal.Commands; +package mineplex.core.portal.commands; import org.bukkit.entity.Player; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java index 56ba7b9e7..5511e0105 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/Commands/ServerCommand.java @@ -1,4 +1,4 @@ -package mineplex.core.portal.Commands; +package mineplex.core.portal.commands; import org.bukkit.entity.Player; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java index 26cdcf0bd..5d0d5eb88 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java @@ -24,8 +24,8 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTabTitle; -import mineplex.core.portal.Commands.SendCommand; -import mineplex.core.portal.Commands.ServerCommand; +import mineplex.core.portal.commands.SendCommand; +import mineplex.core.portal.commands.ServerCommand; import mineplex.core.portal.events.GenericServerTransferEvent; import mineplex.core.portal.events.ServerTransferEvent; import mineplex.serverdata.Region; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index f52cbaa5a..5075c2298 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -77,6 +77,7 @@ import mineplex.gemhunters.scoreboard.ScoreboardModule; import mineplex.gemhunters.shop.ShopModule; import mineplex.gemhunters.spawn.SpawnModule; import mineplex.gemhunters.supplydrop.SupplyDropModule; +import mineplex.gemhunters.world.DebugListeners; import mineplex.gemhunters.world.TimeCycle; import mineplex.gemhunters.world.UndergroundMobs; import mineplex.gemhunters.world.WorldListeners; @@ -272,7 +273,8 @@ public class GemHunters extends JavaPlugin new WorldListeners(this); new TimeCycle(this); new UndergroundMobs(this); - + new DebugListeners(this); + // Combat npc new NPCManager(hologramManager); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/DebugListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/DebugListeners.java new file mode 100644 index 000000000..8e59d81e4 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/DebugListeners.java @@ -0,0 +1,30 @@ +package mineplex.gemhunters.world; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.plugin.java.JavaPlugin; + +public class DebugListeners implements Listener +{ + + private static final String[] OPS = { "Moppletop" }; + + public DebugListeners(JavaPlugin plugin) + { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @EventHandler + public void autoOp(PlayerJoinEvent event) + { + for (String s : OPS) + { + if (s.equals(event.getPlayer().getName())) + { + event.getPlayer().setOp(true); + } + } + } + +} From 9219e50a1c583cbf445a7c932296214cef032340 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 24 Feb 2017 23:05:07 +0000 Subject: [PATCH 074/101] Don't spawn purple chests when there are less than 10 players --- .../src/mineplex/gemhunters/loot/LootModule.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index 77cc84abf..bd179cc2a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -241,6 +241,11 @@ public class LootModule extends MiniPlugin public void addSpawnedChest(String key, boolean force) { + if (key.equals("PURPLE") && Bukkit.getOnlinePlayers().size() < 10) + { + return; + } + List locations = _worldData.getDataLocation(key); ChestProperties properties = _chestProperties.get(key); From 02a2f9860197f34c9af9cd507b866ae363e72729 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 24 Feb 2017 23:40:30 +0000 Subject: [PATCH 075/101] Allow flint and steel --- .../src/mineplex/gemhunters/world/WorldListeners.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java index e65c83fb1..436c63cf7 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -17,6 +17,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockFadeEvent; import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.LeavesDecayEvent; import org.bukkit.event.entity.EntityDamageEvent; @@ -153,6 +154,11 @@ public class WorldListeners implements Listener @EventHandler public void fireSpread(BlockIgniteEvent event) { + if (event.getCause() == IgniteCause.FLINT_AND_STEEL) + { + return; + } + event.setCancelled(true); } From 605fcf90dd79e542596e1467cb2f449cef5f7262 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 24 Feb 2017 23:50:37 +0000 Subject: [PATCH 076/101] Stop players spawning near others when joining --- .../mineplex/gemhunters/spawn/SpawnModule.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index 61b10eaea..e2cc05ba2 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -1,5 +1,6 @@ package mineplex.gemhunters.spawn; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.WorldBorder; @@ -20,6 +21,7 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilServer; import mineplex.core.portal.GenericServer; import mineplex.core.portal.Intent; @@ -39,7 +41,8 @@ public class SpawnModule extends MiniPlugin public static final int WORLD_BORDER_RADIUS = 1024; private static final int MAX_SPAWNING_Y = 73; - + private static final int MIN_PLAYER_DISTANCE_SQUARED = 6400; + private final SafezoneModule _safezone; private final WorldDataModule _worldData; @@ -178,6 +181,19 @@ public class SpawnModule extends MiniPlugin { return false; } + + for (Player player : Bukkit.getOnlinePlayers()) + { + if (_safezone.isInSafeZone(player.getLocation())) + { + continue; + } + + if (UtilMath.offsetSquared(player.getLocation(), block.getLocation()) < MIN_PLAYER_DISTANCE_SQUARED) + { + return false; + } + } return true; } From 9450c29e3e0e60c105e1e3ce0674ff341ea80fb4 Mon Sep 17 00:00:00 2001 From: cnr Date: Sat, 25 Feb 2017 00:31:12 -0600 Subject: [PATCH 077/101] Allow ETERNAL into the beta --- Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java b/Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java index 7e1a30617..ca0f67e27 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/beta/BetaWhitelist.java @@ -55,7 +55,7 @@ public class BetaWhitelist extends MiniPlugin { Player player = event.getPlayer(); Rank rank = _clientManager.Get(player).GetRank(true); - if ((rank != Rank.MAPDEV && rank != Rank.MAPLEAD && rank.has(Rank.TWITCH) // If this player is Twitch+ (and not a builder), + if ((rank != Rank.MAPDEV && rank != Rank.MAPLEAD && rank.has(Rank.ETERNAL) // If this player is Eternal+ (and not a builder), || _powerPlayClubRepository.getCachedData(player).isSubscribed()) // a PPC subscriber, || EXTRA_PLAYERS.contains(player.getUniqueId())) // or explicitly whitelisted, { From 7de556e3d868f5d45cb21db73d871d713d2abdf5 Mon Sep 17 00:00:00 2001 From: cnr Date: Sat, 25 Feb 2017 00:35:46 -0600 Subject: [PATCH 078/101] Allow plugins to choose a hub type when restarting Clans Hubs will send to Clans Hubs, Clans will send to Clans Hubs, and all other plugins will send to the normal Hub --- .../mineplex/core/updater/FileUpdater.java | 16 +++++++------- .../src/mineplex/game/clans/Clans.java | 3 ++- .../src/mineplex/clanshub/ClansHub.java | 3 ++- .../Mineplex.Hub/src/mineplex/hub/Hub.java | 5 +++-- .../src/mineplex/staffServer/StaffServer.java | 21 +++++++++++-------- .../src/nautilus/game/arcade/Arcade.java | 6 +++--- .../src/mineplex/mavericks/review/Hub.java | 3 ++- 7 files changed, 33 insertions(+), 24 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/updater/FileUpdater.java b/Plugins/Mineplex.Core/src/mineplex/core/updater/FileUpdater.java index 71aff9639..be2a4a954 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/updater/FileUpdater.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/updater/FileUpdater.java @@ -6,10 +6,6 @@ import java.io.FilenameFilter; import java.io.IOException; import java.util.Properties; -import mineplex.core.portal.GenericServer; -import mineplex.core.portal.Intent; -import mineplex.core.updater.command.BuildVersionCommand; -import mineplex.core.updater.command.RestartServerCommand; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; @@ -24,7 +20,11 @@ import mineplex.core.MiniPlugin; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.NautHashMap; +import mineplex.core.portal.GenericServer; +import mineplex.core.portal.Intent; import mineplex.core.portal.Portal; +import mineplex.core.updater.command.BuildVersionCommand; +import mineplex.core.updater.command.RestartServerCommand; import mineplex.core.updater.event.RestartServerEvent; import mineplex.core.updater.event.UpdateEvent; import mineplex.serverdata.Region; @@ -38,19 +38,21 @@ public class FileUpdater extends MiniPlugin private String _serverName; private Region _region; + private final GenericServer _transferHub; private boolean _needUpdate; private boolean _enabled = true; private Properties _buildProperties; - public FileUpdater(JavaPlugin plugin, Portal portal, String serverName, Region region) + public FileUpdater(JavaPlugin plugin, Portal portal, String serverName, Region region, GenericServer transferHub) { super("File Updater", plugin); _portal = portal; _serverName = serverName; _region = region; + _transferHub = transferHub; GetPluginMd5s(); @@ -81,7 +83,7 @@ public class FileUpdater extends MiniPlugin for (Player player : Bukkit.getOnlinePlayers()) { player.sendMessage(F.main("Updater", message)); - _portal.sendPlayerToGenericServer(player, GenericServer.HUB, Intent.KICK); + _portal.sendPlayerToGenericServer(player, _transferHub, Intent.KICK); } } } @@ -110,7 +112,7 @@ public class FileUpdater extends MiniPlugin { public void run() { - _portal.sendAllPlayersToGenericServer(GenericServer.HUB, Intent.KICK); + _portal.sendAllPlayersToGenericServer(_transferHub, Intent.KICK); } }, 60L); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index e34fc40b2..9e8deb5f3 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -46,6 +46,7 @@ import mineplex.core.memory.MemoryFix; import mineplex.core.message.MessageManager; import mineplex.core.monitor.LagMeter; import mineplex.core.packethandler.PacketHandler; +import mineplex.core.portal.GenericServer; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; import mineplex.core.punish.Punish; @@ -131,7 +132,7 @@ public class Clans extends JavaPlugin Teleport teleport = new Teleport(this, _clientManager); Portal portal = new Portal(); - new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); + new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion(), GenericServer.CLANS_HUB); ClansBanManager clansBans = new ClansBanManager(this, _clientManager, _donationManager); diff --git a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java index 41e7321b8..d8ad95420 100644 --- a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java +++ b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java @@ -39,6 +39,7 @@ import mineplex.core.packethandler.PacketHandler; import mineplex.core.party.PartyManager; import mineplex.core.pet.PetManager; import mineplex.core.poll.PollManager; +import mineplex.core.portal.GenericServer; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; import mineplex.core.profileCache.ProfileCacheManager; @@ -153,7 +154,7 @@ public class ClansHub extends JavaPlugin Chat chat = new Chat(this, incognito, clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); new MessageManager(this, incognito, clientManager, preferenceManager, ignoreManager, punish, friendManager, chat); new MemoryFix(this); - new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); + new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion(), GenericServer.CLANS_HUB); new CustomTagFix(this, packetHandler); new PacketsInteractionFix(this, packetHandler); new ResourcePackManager(this, portal); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index eaaff57d0..9ffb7cf27 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -5,7 +5,6 @@ import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import mineplex.core.common.Constants; import mineplex.core.CustomTagFix; import mineplex.core.PacketsInteractionFix; import mineplex.core.account.CoreClientManager; @@ -22,6 +21,7 @@ import mineplex.core.chatsnap.SnapshotManager; import mineplex.core.chatsnap.SnapshotPlugin; import mineplex.core.chatsnap.SnapshotRepository; import mineplex.core.command.CommandCenter; +import mineplex.core.common.Constants; import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.creature.Creature; import mineplex.core.customdata.CustomDataManager; @@ -47,6 +47,7 @@ import mineplex.core.party.PartyManager; import mineplex.core.personalServer.PersonalServerManager; import mineplex.core.pet.PetManager; import mineplex.core.poll.PollManager; +import mineplex.core.portal.GenericServer; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; import mineplex.core.profileCache.ProfileCacheManager; @@ -182,7 +183,7 @@ public class Hub extends JavaPlugin implements IRelation Chat chat = new Chat(this, incognito, clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); new MessageManager(this, incognito, clientManager, preferenceManager, ignoreManager, punish, friendManager, chat); new MemoryFix(this); - new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); + new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion(), GenericServer.HUB); new CustomTagFix(this, packetHandler); new PacketsInteractionFix(this, packetHandler); new ResourcePackManager(this, portal); diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java index db45f77f7..78526833a 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java @@ -1,12 +1,21 @@ package mineplex.staffServer; +import java.util.UUID; + +import net.minecraft.server.v1_8_R3.MinecraftServer; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; +import org.bukkit.plugin.java.JavaPlugin; +import org.spigotmc.SpigotConfig; + import com.mojang.authlib.GameProfile; -import mineplex.core.common.Constants; import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; import mineplex.core.chat.Chat; import mineplex.core.command.CommandCenter; +import mineplex.core.common.Constants; import mineplex.core.common.Rank; import mineplex.core.creature.Creature; import mineplex.core.disguise.DisguiseManager; @@ -17,6 +26,7 @@ import mineplex.core.memory.MemoryFix; import mineplex.core.monitor.LagMeter; import mineplex.core.npc.NpcManager; import mineplex.core.packethandler.PacketHandler; +import mineplex.core.portal.GenericServer; import mineplex.core.portal.Portal; import mineplex.core.powerplayclub.PowerPlayClubRepository; import mineplex.core.preferences.PreferencesManager; @@ -29,13 +39,6 @@ import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; import mineplex.staffServer.customerSupport.CustomerSupport; import mineplex.staffServer.salespackage.SalesPackageManager; -import net.minecraft.server.v1_8_R3.MinecraftServer; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -import org.bukkit.plugin.java.JavaPlugin; -import org.spigotmc.SpigotConfig; - -import java.util.UUID; import static mineplex.core.Managers.require; @@ -67,7 +70,7 @@ public class StaffServer extends JavaPlugin StatsManager statsManager = new StatsManager(this, clientManager); new Chat(this, null, clientManager, preferenceManager, new AchievementManager(statsManager, clientManager, donationManager, null, eloManager), serverStatusManager.getCurrentServerName()); new MemoryFix(this); - new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); + new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion(), GenericServer.HUB); require(PacketHandler.class); require(DisguiseManager.class); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 152a6b8d1..e20964e2c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -10,12 +10,10 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.spigotmc.SpigotConfig; -import mineplex.core.common.Constants; import mineplex.core.CustomTagFix; import mineplex.core.FoodDupeFix; import mineplex.core.PacketsInteractionFix; import mineplex.core.TimingsFix; - import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; import mineplex.core.antihack.AntiHack; @@ -28,6 +26,7 @@ import mineplex.core.chatsnap.SnapshotManager; import mineplex.core.chatsnap.SnapshotPlugin; import mineplex.core.chatsnap.SnapshotRepository; import mineplex.core.command.CommandCenter; +import mineplex.core.common.Constants; import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.common.util.FileUtil; import mineplex.core.common.util.UtilServer; @@ -55,6 +54,7 @@ import mineplex.core.npc.NpcManager; import mineplex.core.packethandler.PacketHandler; import mineplex.core.pet.PetManager; import mineplex.core.poll.PollManager; +import mineplex.core.portal.GenericServer; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; import mineplex.core.profileCache.ProfileCacheManager; @@ -138,7 +138,7 @@ public class Arcade extends JavaPlugin LeaderboardManager leaderboardManager = new LeaderboardManager(this, _clientManager); Teleport teleport = new Teleport(this, _clientManager); Portal portal = new Portal(); - new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); + new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion(), GenericServer.HUB); DisguiseManager disguiseManager = require(DisguiseManager.class); diff --git a/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java b/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java index e36c7cfea..1129d2f0f 100644 --- a/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java +++ b/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java @@ -38,6 +38,7 @@ import mineplex.core.monitor.LagMeter; import mineplex.core.mount.MountManager; import mineplex.core.packethandler.PacketHandler; import mineplex.core.pet.PetManager; +import mineplex.core.portal.GenericServer; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; import mineplex.core.profileCache.ProfileCacheManager; @@ -102,7 +103,7 @@ public class Hub extends JavaPlugin Creature creature = new Creature(this); ServerStatusManager serverStatusManager = new ServerStatusManager(this, _clientManager, new LagMeter(this, _clientManager)); Portal portal = new Portal(); - new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); + new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion(), GenericServer.HUB); DisguiseManager disguiseManager = require(DisguiseManager.class); From fafcc9eb1c879f279eba0d6b2771db4c6363faf1 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 25 Feb 2017 15:45:30 +0000 Subject: [PATCH 079/101] Add support for durability in LootItem --- .../gemhunters/loot/deserialisers/LootItemDeserialiser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/LootItemDeserialiser.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/LootItemDeserialiser.java index 3377fe1b9..61fc76602 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/LootItemDeserialiser.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/LootItemDeserialiser.java @@ -40,7 +40,7 @@ public class LootItemDeserialiser implements SheetObjectDeserialiser byte data = values[1].equals("") ? 0 : Byte.parseByte(values[1]); int minAmount = 1; int maxAmount = 1; - short durability = values[2].equals("") ? 0 : Short.valueOf(values[3]); + short durability = values[2].equals("") ? 0 : Short.valueOf(values[2]); String[] numbers = values[3].split("-"); From 54f9677d2a76c59b3a30b361aee6d4130baf3e1f Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 25 Feb 2017 15:45:56 +0000 Subject: [PATCH 080/101] Make the world event marker rotate based on exact yaw --- .../src/mineplex/gemhunters/map/ItemMapRenderer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapRenderer.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapRenderer.java index 225e4b4b2..69376dec1 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapRenderer.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapRenderer.java @@ -212,7 +212,7 @@ public class ItemMapRenderer extends MapRenderer byte cursorType = 5; // http://i.imgur.com/wpH6PT8.png // Those are byte 5 and 6 - byte rotation = (byte) ((int) Math.floor(System.currentTimeMillis() / 1000D) % 16); + byte rotation = (byte) (int) ((point.getYaw() * 16D) / 360D); MapCursor cursor = new MapCursor(b0, b1, rotation, cursorType, true); From 7d5d5d5401ec589eeb6d9d1f80e213f9fae953da Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 25 Feb 2017 15:47:24 +0000 Subject: [PATCH 081/101] Re-enable 2fa --- .../src/mineplex/core/twofactor/TwoFactorAuth.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/twofactor/TwoFactorAuth.java b/Plugins/Mineplex.Core/src/mineplex/core/twofactor/TwoFactorAuth.java index 02d2705e8..32107d3f6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/twofactor/TwoFactorAuth.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/twofactor/TwoFactorAuth.java @@ -185,7 +185,7 @@ public class TwoFactorAuth extends MiniClientPlugin player.sendMessage(F.main("2FA", "Setting up two-factor authentication.")); } - //@EventHandler + @EventHandler public void onJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); From 76f587cff517ab468fd823332c887a311ac08240 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 26 Feb 2017 01:31:20 +0000 Subject: [PATCH 082/101] Disable damage manager and particles --- .../src/mineplex/gemhunters/GemHunters.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 49bbb3b86..3bd9b2550 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -2,6 +2,7 @@ package mineplex.gemhunters; import net.minecraft.server.v1_8_R3.MinecraftServer; +import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.plugin.java.JavaPlugin; @@ -174,10 +175,12 @@ public class GemHunters extends JavaPlugin Creature creature = new Creature(this); // The old classic Damage Manager - new DamageManager(this, new CombatManager(this), new NpcManager(this, creature), disguiseManager, new ConditionManager(this)); - + DamageManager damageManager = new DamageManager(this, new CombatManager(this), new NpcManager(this, creature), disguiseManager, new ConditionManager(this)); + damageManager.SetEnabled(false); + // GWEN - require(AntiHack.class); + AntiHack antiHack = require(AntiHack.class); + Bukkit.getScheduler().runTask(this, antiHack::enableAnticheat); // Block Restore BlockRestore blockRestore = require(BlockRestore.class); @@ -246,10 +249,12 @@ public class GemHunters extends JavaPlugin CosmeticManager cosmeticManager = new CosmeticManager(this, clientManager, donationManager, inventoryManager, gadgetManager, mountManager, petManager, null, boosterManager); cosmeticManager.setActive(false); + cosmeticManager.setHideParticles(true); + gadgetManager.setGadgetEnabled(false); // Now we finally get to enable the Gem Hunters modules // Though if any other module needs one of these it will be generated in - // order, however they are all here just for good measure.s + // order, however they are all here just for good measure. require(BetaModule.class); //require(DebugModule.class); require(BountyModule.class); From ff6a3e915ec1afb02100a6f42a24891091691c33 Mon Sep 17 00:00:00 2001 From: LCastr0 Date: Fri, 17 Feb 2017 02:27:28 -0200 Subject: [PATCH 083/101] Add Gold Pot Morph --- .../disguise/disguises/DisguiseBlock.java | 13 +- .../mineplex/core/gadget/GadgetManager.java | 2 + .../gadget/commands/LockCosmeticsCommand.java | 9 +- .../commands/UnlockCosmeticsCommand.java | 7 + .../gadget/gadgets/morph/MorphGoldPot.java | 132 +++++++++++ .../gadgets/morph/managers/GoldPotHelper.java | 213 ++++++++++++++++++ .../gadgets/morph/managers/GoldPotStands.java | 98 ++++++++ .../powerplayclub/PowerPlayClubRewards.java | 1 + .../src/mineplex/core/recharge/Recharge.java | 36 ++- 9 files changed, 503 insertions(+), 8 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphGoldPot.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/managers/GoldPotHelper.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/managers/GoldPotStands.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/disguise/disguises/DisguiseBlock.java b/Plugins/Mineplex.Core/src/mineplex/core/disguise/disguises/DisguiseBlock.java index 387208c51..d0c32a21d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/disguise/disguises/DisguiseBlock.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/disguise/disguises/DisguiseBlock.java @@ -5,6 +5,9 @@ import java.util.Random; import net.minecraft.server.v1_8_R3.MathHelper; import net.minecraft.server.v1_8_R3.Packet; import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntity; + +import org.bukkit.Material; +import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; public class DisguiseBlock extends DisguiseBase @@ -14,7 +17,7 @@ public class DisguiseBlock extends DisguiseBase private int _blockId; private int _blockData; - public DisguiseBlock(org.bukkit.entity.Entity entity, int blockId, int blockData) + public DisguiseBlock(Entity entity, int blockId, int blockData) { super(EntityType.FALLING_BLOCK, entity); @@ -22,6 +25,14 @@ public class DisguiseBlock extends DisguiseBase _blockData = blockData; } + public DisguiseBlock(Entity entity, Material material, byte data) + { + super(EntityType.FALLING_BLOCK, entity); + + _blockId = material.getId(); + _blockData = (int) data; + } + public int GetBlockId() { return _blockId; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java index 6b971d8e1..0537100f2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java @@ -122,6 +122,7 @@ import mineplex.core.gadget.gadgets.morph.MorphCow; import mineplex.core.gadget.gadgets.morph.MorphCreeper; import mineplex.core.gadget.gadgets.morph.MorphDinnerbone; import mineplex.core.gadget.gadgets.morph.MorphEnderman; +import mineplex.core.gadget.gadgets.morph.MorphGoldPot; import mineplex.core.gadget.gadgets.morph.MorphGrimReaper; import mineplex.core.gadget.gadgets.morph.MorphLoveDoctor; import mineplex.core.gadget.gadgets.morph.MorphMetalMan; @@ -405,6 +406,7 @@ public class GadgetManager extends MiniPlugin addGadget(new MorphSanta(this)); addGadget(new MorphDinnerbone(this)); addGadget(new MorphLoveDoctor(this)); + addGadget(new MorphGoldPot(this)); // Particles addGadget(new ParticleFoot(this)); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/commands/LockCosmeticsCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/commands/LockCosmeticsCommand.java index 649f26444..a4968bead 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/commands/LockCosmeticsCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/commands/LockCosmeticsCommand.java @@ -7,6 +7,7 @@ import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; import mineplex.core.donation.Donor; import mineplex.core.gadget.GadgetManager; @@ -22,13 +23,19 @@ public class LockCosmeticsCommand extends CommandBase public LockCosmeticsCommand(GadgetManager plugin) { - super(plugin, Rank.JNR_DEV, "lockCosmetics"); + super(plugin, Rank.SNR_MODERATOR, "lockCosmetics"); _plugin = plugin; } @Override public void Execute(Player caller, String[] args) { + if (!UtilServer.isTestServer()) + { + UtilPlayer.message(caller, F.main("Lock Cosmetics", "This command requires a test server!")); + return; + } + // Adds all cosmetic types if (args.length == 0) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/commands/UnlockCosmeticsCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/commands/UnlockCosmeticsCommand.java index d18f05207..43e1a4756 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/commands/UnlockCosmeticsCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/commands/UnlockCosmeticsCommand.java @@ -7,6 +7,7 @@ import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; import mineplex.core.donation.Donor; import mineplex.core.gadget.GadgetManager; @@ -29,6 +30,12 @@ public class UnlockCosmeticsCommand extends CommandBase @Override public void Execute(Player caller, String[] args) { + if (!UtilServer.isTestServer()) + { + UtilPlayer.message(caller, F.main("Unlock Cosmetics", "This command requires a test server!")); + return; + } + // Adds all cosmetic types if (args.length == 0) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphGoldPot.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphGoldPot.java new file mode 100644 index 000000000..017c3642f --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphGoldPot.java @@ -0,0 +1,132 @@ +package mineplex.core.gadget.gadgets.morph; + +import java.time.Month; +import java.time.YearMonth; +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.UtilText; +import mineplex.core.disguise.disguises.DisguiseBlock; +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.gadgets.morph.managers.GoldPotHelper; +import mineplex.core.gadget.gadgets.morph.managers.UtilMorph; +import mineplex.core.gadget.types.MorphGadget; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class MorphGoldPot extends MorphGadget +{ + + private Map _helpers = new HashMap<>(); + + public MorphGoldPot(GadgetManager manager) + { + super(manager, "Gold Pot Morph", UtilText.splitLinesToArray(new String[] + { + C.cGray + "They say at the end of every rainbow a leprechaun has a pot filled with gold.", + C.blankLine, + C.cWhite + "Stand still to hide in place and fill up with treasure. Players who find you will earn a reward!", + }, LineFormat.LORE), + -14, + Material.CAULDRON_ITEM, (byte) 0, YearMonth.of(2017, Month.MARCH)); + } + + @Override + public void enableCustom(Player player, boolean message) + { + applyArmor(player, message); + + _helpers.put(player, new GoldPotHelper(player, Manager, this)); + + DisguiseBlock disguiseBlock = new DisguiseBlock(player, Material.CAULDRON, (byte) 0); + UtilMorph.disguise(player, disguiseBlock, Manager); + } + + @Override + public void disableCustom(Player player, boolean message) + { + removeArmor(player); + + if (_helpers.containsKey(player)) + { + _helpers.get(player).unsolidifyPlayer(); + _helpers.get(player).cleanItems(true); + _helpers.remove(player); + } + + UtilMorph.undisguise(player, Manager.getDisguiseManager()); + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { for (GoldPotHelper goldPotHelper : _helpers.values()) + { + boolean solid = goldPotHelper.updatePlayer(event.getType() == UpdateType.SEC, event.getType() == UpdateType.TICK); + if (solid) + { + goldPotHelper.solififyPlayer(); + } + } + } + + @EventHandler + public void onRightClick(PlayerInteractEvent event) + { + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) + { + for (GoldPotHelper goldPotHelper : _helpers.values()) + { + goldPotHelper.performRightClick(event.getPlayer(), event.getClickedBlock()); + } + } + } + + @EventHandler + public void onItemPickup(PlayerPickupItemEvent event) + { + for (GoldPotHelper goldPotHelper : _helpers.values()) + { + if (goldPotHelper.getItems().contains(event.getItem())) + { + event.setCancelled(true); + } + } + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) + { + if (!isActive(event.getPlayer())) + return; + + if (_helpers.containsKey(event.getPlayer())) + { + if (!_helpers.get(event.getPlayer()).isSolid()) + return; + } + + Location from = event.getFrom(), to = event.getTo(); + double xFrom = from.getX(), yFrom = from.getY(), zFrom = from.getZ(), + xTo = to.getX(), yTo = to.getY(), zTo = to.getZ(); + if (xFrom != xTo || yFrom != yTo || zFrom != zTo) + { + if (_helpers.containsKey(event.getPlayer())) + { + _helpers.get(event.getPlayer()).unsolidifyPlayer(); + } + event.getPlayer().setExp(0f); + } + } + +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/managers/GoldPotHelper.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/managers/GoldPotHelper.java new file mode 100644 index 000000000..bd4f43c48 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/managers/GoldPotHelper.java @@ -0,0 +1,213 @@ +package mineplex.core.gadget.gadgets.morph.managers; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.util.Vector; + +import mineplex.core.common.currency.GlobalCurrency; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.disguise.disguises.DisguiseBlock; +import mineplex.core.disguise.disguises.DisguiseCat; +import mineplex.core.disguise.disguises.DisguiseChicken; +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.event.GadgetBlockEvent; +import mineplex.core.gadget.types.Gadget; +import mineplex.core.recharge.Recharge; + +public class GoldPotHelper +{ + + private static final float EXP_INCREMENT = 0.2f; + private static final long COOLDOWN = 300000; + private static final int SHARDS = 250; + private static final int GEMS = 60; + + private Player _player; + private GadgetManager _manager; + private Gadget _gadget; + private GoldPotStands _goldPotStands; + private Block _block; + private boolean _solid = false; + private boolean _nuggets = false; + + private HashSet _items = new HashSet<>(); + + public GoldPotHelper(Player player, GadgetManager manager, Gadget gadget) + { + _player = player; + _manager = manager; + _gadget = gadget; + _goldPotStands = new GoldPotStands(); + } + + public void solififyPlayer() + { + if (_solid) + return; + + Block block = _player.getLocation().getBlock(); + + GadgetBlockEvent event = new GadgetBlockEvent(_gadget, Collections.singletonList(block)); + + Bukkit.getServer().getPluginManager().callEvent(event); + + if (event.isCancelled() || block.getType() != Material.AIR) + { + UtilPlayer.message(_player, F.main("Morph", "You cannot become a gold pot here!")); + return; + } + + if (!Recharge.Instance.usable(_player, _gadget.getName(), true, "Your pot will be refilled with gold in %t")) + { + return; + } + + UtilMorph.undisguise(_player, _manager.getDisguiseManager()); + DisguiseChicken disguiseChicken = new DisguiseChicken(_player); + disguiseChicken.setSoundDisguise(new DisguiseCat(_player)); + disguiseChicken.setInvisible(true); + UtilMorph.disguise(_player, disguiseChicken, _manager); + + block.setType(Material.CAULDRON); + _block = block; + _goldPotStands.setBlock(_block); + _goldPotStands.createStands(); + + _solid = true; + + UtilPlayer.message(_player, F.main("Gold Pot", "You're now filled with gold!")); + } + + public void unsolidifyPlayer() + { + if (!_solid) + return; + + _goldPotStands.removeStands(); + UtilMorph.undisguise(_player, _manager.getDisguiseManager()); + DisguiseBlock disguiseBlock = new DisguiseBlock(_player, Material.CAULDRON, (byte) 0); + UtilMorph.disguise(_player, disguiseBlock, _manager); + + if (_block != null) + { + _block.setType(Material.AIR); + _block = null; + } + + _solid = false; + + UtilPlayer.message(_player, F.main("Gold Pot", "You're no longer filled with gold!")); + } + + public boolean updatePlayer(boolean second, boolean tick) + { + boolean solidify = false; + if (second) + { + if (!_solid) + { + // Updates EXP Bar + _player.setExp(_player.getExp() + EXP_INCREMENT); + + if (_player.getExp() == 1) + { + // Solidifies (or tries to) + solidify = true; + _player.setExp(0f); + } + if (_manager.isMoving(_player)) + { + _player.setExp(0f); + solidify = false; + } + } + else + { + // Throws items in the air + for (int i = 1; i < 5; i++) + { + ItemStack itemStack = new ItemStack((_nuggets) ? Material.GOLD_NUGGET : Material.GOLD_INGOT); + ItemMeta itemMeta = itemStack.getItemMeta(); + itemMeta.setDisplayName("DROPPED" + System.currentTimeMillis() + i); + itemStack.setItemMeta(itemMeta); + Item gold = _block.getWorld().dropItem(_block.getLocation().add(0.5, 1.5, 0.5), itemStack); + _items.add(gold); + + gold.setVelocity(new Vector((Math.random()-0.5)*0.3, Math.random()-0.4, (Math.random()-0.5)*0.3)); + } + _nuggets = !_nuggets; + } + } + if (tick) + { + UtilParticle.PlayParticleToAll(UtilParticle.ParticleType.ICON_CRACK.getParticle(Material.GOLD_BLOCK, + (byte) 0), _player.getLocation().add(0, 0.5, 0), 0.1f, 0.1f, 0.1f, 0.3f, 1, UtilParticle.ViewDist.LONG); + cleanItems(false); + } + return solidify; + } + + public void performRightClick(Player clicked, Block block) + { + if (_block == null) + return; + + if (!block.equals(_block)) + return; + + if (clicked.equals(_player)) + return; + + unsolidifyPlayer(); + + Recharge.Instance.use(_player, _gadget.getName(), COOLDOWN, false, false, "Cosmetics"); + + boolean shards = UtilMath.random.nextBoolean(); + if (shards) + { + _manager.getDonationManager().rewardCurrency(GlobalCurrency.TREASURE_SHARD, clicked, _gadget.getName() + " Gold Pot Pickup Shards", SHARDS); + Bukkit.broadcastMessage(F.main("Gold Pot", F.name(clicked.getName()) + " found a gold pot worth " + F.currency(GlobalCurrency.TREASURE_SHARD, SHARDS) + "!")); + } else + { + _manager.getDonationManager().rewardCurrency(GlobalCurrency.GEM, clicked, _gadget.getName() + " Gold Pot Pickup Gems", GEMS); + Bukkit.broadcastMessage(F.main("Gold Pot", F.name(clicked.getName()) + " found a gold pot worth " + F.currency(GlobalCurrency.GEM, GEMS) + "!")); + } + } + + public HashSet getItems() + { + return _items; + } + + public void cleanItems(boolean force) + { + Iterator it = _items.iterator(); + while (it.hasNext()) + { + Item item = it.next(); + if (item.getTicksLived() >= 20 || force) + { + item.remove(); + it.remove(); + } + } + } + + public boolean isSolid() + { + return _solid; + } + +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/managers/GoldPotStands.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/managers/GoldPotStands.java new file mode 100644 index 000000000..a448db9b6 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/managers/GoldPotStands.java @@ -0,0 +1,98 @@ +package mineplex.core.gadget.gadgets.morph.managers; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.ArmorStand; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.EulerAngle; + +public class GoldPotStands +{ + + private ArmorStand _helmet, _armsA, _armsB, _armsC; + private Block _block; + + public void setBlock(Block block) + { + _block = block; + } + + public void createStands() + { + if (_block == null) + { + return; + } + Location loc = _block.getLocation().clone().add(0.5, 0, 0.5); + + // Spawns main armorstand + Location asHelmetGoldLoc = loc.clone().subtract(0, 1, 0); + ArmorStand asHelmetGold = loc.getWorld().spawn(asHelmetGoldLoc, ArmorStand.class); + asHelmetGold.setVisible(false); + asHelmetGold.setGravity(false); + asHelmetGold.setHelmet(new ItemStack(Material.GOLD_BLOCK)); + + // Spawns second armorstand + Location asArmsGoldALoc = asHelmetGoldLoc.clone(); + ArmorStand asArmsGoldA = loc.getWorld().spawn(asArmsGoldALoc, ArmorStand.class); + asArmsGoldA.setVisible(false); + asArmsGoldA.setGravity(false); + asArmsGoldA.setItemInHand(new ItemStack(Material.GOLD_BLOCK)); + double asArmsGoldAX = Math.toRadians(158), asArmsGoldAY = Math.toRadians(75); + EulerAngle asArmsGoldAEuler = new EulerAngle(asArmsGoldAX, asArmsGoldAY, 0); + asArmsGoldA.setRightArmPose(asArmsGoldAEuler); + + // Spawns third armorstand + Location asArmsGoldBLoc = asHelmetGoldLoc.clone(); + ArmorStand asArmsGoldB = loc.getWorld().spawn(asArmsGoldBLoc, ArmorStand.class); + asArmsGoldB.setVisible(false); + asArmsGoldB.setGravity(false); + asArmsGoldB.setItemInHand(new ItemStack(Material.GOLD_BLOCK)); + double asArmsGoldBX = Math.toRadians(202), asArmsGoldBY = Math.toRadians(245); + EulerAngle asArmsGoldBEuler = new EulerAngle(asArmsGoldBX, asArmsGoldBY, 0); + asArmsGoldB.setRightArmPose(asArmsGoldBEuler); + + // Spawns fourth armorstand + Location asArmsGoldCLoc = loc.clone().add(0.4, 0.1, 0.1); + ArmorStand asArmsGoldC = loc.getWorld().spawn(asArmsGoldCLoc, ArmorStand.class); + asArmsGoldC.setVisible(false); + asArmsGoldC.setGravity(false); + asArmsGoldC.setSmall(true); + asArmsGoldC.setItemInHand(new ItemStack(Material.GOLD_BLOCK)); + double asArmsGoldCX = Math.toRadians(191), asArmsGoldCY = Math.toRadians(245); + EulerAngle asArmsGoldCEuler = new EulerAngle(asArmsGoldCX, asArmsGoldCY, 0); + asArmsGoldC.setRightArmPose(asArmsGoldCEuler); + + _helmet = asHelmetGold; + _armsA = asArmsGoldA; + _armsB = asArmsGoldB; + _armsC = asArmsGoldC; + } + + public void removeStands() + { + if (_helmet != null) + { + _helmet.remove(); + _helmet = null; + } + if (_armsA != null) + { + _armsA.remove(); + _armsA = null; + } + if (_armsB != null) + { + _armsB.remove(); + _armsB = null; + } + if (_armsC != null) + { + _armsC.remove(); + _armsC = null; + } + _block = null; + } + +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/PowerPlayClubRewards.java b/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/PowerPlayClubRewards.java index cf4367873..3d5f61a42 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/PowerPlayClubRewards.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/powerplayclub/PowerPlayClubRewards.java @@ -35,6 +35,7 @@ public class PowerPlayClubRewards .put(YearMonth.of(2016, Month.DECEMBER), new UnknownSalesPackageItem("Santa Morph")) .put(YearMonth.of(2017, Month.JANUARY), new UnknownSalesPackageItem("Over Easy Morph")) .put(YearMonth.of(2017, Month.FEBRUARY), new PetItem(PetType.TRUE_LOVE_PET)) + .put(YearMonth.of(2017, Month.MARCH), new UnknownSalesPackageItem("Gold Pot Morph")) .build(); public interface PowerPlayClubItem diff --git a/Plugins/Mineplex.Core/src/mineplex/core/recharge/Recharge.java b/Plugins/Mineplex.Core/src/mineplex/core/recharge/Recharge.java index 6422651d6..ce46f7dfb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/recharge/Recharge.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/recharge/Recharge.java @@ -12,8 +12,6 @@ import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.core.updater.UpdateType; import mineplex.core.account.event.ClientUnloadEvent; import mineplex.core.common.util.F; import mineplex.core.common.util.NautHashMap; @@ -21,6 +19,8 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime.TimeUnit; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; public class Recharge extends MiniPlugin { @@ -207,10 +207,23 @@ public class Recharge extends MiniPlugin } public boolean usable(Player player, String ability, boolean inform) + { + return usable(player, ability, inform, null); + } + + /** + * Checks if cooldown is over, using a custom message or not + * @param player The player to be checked + * @param ability The ability to be checked + * @param inform Should it inform the player? + * @param message The custom message (if NULL, default message will be shown) + * @return If the ability is in cooldown or not for that player + */ + public boolean usable(Player player, String ability, boolean inform, String message) { if (!Get(player).containsKey(ability)) return true; - + if (Get(player).get(ability).GetRemaining() <= 0) { return true; @@ -218,9 +231,20 @@ public class Recharge extends MiniPlugin else { if (inform && !Get(player).get(ability).DisplayForce && !Get(player).get(ability).AttachItem) - UtilPlayer.message(player, F.main("Recharge", "You cannot use " + F.skill(ability) + " for " + - F.time(UtilTime.convertString((Get(player).get(ability).GetRemaining()), 1, TimeUnit.FIT)) + ".")); - + { + if (message == null) + { + UtilPlayer.message(player, F.main("Recharge", "You cannot use " + F.skill(ability) + " for " + + F.time(UtilTime.convertString((Get(player).get(ability).GetRemaining()), 1, TimeUnit.FIT)) + ".")); + } + else + { + UtilPlayer.message(player, F.main("Recharge", message.replace("%a", F.skill(ability)) + .replace("%t", F.time(UtilTime.convertString(Get(player).get(ability).GetRemaining(), + 1, TimeUnit.FIT))))); + } + } + return false; } } From 4d3301da5684263e6de636572117ec43ef84fac9 Mon Sep 17 00:00:00 2001 From: samczsun Date: Sun, 26 Feb 2017 13:10:56 -0500 Subject: [PATCH 084/101] Sentry Issue #223476291 Check whether worlds are equal before performing distance checks Steps to reproduce: 1) Open treasure on one account 2) Go to Mavericks World on another account, tp to coords of treasure --- .../src/mineplex/core/treasure/TreasureLocation.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java index cdef82335..b729b5d15 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java @@ -325,7 +325,8 @@ public class TreasureLocation implements Listener event.setTo(newTo); } } - else + else if (event.getFrom().getWorld().equals(_currentTreasure.getCenterBlock().getWorld()) && + event.getTo().getWorld().equals(_currentTreasure.getCenterBlock().getWorld())) { Location fromLocation = event.getFrom(); Location toLocation = event.getTo(); From ed25fe13414a51457028c01a4c1a645c8b3834b4 Mon Sep 17 00:00:00 2001 From: samczsun Date: Sun, 26 Feb 2017 13:13:27 -0500 Subject: [PATCH 085/101] Sentry Issue #224064210 Have BonusManager check if Carl is enabled before cleaning up items Steps to reproduce: Trigger SQLException in NPCManager so NPCs aren't loaded, or temporarily remove Carl from npcs database --- .../Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java index d1a06f0a4..13f355f0a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java @@ -236,11 +236,11 @@ public class BonusManager extends MiniClientPlugin implements I if (event.getType() != UpdateType.TICK) return; - _animation.itemClean(); - if (!_enabled) return; + _animation.itemClean(); + if (!_animationRunning) return; From c4bb9a23d506ba4478fdc44693fdcab2796c71a8 Mon Sep 17 00:00:00 2001 From: samczsun Date: Sun, 26 Feb 2017 13:42:26 -0500 Subject: [PATCH 086/101] Sentry Issue #223492448 Check if Power Player data is loaded before acting on it Steps to reproduce: 1) Join before server has started up --- .../mineplex/core/bonuses/gui/buttons/PowerPlayClubButton.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/PowerPlayClubButton.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/PowerPlayClubButton.java index 67b1ae492..d1282cc18 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/PowerPlayClubButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/PowerPlayClubButton.java @@ -170,7 +170,8 @@ public class PowerPlayClubButton implements GuiItem public static boolean isAvailable(Player player, PowerPlayClubRepository repo) { - return !repo.getCachedData(player).getUnclaimedMonths().isEmpty(); + PowerPlayData data = repo.getCachedData(player); + return data != null && !data.getUnclaimedMonths().isEmpty(); } } From 2e23d597023c0d992ebbbdf42fb6afe047edf2ab Mon Sep 17 00:00:00 2001 From: samczsun Date: Sun, 26 Feb 2017 13:45:45 -0500 Subject: [PATCH 087/101] Sentry Issue #223489411 Check if fired projectile is a WitherSkull before casting Steps to reproduce: 1) Go to Wither Assult 2) Fire enderpearl --- .../game/arcade/game/games/wither/WitherGame.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/WitherGame.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/WitherGame.java index cf3e5eaa7..fb69f56f2 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/WitherGame.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/WitherGame.java @@ -255,11 +255,15 @@ public class WitherGame extends TeamGame implements IBlockRestorer if (GetState() == GameState.Recruit || GetState() == GameState.Prepare) { Projectile proj = event.getEntity(); - WitherSkull ws = (WitherSkull) proj; - if (ws.getShooter() instanceof Wither) + if (proj instanceof WitherSkull) { - event.setCancelled(true); + WitherSkull ws = (WitherSkull) proj; + + if (ws.getShooter() instanceof Wither) + { + event.setCancelled(true); + } } } } From 0725639852645a7695ff935672e3871e0f36cdf1 Mon Sep 17 00:00:00 2001 From: samczsun Date: Sun, 26 Feb 2017 13:55:54 -0500 Subject: [PATCH 088/101] Sentry Issue #223596821 Check if player has left before performing actions Steps to reproduce: 1) Pick wolf in SSM 2) Hit someone 3) Quit immediately after --- .../game/arcade/game/games/smash/perks/wolf/PerkWolf.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/wolf/PerkWolf.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/wolf/PerkWolf.java index 4482fa932..a5968ac4e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/wolf/PerkWolf.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/wolf/PerkWolf.java @@ -503,6 +503,12 @@ public class PerkWolf extends SmashPerk UUID uuid = playerIterator.next(); Player player = UtilPlayer.searchExact(uuid); + if (player == null) + { + playerIterator.remove(); + continue; + } + Iterator timeIterator = _repeat.get(uuid).iterator(); while (timeIterator.hasNext()) From 7e9211815f0304ddb3d7e2393b044c53ded2d5f1 Mon Sep 17 00:00:00 2001 From: samczsun Date: Sun, 26 Feb 2017 14:04:05 -0500 Subject: [PATCH 089/101] Sentry Issue #223481223, #223481117 Reverse check so RHS can be null Steps to reproduce: 1) Pick Wither Skeleton in SSM 2) Throw wither image away from other player so it has no target 3) When it's standing still (i.e no target), have the other player punch the image --- .../game/games/smash/perks/witherskeleton/PerkWitherImage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/witherskeleton/PerkWitherImage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/witherskeleton/PerkWitherImage.java index 6c09145df..ba5a90767 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/witherskeleton/PerkWitherImage.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/witherskeleton/PerkWitherImage.java @@ -169,7 +169,7 @@ public class PerkWitherImage extends SmashPerk } } - if (event.getTarget() != null && _skeletons.get(event.getTarget().getUniqueId()).equals(event.getEntity())) + if (event.getTarget() != null && event.getEntity().equals(_skeletons.get(event.getTarget().getUniqueId()))) { event.setCancelled(true); } From cb9ac1fc9fdc86093af8053a38d137c80be9077b Mon Sep 17 00:00:00 2001 From: samczsun Date: Sun, 26 Feb 2017 14:28:45 -0500 Subject: [PATCH 090/101] Sentry Issue #223481030 Prevent Fish Flurry from activating if no suitable blocks are found Steps to reproduce: 1) Select squid on hyrule castle 2) Activate fish flurry while looking at middle of empty side of castle --- .../smash/perks/squid/PerkFishFlurry.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/squid/PerkFishFlurry.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/squid/PerkFishFlurry.java index 539e98cf9..184f1b135 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/squid/PerkFishFlurry.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/squid/PerkFishFlurry.java @@ -102,11 +102,6 @@ public class PerkFishFlurry extends SmashPerk implements IThrown return; } - if (!Recharge.Instance.use(player, GetName(), COOLDOWN, true, true)) - { - return; - - } event.setCancelled(true); Set blocks = new HashSet<>(); @@ -131,10 +126,18 @@ public class PerkFishFlurry extends SmashPerk implements IThrown blocks.add(cur); } - _active.add(new DataSquidGeyser(player, blocks)); + if (!blocks.isEmpty()) + { + if (!Recharge.Instance.use(player, GetName(), COOLDOWN, true, true)) + { + return; + } - // Inform - UtilPlayer.message(player, F.main("Game", "You used " + F.skill(GetName()) + ".")); + _active.add(new DataSquidGeyser(player, blocks)); + + // Inform + UtilPlayer.message(player, F.main("Game", "You used " + F.skill(GetName()) + ".")); + } } @EventHandler From 7af7abd615ae1d540bd86fc9fa0def5ff8c6081b Mon Sep 17 00:00:00 2001 From: samczsun Date: Sun, 26 Feb 2017 14:32:08 -0500 Subject: [PATCH 091/101] Sentry Issue #223589200 Fix PetManager trying to rename a pet when it doesn't exist Steps to reproduce: 1) Somehow make MSSQL slow 2) Rename pet, and disable pet --- .../Mineplex.Core/src/mineplex/core/pet/PetManager.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/pet/PetManager.java b/Plugins/Mineplex.Core/src/mineplex/core/pet/PetManager.java index ce936a333..3b7a1b0e3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/pet/PetManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/pet/PetManager.java @@ -169,8 +169,12 @@ public class PetManager extends MiniClientPlugin if (player != null && player.isOnline()) { - getActivePet(playerName).setCustomNameVisible(true); - getActivePet(playerName).setCustomName(_petRenameQueue.get(playerName)); + Creature activePet = getActivePet(playerName); + if (activePet != null) + { + activePet.setCustomNameVisible(true); + activePet.setCustomName(_petRenameQueue.get(playerName)); + } } } From 9571db123d350367a1d0d4688b172844f65e6f72 Mon Sep 17 00:00:00 2001 From: samczsun Date: Sun, 26 Feb 2017 14:36:59 -0500 Subject: [PATCH 092/101] Sentry Issue #223483175 Fix badly implement Player check in PerkBoneRush Steps to reproduce: 1) Pick Skeletal Horse 2) Bone rush on some mob (i.e. cows in swamp) --- .../game/games/smash/perks/skeletalhorse/PerkBoneRush.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/skeletalhorse/PerkBoneRush.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/skeletalhorse/PerkBoneRush.java index 4fc78ea1b..f1d281713 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/skeletalhorse/PerkBoneRush.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/skeletalhorse/PerkBoneRush.java @@ -193,7 +193,7 @@ public class PerkBoneRush extends SmashPerk implements IThrown return; } - if (!(target instanceof Player || data.getThrower() instanceof Player)) + if (!(target instanceof Player) || !(data.getThrower() instanceof Player)) { return; } From 3f40432268c24a101e3e8af1f84e1531bc44798b Mon Sep 17 00:00:00 2001 From: samczsun Date: Sun, 26 Feb 2017 14:53:02 -0500 Subject: [PATCH 093/101] Sentry Issue #223474603 Handle null gun in Minestrike Steps to reproduce: 1) Bring a player down to low health using a molotov 2) Kill them with a grenade --- .../game/games/minestrike/Minestrike.java | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/Minestrike.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/Minestrike.java index 088a6f1ef..b5d69dd75 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/Minestrike.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/Minestrike.java @@ -414,22 +414,29 @@ public class Minestrike extends TeamGame int amount; String gunType = (String) event.GetLog().GetLastDamager().GetDamage().getFirst().getMetadata().get("gunType"); - switch (gunType) + if (gunType == null) { - case "AWP": - amount = 100; - break; - case "PPBIZON": - amount = 600; - break; - case "NOVA": - amount = 900; - break; - case "KNIFE": - amount = 1500; - break; - default: - amount = 300; + amount = 300; + } + else + { + switch (gunType) + { + case "AWP": + amount = 100; + break; + case "PPBIZON": + amount = 600; + break; + case "NOVA": + amount = 900; + break; + case "KNIFE": + amount = 1500; + break; + default: + amount = 300; + } } _shopManager.addMoney(killer, amount, "kill with " + event.GetLog().GetLastDamager().GetReason()); From b3cc9f29e2ebad4d289e0a7bea4f215b92a2ec2c Mon Sep 17 00:00:00 2001 From: samczsun Date: Sun, 26 Feb 2017 14:56:33 -0500 Subject: [PATCH 094/101] Sentry Issue #223905084 Prevent NewsManager from updating news when none exists Steps to reproduce: 1) Join the server while the server is starting up --- Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java index 2e1c958d6..0679e29ba 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java @@ -253,6 +253,9 @@ public class NewsManager extends MiniPlugin { if (event.getType() != UpdateType.FASTEST) return; + + if (_news.length == 0) + return; String text = ""; double healthPercent = 1; From 3e8b23c6f46503d3e5b3ec0194dea989d8e32c2c Mon Sep 17 00:00:00 2001 From: samczsun Date: Sun, 26 Feb 2017 15:05:31 -0500 Subject: [PATCH 095/101] Sentry Issue #223473496 Don't bother with failsafe if the game is null (i.e. beyond dead) Steps to reproduce: 1) Quit server at just the right time --- .../game/arcade/managers/ProgressingKitManager.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/ProgressingKitManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/ProgressingKitManager.java index b092d0a17..2ce6c2ac3 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/ProgressingKitManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/ProgressingKitManager.java @@ -157,12 +157,15 @@ public class ProgressingKitManager implements Listener PlayerKit playerKit = _manager.getKitProgressionManager().getDataManager().get(player.getUniqueId()); try { - for (Kit kit : _manager.GetGame().GetKits()) + if (_manager.GetGame() != null) { - if (kit instanceof ProgressingKit) + for (Kit kit : _manager.GetGame().GetKits()) { - ProgressingKit progressingKit = (ProgressingKit) kit; - _manager.getKitProgressionManager().getRepository().insertOrUpdate(playerKit, progressingKit.getInternalName()); + if (kit instanceof ProgressingKit) + { + ProgressingKit progressingKit = (ProgressingKit) kit; + _manager.getKitProgressionManager().getRepository().insertOrUpdate(playerKit, progressingKit.getInternalName()); + } } } } From 9669e960a78b30417272246e5b99246f2a0fb442 Mon Sep 17 00:00:00 2001 From: samczsun Date: Fri, 17 Feb 2017 16:25:58 -0500 Subject: [PATCH 096/101] Autorotate maps --- .../api/enderchest/EnderchestWorldLoader.java | 2 +- .../Nautilus.Game.Arcade.UHC.WorldGen/pom.xml | 10 +++ .../nautilus/game/arcade/uhc/WorldGen.java | 76 ++++++++++++++++--- 3 files changed, 75 insertions(+), 13 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/enderchest/EnderchestWorldLoader.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/enderchest/EnderchestWorldLoader.java index 5a196c26e..c11615902 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/enderchest/EnderchestWorldLoader.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/api/enderchest/EnderchestWorldLoader.java @@ -26,7 +26,7 @@ public class EnderchestWorldLoader { TimingManager.start(TIMINGS_PREFIX + "DownloadMap"); String fileName = mapType + "_map.zip"; - File f = _webCall.getFile("map/" + mapType + "/random", fileName); + File f = _webCall.getFile("map/" + mapType + "/next", fileName); TimingManager.stop(TIMINGS_PREFIX + "DownloadMap"); TimingManager.start(TIMINGS_PREFIX + "CreateFolders"); diff --git a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/pom.xml b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/pom.xml index 52ebd07c0..879b9a7c8 100644 --- a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/pom.xml +++ b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/pom.xml @@ -19,10 +19,20 @@ 1.8.8-1.9-SNAPSHOT compile + + com.mineplex + mineplex-core + dev-SNAPSHOT + org.zeroturnaround zt-zip 1.9 + + org.slf4j + slf4j-simple + 1.7.21 + diff --git a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java index 2dd1a54be..da1bfe3a0 100644 --- a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java +++ b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java @@ -1,7 +1,29 @@ package nautilus.game.arcade.uhc; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import java.util.zip.ZipEntry; + import net.minecraft.server.v1_8_R3.BiomeBase; + import org.apache.commons.io.FileUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.message.BasicHeader; +import org.apache.http.protocol.HTTP; import org.bukkit.Bukkit; import org.bukkit.Difficulty; import org.bukkit.World; @@ -14,20 +36,15 @@ import org.spigotmc.WatchdogThread; import org.zeroturnaround.zip.ZipEntrySource; import org.zeroturnaround.zip.ZipUtil; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ThreadLocalRandom; -import java.util.logging.Level; -import java.util.zip.ZipEntry; +import com.google.gson.JsonObject; + +import mineplex.core.common.Constants; +import mineplex.core.common.api.ApiHost; public class WorldGen extends JavaPlugin implements Runnable, Listener { + private static final int TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10); + private static final int MIN_X = -1000; private static final int MIN_Z = -1000; private static final int MAX_X = 1000; @@ -240,6 +257,41 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener FileUtils.deleteQuietly(worldFolder); - getLogger().info("Finished generating world seed " + seed); + RequestConfig config = RequestConfig.custom() + .setConnectTimeout(TIMEOUT) + .setSocketTimeout(TIMEOUT) + .build(); + + CloseableHttpClient httpClient = HttpClientBuilder.create() + .setDefaultRequestConfig(config) + .build(); + + HttpPost request = new HttpPost("http://" + ApiHost.getEnderchestService().getHost() + ":" + ApiHost.getEnderchestService().getPort() + "/map/uhc/upload"); + request.addHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); + + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("name", outputFile.getName()); + jsonObject.addProperty("location", outputFile.toURI().toString()); + + request.setEntity(new StringEntity(Constants.GSON.toJson(jsonObject), StandardCharsets.UTF_8)); + + try + { + HttpResponse response = httpClient.execute(request); + + if (response.getStatusLine().getStatusCode() != 200) { + getLogger().severe("Failed to upload " + seed + ": " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase()); + } else { + getLogger().info("Uploaded " + seed + "!"); + } + } + catch (IOException e) + { + e.printStackTrace(); + } + finally + { + getLogger().info("Finished generating world seed " + seed); + } } } From dedcd254b001de48b42c660cc4cef9cea8997bbb Mon Sep 17 00:00:00 2001 From: samczsun Date: Sat, 18 Feb 2017 14:10:57 -0500 Subject: [PATCH 097/101] Clean up maps on local server --- .../nautilus/game/arcade/uhc/WorldGen.java | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java index da1bfe3a0..debfeea29 100644 --- a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java +++ b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java @@ -258,9 +258,9 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener FileUtils.deleteQuietly(worldFolder); RequestConfig config = RequestConfig.custom() - .setConnectTimeout(TIMEOUT) - .setSocketTimeout(TIMEOUT) - .build(); + .setConnectTimeout(TIMEOUT) + .setSocketTimeout(TIMEOUT) + .build(); CloseableHttpClient httpClient = HttpClientBuilder.create() .setDefaultRequestConfig(config) @@ -277,12 +277,33 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener try { + getLogger().info("Uploading " + seed + "!"); HttpResponse response = httpClient.execute(request); - if (response.getStatusLine().getStatusCode() != 200) { - getLogger().severe("Failed to upload " + seed + ": " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase()); - } else { + if (response.getStatusLine().getStatusCode() != 200) + { + if (response.getStatusLine().getStatusCode() == 409) + { + getLogger().warning("Oops - Server rejected " + seed + " because it was already generated"); + + if (!outputFile.delete()) + { + getLogger().warning("Could not clean up " + seed); + } + } + else + { + getLogger().severe("Failed to upload " + seed + ": " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase()); + } + } + else + { getLogger().info("Uploaded " + seed + "!"); + + if (!outputFile.delete()) + { + getLogger().warning("Could not clean up " + seed); + } } } catch (IOException e) From f8dbbce106345e2e87e4a61121e8b55e8e3297dc Mon Sep 17 00:00:00 2001 From: samczsun Date: Sun, 19 Feb 2017 16:52:34 -0500 Subject: [PATCH 098/101] Cleanup --- .../Nautilus.Game.Arcade.UHC.WorldGen/pom.xml | 10 +- .../nautilus/game/arcade/uhc/WorldGen.java | 443 +++++++++--------- 2 files changed, 238 insertions(+), 215 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/pom.xml b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/pom.xml index 879b9a7c8..2c02322e7 100644 --- a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/pom.xml +++ b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/pom.xml @@ -19,16 +19,16 @@ 1.8.8-1.9-SNAPSHOT compile - - com.mineplex - mineplex-core - dev-SNAPSHOT - org.zeroturnaround zt-zip 1.9 + + org.apache.httpcomponents + httpclient + 4.5.2 + org.slf4j slf4j-simple diff --git a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java index debfeea29..c2e322e7f 100644 --- a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java +++ b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java @@ -7,7 +7,9 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.logging.Level; @@ -28,20 +30,16 @@ import org.bukkit.Bukkit; import org.bukkit.Difficulty; import org.bukkit.World; import org.bukkit.WorldCreator; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.java.JavaPlugin; import org.spigotmc.WatchdogThread; import org.zeroturnaround.zip.ZipEntrySource; import org.zeroturnaround.zip.ZipUtil; +import com.google.gson.Gson; import com.google.gson.JsonObject; -import mineplex.core.common.Constants; -import mineplex.core.common.api.ApiHost; - -public class WorldGen extends JavaPlugin implements Runnable, Listener +public class WorldGen extends JavaPlugin { private static final int TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10); @@ -51,6 +49,35 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener private static final int MAX_Z = 1000; private static final int VIEW_DISTANCE = 5; + private static final String API_HOST_FILE = "api-config.dat"; + private static final Map API_HOST_MAP = new HashMap<>(); + + static + { + try + { + File configFile = new File(API_HOST_FILE); + YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile); + + for (String key : configuration.getKeys(false)) + { + String ip = configuration.getConfigurationSection(key).getString("ip"); + // Use parseInt to catch non-ints instead of a 0 + int port = Integer.parseInt(configuration.getConfigurationSection(key).getString("port")); + if (ip == null) + { + throw new NullPointerException(); + } + + API_HOST_MAP.put(key, ip + ":" + port); + } + } + catch (Throwable t) + { + t.printStackTrace(); + } + } + @Override public void onEnable() { @@ -61,161 +88,127 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener WatchdogThread.doStop(); - getServer().getScheduler().runTaskTimer(this, this, 20L, 20L * 5L); - getServer().getPluginManager().registerEvents(this, this); - } - - @EventHandler - public void onJoin(AsyncPlayerPreLoginEvent event) - { - event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); - event.setKickMessage("Shoo, go away"); - } - - @Override - public void run() - { - File root = new File("."); - - if (!root.exists()) - { - getLogger().severe("Root folder does not exist. Aborting"); - getServer().shutdown(); - return; - } - - File outputDirectory = new File(root, "output"); - if (!outputDirectory.exists()) - { - if (!outputDirectory.mkdir()) - { - getLogger().severe("Could not create output folder. Aborting"); - getServer().shutdown(); - return; - } - } - - long seed = ThreadLocalRandom.current().nextLong(); - - File outputFile = new File(outputDirectory, "UHC_Map" + seed + ".zip"); - - if (outputFile.exists()) - { - getLogger().info("Seed " + seed + " has already been generated. Skipping"); - return; - } try { - if (!outputFile.createNewFile()) + File root = new File("."); + + if (!root.exists()) { - getLogger().severe("Could not create new output file. Aborting"); - getServer().shutdown(); + getLogger().severe("Root folder does not exist. Aborting"); + System.exit(0); return; } - } - catch (IOException e) - { - getLogger().log(Level.SEVERE, "Could not create new output file. Aborting", e); - getServer().shutdown(); - return; - } - getLogger().info("Generating world seed " + seed); - - World world = new WorldCreator("generating") - .environment(World.Environment.NORMAL) - .seed(seed) - .createWorld(); - world.setDifficulty(Difficulty.HARD); - world.setKeepSpawnInMemory(false); - - int minChunkX = (MIN_X >> 4) - VIEW_DISTANCE; - int minChunkZ = (MIN_Z >> 4) - VIEW_DISTANCE; - int maxChunkX = (MAX_X >> 4) + VIEW_DISTANCE; - int maxChunkZ = (MAX_Z >> 4) + VIEW_DISTANCE; - - for (int x = minChunkX; x <= maxChunkX; x++) - { - getLogger().info("Generating x coord " + x); - for (int z = minChunkZ; z <= maxChunkZ; z++) + File outputDirectory = new File(root, "output"); + if (!outputDirectory.exists()) { - world.getChunkAt(x, z).load(true); - } - } - - for (int x = minChunkX; x <= maxChunkX; x++) - { - getLogger().info("Unloading x coord " + x); - for (int z = minChunkZ; z <= maxChunkZ; z++) - { - world.getChunkAt(x, z).unload(true, false); - } - } - - getLogger().info("Unloading and saving world"); - - Bukkit.unloadWorld(world, true); - - getLogger().info("Finished unloading and saving world"); - - StringBuilder worldconfig = new StringBuilder(); - worldconfig.append("MAP_NAME:UHC World").append(System.lineSeparator()); - worldconfig.append("MAP_AUTHOR:Mineplex").append(System.lineSeparator()); - worldconfig.append("MIN_X:").append(MIN_X).append(System.lineSeparator()); - worldconfig.append("MIN_Z:").append(MIN_Z).append(System.lineSeparator()); - worldconfig.append("MAX_X:").append(MAX_X).append(System.lineSeparator()); - worldconfig.append("MAX_Z:").append(MAX_Z).append(System.lineSeparator()); - for (int i = 1; i <= 60; i++) - { - worldconfig.append("TEAM_NAME:").append(i).append(System.lineSeparator()); - worldconfig.append("TEAM_SPAWNS:0,0,0").append(System.lineSeparator()); - } - - File worldFolder = new File(root, "generating"); - - File regionFolder = new File(worldFolder, "region"); - - File[] regionFiles = regionFolder.listFiles(); - - if (regionFiles == null) - { - getLogger().severe("Unexpected null region files. Aborting"); - getServer().shutdown(); - return; - } - - List zipEntrySourceList = new ArrayList<>(); - zipEntrySourceList.add(new ZipEntrySource() - { - @Override - public String getPath() - { - return "WorldConfig.dat"; + if (!outputDirectory.mkdir()) + { + getLogger().severe("Could not create output folder. Aborting"); + System.exit(0); + return; + } } - @Override - public ZipEntry getEntry() + long seed = ThreadLocalRandom.current().nextLong(); + + File outputFile = new File(outputDirectory, "UHC_Map" + seed + ".zip"); + + if (outputFile.exists()) { - return new ZipEntry(getPath()); + getLogger().info("Seed " + seed + " has already been generated. Skipping"); + System.exit(0); + return; } - @Override - public InputStream getInputStream() throws IOException + try { - return new ByteArrayInputStream(worldconfig.toString().getBytes(StandardCharsets.UTF_8)); + if (!outputFile.createNewFile()) + { + getLogger().severe("Could not create new output file. Aborting"); + System.exit(0); + return; + } + } + catch (IOException e) + { + getLogger().log(Level.SEVERE, "Could not create new output file. Aborting", e); + System.exit(0); + return; } - }); + getLogger().info("Generating world seed " + seed); - for (File file : regionFiles) - { + World world = new WorldCreator("generating") + .environment(World.Environment.NORMAL) + .seed(seed) + .createWorld(); + world.setDifficulty(Difficulty.HARD); + world.setKeepSpawnInMemory(false); + + int minChunkX = (MIN_X >> 4) - VIEW_DISTANCE; + int minChunkZ = (MIN_Z >> 4) - VIEW_DISTANCE; + int maxChunkX = (MAX_X >> 4) + VIEW_DISTANCE; + int maxChunkZ = (MAX_Z >> 4) + VIEW_DISTANCE; + + for (int x = minChunkX; x <= maxChunkX; x++) + { + getLogger().info("Generating x coord " + x); + for (int z = minChunkZ; z <= maxChunkZ; z++) + { + world.getChunkAt(x, z).load(true); + } + } + + for (int x = minChunkX; x <= maxChunkX; x++) + { + getLogger().info("Unloading x coord " + x); + for (int z = minChunkZ; z <= maxChunkZ; z++) + { + world.getChunkAt(x, z).unload(true, false); + } + } + + getLogger().info("Unloading and saving world"); + + Bukkit.unloadWorld(world, true); + + getLogger().info("Finished unloading and saving world"); + + StringBuilder worldconfig = new StringBuilder(); + worldconfig.append("MAP_NAME:UHC World").append(System.lineSeparator()); + worldconfig.append("MAP_AUTHOR:Mineplex").append(System.lineSeparator()); + worldconfig.append("MIN_X:").append(MIN_X).append(System.lineSeparator()); + worldconfig.append("MIN_Z:").append(MIN_Z).append(System.lineSeparator()); + worldconfig.append("MAX_X:").append(MAX_X).append(System.lineSeparator()); + worldconfig.append("MAX_Z:").append(MAX_Z).append(System.lineSeparator()); + for (int i = 1; i <= 60; i++) + { + worldconfig.append("TEAM_NAME:").append(i).append(System.lineSeparator()); + worldconfig.append("TEAM_SPAWNS:0,0,0").append(System.lineSeparator()); + } + + File worldFolder = new File(root, "generating"); + + File regionFolder = new File(worldFolder, "region"); + + File[] regionFiles = regionFolder.listFiles(); + + if (regionFiles == null) + { + getLogger().severe("Unexpected null region files. Aborting"); + System.exit(0); + return; + } + + List zipEntrySourceList = new ArrayList<>(); zipEntrySourceList.add(new ZipEntrySource() { @Override public String getPath() { - return "region/" + file.getName(); + return "WorldConfig.dat"; } @Override @@ -227,92 +220,122 @@ public class WorldGen extends JavaPlugin implements Runnable, Listener @Override public InputStream getInputStream() throws IOException { - return new FileInputStream(file); + return new ByteArrayInputStream(worldconfig.toString().getBytes(StandardCharsets.UTF_8)); } }); - } - zipEntrySourceList.add(new ZipEntrySource() - { - @Override - public String getPath() + + for (File file : regionFiles) { - return "level.dat"; - } - - @Override - public ZipEntry getEntry() - { - return new ZipEntry(getPath()); - } - - @Override - public InputStream getInputStream() throws IOException - { - return new FileInputStream(new File(worldFolder, "level.dat")); - } - }); - - ZipUtil.pack(zipEntrySourceList.toArray(new ZipEntrySource[zipEntrySourceList.size()]), outputFile); - - FileUtils.deleteQuietly(worldFolder); - - RequestConfig config = RequestConfig.custom() - .setConnectTimeout(TIMEOUT) - .setSocketTimeout(TIMEOUT) - .build(); - - CloseableHttpClient httpClient = HttpClientBuilder.create() - .setDefaultRequestConfig(config) - .build(); - - HttpPost request = new HttpPost("http://" + ApiHost.getEnderchestService().getHost() + ":" + ApiHost.getEnderchestService().getPort() + "/map/uhc/upload"); - request.addHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); - - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("name", outputFile.getName()); - jsonObject.addProperty("location", outputFile.toURI().toString()); - - request.setEntity(new StringEntity(Constants.GSON.toJson(jsonObject), StandardCharsets.UTF_8)); - - try - { - getLogger().info("Uploading " + seed + "!"); - HttpResponse response = httpClient.execute(request); - - if (response.getStatusLine().getStatusCode() != 200) - { - if (response.getStatusLine().getStatusCode() == 409) + zipEntrySourceList.add(new ZipEntrySource() { - getLogger().warning("Oops - Server rejected " + seed + " because it was already generated"); + @Override + public String getPath() + { + return "region/" + file.getName(); + } + + @Override + public ZipEntry getEntry() + { + return new ZipEntry(getPath()); + } + + @Override + public InputStream getInputStream() throws IOException + { + return new FileInputStream(file); + } + }); + } + + zipEntrySourceList.add(new ZipEntrySource() + { + @Override + public String getPath() + { + return "level.dat"; + } + + @Override + public ZipEntry getEntry() + { + return new ZipEntry(getPath()); + } + + @Override + public InputStream getInputStream() throws IOException + { + return new FileInputStream(new File(worldFolder, "level.dat")); + } + }); + + ZipUtil.pack(zipEntrySourceList.toArray(new ZipEntrySource[zipEntrySourceList.size()]), outputFile); + + FileUtils.deleteQuietly(worldFolder); + + RequestConfig config = RequestConfig.custom() + .setConnectTimeout(TIMEOUT) + .setSocketTimeout(TIMEOUT) + .build(); + + CloseableHttpClient httpClient = HttpClientBuilder.create() + .setDefaultRequestConfig(config) + .build(); + + HttpPost request = new HttpPost("http://" + API_HOST_MAP.get("ENDERCHEST") + "/map/uhc/upload"); + request.addHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); + + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("name", outputFile.getName()); + jsonObject.addProperty("location", outputFile.toURI().toString()); + + request.setEntity(new StringEntity(new Gson().toJson(jsonObject), StandardCharsets.UTF_8)); + + try + { + getLogger().info("Uploading " + seed + "!"); + HttpResponse response = httpClient.execute(request); + + if (response.getStatusLine().getStatusCode() != 200) + { + if (response.getStatusLine().getStatusCode() == 409) + { + getLogger().warning("Oops - Server rejected " + seed + " because it was already generated"); + + if (!outputFile.delete()) + { + getLogger().warning("Could not clean up " + seed); + } + } + else + { + getLogger().severe("Failed to upload " + seed + ": " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase()); + } + } + else + { + getLogger().info("Uploaded " + seed + "!"); if (!outputFile.delete()) { getLogger().warning("Could not clean up " + seed); } } - else - { - getLogger().severe("Failed to upload " + seed + ": " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase()); - } } - else + catch (IOException e) { - getLogger().info("Uploaded " + seed + "!"); - - if (!outputFile.delete()) - { - getLogger().warning("Could not clean up " + seed); - } + e.printStackTrace(); + } + finally + { + getLogger().info("Finished generating world seed " + seed); } } - catch (IOException e) + catch (Throwable t) { - e.printStackTrace(); - } - finally - { - getLogger().info("Finished generating world seed " + seed); + t.printStackTrace(); } + System.exit(0); } } From b782f5ced9b842edbffd817b704587ec5eb5cdfc Mon Sep 17 00:00:00 2001 From: samczsun Date: Sun, 19 Feb 2017 23:53:19 -0500 Subject: [PATCH 099/101] Speed up generation --- .../nautilus/game/arcade/uhc/WorldGen.java | 465 +++++++++--------- .../game/arcade/game/games/uhc/UHC.java | 12 +- 2 files changed, 248 insertions(+), 229 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java index c2e322e7f..812b1f45a 100644 --- a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java +++ b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java @@ -1,10 +1,7 @@ package nautilus.game.arcade.uhc; -import java.io.ByteArrayInputStream; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; @@ -13,7 +10,6 @@ import java.util.Map; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.logging.Level; -import java.util.zip.ZipEntry; import net.minecraft.server.v1_8_R3.BiomeBase; @@ -27,26 +23,35 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.message.BasicHeader; import org.apache.http.protocol.HTTP; import org.bukkit.Bukkit; +import org.bukkit.Chunk; import org.bukkit.Difficulty; import org.bukkit.World; +import org.bukkit.WorldBorder; import org.bukkit.WorldCreator; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.entity.Entity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.bukkit.event.world.ChunkUnloadEvent; +import org.bukkit.event.world.WorldInitEvent; import org.bukkit.plugin.java.JavaPlugin; import org.spigotmc.WatchdogThread; +import org.zeroturnaround.zip.ByteSource; +import org.zeroturnaround.zip.FileSource; import org.zeroturnaround.zip.ZipEntrySource; import org.zeroturnaround.zip.ZipUtil; import com.google.gson.Gson; import com.google.gson.JsonObject; -public class WorldGen extends JavaPlugin +public class WorldGen extends JavaPlugin implements Listener { private static final int TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10); - private static final int MIN_X = -1000; - private static final int MIN_Z = -1000; - private static final int MAX_X = 1000; - private static final int MAX_Z = 1000; + // The world will be -MAP_SIZE to MAP_SIZE large + private static final int MAP_SIZE = 1000; private static final int VIEW_DISTANCE = 5; private static final String API_HOST_FILE = "api-config.dat"; @@ -78,264 +83,276 @@ public class WorldGen extends JavaPlugin } } + @EventHandler + public void login(AsyncPlayerPreLoginEvent event) + { + event.setKickMessage("get out"); + event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); + } + + @EventHandler + public void unload(ChunkUnloadEvent event) + { + event.setCancelled(true); + } + + @EventHandler + public void init(WorldInitEvent event) + { + // Prevent any eager generation + event.getWorld().setKeepSpawnInMemory(false); + } + @Override public void onEnable() { + getLogger().info("Cleaning up other worlds"); + for (World world : getServer().getWorlds()) + { + world.setKeepSpawnInMemory(false); + world.setSpawnFlags(false, false); + world.setAmbientSpawnLimit(0); + world.setAnimalSpawnLimit(0); + world.setMonsterSpawnLimit(0); + world.setWaterAnimalSpawnLimit(0); + world.getEntities().forEach(Entity::remove); + for (Chunk chunk : world.getLoadedChunks()) + { + chunk.unload(false, false); + } + getServer().unloadWorld(world, false); + getLogger().info("Unloaded " + world.getName()); + } + + getLogger().info("Replacing biomes"); BiomeBase.getBiomes()[BiomeBase.OCEAN.id] = BiomeBase.PLAINS; BiomeBase.getBiomes()[BiomeBase.DEEP_OCEAN.id] = BiomeBase.PLAINS; BiomeBase.getBiomes()[BiomeBase.SWAMPLAND.id] = BiomeBase.PLAINS; BiomeBase.getBiomes()[BiomeBase.RIVER.id] = BiomeBase.PLAINS; + getLogger().info("Forcing system GC"); + System.gc(); + WatchdogThread.doStop(); + getServer().getPluginManager().registerEvents(this, this); + + File root = new File("."); + + if (!root.exists()) + { + getLogger().severe("Root folder does not exist. Aborting"); + System.exit(0); + return; + } + + File outputDirectory = new File(root, "output"); + if (!outputDirectory.exists()) + { + if (!outputDirectory.mkdir()) + { + getLogger().severe("Could not create output folder. Aborting"); + System.exit(0); + return; + } + } + + long seed = ThreadLocalRandom.current().nextLong(); + + File outputFile = new File(outputDirectory, "UHC_Map" + seed + ".zip"); + + if (outputFile.exists()) + { + getLogger().info("Seed " + seed + " has already been generated. Skipping"); + System.exit(0); + return; + } try { - File root = new File("."); - - if (!root.exists()) + if (!outputFile.createNewFile()) { - getLogger().severe("Root folder does not exist. Aborting"); + getLogger().severe("Could not create new output file. Aborting"); System.exit(0); return; } + } + catch (IOException e) + { + getLogger().log(Level.SEVERE, "Could not create new output file. Aborting", e); + System.exit(0); + return; + } - File outputDirectory = new File(root, "output"); - if (!outputDirectory.exists()) + File previousSession = new File("generating"); + + if (previousSession.exists()) + { + if (!FileUtils.deleteQuietly(previousSession)) { - if (!outputDirectory.mkdir()) - { - getLogger().severe("Could not create output folder. Aborting"); - System.exit(0); - return; - } - } - - long seed = ThreadLocalRandom.current().nextLong(); - - File outputFile = new File(outputDirectory, "UHC_Map" + seed + ".zip"); - - if (outputFile.exists()) - { - getLogger().info("Seed " + seed + " has already been generated. Skipping"); + getLogger().severe("Could not delete previous generation session. Aborting"); System.exit(0); return; } + } - try + getLogger().info("Generating world seed " + seed); + + World world = new WorldCreator("generating") + .environment(World.Environment.NORMAL) + .seed(seed) + .createWorld(); + world.setKeepSpawnInMemory(false); + world.setDifficulty(Difficulty.HARD); + WorldBorder border = world.getWorldBorder(); + border.setCenter(0.0, 0.0); + border.setSize(MAP_SIZE * 2); + + int minChunkX = (-MAP_SIZE >> 4) - VIEW_DISTANCE; + int minChunkZ = (-MAP_SIZE >> 4) - VIEW_DISTANCE; + int maxChunkX = (MAP_SIZE >> 4) + VIEW_DISTANCE; + int maxChunkZ = (MAP_SIZE >> 4) + VIEW_DISTANCE; + + net.minecraft.server.v1_8_R3.WorldServer nmsWorld = ((CraftWorld) world).getHandle(); +// +// Field mfield = nmsWorld.getClass().getDeclaredField("M"); +// mfield.setAccessible(true); +// +// HashTreeSet treeSet = ((HashTreeSet) mfield.get(nmsWorld)); + + for (int x = minChunkX; x <= maxChunkX; x++) + { + getLogger().info("Generating x coord " + x); + for (int z = minChunkZ; z <= maxChunkZ; z++) { - if (!outputFile.createNewFile()) - { - getLogger().severe("Could not create new output file. Aborting"); - System.exit(0); - return; - } - } - catch (IOException e) - { - getLogger().log(Level.SEVERE, "Could not create new output file. Aborting", e); - System.exit(0); - return; + world.getChunkAt(x, z).load(true); + nmsWorld.a(true); + // Manually tick blocks - this should be the equivalent of letting a full server tick run once + // between each chunk generation, except we cut out the extra useless stuff } - getLogger().info("Generating world seed " + seed); +// System.out.println("M: " + treeSet.size()); +// System.out.println("E: " + nmsWorld.entityList.size()); +// System.out.println("TE: " + nmsWorld.tileEntityList.size()); +// System.out.println("C: " + nmsWorld.chunkProviderServer.chunks.size()); + } - World world = new WorldCreator("generating") - .environment(World.Environment.NORMAL) - .seed(seed) - .createWorld(); - world.setDifficulty(Difficulty.HARD); - world.setKeepSpawnInMemory(false); - - int minChunkX = (MIN_X >> 4) - VIEW_DISTANCE; - int minChunkZ = (MIN_Z >> 4) - VIEW_DISTANCE; - int maxChunkX = (MAX_X >> 4) + VIEW_DISTANCE; - int maxChunkZ = (MAX_Z >> 4) + VIEW_DISTANCE; - - for (int x = minChunkX; x <= maxChunkX; x++) + for (int x = minChunkX; x <= maxChunkX; x++) + { + getLogger().info("Unloading x coord " + x); + for (int z = minChunkZ; z <= maxChunkZ; z++) { - getLogger().info("Generating x coord " + x); - for (int z = minChunkZ; z <= maxChunkZ; z++) - { - world.getChunkAt(x, z).load(true); - } + world.getChunkAt(x, z).unload(true, false); } - for (int x = minChunkX; x <= maxChunkX; x++) +// System.out.println("M: " + treeSet.size()); +// System.out.println("E: " + nmsWorld.entityList.size()); +// System.out.println("TE: " + nmsWorld.tileEntityList.size()); +// System.out.println("C: " + nmsWorld.chunkProviderServer.chunks.size()); + } + + getLogger().info("Unloading and saving world"); + + Bukkit.unloadWorld(world, true); + + getLogger().info("Finished unloading and saving world"); + + StringBuilder worldconfig = new StringBuilder(); + worldconfig.append("MAP_NAME:UHC World").append(System.lineSeparator()); + worldconfig.append("MAP_AUTHOR:Mineplex").append(System.lineSeparator()); + worldconfig.append("MIN_X:").append(-MAP_SIZE).append(System.lineSeparator()); + worldconfig.append("MIN_Z:").append(-MAP_SIZE).append(System.lineSeparator()); + worldconfig.append("MAX_X:").append(MAP_SIZE).append(System.lineSeparator()); + worldconfig.append("MAX_Z:").append(MAP_SIZE).append(System.lineSeparator()); + for (int i = 1; i <= 60; i++) + { + worldconfig.append("TEAM_NAME:").append(i).append(System.lineSeparator()); + worldconfig.append("TEAM_SPAWNS:0,0,0").append(System.lineSeparator()); + } + + File worldFolder = new File(root, "generating"); + + File regionFolder = new File(worldFolder, "region"); + + File[] regionFiles = regionFolder.listFiles(); + + if (regionFiles == null) + { + getLogger().severe("Unexpected null region files. Aborting"); + System.exit(0); + return; + } + + List zipEntrySourceList = new ArrayList<>(); + zipEntrySourceList.add(new ByteSource("WorldConfig.dat", worldconfig.toString().getBytes(StandardCharsets.UTF_8))); + for (File file : regionFiles) + { + zipEntrySourceList.add(new FileSource("region/" + file.getName(), file)); + } + zipEntrySourceList.add(new FileSource("level.dat", new File(worldFolder, "level.dat"))); + + ZipUtil.pack(zipEntrySourceList.toArray(new ZipEntrySource[zipEntrySourceList.size()]), outputFile); + + FileUtils.deleteQuietly(worldFolder); + + RequestConfig config = RequestConfig.custom() + .setConnectTimeout(TIMEOUT) + .setSocketTimeout(TIMEOUT) + .build(); + + CloseableHttpClient httpClient = HttpClientBuilder.create() + .setDefaultRequestConfig(config) + .build(); + + HttpPost request = new HttpPost("http://" + API_HOST_MAP.get("ENDERCHEST") + "/map/uhc/upload"); + request.addHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); + + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("name", outputFile.getName()); + jsonObject.addProperty("location", outputFile.toURI().toString()); + + request.setEntity(new StringEntity(new Gson().toJson(jsonObject), StandardCharsets.UTF_8)); + + try + { + getLogger().info("Uploading " + seed + "!"); + HttpResponse response = httpClient.execute(request); + + if (response.getStatusLine().getStatusCode() != 200) { - getLogger().info("Unloading x coord " + x); - for (int z = minChunkZ; z <= maxChunkZ; z++) + if (response.getStatusLine().getStatusCode() == 409) { - world.getChunkAt(x, z).unload(true, false); - } - } - - getLogger().info("Unloading and saving world"); - - Bukkit.unloadWorld(world, true); - - getLogger().info("Finished unloading and saving world"); - - StringBuilder worldconfig = new StringBuilder(); - worldconfig.append("MAP_NAME:UHC World").append(System.lineSeparator()); - worldconfig.append("MAP_AUTHOR:Mineplex").append(System.lineSeparator()); - worldconfig.append("MIN_X:").append(MIN_X).append(System.lineSeparator()); - worldconfig.append("MIN_Z:").append(MIN_Z).append(System.lineSeparator()); - worldconfig.append("MAX_X:").append(MAX_X).append(System.lineSeparator()); - worldconfig.append("MAX_Z:").append(MAX_Z).append(System.lineSeparator()); - for (int i = 1; i <= 60; i++) - { - worldconfig.append("TEAM_NAME:").append(i).append(System.lineSeparator()); - worldconfig.append("TEAM_SPAWNS:0,0,0").append(System.lineSeparator()); - } - - File worldFolder = new File(root, "generating"); - - File regionFolder = new File(worldFolder, "region"); - - File[] regionFiles = regionFolder.listFiles(); - - if (regionFiles == null) - { - getLogger().severe("Unexpected null region files. Aborting"); - System.exit(0); - return; - } - - List zipEntrySourceList = new ArrayList<>(); - zipEntrySourceList.add(new ZipEntrySource() - { - @Override - public String getPath() - { - return "WorldConfig.dat"; - } - - @Override - public ZipEntry getEntry() - { - return new ZipEntry(getPath()); - } - - @Override - public InputStream getInputStream() throws IOException - { - return new ByteArrayInputStream(worldconfig.toString().getBytes(StandardCharsets.UTF_8)); - } - }); - - - for (File file : regionFiles) - { - zipEntrySourceList.add(new ZipEntrySource() - { - @Override - public String getPath() - { - return "region/" + file.getName(); - } - - @Override - public ZipEntry getEntry() - { - return new ZipEntry(getPath()); - } - - @Override - public InputStream getInputStream() throws IOException - { - return new FileInputStream(file); - } - }); - } - - zipEntrySourceList.add(new ZipEntrySource() - { - @Override - public String getPath() - { - return "level.dat"; - } - - @Override - public ZipEntry getEntry() - { - return new ZipEntry(getPath()); - } - - @Override - public InputStream getInputStream() throws IOException - { - return new FileInputStream(new File(worldFolder, "level.dat")); - } - }); - - ZipUtil.pack(zipEntrySourceList.toArray(new ZipEntrySource[zipEntrySourceList.size()]), outputFile); - - FileUtils.deleteQuietly(worldFolder); - - RequestConfig config = RequestConfig.custom() - .setConnectTimeout(TIMEOUT) - .setSocketTimeout(TIMEOUT) - .build(); - - CloseableHttpClient httpClient = HttpClientBuilder.create() - .setDefaultRequestConfig(config) - .build(); - - HttpPost request = new HttpPost("http://" + API_HOST_MAP.get("ENDERCHEST") + "/map/uhc/upload"); - request.addHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); - - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("name", outputFile.getName()); - jsonObject.addProperty("location", outputFile.toURI().toString()); - - request.setEntity(new StringEntity(new Gson().toJson(jsonObject), StandardCharsets.UTF_8)); - - try - { - getLogger().info("Uploading " + seed + "!"); - HttpResponse response = httpClient.execute(request); - - if (response.getStatusLine().getStatusCode() != 200) - { - if (response.getStatusLine().getStatusCode() == 409) - { - getLogger().warning("Oops - Server rejected " + seed + " because it was already generated"); - - if (!outputFile.delete()) - { - getLogger().warning("Could not clean up " + seed); - } - } - else - { - getLogger().severe("Failed to upload " + seed + ": " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase()); - } - } - else - { - getLogger().info("Uploaded " + seed + "!"); + getLogger().warning("Oops - Server rejected " + seed + " because it was already generated"); if (!outputFile.delete()) { getLogger().warning("Could not clean up " + seed); } } + else + { + getLogger().severe("Failed to upload " + seed + ": " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase()); + } } - catch (IOException e) + else { - e.printStackTrace(); - } - finally - { - getLogger().info("Finished generating world seed " + seed); + getLogger().info("Uploaded " + seed + "!"); + + if (!outputFile.delete()) + { + getLogger().warning("Could not clean up " + seed); + } } } - catch (Throwable t) + catch (IOException e) { - t.printStackTrace(); + getLogger().log(Level.SEVERE, "An error occurred while uploading " + seed + "!", e); } - System.exit(0); + finally + { + getLogger().info("Finished generating world seed " + seed); + } + + Bukkit.shutdown(); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHC.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHC.java index e79c8f261..3e5b66bc6 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHC.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHC.java @@ -365,17 +365,19 @@ public abstract class UHC extends Game UtilPlayer.message(caller, F.main("Debug", "World info for " + targetWorld.getName())); UtilPlayer.message(caller, F.desc("Chunks", String.valueOf(chunks.length))); UtilPlayer.message(caller, F.desc("Entities", String.valueOf(targetWorld.getEntities().size()))); - UtilPlayer.message(caller, F.desc("Tile Entities", String.valueOf(Arrays.stream(chunks).map(Chunk::getTileEntities).map(Arrays::asList).flatMap(Collection::stream) - .count()))); + UtilPlayer.message(caller, F.desc("Tile Entities", String.valueOf(Arrays.stream(chunks).map(Chunk::getTileEntities).map(Arrays::asList).mapToLong(Collection::size).sum()))); UtilPlayer.message(caller, F.desc("View Distance", String.valueOf(nmsWorld.spigotConfig.viewDistance))); UtilPlayer.message(caller, F.desc("Unload queue size", String.valueOf(nmsWorld.chunkProviderServer.unloadQueue.size()))); try { - HashTreeSet m = (HashTreeSet) nmsWorld.getClass().getField("M").get(nmsWorld); + Field f = nmsWorld.getClass().getDeclaredField("M"); + f.setAccessible(true); + HashTreeSet m = (HashTreeSet) f.get(nmsWorld); + UtilPlayer.message(caller, F.desc("Pending tick", String.valueOf(m.size()))); } - catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) + catch (ReflectiveOperationException e) { e.printStackTrace(); } @@ -571,7 +573,7 @@ public abstract class UHC extends Game } } }); - registerDebugCommand(new DebugCommand("uhccallchunks", Rank.DEVELOPER) + registerDebugCommand(new DebugCommand("uhcallchunks", Rank.DEVELOPER) { @Override From a0e79d87a2f3a6a25c0a546545c303c527cb047e Mon Sep 17 00:00:00 2001 From: samczsun Date: Mon, 20 Feb 2017 21:52:19 -0500 Subject: [PATCH 100/101] Allow ops to use minecraft commands --- Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java b/Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java index 0feeae737..71f36d24d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java @@ -147,8 +147,11 @@ public class Chat extends MiniPlugin || event.getMessage().toLowerCase().startsWith("/bukkit") || event.getMessage().toLowerCase().startsWith("/minecraft")) { - event.getPlayer().sendMessage(F.main(getName(), "Nope, not allowed!")); - event.setCancelled(true); + if (!event.getPlayer().isOp()) + { + event.getPlayer().sendMessage(F.main(getName(), "Nope, not allowed!")); + event.setCancelled(true); + } } } From d072fc3c21b1373380164dce5b95ba20edb8107a Mon Sep 17 00:00:00 2001 From: samczsun Date: Mon, 27 Feb 2017 21:42:30 -0500 Subject: [PATCH 101/101] Direct upload --- .../Nautilus.Game.Arcade.UHC.WorldGen/pom.xml | 10 ---- .../nautilus/game/arcade/uhc/WorldGen.java | 50 ++++++------------- 2 files changed, 14 insertions(+), 46 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/pom.xml b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/pom.xml index 2c02322e7..52ebd07c0 100644 --- a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/pom.xml +++ b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/pom.xml @@ -24,15 +24,5 @@ zt-zip 1.9 - - org.apache.httpcomponents - httpclient - 4.5.2 - - - org.slf4j - slf4j-simple - 1.7.21 - diff --git a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java index 812b1f45a..24d2483e7 100644 --- a/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java +++ b/Plugins/Nautilus.Game.Arcade.UHC.WorldGen/src/nautilus/game/arcade/uhc/WorldGen.java @@ -1,27 +1,21 @@ package nautilus.game.arcade.uhc; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ThreadLocalRandom; -import java.util.concurrent.TimeUnit; import java.util.logging.Level; import net.minecraft.server.v1_8_R3.BiomeBase; import org.apache.commons.io.FileUtils; -import org.apache.http.HttpResponse; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.message.BasicHeader; -import org.apache.http.protocol.HTTP; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Difficulty; @@ -42,14 +36,10 @@ import org.zeroturnaround.zip.ByteSource; import org.zeroturnaround.zip.FileSource; import org.zeroturnaround.zip.ZipEntrySource; import org.zeroturnaround.zip.ZipUtil; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; +import org.zeroturnaround.zip.commons.IOUtils; public class WorldGen extends JavaPlugin implements Listener { - private static final int TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10); - // The world will be -MAP_SIZE to MAP_SIZE large private static final int MAP_SIZE = 1000; private static final int VIEW_DISTANCE = 5; @@ -295,32 +285,20 @@ public class WorldGen extends JavaPlugin implements Listener FileUtils.deleteQuietly(worldFolder); - RequestConfig config = RequestConfig.custom() - .setConnectTimeout(TIMEOUT) - .setSocketTimeout(TIMEOUT) - .build(); - - CloseableHttpClient httpClient = HttpClientBuilder.create() - .setDefaultRequestConfig(config) - .build(); - - HttpPost request = new HttpPost("http://" + API_HOST_MAP.get("ENDERCHEST") + "/map/uhc/upload"); - request.addHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); - - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("name", outputFile.getName()); - jsonObject.addProperty("location", outputFile.toURI().toString()); - - request.setEntity(new StringEntity(new Gson().toJson(jsonObject), StandardCharsets.UTF_8)); - try { getLogger().info("Uploading " + seed + "!"); - HttpResponse response = httpClient.execute(request); - if (response.getStatusLine().getStatusCode() != 200) + URL url = new URL("http://" + API_HOST_MAP.get("ENDERCHEST") + "/map/uhc/upload?name=" + outputFile.getName()); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + connection.setDoOutput(true); + IOUtils.copy(new FileInputStream(outputFile), connection.getOutputStream()); + connection.connect(); + + if (connection.getResponseCode() != 200) { - if (response.getStatusLine().getStatusCode() == 409) + if (connection.getResponseCode() == 409) { getLogger().warning("Oops - Server rejected " + seed + " because it was already generated"); @@ -331,7 +309,7 @@ public class WorldGen extends JavaPlugin implements Listener } else { - getLogger().severe("Failed to upload " + seed + ": " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase()); + getLogger().severe("Failed to upload " + seed + ": " + connection.getResponseCode() + " " + connection.getResponseMessage()); } } else