mirror of
https://github.com/taoneill/war.git
synced 2024-11-27 20:59:39 +01:00
Documentation
This commit is contained in:
parent
9dae88a5fc
commit
8891b97a9d
@ -83,11 +83,19 @@ public class War extends JavaPlugin {
|
||||
War.war = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see JavaPlugin.onEnable()
|
||||
* @see War.loadWar()
|
||||
*/
|
||||
public void onEnable() {
|
||||
War.war = this;
|
||||
this.loadWar();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see JavaPlugin.onDisable()
|
||||
* @see War.unloadWar()
|
||||
*/
|
||||
public void onDisable() {
|
||||
this.unloadWar();
|
||||
}
|
||||
@ -169,7 +177,7 @@ public class War extends JavaPlugin {
|
||||
* Handles war commands
|
||||
*/
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
return this.commandHandler.handle(sender, cmd, commandLabel, args);
|
||||
return this.commandHandler.handle(sender, cmd, args);
|
||||
|
||||
/*
|
||||
if (this.isZoneMaker(player)) {
|
||||
|
@ -24,14 +24,20 @@ import com.tommytony.war.Warzone;
|
||||
*/
|
||||
public class WarBlockListener extends BlockListener {
|
||||
|
||||
/**
|
||||
* @see BlockListener.onBlockPlace()
|
||||
*/
|
||||
@Override
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
if (!War.war.isLoaded()) return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
if (player != null && block != null) {
|
||||
if (player == null || block == null) return;
|
||||
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
// Monument capturing
|
||||
if (team != null && block != null && zone != null && zone.isMonumentCenterBlock(block) && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) {
|
||||
Monument monument = zone.getMonumentFromCenterBlock(block);
|
||||
if (monument != null && !monument.hasOwner()) {
|
||||
@ -48,12 +54,15 @@ public class WarBlockListener extends BlockListener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isZoneMaker = War.war.isZoneMaker(player);
|
||||
// prevent build in important parts
|
||||
if (zone != null && zone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
|
||||
War.war.badMsg(player, "Can't build here.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// protect warzone lobbies
|
||||
for (Warzone wz : War.war.getWarzones()) {
|
||||
if (wz.getLobby() != null && wz.getLobby().getVolume() != null && wz.getLobby().getVolume().contains(block)) {
|
||||
@ -62,6 +71,7 @@ public class WarBlockListener extends BlockListener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// protect the hub
|
||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
|
||||
War.war.badMsg(player, "Can't build here.");
|
||||
@ -83,8 +93,8 @@ public class WarBlockListener extends BlockListener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (team != null && zone != null && zone.isFlagThief(player.getName())) {
|
||||
// a flag thief can't drop his flag
|
||||
if (team != null && zone != null && zone.isFlagThief(player.getName())) {
|
||||
War.war.badMsg(player, "Can't drop the flag. What are you doing? Run!");
|
||||
event.setCancelled(true);
|
||||
|
||||
@ -98,19 +108,19 @@ public class WarBlockListener extends BlockListener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see BlockListener.onBlockBreak()
|
||||
*/
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
if (!War.war.isLoaded()) return;
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
if (player != null && block != null) {
|
||||
this.handleBreakOrDamage(player, block, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleBreakOrDamage(Player player, Block block, Cancellable event) {
|
||||
Warzone warzone = Warzone.getZoneByLocation(player);
|
||||
@ -122,10 +132,11 @@ public class WarBlockListener extends BlockListener {
|
||||
War.war.badMsg(player, "Can't destroy part of a warzone if you're not in a team.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
} else if (team != null && block != null && warzone != null && warzone.isMonumentCenterBlock(block)) {
|
||||
}
|
||||
// monument's center is destroyed
|
||||
if (team != null && block != null && warzone != null && warzone.isMonumentCenterBlock(block)) {
|
||||
Monument monument = warzone.getMonumentFromCenterBlock(block);
|
||||
if (monument.hasOwner()) {
|
||||
|
||||
List<Team> teams = warzone.getTeams();
|
||||
for (Team t : teams) {
|
||||
t.teamcast("Team " + monument.getOwnerTeam().getName() + " loses control of monument " + monument.getName());
|
||||
@ -134,10 +145,13 @@ public class WarBlockListener extends BlockListener {
|
||||
}
|
||||
event.setCancelled(false);
|
||||
return;
|
||||
} else if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
|
||||
|
||||
}
|
||||
// changes in parts of important areas
|
||||
if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
|
||||
// breakage of spawn
|
||||
if (team != null && team.getSpawnVolume().contains(block)) {
|
||||
ItemStack teamKindBlock = new ItemStack(team.getKind().getMaterial(), team.getKind().getData());
|
||||
// let team members loot one block the spawn for monument captures
|
||||
if (player.getInventory().contains(teamKindBlock)) {
|
||||
War.war.badMsg(player, "You already have a " + team.getName() + " block.");
|
||||
event.setCancelled(true);
|
||||
@ -146,8 +160,9 @@ public class WarBlockListener extends BlockListener {
|
||||
event.setCancelled(false); // very important, otherwise could get cancelled but unbreakableZoneBlocks further down
|
||||
return;
|
||||
}
|
||||
// let team members loot one block the spawn for monument captures
|
||||
} else if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) {
|
||||
}
|
||||
// stealing of flag
|
||||
if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) {
|
||||
if (warzone.isFlagThief(player.getName())) {
|
||||
// detect audacious thieves
|
||||
War.war.badMsg(player, "You can only steal one flag at a time!");
|
||||
|
@ -6,12 +6,22 @@ import org.bukkit.command.CommandSender;
|
||||
import bukkit.tommytony.war.command.*;
|
||||
|
||||
/**
|
||||
* Handles commands received by War
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
* @package bukkit.tommytony.war
|
||||
*/
|
||||
public class WarCommandHandler {
|
||||
|
||||
public boolean handle(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
/**
|
||||
* Handles a command
|
||||
*
|
||||
* @param sender The sender of the command
|
||||
* @param cmd The command
|
||||
* @param args The arguments
|
||||
* @return Success
|
||||
*/
|
||||
public boolean handle(CommandSender sender, Command cmd, String[] args) {
|
||||
String command = cmd.getName();
|
||||
String[] arguments = null;
|
||||
|
||||
|
@ -132,10 +132,12 @@ public class WarEntityListener extends EntityListener {
|
||||
|
||||
/**
|
||||
* Protects important structures from explosions
|
||||
*
|
||||
* @see EntityListener.onEntityExplode()
|
||||
*/
|
||||
@Override
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
if (!War.war.isLoaded()) return;
|
||||
// protect zones elements, lobbies and warhub from creepers
|
||||
List<Block> explodedBlocks = event.blockList();
|
||||
for (Block block : explodedBlocks) {
|
||||
@ -144,6 +146,7 @@ public class WarEntityListener extends EntityListener {
|
||||
War.war.log("Explosion prevented at warhub.", Level.INFO);
|
||||
return;
|
||||
}
|
||||
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
if (zone.isImportantBlock(block)) {
|
||||
event.setCancelled(true);
|
||||
@ -157,14 +160,16 @@ public class WarEntityListener extends EntityListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles damage on Players
|
||||
*
|
||||
* @see EntityListener.onEntityDamage()
|
||||
*/
|
||||
@Override
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
if (!War.war.isLoaded()) return;
|
||||
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof Player)) {
|
||||
return;
|
||||
@ -193,11 +198,10 @@ public class WarEntityListener extends EntityListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCombust(EntityCombustEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
if (!War.war.isLoaded()) return;
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
@ -213,14 +217,16 @@ public class WarEntityListener extends EntityListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents creatures from spawning in warzones if no creatures is active
|
||||
*
|
||||
* @see EntityListener.onCreatureSpawn()
|
||||
*/
|
||||
@Override
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
if (!War.war.isLoaded()) return;
|
||||
|
||||
Location location = event.getLocation();
|
||||
Warzone zone = Warzone.getZoneByLocation(location);
|
||||
if (zone != null && zone.isNoCreatures()) {
|
||||
@ -228,22 +234,22 @@ public class WarEntityListener extends EntityListener {
|
||||
// war.logInfo("Prevented " + event.getMobType().getName() + " from spawning in zone " + zone.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents health regaining caused by peaceful mode
|
||||
*
|
||||
* @see EntityListener.onEntityRegainHealth()
|
||||
*/
|
||||
@Override
|
||||
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
|
||||
if (War.war.isLoaded() && event.getRegainReason() == RegainReason.REGEN) {
|
||||
if (!War.war.isLoaded() || event.getRegainReason() != RegainReason.REGEN) return;
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
if (!(entity instanceof Player)) return;
|
||||
|
||||
Player player = (Player) entity;
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
if (zone != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,9 +32,13 @@ import com.tommytony.war.ZoneSetter;
|
||||
* @package bukkit.tommytony.war
|
||||
*/
|
||||
public class WarPlayerListener extends PlayerListener {
|
||||
|
||||
private java.util.Random random = new java.util.Random();
|
||||
|
||||
/**
|
||||
* Correctly removes quitting players from warzones
|
||||
*
|
||||
* @see PlayerListener.onPlayerQuit()
|
||||
*/
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
@ -82,6 +86,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (War.war.isWandBearer(player)) {
|
||||
Item item = event.getItemDrop();
|
||||
if (item.getItemStack().getType() == Material.WOOD_SWORD) {
|
||||
@ -112,7 +117,6 @@ public class WarPlayerListener extends PlayerListener {
|
||||
ItemStack itemStack = cItem.getItemStack();
|
||||
if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && player.getInventory().contains(new ItemStack(team.getKind().getMaterial(), team.getKind().getData()))) {
|
||||
// Can't pick up a second precious block
|
||||
// war.badMsg(player, "You already have a " + team.getName() + " block.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -154,11 +158,13 @@ public class WarPlayerListener extends PlayerListener {
|
||||
if (!War.war.isZoneMaker(player) && split.length > 0 && split[0].startsWith("/")) {
|
||||
String command = split[0].substring(1);
|
||||
if (!command.equals("war") && !command.equals("zones") && !command.equals("warzones") && !command.equals("zone") && !command.equals("warzone") && !command.equals("teams") && !command.equals("join") && !command.equals("leave") && !command.equals("team") && !command.equals("warhub") && !command.equals("zonemaker")) {
|
||||
// allow white commands
|
||||
for (String whiteCommand : War.war.getCommandWhitelist()) {
|
||||
if (whiteCommand.equals(command)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
War.war.badMsg(player, "Can't use anything but War commands (e.g. /leave, /warhub) while you're playing in a warzone.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@ -209,13 +215,12 @@ public class WarPlayerListener extends PlayerListener {
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
if (!War.war.isLoaded()) return;
|
||||
Player player = event.getPlayer();
|
||||
Location playerLoc = event.getFrom(); // same as player.getLoc. Don't call again we need same result.
|
||||
Warzone locZone = null;
|
||||
ZoneLobby locLobby = null;
|
||||
locZone = Warzone.getZoneByLocation(playerLoc);
|
||||
locLobby = ZoneLobby.getLobbyByLocation(playerLoc);
|
||||
Warzone locZone = Warzone.getZoneByLocation(playerLoc);
|
||||
ZoneLobby locLobby = ZoneLobby.getLobbyByLocation(playerLoc);
|
||||
|
||||
boolean canPlay = War.war.canPlayWar(player);
|
||||
boolean isMaker = War.war.isZoneMaker(player);
|
||||
|
||||
@ -354,8 +359,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
if (newHp - currentHp == 2) { // no 's' in 'hearts' when it's just one heart
|
||||
isS = "";
|
||||
heartNum = "one ";
|
||||
}
|
||||
else if (newHp - currentHp % 2 == 0) {
|
||||
} else if (newHp - currentHp % 2 == 0) {
|
||||
heartNum = ((newHp - currentHp) / 2) + " ";
|
||||
} else {
|
||||
heartNum = ((newHp - currentHp - 1) / 2) + ".5 ";
|
||||
@ -406,7 +410,6 @@ public class WarPlayerListener extends PlayerListener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDisabledZone(PlayerMoveEvent event, Player player, Warzone zone) {
|
||||
if (zone.getLobby() != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user