This commit is contained in:
Olof Larsson 2011-02-13 17:04:06 +01:00
parent 478116c418
commit d3c5868ca4
10 changed files with 50 additions and 79 deletions

View File

@ -1,3 +1,3 @@
name: Factions name: Factions
version: 1.0 beta4 version: 1.0 beta5
main: com.bukkit.mcteam.factions.Factions main: com.bukkit.mcteam.factions.Factions

Binary file not shown.

View File

@ -775,7 +775,7 @@ public class Commands {
} }
public static void version(Follower me) { public static void version(Follower me) {
me.sendMessage(Conf.colorSystem+"You are running "+Factions.desc.getFullName()); me.sendMessage(Conf.colorSystem+"You are running "+Factions.factions.getDescription().getFullName());
} }
} }

View File

@ -1,11 +1,6 @@
package com.bukkit.mcteam.factions; package com.bukkit.mcteam.factions;
import java.io.File;
import org.bukkit.Server;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -16,51 +11,12 @@ import com.bukkit.mcteam.factions.listeners.FactionsPlayerListener;
import com.bukkit.mcteam.factions.util.Log; import com.bukkit.mcteam.factions.util.Log;
public class Factions extends JavaPlugin { public class Factions extends JavaPlugin {
public static PluginLoader pluginLoader; public static Factions factions;
public static Server server;
public static PluginDescriptionFile desc;
public static File folder;
public static File plugin;
public static ClassLoader cLoader;
private final FactionsPlayerListener playerListener = new FactionsPlayerListener(this); private final FactionsPlayerListener playerListener = new FactionsPlayerListener(this);
private final FactionsEntityListener entityListener = new FactionsEntityListener(this); private final FactionsEntityListener entityListener = new FactionsEntityListener(this);
private final FactionsBlockListener blockListener = new FactionsBlockListener(this); private final FactionsBlockListener blockListener = new FactionsBlockListener(this);
public Factions(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
super(pluginLoader, instance, desc, folder, plugin, cLoader);
Factions.pluginLoader = pluginLoader;
Factions.server = instance;
Factions.desc = desc;
Factions.folder = folder;
Factions.plugin = plugin;
Factions.cLoader = cLoader;
Log.info("=== INIT START ===");
long timeInitStart = System.currentTimeMillis();
Log.info("You are running version: "+desc.getVersion());
EM.loadAll();
// Register events
PluginManager pm = instance.getPluginManager();
pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.Highest, this);
pm.registerEvent(Event.Type.PLAYER_COMMAND, this.playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DEATH, this.entityListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_ENTITY, this.entityListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DAMAGEDBY_PROJECTILE, 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);
Log.info("=== INIT DONE (Took "+(System.currentTimeMillis()-timeInitStart)+"ms) ===");
Log.threshold = Conf.logThreshold;
}
@Override @Override
public void onDisable() { public void onDisable() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@ -69,8 +25,29 @@ public class Factions extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
// TODO Auto-generated method stub Factions.factions = this;
Log.info("=== INIT START ===");
long timeInitStart = System.currentTimeMillis();
Log.info("You are running version: "+this.getDescription().getVersion());
EM.loadAll();
// Register events
PluginManager pm = this.getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.Highest, this);
pm.registerEvent(Event.Type.PLAYER_COMMAND, this.playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Event.Priority.Normal, this);
pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Event.Priority.Normal, 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.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);
Log.info("=== INIT DONE (Took "+(System.currentTimeMillis()-timeInitStart)+"ms) ===");
Log.threshold = Conf.logThreshold;
} }
} }

View File

