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;