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
version: 1.0 beta4
version: 1.0 beta5
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) {
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;
import java.io.File;
import org.bukkit.Server;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
@ -16,51 +11,12 @@ import com.bukkit.mcteam.factions.listeners.FactionsPlayerListener;
import com.bukkit.mcteam.factions.util.Log;
public class Factions extends JavaPlugin {
public static PluginLoader pluginLoader;
public static Server server;
public static PluginDescriptionFile desc;
public static File folder;
public static File plugin;
public static ClassLoader cLoader;
public static Factions factions;
private final FactionsPlayerListener playerListener = new FactionsPlayerListener(this);
private final FactionsEntityListener entityListener = new FactionsEntityListener(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
public void onDisable() {
// TODO Auto-generated method stub
@ -69,8 +25,29 @@ public class Factions extends JavaPlugin {
@Override
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
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 folderFollower = new File(folderBase, "follower");
protected final static File folderBoard = new File(folderBase, "board");

View File

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

View File

@ -11,6 +11,7 @@ import com.bukkit.mcteam.util.ChatFixUtil;
public class Follower {
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 Role role;
@ -46,7 +47,7 @@ public class Follower {
}
public Player getPlayer() {
return Factions.server.getPlayer(this.getName());
return Factions.factions.getServer().getPlayer(this.getName());
}
public boolean isOnline() {

View File

@ -7,6 +7,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityListener;
@ -33,6 +34,7 @@ public class FactionsEntityListener extends EntityListener {
follower.onDeath();
follower.sendMessage(Conf.colorSystem+"Your power is now "+follower.getPowerRounded()+" / "+follower.getPowerMaxRounded());
}
/**
* Who can I hurt?
* 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.
*/
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
public void onEntityDamage(EntityDamageEvent event) {
if ( event.isCancelled()) {
return; // Some other plugin decided. Alright then.
}
if ( ! this.canDamagerHurtDamagee(event.getDamager(), event.getEntity(), event.getDamage())) {
event.setCancelled(true);
}
}
@Override
public void onEntityDamageByProjectile(EntityDamageByProjectileEvent event) {
//DamageCause dc = event.getCause();
//Log.debug("dc.toString(): "+dc.toString());
//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);
}
if (event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent)event;
if ( ! this.canDamagerHurtDamagee(sub.getDamager(), sub.getEntity(), sub.getDamage())) {
event.setCancelled(true);
}
} else if (event instanceof EntityDamageByProjectileEvent) {
EntityDamageByProjectileEvent sub = (EntityDamageByProjectileEvent)event;
if ( ! this.canDamagerHurtDamagee(sub.getDamager(), sub.getEntity(), sub.getDamage())) {
event.setCancelled(true);
}
}
}
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.logging.Logger;
import org.bukkit.Location;
import org.bukkit.entity.*;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerEvent;
@ -82,7 +81,7 @@ public class FactionsPlayerListener extends PlayerListener{
// Why? Because the relations will differ.
event.setCancelled(true);
for (Player listeningPlayer : Factions.server.getOnlinePlayers()) {
for (Player listeningPlayer : Factions.factions.getServer().getOnlinePlayers()) {
Follower you = Follower.get(listeningPlayer);
String yourFormat = formatStart + me.getChatTag(you) + formatEnd;
listeningPlayer.sendMessage(String.format(yourFormat, talkingPlayer.getDisplayName(), msg));
@ -122,17 +121,17 @@ public class FactionsPlayerListener extends PlayerListener{
@Override
public void onPlayerMove(PlayerMoveEvent event) {
Follower me = Follower.get(event.getPlayer());
// Did we change coord?
Location from = event.getFrom();
Location to = event.getTo();
Coord coordFrom = Coord.from(from);
Coord coordTo = Coord.from(to);
Coord coordFrom = me.lastStoodInCoord;
Coord coordTo = Coord.from(event.getTo());
if (coordFrom.equals(coordTo)) {
return;
}
// Yes we did change coord (:
Follower me = Follower.get(event.getPlayer());
me.lastStoodInCoord = coordTo;
Board board = Board.get(event.getPlayer().getWorld());
if (me.isMapAutoUpdating()) {

View File

@ -7,7 +7,7 @@ import org.bukkit.entity.Player;
import com.bukkit.mcteam.factions.Factions;
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 int threshold = 10;