@ -25,7 +25,7 @@ public class EM {
// hardcoded config // hardcoded config
protected final static String ext = ".json"; protected final static String ext = ".json";
protected final static File folderBase = Factions.folder; protected final static File folderBase = Factions.factions.getDataFolder();
protected final static File folderFaction = new File(folderBase, "faction"); protected final static File folderFaction = new File(folderBase, "faction");
protected final static File folderFollower = new File(folderBase, "follower"); protected final static File folderFollower = new File(folderBase, "follower");
protected final static File folderBoard = new File(folderBase, "board"); protected final static File folderBoard = new File(folderBase, "board");

View File

@ -202,7 +202,7 @@ public class Faction {
public ArrayList<Player> getOnlinePlayers() { public ArrayList<Player> getOnlinePlayers() {
ArrayList<Player> ret = new ArrayList<Player>(); ArrayList<Player> ret = new ArrayList<Player>();
for (Player player: Factions.server.getOnlinePlayers()) { for (Player player: Factions.factions.getServer().getOnlinePlayers()) {
Follower follower = Follower.get(player); Follower follower = Follower.get(player);
if (follower.factionId == this.id) { if (follower.factionId == this.id) {
ret.add(player); ret.add(player);

View File

@ -11,6 +11,7 @@ import com.bukkit.mcteam.util.ChatFixUtil;
public class Follower { public class Follower {
public transient String id; // The is the name of the player public transient String id; // The is the name of the player
public transient Coord lastStoodInCoord = new Coord(); // Where did this player stand the last time we checked?
public int factionId; public int factionId;
public Role role; public Role role;
@ -46,7 +47,7 @@ public class Follower {
} }
public Player getPlayer() { public Player getPlayer() {
return Factions.server.getPlayer(this.getName()); return Factions.factions.getServer().getPlayer(this.getName());
} }
public boolean isOnline() { public boolean isOnline() {

View File

@ -7,6 +7,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageByProjectileEvent; import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityListener; import org.bukkit.event.entity.EntityListener;
@ -33,6 +34,7 @@ public class FactionsEntityListener extends EntityListener {
follower.onDeath(); follower.onDeath();
follower.sendMessage(Conf.colorSystem+"Your power is now "+follower.getPowerRounded()+" / "+follower.getPowerMaxRounded()); follower.sendMessage(Conf.colorSystem+"Your power is now "+follower.getPowerRounded()+" / "+follower.getPowerMaxRounded());
} }
/** /**
* Who can I hurt? * Who can I hurt?
* I can never hurt members or allies. * I can never hurt members or allies.
@ -40,30 +42,22 @@ public class FactionsEntityListener extends EntityListener {
* I can hurt neutrals as long as they are outside their own territory. * I can hurt neutrals as long as they are outside their own territory.
*/ */
@Override @Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { public void onEntityDamage(EntityDamageEvent event) {
if ( event.isCancelled()) { if ( event.isCancelled()) {
return; // Some other plugin decided. Alright then. return; // Some other plugin decided. Alright then.
} }
if ( ! this.canDamagerHurtDamagee(event.getDamager(), event.getEntity(), event.getDamage())) { if (event instanceof EntityDamageByEntityEvent) {
event.setCancelled(true); EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent)event;
} if ( ! this.canDamagerHurtDamagee(sub.getDamager(), sub.getEntity(), sub.getDamage())) {
} event.setCancelled(true);
}
@Override } else if (event instanceof EntityDamageByProjectileEvent) {
public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) { EntityDamageByProjectileEvent sub = (EntityDamageByProjectileEvent)event;
//DamageCause dc = event.getCause(); if ( ! this.canDamagerHurtDamagee(sub.getDamager(), sub.getEntity(), sub.getDamage())) {
//Log.debug("dc.toString(): "+dc.toString()); event.setCancelled(true);
//Log.debug("event.getDamager().getClass(): "+event.getDamager().getClass()); }
//Log.debug("event.getEntity().getClass(): "+event.getEntity().getClass()); }
if ( event.isCancelled()) {
return; // Some other plugin decided. Alright then.
}
if ( ! this.canDamagerHurtDamagee(event.getDamager(), event.getEntity(), event.getDamage())) {
event.setCancelled(true);
}
} }
public boolean canDamagerHurtDamagee(Entity damager, Entity damagee, int damage) { public boolean canDamagerHurtDamagee(Entity damager, Entity damagee, int damage) {

View File

@ -3,7 +3,6 @@ package com.bukkit.mcteam.factions.listeners;
import java.util.*; import java.util.*;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Location;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerEvent;
@ -82,7 +81,7 @@ public class FactionsPlayerListener extends PlayerListener{
// Why? Because the relations will differ. // Why? Because the relations will differ.
event.setCancelled(true); event.setCancelled(true);
for (Player listeningPlayer : Factions.server.getOnlinePlayers()) { for (Player listeningPlayer : Factions.factions.getServer().getOnlinePlayers()) {
Follower you = Follower.get(listeningPlayer); Follower you = Follower.get(listeningPlayer);
String yourFormat = formatStart + me.getChatTag(you) + formatEnd; String yourFormat = formatStart + me.getChatTag(you) + formatEnd;
listeningPlayer.sendMessage(String.format(yourFormat, talkingPlayer.getDisplayName(), msg)); listeningPlayer.sendMessage(String.format(yourFormat, talkingPlayer.getDisplayName(), msg));
@ -122,17 +121,17 @@ public class FactionsPlayerListener extends PlayerListener{
@Override @Override
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
Follower me = Follower.get(event.getPlayer());
// Did we change coord? // Did we change coord?
Location from = event.getFrom(); Coord coordFrom = me.lastStoodInCoord;
Location to = event.getTo(); Coord coordTo = Coord.from(event.getTo());
Coord coordFrom = Coord.from(from);
Coord coordTo = Coord.from(to);
if (coordFrom.equals(coordTo)) { if (coordFrom.equals(coordTo)) {
return; return;
} }
// Yes we did change coord (: // Yes we did change coord (:
Follower me = Follower.get(event.getPlayer()); me.lastStoodInCoord = coordTo;
Board board = Board.get(event.getPlayer().getWorld()); Board board = Board.get(event.getPlayer().getWorld());
if (me.isMapAutoUpdating()) { if (me.isMapAutoUpdating()) {

View File

@ -7,7 +7,7 @@ import org.bukkit.entity.Player;
import com.bukkit.mcteam.factions.Factions; import com.bukkit.mcteam.factions.Factions;
public class Log { public class Log {
public static String prefix = Factions.desc.getName(); public static String prefix = Factions.factions.getDescription().getName();
public static ArrayList<Player> debuggers = new ArrayList<Player>(); public static ArrayList<Player> debuggers = new ArrayList<Player>();
public static int threshold = 10; public static int threshold = 10;