Initialize online players when Factions is enabled

This commit is contained in:
eueln 2015-01-10 14:42:52 -06:00
parent 2955370c9e
commit b52805f7a4
2 changed files with 18 additions and 24 deletions

View File

@ -33,13 +33,6 @@ public class P extends MPlugin {
// Single 4 life.
public static P p;
// Listeners
public final FactionsPlayerListener playerListener;
public final FactionsChatListener chatListener;
public final FactionsEntityListener entityListener;
public final FactionsExploitListener exploitListener;
public final FactionsBlockListener blockListener;
// Persistence related
private boolean locked = false;
@ -60,11 +53,6 @@ public class P extends MPlugin {
public P() {
p = this;
this.playerListener = new FactionsPlayerListener(this);
this.chatListener = new FactionsChatListener(this);
this.entityListener = new FactionsEntityListener(this);
this.exploitListener = new FactionsExploitListener();
this.blockListener = new FactionsBlockListener(this);
}
@Override
@ -73,6 +61,7 @@ public class P extends MPlugin {
return;
}
this.loadSuccessful = false;
saveDefaultConfig();
// Load Conf from disk
Conf.load();
@ -108,13 +97,11 @@ public class P extends MPlugin {
startAutoLeaveTask(false);
// Register Event Handlers
getServer().getPluginManager().registerEvents(playerListener, this);
getServer().getPluginManager().registerEvents(chatListener, this);
getServer().getPluginManager().registerEvents(entityListener, this);
getServer().getPluginManager().registerEvents(exploitListener, this);
getServer().getPluginManager().registerEvents(blockListener, this);
saveDefaultConfig();
getServer().getPluginManager().registerEvents(new FactionsPlayerListener(this), this);
getServer().getPluginManager().registerEvents(new FactionsChatListener(this), this);
getServer().getPluginManager().registerEvents(new FactionsEntityListener(this), this);
getServer().getPluginManager().registerEvents(new FactionsExploitListener(), this);
getServer().getPluginManager().registerEvents(new FactionsBlockListener(this), this);
// since some other plugins execute commands directly through this command interface, provide it
this.getCommand(this.refCommand).setExecutor(this);

View File

@ -37,18 +37,25 @@ public class FactionsPlayerListener implements Listener {
public FactionsPlayerListener(P p) {
this.p = p;
for (Player player : p.getServer().getOnlinePlayers()) {
initPlayer(player);
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerJoin(PlayerJoinEvent event) {
initPlayer(event.getPlayer());
}
private void initPlayer(Player player) {
// Make sure that all online players do have a fplayer.
final FPlayer me = FPlayers.getInstance().getByPlayer(event.getPlayer());
final FPlayer me = FPlayers.getInstance().getByPlayer(player);
// Update the lastLoginTime for this fplayer
me.setLastLoginTime(System.currentTimeMillis());
// Store player's current FLocation and notify them where they are
me.setLastStoodAt(new FLocation(event.getPlayer().getLocation()));
me.setLastStoodAt(new FLocation(player.getLocation()));
// Check for Faction announcements. Let's delay this so they actually see it.
Bukkit.getScheduler().runTaskLater(P.p, new Runnable() {
@ -68,9 +75,9 @@ public class FactionsPlayerListener implements Listener {
Faction myFaction = me.getFaction();
if (!myFaction.isNone()) {
for (FPlayer player : myFaction.getFPlayersWhereOnline(true)) {
if (player != me && player.isMonitoringJoins()) {
player.msg(TL.FACTION_LOGIN, me.getName());
for (FPlayer other : myFaction.getFPlayersWhereOnline(true)) {
if (other != me && other.isMonitoringJoins()) {
other.msg(TL.FACTION_LOGIN, me.getName());
}
}
}