Lots more changes

This commit is contained in:
Sam 2017-01-02 14:40:13 +00:00
parent 0ba22f9201
commit 571840e249
21 changed files with 538 additions and 176 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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<UUID, CashOutSession> _sessions;
private static final int CASH_OUT_MAX_MOVE_DISTANCE_SQUARED = 4;
private final Map<UUID, CashOutSession> _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<UUID> 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!");
}

View File

@ -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;
}
}

View File

@ -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<String, Set<LootItem>> _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<LootItemReward> iterator = _itemRewards.iterator();
while (iterator.hasNext())
{
LootItemReward reward = iterator.next();
if (player.equals(reward.getPlayer()))
{
reward.success();
iterator.remove();
}
}
}
}

View File

@ -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()
{

View File

@ -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()
{
}
}

View File

@ -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<UUID, String> _currentSafezone;
private final Map<UUID, String> _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;
}
}

View File

@ -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");
}
}

View File

@ -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<Player>()
{
@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;
}
}

View File

@ -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<Player> _clickEvent;
private final boolean _vegetated;
public SimpleNPC(JavaPlugin plugin, Location spawn, Class<? extends LivingEntity> type, String name, Callback<Player> clickEvent)
{
this(plugin, spawn, type, name, clickEvent, true);
}
public SimpleNPC(JavaPlugin plugin, Location spawn, Class<? extends LivingEntity> type, String name, Callback<Player> 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);
}
}

View File

@ -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;

View File

@ -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()
{
}
}

View File

@ -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<WorldEvent> _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))
{
}
}
}

View File

@ -5,4 +5,5 @@ public enum WorldEventState
}

View File

@ -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<? extends WorldEvent> _clazz;

View File

@ -1,8 +0,0 @@
package mineplex.gemhunters.worldevent.coldweather;
import mineplex.gemhunters.worldevent.WorldEvent;
public class ColdWeatherEvent extends WorldEvent
{
}

View File

@ -0,0 +1,6 @@
package mineplex.gemhunters.worldevent.command;
public class AddCommand
{
}

View File

@ -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<WorldEventModule>
{
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));
}
}