auto-replanting trees
This commit is contained in:
parent
2adfef41ca
commit
9a8fba543d
@ -41,8 +41,8 @@ public class UtilItem
|
||||
_materials.put(Material.IRON_ORE, EnumSet.of(ItemCategory.BLOCK, ItemCategory.ORE, ItemCategory.IRON));
|
||||
_materials.put(Material.IRON_ORE, EnumSet.of(ItemCategory.BLOCK, ItemCategory.ORE, ItemCategory.IRON));
|
||||
_materials.put(Material.COAL_ORE, EnumSet.of(ItemCategory.BLOCK, ItemCategory.ORE, ItemCategory.IRON));
|
||||
_materials.put(Material.LOG, EnumSet.of(ItemCategory.BLOCK, ItemCategory.WOOD));
|
||||
_materials.put(Material.LEAVES, EnumSet.of(ItemCategory.BLOCK, ItemCategory.TRANSLUCENT));
|
||||
_materials.put(Material.LOG, EnumSet.of(ItemCategory.BLOCK, ItemCategory.WOOD, ItemCategory.LOG));
|
||||
_materials.put(Material.LEAVES, EnumSet.of(ItemCategory.BLOCK, ItemCategory.TRANSLUCENT, ItemCategory.LEAVES));
|
||||
_materials.put(Material.SPONGE, EnumSet.of(ItemCategory.BLOCK));
|
||||
_materials.put(Material.GLASS, EnumSet.of(ItemCategory.BLOCK, ItemCategory.TRANSLUCENT, ItemCategory.GLASS));
|
||||
_materials.put(Material.LAPIS_ORE, EnumSet.of(ItemCategory.BLOCK, ItemCategory.ORE));
|
||||
@ -185,8 +185,8 @@ public class UtilItem
|
||||
_materials.put(Material.DROPPER, EnumSet.of(ItemCategory.BLOCK, ItemCategory.GUI));
|
||||
_materials.put(Material.STAINED_CLAY, EnumSet.of(ItemCategory.BLOCK));
|
||||
_materials.put(Material.STAINED_GLASS_PANE, EnumSet.of(ItemCategory.BLOCK, ItemCategory.TRANSLUCENT, ItemCategory.GLASS));
|
||||
_materials.put(Material.LEAVES_2, EnumSet.of(ItemCategory.BLOCK, ItemCategory.TRANSLUCENT));
|
||||
_materials.put(Material.LOG_2, EnumSet.of(ItemCategory.BLOCK, ItemCategory.WOOD));
|
||||
_materials.put(Material.LEAVES_2, EnumSet.of(ItemCategory.BLOCK, ItemCategory.TRANSLUCENT, ItemCategory.LEAVES));
|
||||
_materials.put(Material.LOG_2, EnumSet.of(ItemCategory.BLOCK, ItemCategory.WOOD, ItemCategory.LOG));
|
||||
_materials.put(Material.ACACIA_STAIRS, EnumSet.of(ItemCategory.BLOCK, ItemCategory.TRANSLUCENT));
|
||||
_materials.put(Material.DARK_OAK_STAIRS, EnumSet.of(ItemCategory.BLOCK, ItemCategory.TRANSLUCENT));
|
||||
_materials.put(Material.HAY_BLOCK, EnumSet.of(ItemCategory.BLOCK));
|
||||
@ -808,6 +808,26 @@ public class UtilItem
|
||||
return isItem(stack == null ? null : stack.getType());
|
||||
}
|
||||
|
||||
public static boolean isLog(Material material)
|
||||
{
|
||||
return material == null ? false : (_materials.get(material).contains(ItemCategory.LOG));
|
||||
}
|
||||
|
||||
public static boolean isLog(ItemStack stack)
|
||||
{
|
||||
return isLog(stack == null ? null : stack.getType());
|
||||
}
|
||||
|
||||
public static boolean isLeaf(Material material)
|
||||
{
|
||||
return material == null ? false : (_materials.get(material).contains(ItemCategory.LEAVES));
|
||||
}
|
||||
|
||||
public static boolean isLeaf(ItemStack stack)
|
||||
{
|
||||
return isLeaf(stack == null ? null : stack.getType());
|
||||
}
|
||||
|
||||
public static boolean isTool(Material material)
|
||||
{
|
||||
return material == null ? false : (_materials.get(material).contains(ItemCategory.TOOL));
|
||||
@ -970,7 +990,9 @@ public class UtilItem
|
||||
HOE,
|
||||
ITEM,
|
||||
BLOCK,
|
||||
ITEM_BLOCK;
|
||||
ITEM_BLOCK,
|
||||
LOG,
|
||||
LEAVES;
|
||||
}
|
||||
|
||||
public enum ArmorMaterial
|
||||
|
@ -31,7 +31,6 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
@ -44,10 +43,12 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.blockrestore.BlockRestore;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilEvent;
|
||||
import mineplex.core.common.util.UtilEvent.ActionType;
|
||||
import mineplex.core.common.util.UtilGear;
|
||||
import mineplex.core.common.util.UtilInv;
|
||||
import mineplex.core.common.util.UtilItem;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
@ -69,14 +70,15 @@ public class Gameplay extends MiniPlugin
|
||||
private ClansManager _clansManager;
|
||||
private BlockRestore _blockRestore;
|
||||
private DamageManager _damageManager;
|
||||
private WeightSet<Boolean> _foodDecrease; // Weighted probability sets for food decrease event outcomes
|
||||
private WeightSet<Boolean> _foodDecrease; // Weighted probability sets for
|
||||
// food decrease event outcomes
|
||||
|
||||
private Map<Block, Long> _bucketWater = new HashMap<Block, Long>();
|
||||
|
||||
public Gameplay(JavaPlugin plugin, ClansManager clansManager, BlockRestore blockRestore, DamageManager damageManager)
|
||||
|
||||
public Gameplay(JavaPlugin plugin, ClansManager clansManager, BlockRestore blockRestore, DamageManager damageManager)
|
||||
{
|
||||
super("PvP Gameplay", plugin);
|
||||
|
||||
|
||||
_clansManager = clansManager;
|
||||
_blockRestore = blockRestore;
|
||||
_damageManager = damageManager;
|
||||
@ -94,7 +96,7 @@ public class Gameplay extends MiniPlugin
|
||||
if (state == State.CAUGHT_ENTITY || state == State.CAUGHT_FISH)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
notify(event.getPlayer(), "Fishing is disabled!");
|
||||
notify(event.getPlayer(), "Fishing is disabled!");
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,37 +130,40 @@ public class Gameplay extends MiniPlugin
|
||||
public void BucketEmpty(PlayerBucketEmptyEvent event)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
|
||||
|
||||
Block block = event.getBlockClicked().getRelative(event.getBlockFace());
|
||||
|
||||
|
||||
if (event.getBucket() == Material.WATER_BUCKET)
|
||||
{
|
||||
block.setTypeIdAndData(8, (byte)1, true);
|
||||
block.setTypeIdAndData(8, (byte) 1, true);
|
||||
_blockRestore.add(event.getBlockClicked().getRelative(event.getBlockFace()), 8, (byte) 0, 1000);
|
||||
_bucketWater.put(block, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
||||
if (event.getBucket() == Material.LAVA_BUCKET)
|
||||
{
|
||||
block.setTypeIdAndData(10, (byte)6, true);
|
||||
block.setTypeIdAndData(10, (byte) 6, true);
|
||||
_blockRestore.add(event.getBlockClicked().getRelative(event.getBlockFace()), 10, (byte) 0, 2000);
|
||||
}
|
||||
|
||||
|
||||
event.getPlayer().setItemInHand(ItemStackFactory.Instance.CreateStack(Material.BUCKET));
|
||||
|
||||
event.getPlayer().setItemInHand(ItemStackFactory.Instance.CreateStack(Material.BUCKET));
|
||||
UtilInv.Update(event.getPlayer());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decreases the hunger rate decrease speed by arbitrarily canceling a portion of decrease events.
|
||||
* Decreases the hunger rate decrease speed by arbitrarily canceling a
|
||||
* portion of decrease events.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(ignoreCancelled=true)
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void foodChangeLevel(FoodLevelChangeEvent event)
|
||||
{
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if (event.getFoodLevel() < player.getFoodLevel()) // Hunger is decreasing for player
|
||||
if (event.getFoodLevel() < player.getFoodLevel()) // Hunger is
|
||||
// decreasing for
|
||||
// player
|
||||
{
|
||||
event.setCancelled(_foodDecrease.generateRandom());
|
||||
}
|
||||
@ -168,30 +173,26 @@ public class Gameplay extends MiniPlugin
|
||||
public void BucketFill(PlayerBucketFillEvent event)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
|
||||
if (event.getItemStack().getType() == Material.WATER_BUCKET)
|
||||
if (!_bucketWater.containsKey(event.getBlockClicked()))
|
||||
event.getPlayer().setItemInHand(ItemStackFactory.Instance.CreateStack(Material.WATER_BUCKET));
|
||||
|
||||
|
||||
if (event.getItemStack().getType() == Material.WATER_BUCKET) if (!_bucketWater.containsKey(event.getBlockClicked())) event.getPlayer().setItemInHand(ItemStackFactory.Instance.CreateStack(Material.WATER_BUCKET));
|
||||
|
||||
UtilInv.Update(event.getPlayer());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void BucketWaterExpire(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.FAST)
|
||||
return;
|
||||
|
||||
if (event.getType() != UpdateType.FAST) return;
|
||||
|
||||
HashSet<Block> remove = new HashSet<Block>();
|
||||
|
||||
|
||||
for (Block cur : _bucketWater.keySet())
|
||||
if (UtilTime.elapsed(_bucketWater.get(cur), 2000))
|
||||
remove.add(cur);
|
||||
|
||||
if (UtilTime.elapsed(_bucketWater.get(cur), 2000)) remove.add(cur);
|
||||
|
||||
for (Block cur : remove)
|
||||
_bucketWater.remove(cur);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void ObsidianCancel(BlockPlaceEvent event)
|
||||
{
|
||||
@ -205,9 +206,7 @@ public class Gameplay extends MiniPlugin
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void CommandPlace(BlockPlaceEvent event)
|
||||
{
|
||||
if (event.getBlock().getType() == Material.COMMAND ||
|
||||
event.getBlock().getType() == Material.NOTE_BLOCK ||
|
||||
event.getBlock().getType() == Material.REDSTONE_LAMP_ON)
|
||||
if (event.getBlock().getType() == Material.COMMAND || event.getBlock().getType() == Material.NOTE_BLOCK || event.getBlock().getType() == Material.REDSTONE_LAMP_ON)
|
||||
{
|
||||
UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot place " + F.item("Proximity Devices") + "."));
|
||||
event.setCancelled(true);
|
||||
@ -226,20 +225,22 @@ public class Gameplay extends MiniPlugin
|
||||
|
||||
/**
|
||||
* Disable all Piston related events in Clans
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPistonExtend(BlockPistonExtendEvent event)
|
||||
public void onPistonExtend(BlockPistonExtendEvent event)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable all Piston related events in Clans
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPistonRetract(BlockPistonRetractEvent event)
|
||||
public void onPistonRetract(BlockPistonRetractEvent event)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@ -249,8 +250,7 @@ public class Gameplay extends MiniPlugin
|
||||
{
|
||||
Material material = event.getItem().getType();
|
||||
|
||||
if (material == Material.LAVA_BUCKET || material == Material.LAVA
|
||||
|| material == Material.WATER_BUCKET || material == Material.WATER)
|
||||
if (material == Material.LAVA_BUCKET || material == Material.LAVA || material == Material.WATER_BUCKET || material == Material.WATER)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@ -259,25 +259,21 @@ public class Gameplay extends MiniPlugin
|
||||
@EventHandler
|
||||
public void WebBreak(BlockDamageEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
if (event.getBlock().getType() == Material.WEB)
|
||||
event.setInstaBreak(true);
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
if (event.getBlock().getType() == Material.WEB) event.setInstaBreak(true);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void LapisPlace(BlockPlaceEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
if (event.getBlock().getType() != Material.LAPIS_BLOCK)
|
||||
return;
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
if (event.getBlock().getType() != Material.LAPIS_BLOCK) return;
|
||||
|
||||
UtilInv.remove(event.getPlayer(), Material.LAPIS_BLOCK, (byte)0, 1);
|
||||
event.setCancelled(true);
|
||||
|
||||
UtilInv.remove(event.getPlayer(), Material.LAPIS_BLOCK, (byte) 0, 1);
|
||||
|
||||
final Block block = event.getBlock();
|
||||
|
||||
@ -286,7 +282,7 @@ public class Gameplay extends MiniPlugin
|
||||
public void run()
|
||||
{
|
||||
block.setType(Material.WATER);
|
||||
block.setData((byte)0);
|
||||
block.setData((byte) 0);
|
||||
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, 8);
|
||||
block.getWorld().playSound(block.getLocation(), Sound.SPLASH, 2f, 1f);
|
||||
}
|
||||
@ -296,23 +292,20 @@ public class Gameplay extends MiniPlugin
|
||||
@EventHandler
|
||||
public void EnderChestBreak(BlockBreakEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
if (event.getBlock().getType() != Material.ENDER_CHEST) return;
|
||||
|
||||
if (event.getBlock().getType() != Material.ENDER_CHEST)
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
event.getBlock().setTypeId(0);
|
||||
event.getBlock().getWorld().dropItemNaturally(event.getBlock().getLocation().add(0.5, 0.5, 0.5), ItemStackFactory.Instance.CreateStack(Material.ENDER_CHEST));
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void disableEnderPearls(PlayerInteractEvent event)
|
||||
{
|
||||
if (!isRightClick(event.getAction()))
|
||||
return;
|
||||
if (!isRightClick(event.getAction())) return;
|
||||
|
||||
if (event.hasItem() && event.getItem().getType() == Material.ENDER_PEARL)
|
||||
{
|
||||
@ -324,8 +317,7 @@ public class Gameplay extends MiniPlugin
|
||||
@EventHandler
|
||||
public void disableFlintNSteel(PlayerInteractEvent event)
|
||||
{
|
||||
if (!isRightClick(event.getAction()))
|
||||
return;
|
||||
if (!isRightClick(event.getAction())) return;
|
||||
|
||||
if (event.hasItem() && event.getItem().getType() == Material.FLINT_AND_STEEL)
|
||||
{
|
||||
@ -336,52 +328,48 @@ public class Gameplay extends MiniPlugin
|
||||
|
||||
private static boolean isRightClick(Action action)
|
||||
{
|
||||
return action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK;
|
||||
return action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void IronDoor(PlayerInteractEvent event)
|
||||
{
|
||||
if (!UtilEvent.isAction(event, ActionType.R_BLOCK))
|
||||
return;
|
||||
|
||||
if (event.getClickedBlock().getTypeId() != 71)
|
||||
return;
|
||||
|
||||
if (!UtilEvent.isAction(event, ActionType.R_BLOCK)) return;
|
||||
|
||||
if (event.getClickedBlock().getTypeId() != 71) return;
|
||||
|
||||
Block block = event.getClickedBlock();
|
||||
|
||||
//Knock
|
||||
|
||||
// Knock
|
||||
if (event.isCancelled())
|
||||
{
|
||||
if (!Recharge.Instance.use(event.getPlayer(), "Door Knock", 500, false, false))
|
||||
return;
|
||||
|
||||
if (!Recharge.Instance.use(event.getPlayer(), "Door Knock", 500, false, false)) return;
|
||||
|
||||
block.getWorld().playEffect(block.getLocation(), Effect.ZOMBIE_CHEW_WOODEN_DOOR, 0);
|
||||
}
|
||||
|
||||
//Open
|
||||
|
||||
// Open
|
||||
else
|
||||
{
|
||||
if (block.getData() >= 8)
|
||||
block = block.getRelative(BlockFace.DOWN);
|
||||
|
||||
if (block.getData() < 4) block.setData((byte)(block.getData()+4), true);
|
||||
else block.setData((byte)(block.getData()-4), true);
|
||||
|
||||
//Effect
|
||||
if (block.getData() >= 8) block = block.getRelative(BlockFace.DOWN);
|
||||
|
||||
if (block.getData() < 4)
|
||||
block.setData((byte) (block.getData() + 4), true);
|
||||
else
|
||||
block.setData((byte) (block.getData() - 4), true);
|
||||
|
||||
// Effect
|
||||
block.getWorld().playEffect(block.getLocation(), Effect.DOOR_TOGGLE, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void BrewingDisable(PlayerInteractEvent event)
|
||||
{
|
||||
if (!UtilEvent.isAction(event, ActionType.R_BLOCK))
|
||||
return;
|
||||
|
||||
if (event.getClickedBlock().getTypeId() != 117)
|
||||
return;
|
||||
|
||||
if (!UtilEvent.isAction(event, ActionType.R_BLOCK)) return;
|
||||
|
||||
if (event.getClickedBlock().getTypeId() != 117) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@ -390,177 +378,183 @@ public class Gameplay extends MiniPlugin
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!UtilEvent.isAction(event, ActionType.R_BLOCK)) return;
|
||||
else if (event.getClickedBlock().getType() != Material.ANVIL) return;
|
||||
if (!UtilEvent.isAction(event, ActionType.R_BLOCK))
|
||||
return;
|
||||
else if (event.getClickedBlock().getType() != Material.ANVIL)
|
||||
return;
|
||||
else if (player.isSneaking() && player.getItemInHand().getType() != Material.AIR) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void BonemealCancel(PlayerInteractEvent event)
|
||||
{
|
||||
if (!UtilEvent.isAction(event, ActionType.R))
|
||||
return;
|
||||
|
||||
{
|
||||
if (!UtilEvent.isAction(event, ActionType.R)) return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (player.getItemInHand() == null)
|
||||
return;
|
||||
|
||||
if (player.getItemInHand().getType() != Material.INK_SACK)
|
||||
return;
|
||||
|
||||
if (player.getItemInHand().getData() == null)
|
||||
return;
|
||||
|
||||
if (player.getItemInHand().getData().getData() != 15)
|
||||
return;
|
||||
|
||||
|
||||
if (player.getItemInHand() == null) return;
|
||||
|
||||
if (player.getItemInHand().getType() != Material.INK_SACK) return;
|
||||
|
||||
if (player.getItemInHand().getData() == null) return;
|
||||
|
||||
if (player.getItemInHand().getData().getData() != 15) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void replantTree(BlockBreakEvent event){
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void replantTree(BlockBreakEvent event)
|
||||
{
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (!UtilItem.isLog(block.getType()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (UtilItem.isLog(block.getRelative(BlockFace.DOWN).getType()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (UtilItem.isLeaf(block.getRelative(BlockFace.DOWN).getType()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (block.getRelative(BlockFace.DOWN).getType() != Material.DIRT && block.getRelative(BlockFace.DOWN).getType() != Material.GRASS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Location saplingArea = null;
|
||||
|
||||
for (Block otherBlock : UtilBlock.getInRadius(event.getBlock().getLocation(), 4.5).keySet())
|
||||
{
|
||||
if (!otherBlock.equals(UtilBlock.getHighest(otherBlock.getLocation().getWorld(), otherBlock.getX(), otherBlock.getZ())))
|
||||
{
|
||||
saplingArea = otherBlock.getLocation();
|
||||
if (Math.random() > .75)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
saplingArea.add(0, 1, 0).getBlock().setType(Material.SAPLING);
|
||||
saplingArea.getBlock().setData(block.getData());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void WildfireSpread(BlockBurnEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
for (int x=-1 ; x<=1 ; x++)
|
||||
for (int y=-1 ; y<=1 ; y++)
|
||||
for (int z=-1 ; z<=1 ; z++)
|
||||
for (int x = -1; x <= 1; x++)
|
||||
for (int y = -1; y <= 1; y++)
|
||||
for (int z = -1; z <= 1; z++)
|
||||
{
|
||||
//Self
|
||||
// Self
|
||||
if (x == 0 && y == 0 && z == 0)
|
||||
{
|
||||
event.getBlock().setType(Material.FIRE);
|
||||
|
||||
if (event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.GRASS)
|
||||
event.getBlock().getRelative(BlockFace.DOWN).setType(Material.DIRT);
|
||||
if (event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.GRASS) event.getBlock().getRelative(BlockFace.DOWN).setType(Material.DIRT);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getBlock().getRelative(x, y, z);
|
||||
|
||||
if (block.getRelative(BlockFace.DOWN).getType() == Material.GRASS)
|
||||
block.getRelative(BlockFace.DOWN).setType(Material.DIRT);
|
||||
if (block.getRelative(BlockFace.DOWN).getType() == Material.GRASS) block.getRelative(BlockFace.DOWN).setType(Material.DIRT);
|
||||
|
||||
//Surroundings
|
||||
if (!(
|
||||
(x == 0 && y == 0) ||
|
||||
(x == 0 && z == 0) ||
|
||||
(y == 0 && z == 0)
|
||||
))
|
||||
continue;
|
||||
|
||||
if (block.getTypeId() == 0)
|
||||
block.setType(Material.FIRE);
|
||||
// Surroundings
|
||||
if (!((x == 0 && y == 0) || (x == 0 && z == 0) || (y == 0 && z == 0))) continue;
|
||||
|
||||
if (block.getTypeId() == 0) block.setType(Material.FIRE);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void WildfireDirt(BlockIgniteEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
if (event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.GRASS)
|
||||
event.getBlock().getRelative(BlockFace.DOWN).setType(Material.DIRT);
|
||||
if (event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.GRASS) event.getBlock().getRelative(BlockFace.DOWN).setType(Material.DIRT);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void WildfireCancel(BlockIgniteEvent event)
|
||||
{
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
if (event.getBlock().getBiome() == Biome.JUNGLE || event.getBlock().getBiome() == Biome.JUNGLE_HILLS)
|
||||
if (event.getCause() == IgniteCause.SPREAD)
|
||||
event.setCancelled(true);
|
||||
if (event.getBlock().getBiome() == Biome.JUNGLE || event.getBlock().getBiome() == Biome.JUNGLE_HILLS) if (event.getCause() == IgniteCause.SPREAD) event.setCancelled(true);
|
||||
}
|
||||
|
||||
// @EventHandler
|
||||
// public void onBlockPlace(BlockPlaceEvent event)
|
||||
// {
|
||||
// Location location = event.getBlock().getLocation();
|
||||
//
|
||||
// if (_clansManager.getClanUtility().isNearAdminClaim(location))
|
||||
// {
|
||||
// event.setCancelled(true);
|
||||
// UtilPlayer.message(event.getPlayer(), F.main("Admin", "You cannot place blocks near admin territories!"));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @EventHandler
|
||||
// public void onBlockBreak(BlockBreakEvent event)
|
||||
// {
|
||||
// Location location = event.getBlock().getLocation();
|
||||
//
|
||||
// if (_clansManager.getClanUtility().isNearAdminClaim(location))
|
||||
// {
|
||||
// event.setCancelled(true);
|
||||
// UtilPlayer.message(event.getPlayer(), F.main("Admin", "You cannot break blocks near admin territories!"));
|
||||
// }
|
||||
// }
|
||||
// @EventHandler
|
||||
// public void onBlockPlace(BlockPlaceEvent event)
|
||||
// {
|
||||
// Location location = event.getBlock().getLocation();
|
||||
//
|
||||
// if (_clansManager.getClanUtility().isNearAdminClaim(location))
|
||||
// {
|
||||
// event.setCancelled(true);
|
||||
// UtilPlayer.message(event.getPlayer(), F.main("Admin", "You cannot place
|
||||
// blocks near admin territories!"));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @EventHandler
|
||||
// public void onBlockBreak(BlockBreakEvent event)
|
||||
// {
|
||||
// Location location = event.getBlock().getLocation();
|
||||
//
|
||||
// if (_clansManager.getClanUtility().isNearAdminClaim(location))
|
||||
// {
|
||||
// event.setCancelled(true);
|
||||
// UtilPlayer.message(event.getPlayer(), F.main("Admin", "You cannot break
|
||||
// blocks near admin territories!"));
|
||||
// }
|
||||
// }
|
||||
|
||||
/*
|
||||
@EventHandler (priority = EventPriority.HIGHEST)
|
||||
public void MoneyLossSteal(CombatDeathEvent event)
|
||||
{
|
||||
if (!(event.GetEvent().getEntity() instanceof Player))
|
||||
return;
|
||||
|
||||
Player player = (Player)event.GetEvent().getEntity();
|
||||
|
||||
int balance = Clients().Get(player).Game().GetEconomyBalance();
|
||||
|
||||
int lose = (int) (0.04 * balance);
|
||||
|
||||
//Balance
|
||||
Clients().Get(player).Game().SetEconomyBalance(balance - lose);
|
||||
|
||||
CombatLog log = event.GetLog();
|
||||
if (log.GetKiller() != null)
|
||||
{
|
||||
//Inform
|
||||
UtilPlayer.message(UtilPlayer.searchExact(log.GetKiller().getName()), F.main("Death", "You stole " + F.count((lose) + " Coins") + " from " + F.name(player.getName()) + "."));
|
||||
|
||||
//Inform
|
||||
UtilPlayer.message(player, F.main("Death", "You lost " + F.count((lose) + " Coins") + " to " + F.name(log.GetKiller().getName()) + "."));
|
||||
}
|
||||
else
|
||||
{
|
||||
//Inform
|
||||
UtilPlayer.message(player, F.main("Death", "You lost " + F.count((lose) + " Coins") + " for dying."));
|
||||
}
|
||||
}
|
||||
*/
|
||||
* @EventHandler (priority = EventPriority.HIGHEST) public void
|
||||
* MoneyLossSteal(CombatDeathEvent event) { if
|
||||
* (!(event.GetEvent().getEntity() instanceof Player)) return; Player player
|
||||
* = (Player)event.GetEvent().getEntity(); int balance =
|
||||
* Clients().Get(player).Game().GetEconomyBalance(); int lose = (int) (0.04
|
||||
* * balance); //Balance
|
||||
* Clients().Get(player).Game().SetEconomyBalance(balance - lose); CombatLog
|
||||
* log = event.GetLog(); if (log.GetKiller() != null) { //Inform
|
||||
* UtilPlayer.message(UtilPlayer.searchExact(log.GetKiller().getName()),
|
||||
* F.main("Death", "You stole " + F.count((lose) + " Coins") + " from " +
|
||||
* F.name(player.getName()) + ".")); //Inform UtilPlayer.message(player,
|
||||
* F.main("Death", "You lost " + F.count((lose) + " Coins") + " to " +
|
||||
* F.name(log.GetKiller().getName()) + ".")); } else { //Inform
|
||||
* UtilPlayer.message(player, F.main("Death", "You lost " + F.count((lose) +
|
||||
* " Coins") + " for dying.")); } }
|
||||
*/
|
||||
|
||||
@EventHandler
|
||||
public void SpawnDamage(CustomDamageEvent event)
|
||||
{
|
||||
if (event.IsCancelled())
|
||||
return;
|
||||
|
||||
if (event.GetCause() != DamageCause.FALL)
|
||||
return;
|
||||
|
||||
if (!_clansManager.getClanUtility().isSpecial(event.GetDamageeEntity().getLocation(), "Spawn"))
|
||||
return;
|
||||
|
||||
if (event.IsCancelled()) return;
|
||||
|
||||
if (event.GetCause() != DamageCause.FALL) return;
|
||||
|
||||
if (!_clansManager.getClanUtility().isSpecial(event.GetDamageeEntity().getLocation(), "Spawn")) return;
|
||||
|
||||
event.SetCancelled("Spawn Fall");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cancel the spawning of all Witches.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler
|
||||
@ -577,11 +571,7 @@ public class Gameplay extends MiniPlugin
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (event.getClickedBlock() == null
|
||||
|| event.getClickedBlock().getType() != Material.ANVIL
|
||||
|| !UtilEvent.isAction(event, ActionType.R_BLOCK)
|
||||
|| player.isSneaking()
|
||||
|| player.getItemInHand().getType() == Material.AIR)
|
||||
if (event.getClickedBlock() == null || event.getClickedBlock().getType() != Material.ANVIL || !UtilEvent.isAction(event, ActionType.R_BLOCK) || player.isSneaking() || player.getItemInHand().getType() == Material.AIR)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -591,7 +581,7 @@ public class Gameplay extends MiniPlugin
|
||||
UtilPlayer.message(player, F.main("Repair", "You are too far from the " + F.item("Anvil") + "."));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ItemStack item = player.getItemInHand();
|
||||
|
||||
if (item.getDurability() <= 0)
|
||||
@ -605,46 +595,44 @@ public class Gameplay extends MiniPlugin
|
||||
UtilPlayer.message(player, F.main("Repair", "You cannot repair " + F.item(item.getItemMeta().getDisplayName()) + "."));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int repairs = ItemStackFactory.Instance.GetLoreVar(item, "Repaired", 0);
|
||||
boolean canRepair = canRepair(item);
|
||||
|
||||
|
||||
if (!canRepair)
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Repair", "This item cannot be repaired anymore."));
|
||||
return;
|
||||
}
|
||||
|
||||
String creator = ItemStackFactory.Instance.GetLoreVar(item, "Owner");
|
||||
|
||||
|
||||
String creator = ItemStackFactory.Instance.GetLoreVar(item, "Owner");
|
||||
|
||||
if (creator != null)
|
||||
{
|
||||
if (creator.length() > 2)
|
||||
creator = creator.substring(2, creator.length());
|
||||
if (creator.length() > 2) creator = creator.substring(2, creator.length());
|
||||
|
||||
if (!creator.equals(player.getName()))
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Repair", "You cannot repair " + F.item(item.getItemMeta().getDisplayName()) + " by " + F.name(creator) + "."));
|
||||
UtilPlayer.message(player, F.main("Repair", "You cannot repair " + F.item(item.getItemMeta().getDisplayName()) + " by " + F.name(creator) + "."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Repair!
|
||||
|
||||
// Repair!
|
||||
UtilPlayer.message(player, F.main("Repair", "You repaired " + F.item(item.getItemMeta().getDisplayName()) + "."));
|
||||
item.setDurability((short)0);
|
||||
item.setDurability((short) 0);
|
||||
UtilInv.Update(player);
|
||||
|
||||
//Break
|
||||
if (Math.random() > 0.85)
|
||||
event.getClickedBlock().setData((byte) (event.getClickedBlock().getData() + 4));
|
||||
|
||||
// Break
|
||||
if (Math.random() > 0.85) event.getClickedBlock().setData((byte) (event.getClickedBlock().getData() + 4));
|
||||
|
||||
if (event.getClickedBlock().getData() >= 12)
|
||||
{
|
||||
player.getWorld().playEffect(event.getClickedBlock().getLocation(), Effect.STEP_SOUND, 145);
|
||||
event.getClickedBlock().setTypeIdAndData(0, (byte)0, true);
|
||||
event.getClickedBlock().setTypeIdAndData(0, (byte) 0, true);
|
||||
}
|
||||
|
||||
//Record
|
||||
|
||||
// Record
|
||||
ItemStackFactory.Instance.SetLoreVar(item, "Repaired", (repairs + 1) + "");
|
||||
if (!canRepair(item))
|
||||
{
|
||||
@ -653,24 +641,23 @@ public class Gameplay extends MiniPlugin
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
//Effect
|
||||
// Effect
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_USE, 1f, 1f);
|
||||
}
|
||||
|
||||
|
||||
private boolean canRepair(ItemStack item)
|
||||
{
|
||||
int repairs = ItemStackFactory.Instance.GetLoreVar(item, "Repaired", 0);
|
||||
boolean gold = UtilGear.isGold(item);
|
||||
boolean canRepair = true;
|
||||
|
||||
|
||||
if (repairs >= 3 && gold)
|
||||
canRepair = false;
|
||||
else if (repairs >= 2 && !gold)
|
||||
canRepair = false;
|
||||
|
||||
else if (repairs >= 2 && !gold) canRepair = false;
|
||||
|
||||
return canRepair;
|
||||
}
|
||||
|
||||
|
||||
public DamageManager getDamageManager()
|
||||
{
|
||||
return _damageManager;
|
||||
|
Loading…
Reference in New Issue
Block a user