Add 'Safe' items replacing normal trapped chests and make craters not spam message when they explode
This commit is contained in:
parent
5985731909
commit
e16d88e52b
@ -1,6 +1,7 @@
|
|||||||
package mineplex.game.clans.clans;
|
package mineplex.game.clans.clans;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -12,6 +13,7 @@ import org.bukkit.World.Environment;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
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.EventPriority;
|
||||||
@ -25,12 +27,16 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
|||||||
import org.bukkit.event.enchantment.EnchantItemEvent;
|
import org.bukkit.event.enchantment.EnchantItemEvent;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryPickupItemEvent;
|
||||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||||
import org.bukkit.event.player.PlayerFishEvent;
|
import org.bukkit.event.player.PlayerFishEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.Recipe;
|
||||||
|
import org.bukkit.inventory.ShapedRecipe;
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@ -48,6 +54,7 @@ import mineplex.core.common.util.UtilItem;
|
|||||||
import mineplex.core.common.util.UtilMath;
|
import mineplex.core.common.util.UtilMath;
|
||||||
import mineplex.core.common.util.UtilPlayer;
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
import mineplex.core.common.util.UtilServer;
|
import mineplex.core.common.util.UtilServer;
|
||||||
|
import mineplex.core.itemstack.ItemBuilder;
|
||||||
import mineplex.core.itemstack.ItemStackFactory;
|
import mineplex.core.itemstack.ItemStackFactory;
|
||||||
import mineplex.core.recharge.Recharge;
|
import mineplex.core.recharge.Recharge;
|
||||||
import mineplex.core.updater.UpdateType;
|
import mineplex.core.updater.UpdateType;
|
||||||
@ -67,6 +74,27 @@ public class ClansGame extends MiniPlugin
|
|||||||
super("Clans Game", plugin);
|
super("Clans Game", plugin);
|
||||||
|
|
||||||
_clans = clans;
|
_clans = clans;
|
||||||
|
setupSafes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupSafes()
|
||||||
|
{
|
||||||
|
Iterator<Recipe> it = Bukkit.getServer().recipeIterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
Recipe recipe = it.next();
|
||||||
|
if (recipe != null && recipe.getResult().getType() == Material.TRAPPED_CHEST)
|
||||||
|
{
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ShapedRecipe safe = new ShapedRecipe(new ItemBuilder(Material.TRAPPED_CHEST).setAmount(1).setTitle(C.cDGray + "Safe").build())
|
||||||
|
.shape(new String[] {"III", "ICI", "III"})
|
||||||
|
.setIngredient('I', Material.IRON_INGOT)
|
||||||
|
.setIngredient('C', Material.CHEST);
|
||||||
|
|
||||||
|
Bukkit.addRecipe(safe);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDupedFromClassShop(ItemStack item)
|
public static boolean isDupedFromClassShop(ItemStack item)
|
||||||
@ -626,7 +654,7 @@ public class ClansGame extends MiniPlugin
|
|||||||
{
|
{
|
||||||
ClanTerritory claim = _clans.getClanUtility().getClaim(event.getBlockPlaced().getLocation());
|
ClanTerritory claim = _clans.getClanUtility().getClaim(event.getBlockPlaced().getLocation());
|
||||||
|
|
||||||
if (claim != null && (claim.Owner.equals("Spawn") || claim.Owner.equals("Shops")))
|
if (claim != null && (claim.Owner.equals("Spawn") || claim.Owner.equals("Shops") || claim.Owner.equals("Fields") || _clans.getClanUtility().getAccess(event.getPlayer(), event.getBlockPlaced().getLocation()) != ClanRelation.SELF))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -706,7 +734,10 @@ public class ClansGame extends MiniPlugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clan.inform(C.cRed + "Your Territory is under attack!", null);
|
if (Recharge.Instance.use(event.getShooter(), "TNT TERRITORY ALERT", 1000, false, false))
|
||||||
|
{
|
||||||
|
clan.inform(C.cRed + "Your Territory is under attack!", null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -907,4 +938,30 @@ public class ClansGame extends MiniPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPickupSafe(PlayerPickupItemEvent event)
|
||||||
|
{
|
||||||
|
Item item = event.getItem();
|
||||||
|
ItemStack stack = item.getItemStack();
|
||||||
|
if (stack.getType() == Material.TRAPPED_CHEST)
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
item.remove();
|
||||||
|
UtilInv.insert(event.getPlayer(), new ItemBuilder(Material.TRAPPED_CHEST).setAmount(stack.getAmount()).setTitle(C.cDGray + "Safe").build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPickupSafe(InventoryPickupItemEvent event)
|
||||||
|
{
|
||||||
|
Item item = event.getItem();
|
||||||
|
ItemStack stack = item.getItemStack();
|
||||||
|
if (stack.getType() == Material.TRAPPED_CHEST)
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
item.remove();
|
||||||
|
event.getInventory().addItem(new ItemBuilder(Material.TRAPPED_CHEST).setAmount(stack.getAmount()).setTitle(C.cDGray + "Safe").build());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -78,7 +78,7 @@ public class Crater
|
|||||||
|
|
||||||
ClansManager.getInstance().runSyncLater(() ->
|
ClansManager.getInstance().runSyncLater(() ->
|
||||||
{
|
{
|
||||||
CraterExplodeEvent event = UtilServer.CallEvent(new CraterExplodeEvent(_weapon, _origin, blocks));
|
CraterExplodeEvent event = UtilServer.CallEvent(new CraterExplodeEvent(_weapon, _cause, _origin, blocks));
|
||||||
UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, _origin, null, 0, 1, ViewDist.NORMAL);
|
UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, _origin, null, 0, 1, ViewDist.NORMAL);
|
||||||
for (Block block : event.getBlocks())
|
for (Block block : event.getBlocks())
|
||||||
{
|
{
|
||||||
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
@ -17,12 +18,14 @@ public class CraterExplodeEvent extends Event
|
|||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
private SiegeWeapon _weapon;
|
private SiegeWeapon _weapon;
|
||||||
|
private Player _shooter;
|
||||||
private Location _origin;
|
private Location _origin;
|
||||||
private List<Block> _blocks;
|
private List<Block> _blocks;
|
||||||
|
|
||||||
public CraterExplodeEvent(SiegeWeapon weapon, Location explosionOrigin, List<Block> blocks)
|
public CraterExplodeEvent(SiegeWeapon weapon, Player shooter, Location explosionOrigin, List<Block> blocks)
|
||||||
{
|
{
|
||||||
_weapon = weapon;
|
_weapon = weapon;
|
||||||
|
_shooter = shooter;
|
||||||
_origin = explosionOrigin;
|
_origin = explosionOrigin;
|
||||||
_blocks = blocks;
|
_blocks = blocks;
|
||||||
}
|
}
|
||||||
@ -46,6 +49,15 @@ public class CraterExplodeEvent extends Event
|
|||||||
return _weapon;
|
return _weapon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the player responsible for this crater
|
||||||
|
* @return The player responsible for this crater
|
||||||
|
*/
|
||||||
|
public Player getShooter()
|
||||||
|
{
|
||||||
|
return _shooter;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the location where this explosion originated
|
* Gets the location where this explosion originated
|
||||||
* @return The origin point of this explosion
|
* @return The origin point of this explosion
|
||||||
|
Loading…
Reference in New Issue
Block a user