Initial update for RB 600... bucket use still not prevented properly yet though, needs a bit more work before release

This commit is contained in:
Brettflan 2011-03-29 23:37:32 -05:00
parent ebde7bcc1a
commit e429bc8020
4 changed files with 64 additions and 83 deletions

View File

@ -69,27 +69,10 @@ public class Conf {
territoryProtectedMaterials.add(Material.CHEST);
territoryProtectedMaterials.add(Material.FURNACE);
territoryDenyUseageMaterials.add(Material.REDSTONE);
territoryDenyUseageMaterials.add(Material.SIGN);
territoryDenyUseageMaterials.add(Material.FLINT_AND_STEEL);
territoryDenyUseageMaterials.add(Material.BED);
territoryDenyUseageMaterials.add(Material.BUCKET);
territoryDenyUseageMaterials.add(Material.WATER_BUCKET);
territoryDenyUseageMaterials.add(Material.DIODE);
territoryDenyUseageMaterials.add(Material.SUGAR_CANE);
instaDestroyMaterials.add(Material.SAPLING);
instaDestroyMaterials.add(Material.TORCH);
instaDestroyMaterials.add(Material.REDSTONE_WIRE);
instaDestroyMaterials.add(Material.CROPS);
instaDestroyMaterials.add(Material.REDSTONE_TORCH_OFF);
instaDestroyMaterials.add(Material.REDSTONE_TORCH_ON);
instaDestroyMaterials.add(Material.SUGAR_CANE_BLOCK);
instaDestroyMaterials.add(Material.DIODE_BLOCK_OFF);
instaDestroyMaterials.add(Material.DIODE_BLOCK_ON);
instaDestroyMaterials.add(Material.PAINTING);
instaDestroyMaterials.add(Material.RED_ROSE);
instaDestroyMaterials.add(Material.YELLOW_FLOWER);
territoryDenyUseageMaterials.add(Material.LAVA_BUCKET);
safeZoneNerfedCreatureTypes.add(CreatureType.CREEPER);
safeZoneNerfedCreatureTypes.add(CreatureType.GHAST);

View File

@ -136,18 +136,18 @@ public class Factions extends JavaPlugin {
// Register events
PluginManager pm = this.getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.Highest, this);
pm.registerEvent(Event.Type.PLAYER_ITEM, this.playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_INTERACT, this.playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Event.Priority.High, this);
pm.registerEvent(Event.Type.ENTITY_DEATH, this.entityListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGED, this.entityListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_TARGET, this.entityListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_DAMAGED, this.blockListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PLACED, this.blockListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_INTERACT, this.blockListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_BREAK, this.blockListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_DAMAGE, this.blockListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PLACE, this.blockListener, Event.Priority.Normal, this);
// Register recurring tasks
long saveTicks = 20 * 60 * 30; // Approximately every 30 min

View File

@ -2,10 +2,9 @@ package com.bukkit.mcteam.factions.listeners;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockDamageLevel;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockInteractEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
@ -24,21 +23,33 @@ public class FactionsBlockListener extends BlockListener {
if (event.isCancelled()) {
return;
}
if (!event.canBuild()) {
return;
}
if ( ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "build")) {
event.setCancelled(true);
}
}
@Override
public void onBlockBreak(BlockBreakEvent event) {
if (event.isCancelled()) {
return;
}
if ( ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "destroy")) {
event.setCancelled(true);
}
}
@Override
public void onBlockDamage(BlockDamageEvent event) {
if (event.isCancelled()) {
return;
}
boolean blockDestroyed = event.getDamageLevel() == BlockDamageLevel.STOPPED || Conf.instaDestroyMaterials.contains(event.getBlock().getType());
if (blockDestroyed && ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "destroy")) {
if (event.getInstaBreak() && ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "destroy")) {
event.setCancelled(true);
}
}
@ -70,45 +81,4 @@ public class FactionsBlockListener extends BlockListener {
return true;
}
@Override
public void onBlockInteract(BlockInteractEvent event) {
if (event.isCancelled()) {
return;
}
if ( ! (event.getEntity() instanceof Player)) {
// So far mobs does not interact with the environment :P
return;
}
Block block = event.getBlock();
Player player = (Player) event.getEntity();
if ( ! canPlayerUseRightclickBlock(player, block)) {
event.setCancelled(true);
}
}
public boolean canPlayerUseRightclickBlock(Player player, Block block) {
Material material = block.getType();
// We only care about some material types.
if ( ! Conf.territoryProtectedMaterials.contains(material)) {
return true;
}
FPlayer me = FPlayer.get(player);
Faction myFaction = me.getFaction();
Faction otherFaction = Board.getFactionAt(new FLocation(block));
// In safe zones you may use any block...
if (otherFaction.isNormal() && myFaction != otherFaction) {
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction));
return false;
}
// You may use doors in both safeZone and wilderness
return true;
}
}

View File

@ -8,9 +8,10 @@ import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
@ -89,7 +90,7 @@ public class FactionsPlayerListener extends PlayerListener{
}
@Override
public void onPlayerJoin(PlayerEvent event) {
public void onPlayerJoin(PlayerJoinEvent event) {
// Make sure that all online players do have a fplayer.
FPlayer me = FPlayer.get(event.getPlayer());
@ -130,20 +131,25 @@ public class FactionsPlayerListener extends PlayerListener{
}
@Override
public void onPlayerItem(PlayerItemEvent event) {
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.isCancelled()) {
return;
}
if (event.getBlockClicked() == null) {
return; // right-clicked on air, not a block; no worries then
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return; // only interested on right-clicks on blocks, whether player is using an item or interacting with a block
}
if ( ! this.playerCanUseItemHere(event.getPlayer(), event.getBlockClicked(), event.getMaterial())) {
Block block = event.getClickedBlock();
Player player = event.getPlayer();
if ( ! canPlayerUseRightclickBlock(player, block)) {
event.setCancelled(true);
return;
}
if ( ! this.playerCanUseItemHere(player, block, event.getMaterial())) {
event.setCancelled(true);
return;
}
}
public boolean playerCanUseItemHere(Player player, Block block, Material material) {
@ -179,6 +185,28 @@ public class FactionsPlayerListener extends PlayerListener{
return true;
}
public boolean canPlayerUseRightclickBlock(Player player, Block block) {
Material material = block.getType();
// We only care about some material types.
if ( ! Conf.territoryProtectedMaterials.contains(material)) {
return true;
}
FPlayer me = FPlayer.get(player);
Faction myFaction = me.getFaction();
Faction otherFaction = Board.getFactionAt(new FLocation(block));
// In safe zones you may use any block...
if (otherFaction.isNormal() && myFaction != otherFaction) {
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction));
return false;
}
// You may use doors in both safeZone and wilderness
return true;
}
@Override
public void onPlayerRespawn(PlayerRespawnEvent event) {
FPlayer me = FPlayer.get(event.getPlayer());