Allow Media to join server, Supply drop work
This commit is contained in:
parent
894a46edf9
commit
fa0fd062d4
@ -68,6 +68,7 @@ import mineplex.game.clans.clans.redis.ClanDeleteCommandHandler;
|
||||
import mineplex.game.clans.clans.redis.ClanLoadCommandHandler;
|
||||
import mineplex.game.clans.clans.regions.ClansRegions;
|
||||
import mineplex.game.clans.clans.scoreboard.ClansScoreboardManager;
|
||||
import mineplex.game.clans.clans.supplyDrop.SupplyDropManager;
|
||||
import mineplex.game.clans.clans.tntGenerator.TntGeneratorManager;
|
||||
import mineplex.game.clans.clans.war.WarManager;
|
||||
import mineplex.game.clans.economy.GoldManager;
|
||||
@ -195,6 +196,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
|
||||
_clanUtility = new ClansUtility(this);
|
||||
_itemMapManager = new ItemMapManager(this, _worldEvent);
|
||||
new TntGeneratorManager(plugin, this);
|
||||
new SupplyDropManager(plugin, this);
|
||||
|
||||
_explosion = new Explosion(plugin, blockRestore);
|
||||
|
||||
@ -777,11 +779,11 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
|
||||
public void onJoin(PlayerLoginEvent event)
|
||||
{
|
||||
Rank rank = _clientManager.Get(event.getPlayer()).GetRank();
|
||||
if (!rank.Has(Rank.MAPDEV) && !event.getPlayer().isWhitelisted())
|
||||
if (!rank.Has(Rank.MEDIA) && !event.getPlayer().isWhitelisted())
|
||||
{
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
// event.setKickMessage("This server is whitelisted!");
|
||||
event.setKickMessage("Only MapDev+ can join this server");
|
||||
event.setKickMessage("Only Media+ can join this server!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,93 @@
|
||||
package mineplex.game.clans.clans.supplyDrop;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
|
||||
import org.bukkit.entity.Player;
|
||||
import net.minecraft.server.v1_7_R4.TileEntity;
|
||||
import net.minecraft.server.v1_7_R4.TileEntityBeacon;
|
||||
|
||||
import mineplex.core.common.util.UtilFirework;
|
||||
|
||||
public class SupplyDrop
|
||||
{
|
||||
private static int DROP_TICKS = 20 * 50;
|
||||
|
||||
private Block _block;
|
||||
private Player _owner;
|
||||
private int _ticks;
|
||||
private boolean _running;
|
||||
|
||||
public SupplyDrop(Player owner, Block block)
|
||||
{
|
||||
_owner = owner;
|
||||
_block = block;
|
||||
_ticks = 0;
|
||||
_running = true;
|
||||
}
|
||||
|
||||
public void tick()
|
||||
{
|
||||
if (getTicks() == 10)
|
||||
{
|
||||
try
|
||||
{
|
||||
TileEntity tileEntity = ((CraftWorld) _block.getWorld()).getHandle().getTileEntity(_block.getX(), _block.getY(), _block.getZ());
|
||||
Field k = TileEntityBeacon.class.getDeclaredField("k");
|
||||
k.setAccessible(true);
|
||||
|
||||
Field l = TileEntityBeacon.class.getDeclaredField("l");
|
||||
l.setAccessible(true);
|
||||
|
||||
if (tileEntity instanceof TileEntityBeacon)
|
||||
{
|
||||
k.set(tileEntity, true);
|
||||
l.set(tileEntity, 3);
|
||||
tileEntity.update();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (getTicks() > 15 && getTicks() % 10 == 0)
|
||||
{
|
||||
FireworkEffect effect = FireworkEffect.builder().with(FireworkEffect.Type.BURST).withColor(Color.AQUA, Color.WHITE, Color.GRAY).withFade(Color.BLACK).withFlicker().build();
|
||||
UtilFirework.playFirework(_block.getLocation().add(0.5, 0.5, 0.5), effect);
|
||||
}
|
||||
|
||||
if (getTicks() >= DROP_TICKS)
|
||||
{
|
||||
// Drop supply drop
|
||||
_running = false;
|
||||
}
|
||||
|
||||
_ticks++;
|
||||
}
|
||||
|
||||
public boolean isRunning()
|
||||
{
|
||||
return _running;
|
||||
}
|
||||
|
||||
public Block getBlock()
|
||||
{
|
||||
return _block;
|
||||
}
|
||||
|
||||
public Player getOwner()
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
|
||||
public int getTicks()
|
||||
{
|
||||
return _ticks;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,166 @@
|
||||
package mineplex.game.clans.clans.supplyDrop;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.game.clans.clans.ClansManager;
|
||||
import mineplex.game.clans.core.repository.ClanTerritory;
|
||||
|
||||
public class SupplyDropManager extends MiniPlugin
|
||||
{
|
||||
public static Material SUPPLY_DROP_MATERIAL = Material.BEACON;
|
||||
|
||||
private ClansManager _clansManager;
|
||||
private List<SupplyDrop> _supplyDrops;
|
||||
|
||||
public SupplyDropManager(JavaPlugin plugin, ClansManager clansManager)
|
||||
{
|
||||
super("Supply Drops", plugin);
|
||||
|
||||
_clansManager = clansManager;
|
||||
_supplyDrops = new LinkedList<SupplyDrop>();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void placeSupplyDrop(BlockPlaceEvent event)
|
||||
{
|
||||
ItemStack item = event.getItemInHand();
|
||||
|
||||
if (isSupplyDropItem(item))
|
||||
{
|
||||
ClanTerritory claim = _clansManager.getClanUtility().getClaim(event.getBlock().getLocation());
|
||||
if (claim != null)
|
||||
{
|
||||
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You can only place " + F.elem("Supply Drop") + " in the Wilderness"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
event.getPlayer().setItemInHand(null);
|
||||
placeSupplyDrop(event.getPlayer(), event.getBlock());
|
||||
|
||||
Bukkit.broadcastMessage(F.main("Clans", F.name(event.getPlayer().getName()) + " placed a supply drop at " + F.elem(UtilWorld.blockToStrClean(event.getBlock()))));
|
||||
}
|
||||
}
|
||||
|
||||
// @EventHandler
|
||||
// public void debug(PlayerCommandPreprocessEvent event)
|
||||
// {
|
||||
// if (event.getMessage().equalsIgnoreCase("/supplydrop"))
|
||||
// {
|
||||
// UtilPlayer.message(event.getPlayer(), F.main("Clans", "You received a " + F.elem("Supply Drop")));
|
||||
// giveSupplyDropItem(event.getPlayer());
|
||||
// }
|
||||
// }
|
||||
|
||||
@EventHandler
|
||||
public void update(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
return;
|
||||
|
||||
Iterator<SupplyDrop> iterator = _supplyDrops.iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
SupplyDrop supplyDrop = iterator.next();
|
||||
|
||||
if (supplyDrop.isRunning())
|
||||
{
|
||||
supplyDrop.tick();
|
||||
}
|
||||
else
|
||||
{
|
||||
supplyDrop.getBlock().setType(Material.AIR);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void cancelInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK)
|
||||
{
|
||||
if (event.getClickedBlock() != null && event.getClickedBlock().getType() == SUPPLY_DROP_MATERIAL)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void cancelBreak(BlockBreakEvent event)
|
||||
{
|
||||
for (SupplyDrop supplyDrop : _supplyDrops)
|
||||
{
|
||||
if (supplyDrop.getBlock().equals(event.getBlock()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void placeSupplyDrop(Player player, Block block)
|
||||
{
|
||||
SupplyDrop supplyDrop = new SupplyDrop(player, block);
|
||||
_supplyDrops.add(supplyDrop);
|
||||
|
||||
block.setType(SUPPLY_DROP_MATERIAL);
|
||||
|
||||
for (int x = -1; x <= 1; x++)
|
||||
{
|
||||
for (int z = -1; z <= 1; z++)
|
||||
{
|
||||
Block b = block.getRelative(x, -1, z);
|
||||
_clansManager.getBlockRestore().add(b, Material.DIAMOND_BLOCK.getId(), (byte) 0, 60000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void giveSupplyDropItem(Player player)
|
||||
{
|
||||
ItemStack item = ItemStackFactory.Instance.CreateStack(Material.BEACON, (byte) 0, 1, C.cGold + "Supply Drop");
|
||||
player.getInventory().addItem(item);
|
||||
}
|
||||
|
||||
private boolean isSupplyDropItem(ItemStack item)
|
||||
{
|
||||
if (item == null)
|
||||
return false;
|
||||
|
||||
return item.getType() == SUPPLY_DROP_MATERIAL;
|
||||
|
||||
// if (item.getType() == SUPPLY_DROP_MATERIAL)
|
||||
// {
|
||||
// CustomItem customItem = GearManager.parseItem(item);
|
||||
// if (customItem != null && customItem instanceof SupplyDropItem)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user