Merge branch '1.6.x' of https://github.com/hintss/Factions into hintss-1.6.x

This commit is contained in:
drtshock 2014-07-09 13:18:50 -05:00
commit 484a8cc233
6 changed files with 27 additions and 80 deletions

View File

@ -131,10 +131,18 @@ public class FLocation {
return Math.sqrt(dx * dx + dz * dz); return Math.sqrt(dx * dx + dz * dz);
} }
public double getDistanceSquaredTo(FLocation that) {
double dx = that.x - this.x;
double dz = that.z - this.z;
return dx * dx + dz * dz;
}
//----------------------------------------------// //----------------------------------------------//
// Some Geometry // Some Geometry
//----------------------------------------------// //----------------------------------------------//
public Set<FLocation> getCircle(double radius) { public Set<FLocation> getCircle(double radius) {
double radiusSquared = radius * radius;
Set<FLocation> ret = new LinkedHashSet<FLocation>(); Set<FLocation> ret = new LinkedHashSet<FLocation>();
if (radius <= 0) { if (radius <= 0) {
return ret; return ret;
@ -148,7 +156,7 @@ public class FLocation {
for (int x = xfrom; x <= xto; x++) { for (int x = xfrom; x <= xto; x++) {
for (int z = zfrom; z <= zto; z++) { for (int z = zfrom; z <= zto; z++) {
FLocation potential = new FLocation(this.worldName, x, z); FLocation potential = new FLocation(this.worldName, x, z);
if (this.getDistanceTo(potential) <= radius) { if (this.getDistanceSquaredTo(potential) <= radiusSquared) {
ret.add(potential); ret.add(potential);
} }
} }

View File

@ -209,7 +209,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
this.autoClaimFor = null; this.autoClaimFor = null;
this.autoSafeZoneEnabled = false; this.autoSafeZoneEnabled = false;
this.autoWarZoneEnabled = false; this.autoWarZoneEnabled = false;
this.loginPvpDisabled = (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) ? true : false; this.loginPvpDisabled = Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0;
this.deleteMe = false; this.deleteMe = false;
this.powerBoost = 0.0; this.powerBoost = 0.0;
@ -634,15 +634,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator {
} }
public boolean canClaimForFaction(Faction forFaction) { public boolean canClaimForFaction(Faction forFaction) {
if (forFaction.isNone()) { return !forFaction.isNone() && (this.isAdminBypassing() || (forFaction == this.getFaction() && this.getRole().isAtLeast(Role.MODERATOR)) || (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer())) || (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer())));
return false;
}
if (this.isAdminBypassing() || (forFaction == this.getFaction() && this.getRole().isAtLeast(Role.MODERATOR)) || (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer())) || (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer()))) {
return true;
}
return false;
} }
public boolean canClaimForFactionAtLocation(Faction forFaction, Location location, boolean notifyFailure) { public boolean canClaimForFactionAtLocation(Faction forFaction, Location location, boolean notifyFailure) {

View File

@ -391,25 +391,18 @@ public class Faction extends Entity implements EconomyParticipator {
} }
protected boolean addFPlayer(FPlayer fplayer) { protected boolean addFPlayer(FPlayer fplayer) {
if (this.isPlayerFreeType()) { return !this.isPlayerFreeType() && fplayers.add(fplayer);
return false;
}
return fplayers.add(fplayer);
} }
protected boolean removeFPlayer(FPlayer fplayer) { protected boolean removeFPlayer(FPlayer fplayer) {
if (this.isPlayerFreeType()) { return !this.isPlayerFreeType() && fplayers.remove(fplayer);
return false;
}
return fplayers.remove(fplayer);
} }
public Set<FPlayer> getFPlayers() { public Set<FPlayer> getFPlayers() {
// return a shallow copy of the FPlayer list, to prevent tampering and concurrency issues // return a shallow copy of the FPlayer list, to prevent tampering and concurrency issues
Set<FPlayer> ret = new HashSet<FPlayer>(fplayers); return new HashSet<FPlayer>(fplayers);
return ret;
} }
public Set<FPlayer> getFPlayersWhereOnline(boolean online) { public Set<FPlayer> getFPlayersWhereOnline(boolean online) {
@ -483,10 +476,7 @@ public class Faction extends Entity implements EconomyParticipator {
} }
// even if all players are technically logged off, maybe someone was on recently enough to not consider them officially offline yet // even if all players are technically logged off, maybe someone was on recently enough to not consider them officially offline yet
if (Conf.considerFactionsReallyOfflineAfterXMinutes > 0 && System.currentTimeMillis() < lastPlayerLoggedOffTime + (Conf.considerFactionsReallyOfflineAfterXMinutes * 60000)) { return Conf.considerFactionsReallyOfflineAfterXMinutes > 0 && System.currentTimeMillis() < lastPlayerLoggedOffTime + (Conf.considerFactionsReallyOfflineAfterXMinutes * 60000);
return true;
}
return false;
} }
public void memberLoggedOff() { public void memberLoggedOff() {
@ -628,11 +618,7 @@ public class Faction extends Entity implements EconomyParticipator {
if (ownerData == null) { if (ownerData == null) {
return false; return false;
} }
if (ownerData.contains(player.getId())) { return ownerData.contains(player.getId());
return true;
}
return false;
} }
public void setPlayerAsOwner(FPlayer player, FLocation loc) { public void setPlayerAsOwner(FPlayer player, FLocation loc) {
@ -691,11 +677,7 @@ public class Faction extends Entity implements EconomyParticipator {
Set<String> ownerData = claimOwnership.get(loc); Set<String> ownerData = claimOwnership.get(loc);
// if no owner list, owner list is empty, or player is in owner list, they're allowed // if no owner list, owner list is empty, or player is in owner list, they're allowed
if (ownerData == null || ownerData.isEmpty() || ownerData.contains(fplayer.getId())) { return ownerData == null || ownerData.isEmpty() || ownerData.contains(fplayer.getId());
return true;
}
return false;
} }

View File

@ -168,11 +168,8 @@ public class P extends MPlugin {
@Override @Override
public boolean handleCommand(CommandSender sender, String commandString, boolean testOnly) { public boolean handleCommand(CommandSender sender, String commandString, boolean testOnly) {
if (sender instanceof Player && FactionsPlayerListener.preventCommand(commandString, (Player) sender)) { return sender instanceof Player && FactionsPlayerListener.preventCommand(commandString, (Player) sender) || super.handleCommand(sender, commandString, testOnly);
return true;
}
return super.handleCommand(sender, commandString, testOnly);
} }
@Override @Override
@ -206,10 +203,7 @@ public class P extends MPlugin {
// enabled or use of the Factions f command without a slash; combination of isPlayerFactionChatting() and isFactionsCommand() // enabled or use of the Factions f command without a slash; combination of isPlayerFactionChatting() and isFactionsCommand()
public boolean shouldLetFactionsHandleThisChat(AsyncPlayerChatEvent event) { public boolean shouldLetFactionsHandleThisChat(AsyncPlayerChatEvent event) {
if (event == null) { return event != null && (isPlayerFactionChatting(event.getPlayer()) || isFactionsCommand(event.getMessage()));
return false;
}
return (isPlayerFactionChatting(event.getPlayer()) || isFactionsCommand(event.getMessage()));
} }
// Does player have Faction Chat enabled? If so, chat plugins should preferably not do channels, // Does player have Faction Chat enabled? If so, chat plugins should preferably not do channels,
@ -220,10 +214,7 @@ public class P extends MPlugin {
} }
FPlayer me = FPlayers.i.get(player); FPlayer me = FPlayers.i.get(player);
if (me == null) { return me != null && me.getChatMode().isAtLeast(ChatMode.ALLIANCE);
return false;
}
return me.getChatMode().isAtLeast(ChatMode.ALLIANCE);
} }
// Is this chat message actually a Factions command, and thus should be left alone by other plugins? // Is this chat message actually a Factions command, and thus should be left alone by other plugins?
@ -231,10 +222,7 @@ public class P extends MPlugin {
// TODO: GET THIS BACK AND WORKING // TODO: GET THIS BACK AND WORKING
public boolean isFactionsCommand(String check) { public boolean isFactionsCommand(String check) {
if (check == null || check.isEmpty()) { return !(check == null || check.isEmpty()) && this.handleCommand(null, check, true);
return false;
}
return this.handleCommand(null, check, true);
} }
// Get a player's faction tag (faction name), mainly for usage by chat plugins for local/channel chat // Get a player's faction tag (faction name), mainly for usage by chat plugins for local/channel chat

View File

@ -138,19 +138,8 @@ public abstract class MCommand<T extends MPlugin> {
*/ */
// TODO: There should be a boolean for silence // TODO: There should be a boolean for silence
public boolean validCall(CommandSender sender, List<String> args) { public boolean validCall(CommandSender sender, List<String> args) {
if (!validSenderType(sender, true)) { return validSenderType(sender, true) && validSenderPermissions(sender, true) && validArgs(args, sender);
return false;
}
if (!validSenderPermissions(sender, true)) {
return false;
}
if (!validArgs(args, sender)) {
return false;
}
return true;
} }
public boolean isEnabled() { public boolean isEnabled() {
@ -168,10 +157,7 @@ public abstract class MCommand<T extends MPlugin> {
} }
public boolean validSenderPermissions(CommandSender sender, boolean informSenderIfNot) { public boolean validSenderPermissions(CommandSender sender, boolean informSenderIfNot) {
if (this.permission == null) { return this.permission == null || p.perm.has(sender, this.permission, informSenderIfNot);
return true;
}
return p.perm.has(sender, this.permission, informSenderIfNot);
} }
public boolean validArgs(List<String> args, CommandSender sender) { public boolean validArgs(List<String> args, CommandSender sender) {
@ -276,10 +262,7 @@ public abstract class MCommand<T extends MPlugin> {
// Is set? ====================== // Is set? ======================
public boolean argIsSet(int idx) { public boolean argIsSet(int idx) {
if (this.args.size() < idx + 1) { return this.args.size() >= idx + 1;
return false;
}
return true;
} }
// STRING ====================== // STRING ======================
@ -300,8 +283,7 @@ public abstract class MCommand<T extends MPlugin> {
return def; return def;
} }
try { try {
Integer ret = Integer.parseInt(str); return Integer.parseInt(str);
return ret;
} catch (Exception e) { } catch (Exception e) {
return def; return def;
} }
@ -321,8 +303,7 @@ public abstract class MCommand<T extends MPlugin> {
return def; return def;
} }
try { try {
Double ret = Double.parseDouble(str); return Double.parseDouble(str);
return ret;
} catch (Exception e) { } catch (Exception e) {
return def; return def;
} }
@ -340,10 +321,7 @@ public abstract class MCommand<T extends MPlugin> {
// Boolean ====================== // Boolean ======================
public Boolean strAsBool(String str) { public Boolean strAsBool(String str) {
str = str.toLowerCase(); str = str.toLowerCase();
if (str.startsWith("y") || str.startsWith("t") || str.startsWith("on") || str.startsWith("+") || str.startsWith("1")) { return str.startsWith("y") || str.startsWith("t") || str.startsWith("on") || str.startsWith("+") || str.startsWith("1");
return true;
}
return false;
} }
public Boolean argAsBool(int idx, boolean def) { public Boolean argAsBool(int idx, boolean def) {

View File

@ -46,5 +46,4 @@ public class PlayerEntity extends Entity {
this.sendMessage(msg); this.sendMessage(msg);
} }
} }
} }