2011-07-18 22:06:02 +02:00
|
|
|
package com.massivecraft.factions.listeners;
|
2011-02-06 13:36:11 +01:00
|
|
|
|
2011-02-12 18:05:05 +01:00
|
|
|
import java.util.logging.Logger;
|
2011-08-04 07:07:38 +02:00
|
|
|
import java.util.Iterator;
|
2011-08-20 03:36:23 +02:00
|
|
|
import java.util.UnknownFormatConversionException;
|
2011-02-06 13:36:11 +01:00
|
|
|
|
2011-03-30 12:11:06 +02:00
|
|
|
import org.bukkit.ChatColor;
|
2011-03-23 17:39:56 +01:00
|
|
|
import org.bukkit.Location;
|
2011-03-23 12:00:38 +01:00
|
|
|
import org.bukkit.Material;
|
2011-03-08 13:06:52 +01:00
|
|
|
import org.bukkit.block.Block;
|
2011-03-22 18:48:09 +01:00
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
2011-03-30 06:37:32 +02:00
|
|
|
import org.bukkit.event.block.Action;
|
2011-03-30 11:23:20 +02:00
|
|
|
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
|
|
|
import org.bukkit.event.player.PlayerBucketFillEvent;
|
2011-02-06 13:36:11 +01:00
|
|
|
import org.bukkit.event.player.PlayerChatEvent;
|
2011-08-04 07:07:38 +02:00
|
|
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
2011-03-30 06:37:32 +02:00
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
2011-02-06 13:36:11 +01:00
|
|
|
import org.bukkit.event.player.PlayerListener;
|
|
|
|
import org.bukkit.event.player.PlayerMoveEvent;
|
2011-05-29 23:28:29 +02:00
|
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
2011-03-23 17:39:56 +01:00
|
|
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
2011-07-18 22:06:02 +02:00
|
|
|
|
|
|
|
import com.massivecraft.factions.Board;
|
|
|
|
import com.massivecraft.factions.Conf;
|
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
|
|
|
import com.massivecraft.factions.Econ;
|
2011-07-18 22:06:02 +02:00
|
|
|
import com.massivecraft.factions.FLocation;
|
|
|
|
import com.massivecraft.factions.FPlayer;
|
|
|
|
import com.massivecraft.factions.Faction;
|
|
|
|
import com.massivecraft.factions.Factions;
|
2011-08-20 03:36:23 +02:00
|
|
|
import com.massivecraft.factions.SpoutFeatures;
|
2011-07-18 22:06:02 +02:00
|
|
|
import com.massivecraft.factions.struct.Role;
|
2011-08-04 07:07:38 +02:00
|
|
|
import com.massivecraft.factions.struct.Relation;
|
2011-07-18 22:06:02 +02:00
|
|
|
import com.massivecraft.factions.util.TextUtil;
|
2011-08-20 03:36:23 +02:00
|
|
|
import java.util.logging.Level;
|
2011-02-06 13:36:11 +01:00
|
|
|
|
2011-02-13 17:02:51 +01:00
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
|
|
|
|
public class FactionsPlayerListener extends PlayerListener{
|
2011-03-08 13:06:52 +01:00
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
@Override
|
2011-03-22 18:48:09 +01:00
|
|
|
public void onPlayerChat(PlayerChatEvent event) {
|
2011-02-12 18:05:05 +01:00
|
|
|
if (event.isCancelled()) {
|
2011-03-22 18:48:09 +01:00
|
|
|
return;
|
2011-02-12 18:05:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Player talkingPlayer = event.getPlayer();
|
2011-02-06 13:36:11 +01:00
|
|
|
String msg = event.getMessage();
|
|
|
|
|
2011-02-12 18:05:05 +01:00
|
|
|
// ... it was not a command. This means that it is a chat message!
|
2011-03-18 17:33:23 +01:00
|
|
|
FPlayer me = FPlayer.get(talkingPlayer);
|
2011-02-13 09:08:20 +01:00
|
|
|
|
2011-02-12 18:05:05 +01:00
|
|
|
// Are we to insert the Faction tag into the format?
|
|
|
|
// If we are not to insert it - we are done.
|
2011-06-12 02:02:57 +02:00
|
|
|
if ( ! Conf.chatTagEnabled || Conf.chatTagHandledByAnotherPlugin) {
|
2011-02-12 18:05:05 +01:00
|
|
|
return;
|
|
|
|
}
|
2011-04-26 03:29:47 +02:00
|
|
|
|
2011-06-03 20:06:41 +02:00
|
|
|
int InsertIndex = 0;
|
|
|
|
String eventFormat = event.getFormat();
|
|
|
|
|
|
|
|
if (!Conf.chatTagReplaceString.isEmpty() && eventFormat.contains(Conf.chatTagReplaceString)) {
|
|
|
|
// we're using the "replace" method of inserting the faction tags
|
2011-06-21 04:15:41 +02:00
|
|
|
// if they stuck "{FACTION_TITLE}" in there, go ahead and do it too
|
|
|
|
if (eventFormat.contains("{FACTION_TITLE}")) {
|
|
|
|
eventFormat = eventFormat.replace("{FACTION_TITLE}", me.getTitle());
|
|
|
|
}
|
2011-06-03 20:06:41 +02:00
|
|
|
InsertIndex = eventFormat.indexOf(Conf.chatTagReplaceString);
|
|
|
|
eventFormat = eventFormat.replace(Conf.chatTagReplaceString, "");
|
|
|
|
Conf.chatTagPadAfter = false;
|
|
|
|
Conf.chatTagPadBefore = false;
|
|
|
|
}
|
|
|
|
else if (!Conf.chatTagInsertAfterString.isEmpty() && eventFormat.contains(Conf.chatTagInsertAfterString)) {
|
|
|
|
// we're using the "insert after string" method
|
|
|
|
InsertIndex = eventFormat.indexOf(Conf.chatTagInsertAfterString) + Conf.chatTagInsertAfterString.length();
|
|
|
|
}
|
|
|
|
else if (!Conf.chatTagInsertBeforeString.isEmpty() && eventFormat.contains(Conf.chatTagInsertBeforeString)) {
|
|
|
|
// we're using the "insert before string" method
|
|
|
|
InsertIndex = eventFormat.indexOf(Conf.chatTagInsertBeforeString);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// we'll fall back to using the index place method
|
|
|
|
InsertIndex = Conf.chatTagInsertIndex;
|
|
|
|
if (InsertIndex > eventFormat.length())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-06 05:03:58 +02:00
|
|
|
String formatStart = eventFormat.substring(0, InsertIndex) + ((Conf.chatTagPadBefore && !me.getChatTag().isEmpty()) ? " " : "");
|
|
|
|
String formatEnd = ((Conf.chatTagPadAfter && !me.getChatTag().isEmpty()) ? " " : "") + eventFormat.substring(InsertIndex);
|
2011-02-12 18:05:05 +01:00
|
|
|
|
2011-06-03 20:06:41 +02:00
|
|
|
String nonColoredMsgFormat = formatStart + me.getChatTag().trim() + formatEnd;
|
2011-02-12 18:05:05 +01:00
|
|
|
|
|
|
|
// Relation Colored?
|
|
|
|
if (Conf.chatTagRelationColored) {
|
|
|
|
// We must choke the standard message and send out individual messages to all players
|
|
|
|
// Why? Because the relations will differ.
|
|
|
|
event.setCancelled(true);
|
|
|
|
|
2011-07-25 00:38:58 +02:00
|
|
|
for (Player listeningPlayer : event.getRecipients()) {
|
2011-03-18 17:33:23 +01:00
|
|
|
FPlayer you = FPlayer.get(listeningPlayer);
|
2011-06-03 20:06:41 +02:00
|
|
|
String yourFormat = formatStart + me.getChatTag(you).trim() + formatEnd;
|
2011-08-20 03:36:23 +02:00
|
|
|
try {
|
|
|
|
listeningPlayer.sendMessage(String.format(yourFormat, talkingPlayer.getDisplayName(), msg));
|
|
|
|
}
|
|
|
|
catch (UnknownFormatConversionException ex) {
|
|
|
|
Factions.log(Level.SEVERE, "Critical error in chat message formatting! Complete format string: "+yourFormat);
|
|
|
|
Factions.log(Level.SEVERE, "First half of event.getFormat() string: "+formatStart);
|
|
|
|
Factions.log(Level.SEVERE, "Second half of event.getFormat() string: "+formatEnd);
|
|
|
|
ex.printStackTrace();
|
|
|
|
return;
|
|
|
|
}
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
2011-02-12 18:05:05 +01:00
|
|
|
|
|
|
|
// Write to the log... We will write the non colored message.
|
2011-03-30 12:11:06 +02:00
|
|
|
String nonColoredMsg = ChatColor.stripColor(String.format(nonColoredMsgFormat, talkingPlayer.getDisplayName(), msg));
|
2011-02-12 18:05:05 +01:00
|
|
|
Logger.getLogger("Minecraft").info(nonColoredMsg);
|
|
|
|
} else {
|
|
|
|
// No relation color.
|
|
|
|
event.setFormat(nonColoredMsgFormat);
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-03-30 06:37:32 +02:00
|
|
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
2011-08-23 06:48:18 +02:00
|
|
|
final Player player = event.getPlayer();
|
|
|
|
|
2011-03-22 18:48:09 +01:00
|
|
|
// Make sure that all online players do have a fplayer.
|
2011-08-23 06:48:18 +02:00
|
|
|
FPlayer me = FPlayer.get(player);
|
2011-03-22 20:36:33 +01:00
|
|
|
|
|
|
|
// Update the lastLoginTime for this fplayer
|
|
|
|
me.setLastLoginTime(System.currentTimeMillis());
|
|
|
|
|
2011-03-23 12:00:38 +01:00
|
|
|
// Run the member auto kick routine. Twice to get to the admins...
|
2011-03-22 20:36:33 +01:00
|
|
|
FPlayer.autoLeaveOnInactivityRoutine();
|
|
|
|
FPlayer.autoLeaveOnInactivityRoutine();
|
2011-08-20 03:36:23 +02:00
|
|
|
|
2011-08-23 06:48:18 +02:00
|
|
|
// Appearance updates which are run when a player joins don't apply properly for other clients, so they need to be delayed slightly
|
|
|
|
Factions.instance.getServer().getScheduler().scheduleSyncDelayedTask(Factions.instance, new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
SpoutFeatures.updateAppearances(player);
|
|
|
|
}
|
|
|
|
});
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
|
|
|
|
2011-05-29 23:28:29 +02:00
|
|
|
@Override
|
|
|
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
|
|
|
// Make sure player's power is up to date when they log off.
|
|
|
|
FPlayer me = FPlayer.get(event.getPlayer());
|
|
|
|
me.getPower();
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
Faction myFaction = me.getFaction();
|
|
|
|
if (myFaction != null) {
|
|
|
|
myFaction.memberLoggedOff();
|
|
|
|
}
|
2011-05-29 23:28:29 +02:00
|
|
|
}
|
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
@Override
|
|
|
|
public void onPlayerMove(PlayerMoveEvent event) {
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
Player player = event.getPlayer();
|
|
|
|
FPlayer me = FPlayer.get(player);
|
2011-02-13 17:04:06 +01:00
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
// Did we change coord?
|
2011-03-22 18:48:09 +01:00
|
|
|
FLocation from = me.getLastStoodAt();
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
FLocation to = new FLocation(player.getLocation());
|
2011-03-22 18:48:09 +01:00
|
|
|
|
|
|
|
if (from.equals(to)) {
|
2011-02-06 13:36:11 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Yes we did change coord (:
|
2011-03-22 18:48:09 +01:00
|
|
|
|
|
|
|
me.setLastStoodAt(to);
|
2011-02-13 11:18:08 +01:00
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
if (me.isMapAutoUpdating()) {
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
me.sendMessage(Board.getMap(me.getFaction(), to, player.getLocation().getYaw()));
|
2011-02-06 13:36:11 +01:00
|
|
|
} else {
|
|
|
|
// Did we change "host"(faction)?
|
2011-03-22 18:48:09 +01:00
|
|
|
Faction factionFrom = Board.getFactionAt(from);
|
|
|
|
Faction factionTo = Board.getFactionAt(to);
|
2011-08-23 06:31:37 +02:00
|
|
|
Faction myFaction = me.getFaction();
|
|
|
|
String ownersTo = myFaction.getOwnerListString(to);
|
|
|
|
if (factionFrom != factionTo) {
|
2011-02-06 13:36:11 +01:00
|
|
|
me.sendFactionHereMessage();
|
2011-08-23 06:31:37 +02:00
|
|
|
if (Conf.ownedAreasEnabled && Conf.ownedMessageOnBorder && myFaction == factionTo && !ownersTo.isEmpty()) {
|
|
|
|
me.sendMessage(Conf.ownedLandMessage+ownersTo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Conf.ownedAreasEnabled && Conf.ownedMessageInsideTerritory && factionFrom == factionTo && myFaction == factionTo) {
|
|
|
|
String ownersFrom = myFaction.getOwnerListString(from);
|
|
|
|
if (Conf.ownedMessageByChunk || !ownersFrom.equals(ownersTo)) {
|
|
|
|
if (!ownersTo.isEmpty()) {
|
|
|
|
me.sendMessage(Conf.ownedLandMessage+ownersTo);
|
|
|
|
}
|
|
|
|
else if (!Conf.publicLandMessage.isEmpty()) {
|
|
|
|
me.sendMessage(Conf.publicLandMessage);
|
|
|
|
}
|
|
|
|
}
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
|
|
|
}
|
2011-06-10 21:26:12 +02:00
|
|
|
|
|
|
|
if (me.autoClaimEnabled()) {
|
|
|
|
Faction myFaction = me.getFaction();
|
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
|
|
|
Faction otherFaction = Board.getFactionAt(to);
|
|
|
|
double cost = Econ.calculateClaimCost(myFaction.getLandRounded(), otherFaction.isNormal());
|
2011-06-10 21:26:12 +02:00
|
|
|
|
|
|
|
if (me.getRole().value < Role.MODERATOR.value) {
|
|
|
|
me.sendMessage("You must be "+Role.MODERATOR+" to claim land.");
|
|
|
|
me.enableAutoClaim(false);
|
|
|
|
}
|
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
|
|
|
else if (Conf.worldsNoClaiming.contains(to.getWorldName())) {
|
2011-06-10 21:26:12 +02:00
|
|
|
me.sendMessage("Sorry, this world has land claiming disabled.");
|
|
|
|
me.enableAutoClaim(false);
|
|
|
|
}
|
|
|
|
else if (myFaction.getLandRounded() >= myFaction.getPowerRounded()) {
|
|
|
|
me.sendMessage("You can't claim more land! You need more power!");
|
|
|
|
me.enableAutoClaim(false);
|
|
|
|
}
|
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
|
|
|
else if (!Econ.canAfford(player.getName(), cost)) {
|
|
|
|
String costString = Econ.moneyString(cost);
|
|
|
|
me.sendMessage("Claiming this land will cost "+costString+", which you can't currently afford.");
|
|
|
|
me.enableAutoClaim(false);
|
|
|
|
}
|
2011-06-10 21:26:12 +02:00
|
|
|
else
|
|
|
|
me.attemptClaim(false);
|
|
|
|
}
|
|
|
|
else if (me.autoSafeZoneEnabled()) {
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
if (!Factions.hasPermManageSafeZone((CommandSender)player)) {
|
2011-06-10 21:26:12 +02:00
|
|
|
me.enableAutoSafeZone(false);
|
|
|
|
} else {
|
|
|
|
FLocation playerFlocation = new FLocation(me);
|
|
|
|
|
|
|
|
if (!Board.getFactionAt(playerFlocation).isSafeZone()) {
|
|
|
|
Board.setFactionAt(Faction.getSafeZone(), playerFlocation);
|
|
|
|
me.sendMessage("This land is now a safe zone.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (me.autoWarZoneEnabled()) {
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
if (!Factions.hasPermManageWarZone((CommandSender)player)) {
|
2011-06-10 21:26:12 +02:00
|
|
|
me.enableAutoWarZone(false);
|
|
|
|
} else {
|
|
|
|
FLocation playerFlocation = new FLocation(me);
|
|
|
|
|
|
|
|
if (!Board.getFactionAt(playerFlocation).isWarZone()) {
|
|
|
|
Board.setFactionAt(Faction.getWarZone(), playerFlocation);
|
|
|
|
me.sendMessage("This land is now a war zone.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
2011-03-08 13:06:52 +01:00
|
|
|
|
|
|
|
@Override
|
2011-03-30 06:37:32 +02:00
|
|
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
2011-03-22 18:48:09 +01:00
|
|
|
if (event.isCancelled()) {
|
2011-03-08 13:06:52 +01:00
|
|
|
return;
|
2011-03-22 18:48:09 +01:00
|
|
|
}
|
2011-03-10 01:21:17 +01:00
|
|
|
|
2011-03-30 06:37:32 +02:00
|
|
|
Block block = event.getClickedBlock();
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
2011-04-04 15:34:32 +02:00
|
|
|
if (block == null) {
|
|
|
|
return; // clicked in air, apparently
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! canPlayerUseBlock(player, block)) {
|
2011-03-30 06:37:32 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2011-04-04 15:34:32 +02:00
|
|
|
|
|
|
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
|
|
|
return; // only interested on right-clicks for below
|
|
|
|
}
|
|
|
|
|
2011-03-30 06:37:32 +02:00
|
|
|
if ( ! this.playerCanUseItemHere(player, block, event.getMaterial())) {
|
2011-03-08 13:06:52 +01:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-03-30 06:37:32 +02:00
|
|
|
|
2011-03-23 12:00:38 +01:00
|
|
|
public boolean playerCanUseItemHere(Player player, Block block, Material material) {
|
2011-03-08 13:06:52 +01:00
|
|
|
|
2011-04-06 12:04:57 +02:00
|
|
|
if (Conf.adminBypassPlayers.contains(player.getName())) {
|
2011-04-04 14:16:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
FLocation loc = new FLocation(block);
|
|
|
|
Faction otherFaction = Board.getFactionAt(loc);
|
2011-03-08 13:06:52 +01:00
|
|
|
|
2011-06-21 07:20:36 +02:00
|
|
|
if (otherFaction.hasPlayersOnline()){
|
2011-06-04 11:36:28 +02:00
|
|
|
if ( ! Conf.territoryDenyUseageMaterials.contains(material)) {
|
|
|
|
return true; // Item isn't one we're preventing for online factions.
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if ( ! Conf.territoryDenyUseageMaterialsWhenOffline.contains(material)) {
|
|
|
|
return true; // Item isn't one we're preventing for offline factions.
|
|
|
|
}
|
|
|
|
}
|
2011-03-08 13:06:52 +01:00
|
|
|
|
2011-06-02 01:32:09 +02:00
|
|
|
FPlayer me = FPlayer.get(player);
|
|
|
|
|
2011-03-23 17:39:56 +01:00
|
|
|
if (otherFaction.isNone()) {
|
2011-06-02 06:01:51 +02:00
|
|
|
if (!Conf.wildernessDenyUseage || Factions.hasPermAdminBypass(player)) {
|
2011-06-02 01:32:09 +02:00
|
|
|
return true; // This is not faction territory. Use whatever you like here.
|
|
|
|
}
|
|
|
|
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the wilderness.");
|
|
|
|
return false;
|
2011-03-08 13:06:52 +01:00
|
|
|
}
|
2011-06-16 09:37:05 +02:00
|
|
|
else if (otherFaction.isSafeZone()) {
|
|
|
|
if (!Conf.safeZoneDenyUseage || Factions.hasPermManageSafeZone(player)) {
|
2011-03-24 15:49:33 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in a safe zone.");
|
|
|
|
return false;
|
|
|
|
}
|
2011-06-16 09:37:05 +02:00
|
|
|
else if (otherFaction.isWarZone()) {
|
|
|
|
if (!Conf.warZoneDenyUseage || Factions.hasPermManageWarZone(player)) {
|
2011-05-29 23:28:29 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in a war zone.");
|
|
|
|
return false;
|
|
|
|
}
|
2011-03-24 15:49:33 +01:00
|
|
|
|
2011-03-08 13:06:52 +01:00
|
|
|
Faction myFaction = me.getFaction();
|
2011-07-09 08:36:18 +02:00
|
|
|
boolean areEnemies = myFaction.getRelation(otherFaction).isEnemy();
|
2011-03-08 13:06:52 +01:00
|
|
|
|
|
|
|
// Cancel if we are not in our own territory
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
if (myFaction != otherFaction) {
|
|
|
|
if (areEnemies ? Conf.territoryEnemyDenyUseage : Conf.territoryDenyUseage) {
|
|
|
|
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Also cancel if player doesn't have ownership rights for this claim
|
|
|
|
else if (
|
|
|
|
Conf.ownedAreasEnabled
|
|
|
|
&& Conf.ownedAreaDenyUseage
|
|
|
|
&& !myFaction.playerHasOwnershipRights(me, loc)
|
|
|
|
&& !Factions.hasPermOwnershipBypass(player)
|
|
|
|
) {
|
|
|
|
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in this territory, it is owned by: "+myFaction.getOwnerListString(loc));
|
2011-03-08 13:06:52 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-03-30 06:37:32 +02:00
|
|
|
|
2011-04-04 15:34:32 +02:00
|
|
|
public boolean canPlayerUseBlock(Player player, Block block) {
|
2011-04-04 14:16:53 +02:00
|
|
|
|
2011-04-06 12:04:57 +02:00
|
|
|
if (Conf.adminBypassPlayers.contains(player.getName())) {
|
2011-04-04 14:16:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-30 06:37:32 +02:00
|
|
|
Material material = block.getType();
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
FLocation loc = new FLocation(block);
|
|
|
|
Faction otherFaction = Board.getFactionAt(loc);
|
2011-06-04 11:59:35 +02:00
|
|
|
|
2011-03-30 06:37:32 +02:00
|
|
|
// We only care about some material types.
|
2011-06-21 07:20:36 +02:00
|
|
|
if (otherFaction.hasPlayersOnline()){
|
2011-06-04 11:59:35 +02:00
|
|
|
if ( ! Conf.territoryProtectedMaterials.contains(material)) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-06-04 12:14:39 +02:00
|
|
|
} else {
|
2011-06-04 11:59:35 +02:00
|
|
|
if ( ! Conf.territoryProtectedMaterialsWhenOffline.contains(material)) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-03-30 06:37:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FPlayer me = FPlayer.get(player);
|
|
|
|
Faction myFaction = me.getFaction();
|
|
|
|
|
2011-07-09 08:36:18 +02:00
|
|
|
if (myFaction.getRelation(otherFaction).isEnemy() && !Conf.territoryEnemyProtectMaterials) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-10 21:14:02 +02:00
|
|
|
// You may use any block unless it is another faction's territory...
|
2011-03-30 06:37:32 +02:00
|
|
|
if (otherFaction.isNormal() && myFaction != otherFaction) {
|
|
|
|
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction));
|
|
|
|
return false;
|
|
|
|
}
|
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
|
|
|
// Also cancel if player doesn't have ownership rights for this claim
|
|
|
|
else if (
|
|
|
|
myFaction == otherFaction
|
|
|
|
&& Conf.ownedAreasEnabled
|
|
|
|
&& Conf.ownedAreaProtectMaterials
|
|
|
|
&& !myFaction.playerHasOwnershipRights(me, loc)
|
|
|
|
&& !Factions.hasPermOwnershipBypass(player)
|
|
|
|
) {
|
|
|
|
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in this territory, it is owned by: "+myFaction.getOwnerListString(loc));
|
|
|
|
return false;
|
|
|
|
}
|
2011-03-30 06:37:32 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-23 17:39:56 +01:00
|
|
|
@Override
|
|
|
|
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
|
|
|
FPlayer me = FPlayer.get(event.getPlayer());
|
|
|
|
Location home = me.getFaction().getHome();
|
2011-06-30 12:15:16 +02:00
|
|
|
if ( Conf.homesEnabled && Conf.homesTeleportToOnDeath && home != null &&
|
|
|
|
(Conf.homesRespawnFromNoPowerLossWorlds || !Conf.worldsNoPowerLoss.contains(event.getPlayer().getWorld().getName()))
|
|
|
|
) {
|
2011-03-23 17:39:56 +01:00
|
|
|
event.setRespawnLocation(home);
|
|
|
|
}
|
|
|
|
}
|
2011-03-30 11:23:20 +02:00
|
|
|
|
|
|
|
// For some reason onPlayerInteract() sometimes misses bucket events depending on distance (something like 2-3 blocks away isn't detected),
|
|
|
|
// but these separate bucket events below always fire without fail
|
|
|
|
@Override
|
|
|
|
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Block block = event.getBlockClicked();
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
|
|
|
if ( ! this.playerCanUseItemHere(player, block, event.getBucket())) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Block block = event.getBlockClicked();
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
|
|
|
if ( ! this.playerCanUseItemHere(player, block, event.getBucket())) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-08-04 07:07:38 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
2011-08-04 07:34:52 +02:00
|
|
|
if (event.isCancelled()) {
|
2011-08-04 07:07:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-04 07:34:52 +02:00
|
|
|
if (preventCommand(event.getMessage().toLowerCase(), event.getPlayer())) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean preventCommand(String fullCmd, Player player) {
|
|
|
|
if ((Conf.territoryNeutralDenyCommands.isEmpty() && Conf.territoryEnemyDenyCommands.isEmpty())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FPlayer me = FPlayer.get(player);
|
2011-08-04 07:07:38 +02:00
|
|
|
|
|
|
|
if (!me.isInOthersTerritory()) {
|
2011-08-04 07:34:52 +02:00
|
|
|
return false;
|
2011-08-04 07:07:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Relation rel = me.getRelationToLocation();
|
|
|
|
if (rel.isAtLeast(Relation.ALLY)) {
|
2011-08-04 07:34:52 +02:00
|
|
|
return false;
|
2011-08-04 07:07:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String shortCmd = fullCmd.substring(1); // Get rid of the slash at the beginning
|
|
|
|
|
|
|
|
if (
|
|
|
|
rel.isNeutral()
|
|
|
|
&& !Conf.territoryNeutralDenyCommands.isEmpty()
|
|
|
|
&& !Conf.adminBypassPlayers.contains(me.getName())
|
|
|
|
) {
|
|
|
|
Iterator<String> iter = Conf.territoryNeutralDenyCommands.iterator();
|
|
|
|
String cmdCheck;
|
|
|
|
while (iter.hasNext()) {
|
2011-08-05 21:06:35 +02:00
|
|
|
cmdCheck = iter.next();
|
|
|
|
if (cmdCheck == null) {
|
2011-08-20 03:36:23 +02:00
|
|
|
iter.remove();
|
2011-08-05 21:06:35 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdCheck = cmdCheck.toLowerCase();
|
2011-08-04 07:07:38 +02:00
|
|
|
if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) {
|
|
|
|
me.sendMessage("You can't use the command \""+fullCmd+"\" in neutral territory.");
|
2011-08-04 07:34:52 +02:00
|
|
|
return true;
|
2011-08-04 07:07:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (
|
|
|
|
rel.isEnemy()
|
|
|
|
&& !Conf.territoryEnemyDenyCommands.isEmpty()
|
|
|
|
&& !Conf.adminBypassPlayers.contains(me.getName())
|
|
|
|
) {
|
|
|
|
Iterator<String> iter = Conf.territoryEnemyDenyCommands.iterator();
|
|
|
|
String cmdCheck;
|
|
|
|
while (iter.hasNext()) {
|
2011-08-05 21:06:35 +02:00
|
|
|
cmdCheck = iter.next();
|
|
|
|
if (cmdCheck == null) {
|
2011-08-20 03:36:23 +02:00
|
|
|
iter.remove();
|
2011-08-05 21:06:35 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdCheck = cmdCheck.toLowerCase();
|
2011-08-04 07:07:38 +02:00
|
|
|
if (fullCmd.startsWith(cmdCheck) || shortCmd.startsWith(cmdCheck)) {
|
|
|
|
me.sendMessage("You can't use the command \""+fullCmd+"\" in enemy territory.");
|
2011-08-04 07:34:52 +02:00
|
|
|
return true;
|
2011-08-04 07:07:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-04 07:34:52 +02:00
|
|
|
return false;
|
2011-08-04 07:07:38 +02:00
|
|
|
}
|
2011-08-04 07:34:52 +02:00
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|