Villager trading and loot upgrades
This commit is contained in:
parent
571840e249
commit
0218965bee
|
@ -4,18 +4,9 @@ import java.lang.reflect.Field;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R3.Blocks;
|
||||
import net.minecraft.server.v1_8_R3.IBlockData;
|
||||
import net.minecraft.server.v1_8_R3.Item;
|
||||
import net.minecraft.server.v1_8_R3.MathHelper;
|
||||
import net.minecraft.server.v1_8_R3.MinecraftKey;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
||||
import net.minecraft.server.v1_8_R3.TileEntityFlowerPot;
|
||||
import net.minecraft.server.v1_8_R3.WorldServer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.SkullType;
|
||||
|
@ -41,8 +32,18 @@ import org.bukkit.material.Bed;
|
|||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import mineplex.core.common.Pair;
|
||||
import mineplex.core.common.block.MultiBlockUpdaterAgent;
|
||||
import mineplex.core.common.skin.SkinData;
|
||||
import net.minecraft.server.v1_8_R3.BlockPosition;
|
||||
import net.minecraft.server.v1_8_R3.Blocks;
|
||||
import net.minecraft.server.v1_8_R3.IBlockData;
|
||||
import net.minecraft.server.v1_8_R3.Item;
|
||||
import net.minecraft.server.v1_8_R3.MathHelper;
|
||||
import net.minecraft.server.v1_8_R3.MinecraftKey;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
||||
import net.minecraft.server.v1_8_R3.TileEntityFlowerPot;
|
||||
import net.minecraft.server.v1_8_R3.WorldServer;
|
||||
|
||||
public class UtilBlock
|
||||
{
|
||||
|
@ -1670,4 +1671,38 @@ public class UtilBlock
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Pair<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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,22 +18,23 @@ import org.bukkit.event.block.BlockBreakEvent;
|
|||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class BlockRestore extends MiniPlugin
|
||||
{
|
||||
private HashMap<Block, BlockRestoreData> _blocks = new HashMap<Block, BlockRestoreData>();
|
||||
private LinkedList<BlockRestoreMap> _restoreMaps;
|
||||
|
||||
public BlockRestore(JavaPlugin plugin)
|
||||
private BlockRestore()
|
||||
{
|
||||
super("Block Restore", plugin);
|
||||
super("Block Restore");
|
||||
|
||||
_restoreMaps = new LinkedList<BlockRestoreMap>();
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ public enum MineplexGoogleSheet
|
|||
{
|
||||
|
||||
GEM_HUNTERS_CHESTS("11Noztgbpu_gUKkc5F4evKKfyxS-Jv1coE0IrBToX_gg"),
|
||||
GEM_HUNTERS_VILLAGERS("1OcYktxVZaW6Fm29Zh6w4Lb-UVyuN8r1x-TFb_3USYYI"),
|
||||
;
|
||||
|
||||
private String _id;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ public class ClansHub extends JavaPlugin
|
|||
Recharge.Initialize(this);
|
||||
VisibilityManager.Initialize(this); Give.Initialize(this);
|
||||
Punish punish = new Punish(this, webServerAddress, clientManager);
|
||||
BlockRestore blockRestore = new BlockRestore(this);
|
||||
BlockRestore blockRestore = require(BlockRestore.class);
|
||||
DonationManager donationManager = require(DonationManager.class);
|
||||
|
||||
ServerConfiguration serverConfiguration = new ServerConfiguration(this, clientManager);
|
||||
|
|
|
@ -118,7 +118,7 @@ public class Hub extends JavaPlugin implements IRelation
|
|||
Recharge.Initialize(this);
|
||||
VisibilityManager.Initialize(this); Give.Initialize(this);
|
||||
Punish punish = new Punish(this, webServerAddress, clientManager);
|
||||
BlockRestore blockRestore = new BlockRestore(this);
|
||||
BlockRestore blockRestore = require(BlockRestore.class);
|
||||
DonationManager donationManager = require(DonationManager.class);
|
||||
|
||||
ServerConfiguration serverConfiguration = new ServerConfiguration(this, clientManager);
|
||||
|
|
|
@ -166,7 +166,7 @@ public class Arcade extends JavaPlugin
|
|||
new SnapshotPlugin(this, snapshotManager, _clientManager);
|
||||
new ReportPlugin(this, reportManager);
|
||||
|
||||
BlockRestore blockRestore = new BlockRestore(this);
|
||||
BlockRestore blockRestore = require(BlockRestore.class);
|
||||
|
||||
ProjectileManager projectileManager = new ProjectileManager(this);
|
||||
HologramManager hologramManager = new HologramManager(this, packetHandler);
|
||||
|
|
|
@ -328,7 +328,7 @@ public class PvP extends JavaPlugin implements IPlugin, Listener
|
|||
public BlockRestore GetBlockRestore()
|
||||
{
|
||||
if (_blockRestore == null)
|
||||
_blockRestore = new BlockRestore(this);
|
||||
_blockRestore = require(BlockRestore.class);
|
||||
|
||||
return _blockRestore;
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ public class Hub extends JavaPlugin
|
|||
Chat chat = new Chat(this, incognito, _clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName());
|
||||
new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, friendManager, chat);
|
||||
|
||||
BlockRestore blockRestore = new BlockRestore(this);
|
||||
BlockRestore blockRestore = require(BlockRestore.class);
|
||||
|
||||
ProjectileManager projectileManager = new ProjectileManager(this);
|
||||
HologramManager hologramManager = new HologramManager(this, packetHandler);
|
||||
|
|
|
@ -4,6 +4,8 @@ import static mineplex.core.Managers.require;
|
|||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.spigotmc.SpigotConfig;
|
||||
|
||||
|
@ -42,9 +44,7 @@ import mineplex.core.recharge.Recharge;
|
|||
import mineplex.core.serverConfig.ServerConfiguration;
|
||||
import mineplex.core.stats.StatsManager;
|
||||
import mineplex.core.status.ServerStatusManager;
|
||||
import mineplex.core.task.TaskManager;
|
||||
import mineplex.core.teleport.Teleport;
|
||||
import mineplex.core.texttutorial.TextTutorialManager;
|
||||
import mineplex.core.updater.FileUpdater;
|
||||
import mineplex.core.updater.Updater;
|
||||
import mineplex.core.visibility.VisibilityManager;
|
||||
|
@ -73,7 +73,7 @@ public class GemHunters extends JavaPlugin
|
|||
{
|
||||
|
||||
private static final String WEB_CONFIG = "webServer";
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
|
@ -81,84 +81,84 @@ public class GemHunters extends JavaPlugin
|
|||
getConfig().addDefault(WEB_CONFIG, "http://accounts.mineplex.com/");
|
||||
getConfig().set(WEB_CONFIG, getConfig().getString(WEB_CONFIG));
|
||||
saveConfig();
|
||||
|
||||
|
||||
// Get the web server address
|
||||
String webServerAddress = getConfig().getString(WEB_CONFIG);
|
||||
|
||||
|
||||
// Load core modules
|
||||
CommandCenter.Initialize(this);
|
||||
|
||||
|
||||
// Client Manager
|
||||
CoreClientManager clientManager = new CoreClientManager(this, webServerAddress);
|
||||
|
||||
|
||||
// Donation Manager
|
||||
DonationManager donationManager = require(DonationManager.class);
|
||||
|
||||
|
||||
// Command Centre
|
||||
CommandCenter.Instance.setClientManager(clientManager);
|
||||
|
||||
|
||||
// Timings
|
||||
require(TimingsFix.class);
|
||||
|
||||
|
||||
// ItemStacks
|
||||
ItemStackFactory.Initialize(this, false);
|
||||
|
||||
|
||||
// Delayed Tasks
|
||||
DelayedTask.Initialize(this);
|
||||
|
||||
|
||||
// Recharge
|
||||
Recharge.Initialize(this);
|
||||
|
||||
|
||||
// Visibility
|
||||
VisibilityManager.Initialize(this);
|
||||
|
||||
|
||||
// Give
|
||||
Give.Initialize(this);
|
||||
|
||||
|
||||
// Server config
|
||||
new ServerConfiguration(this, clientManager);
|
||||
|
||||
|
||||
// Teleport
|
||||
new Teleport(this, clientManager);
|
||||
|
||||
|
||||
// Packets
|
||||
PacketHandler packetHandler = require(PacketHandler.class);
|
||||
|
||||
|
||||
// Vanish
|
||||
IncognitoManager incognito = new IncognitoManager(this, clientManager, packetHandler);
|
||||
|
||||
|
||||
// Preferences
|
||||
PreferencesManager preferenceManager = new PreferencesManager(this, incognito, clientManager);
|
||||
|
||||
|
||||
// Why do these depend on each other... :(
|
||||
incognito.setPreferencesManager(preferenceManager);
|
||||
|
||||
// Server Status
|
||||
ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager));
|
||||
|
||||
ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager));
|
||||
|
||||
// Portal
|
||||
Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName());
|
||||
|
||||
|
||||
// File Updater
|
||||
new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion());
|
||||
|
||||
|
||||
// Punish
|
||||
Punish punish = new Punish(this, webServerAddress, clientManager);
|
||||
|
||||
// Disguises
|
||||
DisguiseManager disguiseManager = require(DisguiseManager.class);
|
||||
|
||||
|
||||
// Creatures
|
||||
Creature creature = new Creature(this);
|
||||
|
||||
// The old classic Damage Manager
|
||||
new DamageManager(this, new CombatManager(this), new NpcManager(this, creature), disguiseManager, new ConditionManager(this));
|
||||
|
||||
|
||||
// GWEN
|
||||
//require(AntiHack.class);
|
||||
|
||||
// require(AntiHack.class);
|
||||
|
||||
// Block Restore
|
||||
BlockRestore blockRestore = new BlockRestore(this);
|
||||
BlockRestore blockRestore = require(BlockRestore.class);
|
||||
|
||||
// Ignoring
|
||||
IgnoreManager ignoreManager = new IgnoreManager(this, clientManager, preferenceManager, portal);
|
||||
|
@ -168,10 +168,10 @@ public class GemHunters extends JavaPlugin
|
|||
|
||||
// Elo
|
||||
EloManager eloManager = new EloManager(this, clientManager);
|
||||
|
||||
|
||||
// Achievements
|
||||
AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager, incognito, eloManager);
|
||||
|
||||
|
||||
// Chat/Messaging
|
||||
Chat chat = new Chat(this, incognito, clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName());
|
||||
new MessageManager(this, incognito, clientManager, preferenceManager, ignoreManager, punish, new FriendManager(this, clientManager, preferenceManager, portal), chat);
|
||||
|
@ -181,17 +181,21 @@ public class GemHunters extends JavaPlugin
|
|||
// Fixes
|
||||
new MemoryFix(this);
|
||||
new FoodDupeFix(this);
|
||||
|
||||
|
||||
// Explosions
|
||||
new Explosion(this, blockRestore);
|
||||
|
||||
|
||||
// Inventories
|
||||
new InventoryManager(this, clientManager);
|
||||
|
||||
// Reports
|
||||
// SnapshotManager snapshotManager = new SnapshotManager(this, new SnapshotRepository(serverStatusManager.getCurrentServerName(), getLogger()));
|
||||
// new SnapshotPlugin(this, snapshotManager, clientManager);
|
||||
// new ReportPlugin(this, new ReportManager(this, snapshotManager, clientManager, incognito, punish, serverStatusManager.getRegion(), serverStatusManager.getCurrentServerName(), 1));
|
||||
// SnapshotManager snapshotManager = new SnapshotManager(this, new
|
||||
// SnapshotRepository(serverStatusManager.getCurrentServerName(),
|
||||
// getLogger()));
|
||||
// new SnapshotPlugin(this, snapshotManager, clientManager);
|
||||
// new ReportPlugin(this, new ReportManager(this, snapshotManager,
|
||||
// clientManager, incognito, punish, serverStatusManager.getRegion(),
|
||||
// serverStatusManager.getCurrentServerName(), 1));
|
||||
|
||||
// Tag fix
|
||||
new CustomTagFix(this, packetHandler);
|
||||
|
@ -199,8 +203,6 @@ public class GemHunters extends JavaPlugin
|
|||
// Holograms
|
||||
new HologramManager(this, packetHandler);
|
||||
|
||||
new TextTutorialManager(this, donationManager, new TaskManager(this, clientManager, webServerAddress));
|
||||
|
||||
// Now we finally get to enable the Gem Hunters modules
|
||||
require(CashOutModule.class);
|
||||
require(ChatModule.class);
|
||||
|
@ -211,10 +213,10 @@ public class GemHunters extends JavaPlugin
|
|||
require(SpawnModule.class);
|
||||
require(ShopModule.class);
|
||||
require(SupplyDropModule.class);
|
||||
|
||||
//UpdateEvent!!!
|
||||
|
||||
// UpdateEvent!!!
|
||||
new Updater(this);
|
||||
|
||||
|
||||
// Disable spigot's item merging
|
||||
for (World world : getServer().getWorlds())
|
||||
{
|
||||
|
@ -225,11 +227,25 @@ public class GemHunters extends JavaPlugin
|
|||
MinecraftServer.getServer().getPropertyManager().setProperty("debug", false);
|
||||
SpigotConfig.debug = false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
getServer().getPluginManager().callEvent(new ServerShutdownEvent(this));
|
||||
|
||||
// Cleanup all rouge entities
|
||||
for (World world : getServer().getWorlds())
|
||||
{
|
||||
for (Entity entity : world.getEntities())
|
||||
{
|
||||
if (entity instanceof Player)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package mineplex.gemhunters.chat;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
|
@ -12,6 +13,11 @@ import mineplex.core.chat.Chat;
|
|||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
|
||||
/**
|
||||
* This module handles player chat.
|
||||
*
|
||||
* @author Sam
|
||||
*/
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class ChatModule extends MiniPlugin
|
||||
{
|
||||
|
@ -27,9 +33,10 @@ public class ChatModule extends MiniPlugin
|
|||
_chat = require(Chat.class);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void chat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
// Checks if the player has been muted/chat is silenced etc...
|
||||
if (event.isCancelled())
|
||||
{
|
||||
return;
|
||||
|
@ -41,10 +48,16 @@ public class ChatModule extends MiniPlugin
|
|||
Rank rank = _clientManager.Get(player).getRealOrDisguisedRank();
|
||||
String rankString = rank == Rank.ALL ? "" : rank.getTag(true, true);
|
||||
|
||||
// Create a message that follows the rest of the network's chat format
|
||||
String message = (rankString + " " + C.cYellow + playerName + " " + C.cWhite + _chat.getFilteredMessage(player, event.getMessage())).trim();
|
||||
|
||||
// We will handle the broadcast
|
||||
event.setCancelled(true);
|
||||
Bukkit.broadcastMessage(message);
|
||||
|
||||
for (Player other : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
other.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,10 +16,16 @@ import mineplex.core.ReflectivelyCreateMiniPlugin;
|
|||
import mineplex.core.common.util.UtilAction;
|
||||
import mineplex.gemhunters.world.WorldDataModule;
|
||||
|
||||
/**
|
||||
* This module handles anything to do with a players death
|
||||
*
|
||||
* @author Sam
|
||||
*/
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class DeathModule extends MiniPlugin
|
||||
{
|
||||
|
||||
// Some items like the cash out item (and for some reason players drop bones?) don't need to be dropped to avoid duplication.
|
||||
private static final Set<Material> DISALLOWED_DROPS = Sets.newHashSet(Material.EMERALD, Material.BONE);
|
||||
|
||||
private final WorldDataModule _worldData;
|
||||
|
@ -36,12 +42,14 @@ public class DeathModule extends MiniPlugin
|
|||
{
|
||||
Player player = event.getEntity();
|
||||
|
||||
// Stop the player dieing
|
||||
player.setHealth(20);
|
||||
UtilAction.zeroVelocity(player);
|
||||
player.teleport(_worldData.getSpawnLocation("Yellow").get(0));
|
||||
|
||||
Iterator<ItemStack> iterator = event.getDrops().iterator();
|
||||
|
||||
// Iterate through all items and clear any disallowed items
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
ItemStack itemStack = iterator.next();
|
||||
|
|
|
@ -60,7 +60,7 @@ public class LootModule extends MiniPlugin
|
|||
private static final String[] IGNORED_COLOURS = { "RED" };
|
||||
private static final float MAX_CHESTS_FACTOR = 0.25F;
|
||||
private static final int MAX_SEARCH_ATTEMPTS = 40;
|
||||
private static final int MAX_CHEST_PLACEMENT_RANGE = 5;
|
||||
private static final int MAX_CHEST_PLACEMENT_RANGE = 10;
|
||||
private static final int MAX_CHEST_CHECK_DISTANCE_SQUARED = 4;
|
||||
|
||||
private static final MineplexGoogleSheet CHEST_LOOT_SHEET = MineplexGoogleSheet.GEM_HUNTERS_CHESTS;
|
||||
|
@ -212,6 +212,7 @@ public class LootModule extends MiniPlugin
|
|||
continue;
|
||||
}
|
||||
|
||||
//TODO remove debug message
|
||||
Bukkit.broadcastMessage("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index);
|
||||
_spawnedChest.add(new SpawnedChest(chestToPlace, key, index));
|
||||
block.setType(Material.CHEST);
|
||||
|
@ -312,7 +313,6 @@ public class LootModule extends MiniPlugin
|
|||
if (values.size() > 7)
|
||||
{
|
||||
metadata = String.valueOf(values.get(7));
|
||||
Bukkit.broadcastMessage(metadata);
|
||||
}
|
||||
items.add(new LootItem(builder.build(), minAmount, maxAmount, probability, metadata));
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ public class LootModule extends MiniPlugin
|
|||
return;
|
||||
}
|
||||
|
||||
ItemStack itemStack = event.getCursor();
|
||||
ItemStack itemStack = event.getCurrentItem();
|
||||
|
||||
if (itemStack == null)
|
||||
{
|
||||
|
@ -530,8 +530,6 @@ public class LootModule extends MiniPlugin
|
|||
|
||||
if (reward == null)
|
||||
{
|
||||
Bukkit.broadcastMessage(lootItem.getMetadata());
|
||||
|
||||
switch (lootItem.getMetadata())
|
||||
{
|
||||
case "RANK_UPGRADE":
|
||||
|
|
|
@ -2,10 +2,12 @@ package mineplex.gemhunters.loot.command;
|
|||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.gemhunters.loot.LootModule;
|
||||
import mineplex.gemhunters.shop.ShopModule;
|
||||
|
||||
/**
|
||||
* An ADMIN command that allows users to retrieve the latest data from the
|
||||
|
@ -31,7 +33,12 @@ public class UpdateLootCommand extends CommandBase<LootModule>
|
|||
|
||||
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!"));
|
||||
}
|
||||
|
|
|
@ -27,11 +27,12 @@ public class SafezoneModule extends MiniPlugin
|
|||
{
|
||||
|
||||
private static final String SAFEZONE_DATA_PREFIX = "SAFEZONE";
|
||||
private static final String SAFEZONE_DATA_IGNORE = "IGNORE";
|
||||
|
||||
private final WorldDataModule _worldData;
|
||||
|
||||
private final Map<UUID, String> _currentSafezone;
|
||||
|
||||
|
||||
private SafezoneModule()
|
||||
{
|
||||
super("Safezone");
|
||||
|
@ -56,17 +57,23 @@ public class SafezoneModule extends MiniPlugin
|
|||
boolean isInOldSafezone = oldSafezone != null;
|
||||
String newSafezone = getSafezone(player.getLocation());
|
||||
boolean isInNewSafezone = newSafezone != null;
|
||||
|
||||
|
||||
// null -> not null
|
||||
if (!isInOldSafezone && isInNewSafezone)
|
||||
{
|
||||
UtilTextMiddle.display("", C.cYellow + "Entering " + newSafezone, 10, 40, 10, player);
|
||||
if (!newSafezone.contains(SAFEZONE_DATA_IGNORE))
|
||||
{
|
||||
UtilTextMiddle.display("", C.cYellow + "Entering " + newSafezone, 10, 40, 10, player);
|
||||
}
|
||||
_currentSafezone.put(key, newSafezone);
|
||||
}
|
||||
// not null -> null
|
||||
else if (isInOldSafezone && !isInNewSafezone)
|
||||
{
|
||||
UtilTextMiddle.display("", C.cYellow + "Leaving " + oldSafezone, 10, 40, 10, player);
|
||||
if (!oldSafezone.contains(SAFEZONE_DATA_IGNORE))
|
||||
{
|
||||
UtilTextMiddle.display("", C.cYellow + "Leaving " + oldSafezone, 10, 40, 10, player);
|
||||
}
|
||||
_currentSafezone.put(key, null);
|
||||
}
|
||||
}
|
||||
|
@ -153,12 +160,12 @@ public class SafezoneModule extends MiniPlugin
|
|||
{
|
||||
String name = "";
|
||||
String[] split = key.split(" ");
|
||||
|
||||
|
||||
for (int i = 1; i < split.length; i++)
|
||||
{
|
||||
name += split[i] + " ";
|
||||
}
|
||||
|
||||
|
||||
return name.trim();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,27 +2,30 @@ package mineplex.gemhunters.scoreboard;
|
|||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.common.currency.GlobalCurrency;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.scoreboard.WritableMineplexScoreboard;
|
||||
|
||||
public class GemHuntersScoreboard extends WritableMineplexScoreboard
|
||||
{
|
||||
|
||||
private final DonationManager _donation;
|
||||
|
||||
public GemHuntersScoreboard(Player player)
|
||||
{
|
||||
super(player);
|
||||
|
||||
_donation = Managers.require(DonationManager.class);
|
||||
}
|
||||
|
||||
public void writeContent(Player player)
|
||||
{
|
||||
writeNewLine();
|
||||
|
||||
write(C.cGreenB + "Top Players");
|
||||
|
||||
writeNewLine();
|
||||
|
||||
write(C.cYellowB + "Reset Time");
|
||||
write("0 seconds");
|
||||
write(C.cGreenB + "Gems");
|
||||
write(String.valueOf(_donation.Get(player).getBalance(GlobalCurrency.GEM)));
|
||||
|
||||
writeNewLine();
|
||||
}
|
||||
|
|
|
@ -1,15 +1,190 @@
|
|||
package mineplex.gemhunters.shop;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.common.Pair;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.google.GoogleSheetsManager;
|
||||
import mineplex.core.google.MineplexGoogleSheet;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.gemhunters.loot.LootItem;
|
||||
import mineplex.gemhunters.safezone.SafezoneModule;
|
||||
import mineplex.gemhunters.world.WorldDataModule;
|
||||
import mineplex.serverdata.commands.PlayerJoinCommand;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class ShopModule extends MiniPlugin
|
||||
{
|
||||
|
||||
private static final MineplexGoogleSheet VILLAGER_LOOT_SHEET = MineplexGoogleSheet.GEM_HUNTERS_VILLAGERS;
|
||||
|
||||
private final GoogleSheetsManager _sheets;
|
||||
private final WorldDataModule _worldData;
|
||||
|
||||
private final Map<String, Set<TradeableItem>> _tradeItems;
|
||||
|
||||
private boolean _npcsSpawned;
|
||||
|
||||
private ShopModule()
|
||||
{
|
||||
super("Shop");
|
||||
|
||||
_sheets = require(GoogleSheetsManager.class);
|
||||
_worldData = require(WorldDataModule.class);
|
||||
|
||||
_tradeItems = new HashMap<>();
|
||||
|
||||
updateVillagerLoot();
|
||||
}
|
||||
|
||||
public void updateVillagerLoot()
|
||||
{
|
||||
try
|
||||
{
|
||||
Map<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))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -9,6 +9,9 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
|
@ -18,6 +21,7 @@ import mineplex.core.common.util.F;
|
|||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.gemhunters.safezone.SafezoneModule;
|
||||
import mineplex.gemhunters.util.ColouredTextAnimation;
|
||||
import mineplex.gemhunters.util.SimpleNPC;
|
||||
import mineplex.gemhunters.world.WorldDataModule;
|
||||
|
||||
|
@ -50,9 +54,9 @@ public class SpawnModule extends MiniPlugin
|
|||
_spawn = _worldData.getSpawnLocation("Yellow").get(0);
|
||||
_center = _worldData.getCustomLocation("CENTER").get(0);
|
||||
}
|
||||
|
||||
|
||||
event.getPlayer().teleport(_spawn);
|
||||
|
||||
|
||||
if (_npcsSpawned)
|
||||
{
|
||||
return;
|
||||
|
@ -72,16 +76,32 @@ public class SpawnModule extends MiniPlugin
|
|||
public void run(Player data)
|
||||
{
|
||||
Location location = getRandomLocation();
|
||||
|
||||
|
||||
if (location == null)
|
||||
{
|
||||
data.sendMessage(F.main(_moduleName, "A suitable teleport location could not be found. Please try again in a few seconds."));
|
||||
return;
|
||||
}
|
||||
|
||||
data.teleport(location);
|
||||
}
|
||||
|
||||
data.teleport(location);
|
||||
data.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 4 * 20, 9));
|
||||
data.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 4 * 20, 9));
|
||||
|
||||
ColouredTextAnimation animation = new ColouredTextAnimation("GEM HUNTERS", C.cGoldB + "M ", C.cGoldB + " M", new String[] { C.cDGreenB, C.cGreenB, C.cWhiteB });
|
||||
|
||||
runSyncTimer(new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (animation.displayAsTitle(data))
|
||||
{
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}, 10, 4);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -105,11 +125,11 @@ public class SpawnModule extends MiniPlugin
|
|||
|
||||
while (attempts < 100)
|
||||
{
|
||||
Location possible = UtilAlg.getRandomLocation(_center, range, 10, range);
|
||||
Location possible = UtilBlock.getHighest(_worldData.World, UtilAlg.getRandomLocation(_center, range)).getLocation();
|
||||
|
||||
if (isSuitable(possible.getBlock()))
|
||||
{
|
||||
return possible;
|
||||
return possible.add(0, 1, 0);
|
||||
}
|
||||
|
||||
attempts++;
|
||||
|
|
|
@ -72,6 +72,8 @@ public class SupplyDrop
|
|||
_lastHelicopter = new HashSet<>(100);
|
||||
_bladeBlocks = new HashSet<>(20);
|
||||
_diagonal = false;
|
||||
|
||||
spawn.getChunk().load();
|
||||
}
|
||||
|
||||
public boolean advancePath()
|
||||
|
@ -182,6 +184,19 @@ public class SupplyDrop
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
for (Block block : _bladeBlocks)
|
||||
{
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
|
||||
for (Block block : _lastHelicopter)
|
||||
{
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
public void spawnLootChest()
|
||||
{
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package mineplex.gemhunters.supplydrop;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
@ -8,13 +13,21 @@ import org.bukkit.event.EventHandler;
|
|||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.blockrestore.BlockRestore;
|
||||
import mineplex.core.common.Pair;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.common.util.UtilTextMiddle;
|
||||
import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.gemhunters.loot.LootModule;
|
||||
import mineplex.gemhunters.supplydrop.commands.CommandSupplyDropTest;
|
||||
import mineplex.gemhunters.supplydrop.commands.SupplyDropCommand;
|
||||
import mineplex.gemhunters.world.WorldDataModule;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
|
@ -22,33 +35,42 @@ public class SupplyDropModule extends MiniPlugin
|
|||
{
|
||||
|
||||
private static final String CHEST_COLOUR = "RED";
|
||||
private static final String LOCATION_DATA = "SUPPLY_DROP";
|
||||
|
||||
private final BlockRestore _blockRestore;
|
||||
private final LootModule _loot;
|
||||
private final WorldDataModule _worldData;
|
||||
|
||||
|
||||
private final Set<Block> _beaconBlocks;
|
||||
|
||||
private String[] _locationKeys;
|
||||
private SupplyDrop _current;
|
||||
|
||||
private SupplyDropModule()
|
||||
{
|
||||
super("Supply Drop");
|
||||
|
||||
_blockRestore = require(BlockRestore.class);
|
||||
_loot = require(LootModule.class);
|
||||
_worldData = require(WorldDataModule.class);
|
||||
|
||||
_beaconBlocks = new HashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCommands()
|
||||
{
|
||||
addCommand(new CommandSupplyDropTest(this));
|
||||
addCommand(new SupplyDropCommand(this));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void update(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC || _current == null)
|
||||
|
||||
if (event.getType() != UpdateType.SEC || !isActive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (_current.advancePath())
|
||||
{
|
||||
_current = null;
|
||||
|
@ -58,6 +80,7 @@ public class SupplyDropModule extends MiniPlugin
|
|||
@EventHandler
|
||||
public void itemSpawn(ItemSpawnEvent event)
|
||||
{
|
||||
// The Helicopter has a door. This stops it dropping items when it moves.
|
||||
if (event.getEntity().getItemStack().getType() == Material.IRON_DOOR)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
|
@ -73,19 +96,87 @@ public class SupplyDropModule extends MiniPlugin
|
|||
|
||||
block.setType(Material.CHEST);
|
||||
|
||||
// Add location that the chest will appear at into the spawned chest lists so that LootModule can populate it with loot.
|
||||
Managers.require(LootModule.class).addSpawnedChest(block.getLocation(), CHEST_COLOUR);
|
||||
// Add location that the chest will appear at into the spawned chests list so that LootModule can populate it with loot.
|
||||
_loot.addSpawnedChest(block.getLocation(), CHEST_COLOUR);
|
||||
|
||||
// Remove beacon
|
||||
for (Block beacon : _beaconBlocks)
|
||||
{
|
||||
_blockRestore.restore(beacon);
|
||||
}
|
||||
|
||||
_beaconBlocks.clear();
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void startHelicopter()
|
||||
public void startSequence(String locationKey)
|
||||
{
|
||||
Location spawn = _worldData.getCustomLocation("SUPPLY_DROP Fountain Spawn").get(0);
|
||||
Location destination = _worldData.getCustomLocation("SUPPLY_DROP Fountain Chest").get(0);
|
||||
Location despawn = _worldData.getCustomLocation("SUPPLY_DROP Fountain End").get(0);
|
||||
Location spawn = _worldData.getCustomLocation(LOCATION_DATA + " " + locationKey + " Start").get(0);
|
||||
Location destination = _worldData.getCustomLocation(LOCATION_DATA + " " + locationKey + " Chest").get(0);
|
||||
Location despawn = _worldData.getCustomLocation(LOCATION_DATA + " " + locationKey + " End").get(0);
|
||||
|
||||
// Construct a beacon
|
||||
for (Pair<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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -17,33 +17,33 @@ import mineplex.core.common.util.UtilEnt;
|
|||
public class SimpleNPC implements Listener
|
||||
{
|
||||
|
||||
private final LivingEntity _entity;
|
||||
protected final LivingEntity _entity;
|
||||
private final Callback<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)
|
||||
{
|
||||
|
@ -51,11 +51,15 @@ public class SimpleNPC implements Listener
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
event.setCancelled(true);
|
||||
_clickEvent.run(event.getPlayer());
|
||||
|
||||
if (_clickEvent != null)
|
||||
{
|
||||
_clickEvent.run(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void npcDamage(EntityDamageEvent event)
|
||||
{
|
||||
|
@ -63,10 +67,10 @@ public class SimpleNPC implements Listener
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void npcDeath(EntityDeathEvent event)
|
||||
{
|
||||
|
@ -74,8 +78,8 @@ public class SimpleNPC implements Listener
|
|||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -4,12 +4,14 @@ import java.io.BufferedReader;
|
|||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
@ -53,9 +55,9 @@ public class WorldDataModule extends MiniPlugin
|
|||
public void initialize()
|
||||
{
|
||||
final WorldDataModule worldData = this;
|
||||
|
||||
|
||||
runAsync(() -> {
|
||||
|
||||
|
||||
// Unzip
|
||||
worldData.unzipWorld();
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ public class WorldEventCommand extends MultiCommandBase<WorldEventModule>
|
|||
|
||||
public WorldEventCommand(WorldEventModule plugin)
|
||||
{
|
||||
super(plugin, Rank.ADMIN, "worldevent", "we", "event");
|
||||
super(plugin, Rank.ADMIN, "worldevent", "we");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue