Villager trading and loot upgrades

This commit is contained in:
Sam 2017-01-08 15:44:04 +00:00
parent 571840e249
commit 0218965bee
30 changed files with 914 additions and 145 deletions

View File

@ -4,18 +4,9 @@ import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set;
import java.util.UUID; 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.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.SkullType; import org.bukkit.SkullType;
@ -41,8 +32,18 @@ import org.bukkit.material.Bed;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import mineplex.core.common.Pair;
import mineplex.core.common.block.MultiBlockUpdaterAgent; import mineplex.core.common.block.MultiBlockUpdaterAgent;
import mineplex.core.common.skin.SkinData; 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 public class UtilBlock
{ {
@ -1670,4 +1671,38 @@ public class UtilBlock
return null; return null;
} }
/**
* Returns a Pair<Location, Pair<Material, Byte>> {@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<Pair<Location, Pair<Material, Byte>>> getBeaconBlocks(Location surface, byte glassData)
{
Set<Pair<Location, Pair<Material, Byte>>> 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;
}
} }

View File

@ -18,22 +18,23 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.ReflectivelyCreateMiniPlugin;
import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
@ReflectivelyCreateMiniPlugin
public class BlockRestore extends MiniPlugin public class BlockRestore extends MiniPlugin
{ {
private HashMap<Block, BlockRestoreData> _blocks = new HashMap<Block, BlockRestoreData>(); private HashMap<Block, BlockRestoreData> _blocks = new HashMap<Block, BlockRestoreData>();
private LinkedList<BlockRestoreMap> _restoreMaps; private LinkedList<BlockRestoreMap> _restoreMaps;
public BlockRestore(JavaPlugin plugin) private BlockRestore()
{ {
super("Block Restore", plugin); super("Block Restore");
_restoreMaps = new LinkedList<BlockRestoreMap>(); _restoreMaps = new LinkedList<BlockRestoreMap>();
} }

View File

@ -9,6 +9,7 @@ public enum MineplexGoogleSheet
{ {
GEM_HUNTERS_CHESTS("11Noztgbpu_gUKkc5F4evKKfyxS-Jv1coE0IrBToX_gg"), GEM_HUNTERS_CHESTS("11Noztgbpu_gUKkc5F4evKKfyxS-Jv1coE0IrBToX_gg"),
GEM_HUNTERS_VILLAGERS("1OcYktxVZaW6Fm29Zh6w4Lb-UVyuN8r1x-TFb_3USYYI"),
; ;
private String _id; private String _id;

View File

@ -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); IgnoreManager ignoreManager = new IgnoreManager(this, _clientManager, preferenceManager, portal);

View File

@ -96,7 +96,7 @@ public class ClansHub extends JavaPlugin
Recharge.Initialize(this); Recharge.Initialize(this);
VisibilityManager.Initialize(this); Give.Initialize(this); VisibilityManager.Initialize(this); Give.Initialize(this);
Punish punish = new Punish(this, webServerAddress, clientManager); Punish punish = new Punish(this, webServerAddress, clientManager);
BlockRestore blockRestore = new BlockRestore(this); BlockRestore blockRestore = require(BlockRestore.class);
DonationManager donationManager = require(DonationManager.class); DonationManager donationManager = require(DonationManager.class);
ServerConfiguration serverConfiguration = new ServerConfiguration(this, clientManager); ServerConfiguration serverConfiguration = new ServerConfiguration(this, clientManager);

View File

@ -118,7 +118,7 @@ public class Hub extends JavaPlugin implements IRelation
Recharge.Initialize(this); Recharge.Initialize(this);
VisibilityManager.Initialize(this); Give.Initialize(this); VisibilityManager.Initialize(this); Give.Initialize(this);
Punish punish = new Punish(this, webServerAddress, clientManager); Punish punish = new Punish(this, webServerAddress, clientManager);
BlockRestore blockRestore = new BlockRestore(this); BlockRestore blockRestore = require(BlockRestore.class);
DonationManager donationManager = require(DonationManager.class); DonationManager donationManager = require(DonationManager.class);
ServerConfiguration serverConfiguration = new ServerConfiguration(this, clientManager); ServerConfiguration serverConfiguration = new ServerConfiguration(this, clientManager);

View File

@ -166,7 +166,7 @@ public class Arcade extends JavaPlugin
new SnapshotPlugin(this, snapshotManager, _clientManager); new SnapshotPlugin(this, snapshotManager, _clientManager);
new ReportPlugin(this, reportManager); new ReportPlugin(this, reportManager);
BlockRestore blockRestore = new BlockRestore(this); BlockRestore blockRestore = require(BlockRestore.class);
ProjectileManager projectileManager = new ProjectileManager(this); ProjectileManager projectileManager = new ProjectileManager(this);
HologramManager hologramManager = new HologramManager(this, packetHandler); HologramManager hologramManager = new HologramManager(this, packetHandler);

View File

@ -328,7 +328,7 @@ public class PvP extends JavaPlugin implements IPlugin, Listener
public BlockRestore GetBlockRestore() public BlockRestore GetBlockRestore()
{ {
if (_blockRestore == null) if (_blockRestore == null)
_blockRestore = new BlockRestore(this); _blockRestore = require(BlockRestore.class);
return _blockRestore; return _blockRestore;
} }

View File

@ -120,7 +120,7 @@ public class Hub extends JavaPlugin
Chat chat = new Chat(this, incognito, _clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); Chat chat = new Chat(this, incognito, _clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName());
new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, friendManager, chat); 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); ProjectileManager projectileManager = new ProjectileManager(this);
HologramManager hologramManager = new HologramManager(this, packetHandler); HologramManager hologramManager = new HologramManager(this, packetHandler);

View File

@ -4,6 +4,8 @@ import static mineplex.core.Managers.require;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; 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.bukkit.plugin.java.JavaPlugin;
import org.spigotmc.SpigotConfig; import org.spigotmc.SpigotConfig;
@ -42,9 +44,7 @@ import mineplex.core.recharge.Recharge;
import mineplex.core.serverConfig.ServerConfiguration; import mineplex.core.serverConfig.ServerConfiguration;
import mineplex.core.stats.StatsManager; import mineplex.core.stats.StatsManager;
import mineplex.core.status.ServerStatusManager; import mineplex.core.status.ServerStatusManager;
import mineplex.core.task.TaskManager;
import mineplex.core.teleport.Teleport; import mineplex.core.teleport.Teleport;
import mineplex.core.texttutorial.TextTutorialManager;
import mineplex.core.updater.FileUpdater; import mineplex.core.updater.FileUpdater;
import mineplex.core.updater.Updater; import mineplex.core.updater.Updater;
import mineplex.core.visibility.VisibilityManager; import mineplex.core.visibility.VisibilityManager;
@ -155,10 +155,10 @@ public class GemHunters extends JavaPlugin
new DamageManager(this, new CombatManager(this), new NpcManager(this, creature), disguiseManager, new ConditionManager(this)); new DamageManager(this, new CombatManager(this), new NpcManager(this, creature), disguiseManager, new ConditionManager(this));
// GWEN // GWEN
//require(AntiHack.class); // require(AntiHack.class);
// Block Restore // Block Restore
BlockRestore blockRestore = new BlockRestore(this); BlockRestore blockRestore = require(BlockRestore.class);
// Ignoring // Ignoring
IgnoreManager ignoreManager = new IgnoreManager(this, clientManager, preferenceManager, portal); IgnoreManager ignoreManager = new IgnoreManager(this, clientManager, preferenceManager, portal);
@ -189,9 +189,13 @@ public class GemHunters extends JavaPlugin
new InventoryManager(this, clientManager); new InventoryManager(this, clientManager);
// Reports // Reports
// SnapshotManager snapshotManager = new SnapshotManager(this, new SnapshotRepository(serverStatusManager.getCurrentServerName(), getLogger())); // SnapshotManager snapshotManager = new SnapshotManager(this, new
// new SnapshotPlugin(this, snapshotManager, clientManager); // SnapshotRepository(serverStatusManager.getCurrentServerName(),
// new ReportPlugin(this, new ReportManager(this, snapshotManager, clientManager, incognito, punish, serverStatusManager.getRegion(), serverStatusManager.getCurrentServerName(), 1)); // getLogger()));
// new SnapshotPlugin(this, snapshotManager, clientManager);
// new ReportPlugin(this, new ReportManager(this, snapshotManager,
// clientManager, incognito, punish, serverStatusManager.getRegion(),
// serverStatusManager.getCurrentServerName(), 1));
// Tag fix // Tag fix
new CustomTagFix(this, packetHandler); new CustomTagFix(this, packetHandler);
@ -199,8 +203,6 @@ public class GemHunters extends JavaPlugin
// Holograms // Holograms
new HologramManager(this, packetHandler); new HologramManager(this, packetHandler);
new TextTutorialManager(this, donationManager, new TaskManager(this, clientManager, webServerAddress));
// Now we finally get to enable the Gem Hunters modules // Now we finally get to enable the Gem Hunters modules
require(CashOutModule.class); require(CashOutModule.class);
require(ChatModule.class); require(ChatModule.class);
@ -212,7 +214,7 @@ public class GemHunters extends JavaPlugin
require(ShopModule.class); require(ShopModule.class);
require(SupplyDropModule.class); require(SupplyDropModule.class);
//UpdateEvent!!! // UpdateEvent!!!
new Updater(this); new Updater(this);
// Disable spigot's item merging // Disable spigot's item merging
@ -230,6 +232,20 @@ public class GemHunters extends JavaPlugin
public void onDisable() public void onDisable()
{ {
getServer().getPluginManager().callEvent(new ServerShutdownEvent(this)); 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();
}
}
} }
} }

View File

@ -3,6 +3,7 @@ package mineplex.gemhunters.chat;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
@ -12,6 +13,11 @@ import mineplex.core.chat.Chat;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
/**
* This module handles player chat.
*
* @author Sam
*/
@ReflectivelyCreateMiniPlugin @ReflectivelyCreateMiniPlugin
public class ChatModule extends MiniPlugin public class ChatModule extends MiniPlugin
{ {
@ -27,9 +33,10 @@ public class ChatModule extends MiniPlugin
_chat = require(Chat.class); _chat = require(Chat.class);
} }
@EventHandler @EventHandler(priority = EventPriority.HIGHEST)
public void chat(AsyncPlayerChatEvent event) public void chat(AsyncPlayerChatEvent event)
{ {
// Checks if the player has been muted/chat is silenced etc...
if (event.isCancelled()) if (event.isCancelled())
{ {
return; return;
@ -41,10 +48,16 @@ public class ChatModule extends MiniPlugin
Rank rank = _clientManager.Get(player).getRealOrDisguisedRank(); Rank rank = _clientManager.Get(player).getRealOrDisguisedRank();
String rankString = rank == Rank.ALL ? "" : rank.getTag(true, true); 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(); String message = (rankString + " " + C.cYellow + playerName + " " + C.cWhite + _chat.getFilteredMessage(player, event.getMessage())).trim();
// We will handle the broadcast
event.setCancelled(true); event.setCancelled(true);
Bukkit.broadcastMessage(message);
for (Player other : Bukkit.getOnlinePlayers())
{
other.sendMessage(message);
}
} }
} }

View File

@ -16,10 +16,16 @@ import mineplex.core.ReflectivelyCreateMiniPlugin;
import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAction;
import mineplex.gemhunters.world.WorldDataModule; import mineplex.gemhunters.world.WorldDataModule;
/**
* This module handles anything to do with a players death
*
* @author Sam
*/
@ReflectivelyCreateMiniPlugin @ReflectivelyCreateMiniPlugin
public class DeathModule extends MiniPlugin 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<Material> DISALLOWED_DROPS = Sets.newHashSet(Material.EMERALD, Material.BONE); private static final Set<Material> DISALLOWED_DROPS = Sets.newHashSet(Material.EMERALD, Material.BONE);
private final WorldDataModule _worldData; private final WorldDataModule _worldData;
@ -36,12 +42,14 @@ public class DeathModule extends MiniPlugin
{ {
Player player = event.getEntity(); Player player = event.getEntity();
// Stop the player dieing
player.setHealth(20); player.setHealth(20);
UtilAction.zeroVelocity(player); UtilAction.zeroVelocity(player);
player.teleport(_worldData.getSpawnLocation("Yellow").get(0)); player.teleport(_worldData.getSpawnLocation("Yellow").get(0));
Iterator<ItemStack> iterator = event.getDrops().iterator(); Iterator<ItemStack> iterator = event.getDrops().iterator();
// Iterate through all items and clear any disallowed items
while (iterator.hasNext()) while (iterator.hasNext())
{ {
ItemStack itemStack = iterator.next(); ItemStack itemStack = iterator.next();

View File

@ -60,7 +60,7 @@ public class LootModule extends MiniPlugin
private static final String[] IGNORED_COLOURS = { "RED" }; private static final String[] IGNORED_COLOURS = { "RED" };
private static final float MAX_CHESTS_FACTOR = 0.25F; private static final float MAX_CHESTS_FACTOR = 0.25F;
private static final int MAX_SEARCH_ATTEMPTS = 40; 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 int MAX_CHEST_CHECK_DISTANCE_SQUARED = 4;
private static final MineplexGoogleSheet CHEST_LOOT_SHEET = MineplexGoogleSheet.GEM_HUNTERS_CHESTS; private static final MineplexGoogleSheet CHEST_LOOT_SHEET = MineplexGoogleSheet.GEM_HUNTERS_CHESTS;
@ -212,6 +212,7 @@ public class LootModule extends MiniPlugin
continue; continue;
} }
//TODO remove debug message
Bukkit.broadcastMessage("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index); Bukkit.broadcastMessage("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index);
_spawnedChest.add(new SpawnedChest(chestToPlace, key, index)); _spawnedChest.add(new SpawnedChest(chestToPlace, key, index));
block.setType(Material.CHEST); block.setType(Material.CHEST);
@ -312,7 +313,6 @@ public class LootModule extends MiniPlugin
if (values.size() > 7) if (values.size() > 7)
{ {
metadata = String.valueOf(values.get(7)); metadata = String.valueOf(values.get(7));
Bukkit.broadcastMessage(metadata);
} }
items.add(new LootItem(builder.build(), minAmount, maxAmount, probability, metadata)); items.add(new LootItem(builder.build(), minAmount, maxAmount, probability, metadata));
} }
@ -488,7 +488,7 @@ public class LootModule extends MiniPlugin
return; return;
} }
ItemStack itemStack = event.getCursor(); ItemStack itemStack = event.getCurrentItem();
if (itemStack == null) if (itemStack == null)
{ {
@ -530,8 +530,6 @@ public class LootModule extends MiniPlugin
if (reward == null) if (reward == null)
{ {
Bukkit.broadcastMessage(lootItem.getMetadata());
switch (lootItem.getMetadata()) switch (lootItem.getMetadata())
{ {
case "RANK_UPGRADE": case "RANK_UPGRADE":

View File

@ -2,10 +2,12 @@ package mineplex.gemhunters.loot.command;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.Managers;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.gemhunters.loot.LootModule; import mineplex.gemhunters.loot.LootModule;
import mineplex.gemhunters.shop.ShopModule;
/** /**
* An ADMIN command that allows users to retrieve the latest data from the * An ADMIN command that allows users to retrieve the latest data from the
@ -31,7 +33,12 @@ public class UpdateLootCommand extends CommandBase<LootModule>
caller.sendMessage(F.main(Plugin.getName(), "Updating loot tables asynchronusly...")); 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!")); caller.sendMessage(F.main(Plugin.getName(), "Finished!"));
} }

View File

@ -27,6 +27,7 @@ public class SafezoneModule extends MiniPlugin
{ {
private static final String SAFEZONE_DATA_PREFIX = "SAFEZONE"; private static final String SAFEZONE_DATA_PREFIX = "SAFEZONE";
private static final String SAFEZONE_DATA_IGNORE = "IGNORE";
private final WorldDataModule _worldData; private final WorldDataModule _worldData;
@ -59,14 +60,20 @@ public class SafezoneModule extends MiniPlugin
// null -> not null // null -> not null
if (!isInOldSafezone && isInNewSafezone) if (!isInOldSafezone && isInNewSafezone)
{
if (!newSafezone.contains(SAFEZONE_DATA_IGNORE))
{ {
UtilTextMiddle.display("", C.cYellow + "Entering " + newSafezone, 10, 40, 10, player); UtilTextMiddle.display("", C.cYellow + "Entering " + newSafezone, 10, 40, 10, player);
}
_currentSafezone.put(key, newSafezone); _currentSafezone.put(key, newSafezone);
} }
// not null -> null // not null -> null
else if (isInOldSafezone && !isInNewSafezone) else if (isInOldSafezone && !isInNewSafezone)
{
if (!oldSafezone.contains(SAFEZONE_DATA_IGNORE))
{ {
UtilTextMiddle.display("", C.cYellow + "Leaving " + oldSafezone, 10, 40, 10, player); UtilTextMiddle.display("", C.cYellow + "Leaving " + oldSafezone, 10, 40, 10, player);
}
_currentSafezone.put(key, null); _currentSafezone.put(key, null);
} }
} }

View File

@ -2,27 +2,30 @@ package mineplex.gemhunters.scoreboard;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import mineplex.core.Managers;
import mineplex.core.common.currency.GlobalCurrency;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.donation.DonationManager;
import mineplex.core.scoreboard.WritableMineplexScoreboard; import mineplex.core.scoreboard.WritableMineplexScoreboard;
public class GemHuntersScoreboard extends WritableMineplexScoreboard public class GemHuntersScoreboard extends WritableMineplexScoreboard
{ {
private final DonationManager _donation;
public GemHuntersScoreboard(Player player) public GemHuntersScoreboard(Player player)
{ {
super(player); super(player);
_donation = Managers.require(DonationManager.class);
} }
public void writeContent(Player player) public void writeContent(Player player)
{ {
writeNewLine(); writeNewLine();
write(C.cGreenB + "Top Players"); write(C.cGreenB + "Gems");
write(String.valueOf(_donation.Get(player).getBalance(GlobalCurrency.GEM)));
writeNewLine();
write(C.cYellowB + "Reset Time");
write("0 seconds");
writeNewLine(); writeNewLine();
} }

View File

@ -1,15 +1,190 @@
package mineplex.gemhunters.shop; 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.MiniPlugin;
import mineplex.core.ReflectivelyCreateMiniPlugin; 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 @ReflectivelyCreateMiniPlugin
public class ShopModule extends MiniPlugin 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<String, Set<TradeableItem>> _tradeItems;
private boolean _npcsSpawned;
private ShopModule() private ShopModule()
{ {
super("Shop"); super("Shop");
_sheets = require(GoogleSheetsManager.class);
_worldData = require(WorldDataModule.class);
_tradeItems = new HashMap<>();
updateVillagerLoot();
}
public void updateVillagerLoot()
{
try
{
Map<String, List<List<Object>>> map = _sheets.getCellValues(VILLAGER_LOOT_SHEET);
for (String key : map.keySet())
{
Set<TradeableItem> items = new HashSet<>();
List<List<Object>> grid = map.get(key);
int index = 0;
try
{
for (List<Object> 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))));
}
}
} }
} }

View File

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

View File

@ -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<TradeableItem> _selling;
private final Inventory _inv;
public TraderNPC(JavaPlugin plugin, Location spawn, Class<? extends LivingEntity> type, String name, boolean vegetated, Set<TradeableItem> 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;
}
}

View File

@ -9,6 +9,9 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Villager; import org.bukkit.entity.Villager;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent; 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.MiniPlugin;
import mineplex.core.ReflectivelyCreateMiniPlugin; 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.UtilAlg;
import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilBlock;
import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.safezone.SafezoneModule;
import mineplex.gemhunters.util.ColouredTextAnimation;
import mineplex.gemhunters.util.SimpleNPC; import mineplex.gemhunters.util.SimpleNPC;
import mineplex.gemhunters.world.WorldDataModule; import mineplex.gemhunters.world.WorldDataModule;
@ -80,8 +84,24 @@ public class SpawnModule extends MiniPlugin
} }
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) 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())) if (isSuitable(possible.getBlock()))
{ {
return possible; return possible.add(0, 1, 0);
} }
attempts++; attempts++;

View File

@ -72,6 +72,8 @@ public class SupplyDrop
_lastHelicopter = new HashSet<>(100); _lastHelicopter = new HashSet<>(100);
_bladeBlocks = new HashSet<>(20); _bladeBlocks = new HashSet<>(20);
_diagonal = false; _diagonal = false;
spawn.getChunk().load();
} }
public boolean advancePath() public boolean advancePath()
@ -183,6 +185,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() public void spawnLootChest()
{ {
FallingBlock fallingBlock = _blade.getWorld().spawnFallingBlock(_blade.clone().subtract(0, 10, 0), Material.WOOD, (byte) 0); FallingBlock fallingBlock = _blade.getWorld().spawnFallingBlock(_blade.clone().subtract(0, 10, 0), Material.WOOD, (byte) 0);

View File

@ -1,5 +1,10 @@
package mineplex.gemhunters.supplydrop; 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.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; 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.EntityChangeBlockEvent;
import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.ItemSpawnEvent;
import mineplex.core.Managers;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.ReflectivelyCreateMiniPlugin; 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.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.gemhunters.loot.LootModule; import mineplex.gemhunters.loot.LootModule;
import mineplex.gemhunters.supplydrop.commands.CommandSupplyDropTest; import mineplex.gemhunters.supplydrop.commands.SupplyDropCommand;
import mineplex.gemhunters.world.WorldDataModule; import mineplex.gemhunters.world.WorldDataModule;
@ReflectivelyCreateMiniPlugin @ReflectivelyCreateMiniPlugin
@ -22,29 +35,38 @@ public class SupplyDropModule extends MiniPlugin
{ {
private static final String CHEST_COLOUR = "RED"; 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 WorldDataModule _worldData;
private final Set<Block> _beaconBlocks;
private String[] _locationKeys;
private SupplyDrop _current; private SupplyDrop _current;
private SupplyDropModule() private SupplyDropModule()
{ {
super("Supply Drop"); super("Supply Drop");
_blockRestore = require(BlockRestore.class);
_loot = require(LootModule.class);
_worldData = require(WorldDataModule.class); _worldData = require(WorldDataModule.class);
_beaconBlocks = new HashSet<>();
} }
@Override @Override
public void addCommands() public void addCommands()
{ {
addCommand(new CommandSupplyDropTest(this)); addCommand(new SupplyDropCommand(this));
} }
@EventHandler @EventHandler
public void update(UpdateEvent event) public void update(UpdateEvent event)
{ {
if (event.getType() != UpdateType.SEC || _current == null) if (event.getType() != UpdateType.SEC || !isActive())
{ {
return; return;
} }
@ -58,6 +80,7 @@ public class SupplyDropModule extends MiniPlugin
@EventHandler @EventHandler
public void itemSpawn(ItemSpawnEvent event) 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) if (event.getEntity().getItemStack().getType() == Material.IRON_DOOR)
{ {
event.setCancelled(true); event.setCancelled(true);
@ -73,19 +96,87 @@ public class SupplyDropModule extends MiniPlugin
block.setType(Material.CHEST); 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. // Add location that the chest will appear at into the spawned chests list so that LootModule can populate it with loot.
Managers.require(LootModule.class).addSpawnedChest(block.getLocation(), CHEST_COLOUR); _loot.addSpawnedChest(block.getLocation(), CHEST_COLOUR);
// Remove beacon
for (Block beacon : _beaconBlocks)
{
_blockRestore.restore(beacon);
}
_beaconBlocks.clear();
event.setCancelled(true); event.setCancelled(true);
} }
} }
public void startHelicopter() public void startSequence(String locationKey)
{ {
Location spawn = _worldData.getCustomLocation("SUPPLY_DROP Fountain Spawn").get(0); Location spawn = _worldData.getCustomLocation(LOCATION_DATA + " " + locationKey + " Start").get(0);
Location destination = _worldData.getCustomLocation("SUPPLY_DROP Fountain Chest").get(0); Location destination = _worldData.getCustomLocation(LOCATION_DATA + " " + locationKey + " Chest").get(0);
Location despawn = _worldData.getCustomLocation("SUPPLY_DROP Fountain End").get(0); Location despawn = _worldData.getCustomLocation(LOCATION_DATA + " " + locationKey + " End").get(0);
// Construct a beacon
for (Pair<Location, Pair<Material, Byte>> 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); _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<String> 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;
}
} }

View File

@ -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<SupplyDropModule>
{
public CommandSupplyDropTest(SupplyDropModule plugin)
{
super(plugin, Rank.ADMIN, "stest");
}
@Override
public void Execute(Player caller, String[] args)
{
caller.sendMessage("Running!");
Plugin.startHelicopter();
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -17,7 +17,7 @@ import mineplex.core.common.util.UtilEnt;
public class SimpleNPC implements Listener public class SimpleNPC implements Listener
{ {
private final LivingEntity _entity; protected final LivingEntity _entity;
private final Callback<Player> _clickEvent; private final Callback<Player> _clickEvent;
private final boolean _vegetated; private final boolean _vegetated;
@ -53,8 +53,12 @@ public class SimpleNPC implements Listener
} }
event.setCancelled(true); event.setCancelled(true);
if (_clickEvent != null)
{
_clickEvent.run(event.getPlayer()); _clickEvent.run(event.getPlayer());
} }
}
@EventHandler @EventHandler
public void npcDamage(EntityDamageEvent event) public void npcDamage(EntityDamageEvent event)

View File

@ -4,12 +4,14 @@ import java.io.BufferedReader;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.io.FileUtils;
import org.bukkit.Difficulty; import org.bukkit.Difficulty;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;

View File

@ -12,7 +12,7 @@ public class WorldEventCommand extends MultiCommandBase<WorldEventModule>
public WorldEventCommand(WorldEventModule plugin) public WorldEventCommand(WorldEventModule plugin)
{ {
super(plugin, Rank.ADMIN, "worldevent", "we", "event"); super(plugin, Rank.ADMIN, "worldevent", "we");
} }
@Override @Override