diff --git a/src/main/java/com/massivecraft/factions/Conf.java b/src/main/java/com/massivecraft/factions/Conf.java index fb572d10..a2b248a5 100644 --- a/src/main/java/com/massivecraft/factions/Conf.java +++ b/src/main/java/com/massivecraft/factions/Conf.java @@ -371,6 +371,7 @@ public class Conf { territoryDenyUseageMaterials.add(Material.BUCKET); territoryDenyUseageMaterials.add(Material.WATER_BUCKET); territoryDenyUseageMaterials.add(Material.LAVA_BUCKET); + territoryDenyUseageMaterials.add(Material.ARMOR_STAND); territoryProtectedMaterialsWhenOffline.add(P.p.WOODEN_DOOR); territoryProtectedMaterialsWhenOffline.add(P.p.TRAP_DOOR); @@ -397,6 +398,7 @@ public class Conf { territoryDenyUseageMaterialsWhenOffline.add(Material.BUCKET); territoryDenyUseageMaterialsWhenOffline.add(Material.WATER_BUCKET); territoryDenyUseageMaterialsWhenOffline.add(Material.LAVA_BUCKET); + territoryDenyUseageMaterialsWhenOffline.add(Material.ARMOR_STAND); safeZoneNerfedCreatureTypes.add(EntityType.BLAZE); safeZoneNerfedCreatureTypes.add(EntityType.CAVE_SPIDER); diff --git a/src/main/java/com/massivecraft/factions/FLocation.java b/src/main/java/com/massivecraft/factions/FLocation.java index d3f085ee..ab754be5 100644 --- a/src/main/java/com/massivecraft/factions/FLocation.java +++ b/src/main/java/com/massivecraft/factions/FLocation.java @@ -99,6 +99,10 @@ public static int regionToChunk(int regionVal) { return regionVal << 5; // "<< 5" == "* 32" } + public Chunk getChunk(){ + return Bukkit.getWorld(worldName).getChunkAt(x, z); + } + public static HashSet getArea(FLocation from, FLocation to) { HashSet ret = new HashSet<>(); diff --git a/src/main/java/com/massivecraft/factions/Faction.java b/src/main/java/com/massivecraft/factions/Faction.java index 4549d144..08150ee9 100644 --- a/src/main/java/com/massivecraft/factions/Faction.java +++ b/src/main/java/com/massivecraft/factions/Faction.java @@ -326,4 +326,8 @@ public interface Faction extends EconomyParticipator { void remove(); Set getAllClaims(); + + String getPaypal(); + + void paypalSet(String paypal); } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java b/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java index 62a776a0..e9a5b83e 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdCreate.java @@ -100,6 +100,9 @@ public void perform() { if (Conf.logFactionCreate) { P.p.log(fme.getName() + TL.COMMAND_CREATE_CREATEDLOG.toString() + tag); } + if (P.p.getConfig().getBoolean("fpaypal.Enabled")) { + this.fme.msg(TL.COMMAND_PAYPALSET_CREATED); + } } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFly.java b/src/main/java/com/massivecraft/factions/cmd/CmdFly.java index fdc4c68d..e2be20b7 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFly.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFly.java @@ -193,19 +193,19 @@ public void perform() { FLocation myfloc = new FLocation(me.getLocation()); Faction toFac = Board.getInstance().getFactionAt(myfloc); if (!checkBypassPerms(fme, me, toFac)) return; - List entities = me.getNearbyEntities(16, 256, 16); - for (int i = 0; i <= entities.size() - 1; i++) { + List entities = this.me.getNearbyEntities(16.0D, 256.0D, 16.0D); + + for(int i = 0; i <= entities.size() - 1; ++i) { if (entities.get(i) instanceof Player) { - Player eplayer = (Player) entities.get(i); + Player eplayer = (Player)entities.get(i); FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer); - if (efplayer.getRelationTo(fme) == Relation.ENEMY && !efplayer.isStealthEnabled()) { - fme.msg(TL.COMMAND_FLY_CHECK_ENEMY); + if (efplayer.getRelationTo(this.fme) == Relation.ENEMY && !efplayer.isStealthEnabled()) { + this.fme.msg(TL.COMMAND_FLY_CHECK_ENEMY); return; } } } - if (args.size() == 0) { toggleFlight(!fme.isFlying(), me); } else if (args.size() == 1) { diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPaypalSee.java b/src/main/java/com/massivecraft/factions/cmd/CmdPaypalSee.java new file mode 100644 index 00000000..c54e876b --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPaypalSee.java @@ -0,0 +1,50 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.P; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.util.TL; +import org.bukkit.ChatColor; + +public class CmdPaypalSee extends FCommand{ + public CmdPaypalSee() { + aliases.add("seepaypal"); + aliases.add("getpaypal"); + requiredArgs.add("faction"); + permission = Permission.ADMIN.node; + disableOnLock = false; + senderMustBePlayer = false; + senderMustBeMember = false; + senderMustBeModerator = false; + senderMustBeColeader = false; + senderMustBeAdmin = false; + } + + public void perform() { + if (!P.p.getConfig().getBoolean("fpaypal.Enabled")) { + fme.msg(TL.GENERIC_DISABLED); + } else { + Faction faction = argAsFaction(0); + String paypal = argAsString(1); + + if (faction != null) { + if (!faction.isWilderness() && !faction.isSafeZone() && !faction.isWarZone()) { + if (faction.getPaypal() != null) { + fme.msg(TL.COMMAND_PAYPALSEE_FACTION_PAYPAL.toString(), faction.getTag(), faction.getPaypal()); + } else { + fme.msg(TL.COMMAND_PAYPALSEE_FACTION_NOTSET.toString(), faction.getTag(), faction.getPaypal()); + } + + } else { + fme.msg(TL.COMMAND_PAYPALSEE_FACTION_NOFACTION.toString(), me.getName()); + } + } + } + } + + public TL getUsageTranslation() { + return TL.COMMAND_PAYPALSEE_DESCRIPTION; + } +} + + diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPaypalSet.java b/src/main/java/com/massivecraft/factions/cmd/CmdPaypalSet.java new file mode 100644 index 00000000..c4a097b8 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPaypalSet.java @@ -0,0 +1,38 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.P; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.util.TL; + +public class CmdPaypalSet extends FCommand{ + + public CmdPaypalSet() { + this.aliases.add("setpaypal"); + this.aliases.add("paypal"); + this.requiredArgs.add("email"); + this.permission = Permission.PAYPALSET.node; + this.disableOnLock = false; + this.senderMustBePlayer = true; + this.senderMustBeMember = false; + this.senderMustBeModerator = false; + this.senderMustBeColeader = true; + this.senderMustBeAdmin = false; + } + + public void perform() { + if (!P.p.getConfig().getBoolean("fpaypal.Enabled")) { + fme.msg(TL.GENERIC_DISABLED); + } else { + String paypal = argAsString(0); + if (paypal != null) { + myFaction.paypalSet(paypal); + fme.msg(TL.COMMAND_PAYPALSET_SUCCESSFUL, paypal); + } + } + } + + public TL getUsageTranslation() { + return TL.COMMAND_PAYPALSET_DESCRIPTION; + } +} + diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdStealth.java b/src/main/java/com/massivecraft/factions/cmd/CmdStealth.java index b98cc5df..e2771fe2 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdStealth.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdStealth.java @@ -1,5 +1,6 @@ package com.massivecraft.factions.cmd; +import com.massivecraft.factions.Faction; import com.massivecraft.factions.P; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.struct.Permission; @@ -22,41 +23,16 @@ public CmdStealth() { } public void perform() { - if (myFaction != null && !myFaction.isWilderness() && !myFaction.isSafeZone() && !myFaction.isWarZone() && myFaction.isNormal()) { - - - // Sends Enable/Disable Message - if (fme.isStealthEnabled()) { - fme.setStealth(false); - } else { - /* The FPlayer#takeMoney method calls the FPlayer#hasMoney method beforehand to check if the amount - * can be withdrawn successfully. - * The FPlayer#hasMoney method already sends a deny message so there isn't a need to send another. - * Basically the takeMoney is an all in one solution for taking money :) - */ - fme.takeMoney(P.p.getConfig().getInt("stealth-cost")); - fme.setStealth(true); - Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, new Runnable() { - @Override - public void run() { - if (fme.isStealthEnabled()) { - fme.setStealth(false); - fme.msg(TL.COMMAND_STEALTH_DISABLE); - } - } - // We multiplied by 20 here because the value is in ticks. - }, P.p.getConfig().getInt("stealth-timeout") * 20); - } - - fme.sendMessage(fme.isStealthEnabled() ? TL.COMMAND_STEALTH_ENABLE.toString().replace("{timeout}", P.p.getConfig().getInt("stealth-timeout") + "") : TL.COMMAND_STEALTH_DISABLE.toString()); + Faction faction = fme.getFaction(); + if (faction != null && !faction.getId().equalsIgnoreCase("0") && !faction.getId().equalsIgnoreCase("none") && !faction.getId().equalsIgnoreCase("safezone") && !faction.getId().equalsIgnoreCase("warzone")) { + fme.setStealth(!fme.isStealthEnabled()); + fme.msg(fme.isStealthEnabled() ? TL.COMMAND_STEALTH_ENABLE : TL.COMMAND_STEALTH_DISABLE); } else { fme.msg(TL.COMMAND_STEALTH_MUSTBEMEMBER); } } - @Override public TL getUsageTranslation() { return TL.COMMAND_STEALTH_DESCRIPTION; } - } diff --git a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java index bfc21e70..866ac65f 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java @@ -63,6 +63,8 @@ public class FCmdRoot extends FCommand { public CmdSB cmdSB = new CmdSB(); public CmdShowInvites cmdShowInvites = new CmdShowInvites(); public CmdAnnounce cmdAnnounce = new CmdAnnounce(); + public CmdPaypalSet cmdPaypalSet = new CmdPaypalSet(); + public CmdPaypalSee cmdPaypalSee = new CmdPaypalSee(); public CmdSeeChunk cmdSeeChunk = new CmdSeeChunk(); public CmdConvert cmdConvert = new CmdConvert(); public CmdFWarp cmdFWarp = new CmdFWarp(); @@ -231,6 +233,10 @@ public FCmdRoot() { P.p.log(Level.INFO, "Enabling FactionsTop command, this is a very basic /f top please get a dedicated /f top resource if you want land calculation etc."); this.addSubCommand(this.cmdTop); } + if (P.p.getConfig().getBoolean("fpaypal.Enabled")) { + this.addSubCommand(this.cmdPaypalSet); + this.addSubCommand(this.cmdPaypalSee); + } } diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java index ea8e86f3..56b9735e 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -19,6 +19,8 @@ import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause; import org.bukkit.event.hanging.HangingPlaceEvent; +import org.bukkit.event.player.PlayerInteractAtEntityEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -132,6 +134,39 @@ public void onEntityDamage(EntityDamageEvent event) { } } } else { + // Protect armor stands/item frames from being damaged in protected territories + if (damagee.getType() == EntityType.ITEM_FRAME || damagee.getType() == EntityType.ARMOR_STAND) { + // Manage projectiles launched by players + if (damager instanceof Projectile && ((Projectile) damager).getShooter() instanceof Entity) { + damager = (Entity) ((Projectile) damager).getShooter(); + } + + // Run the check for a player + if (damager instanceof Player) { + // Generate the action message. + String entityAction; + + if (damagee.getType() == EntityType.ITEM_FRAME) { + entityAction = "item frames"; + } else { + entityAction = "armor stands"; + } + + if (!FactionsBlockListener.playerCanBuildDestroyBlock((Player) damager, damagee.getLocation(), "destroy " + entityAction, false)) { + event.setCancelled(true); + } + } else { + // we don't want to let mobs/arrows destroy item frames/armor stands + // so we only have to run the check as if there had been an explosion at the damager location + if (!this.checkExplosionForBlock(damager, damagee.getLocation().getBlock())) { + event.setCancelled(true); + } + } + + // we don't need to go after + return; + } + //this one should trigger if something other than a player takes damage if (damager instanceof Player) { // now itll only go here if the damage is dealt by a player @@ -582,6 +617,8 @@ public void onPaintingBreak(HangingBreakEvent event) { public void onPaintingPlace(HangingPlaceEvent event) { if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "place paintings", false)) { event.setCancelled(true); + // Fix: update player's inventory to avoid items glitches + event.getPlayer().updateInventory(); } } @@ -680,6 +717,37 @@ public void onBowHit(EntityDamageByEntityEvent e) { } } + // For disabling interactions with item frames in another faction's territory + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + // only need to check for item frames + if (event.getRightClicked().getType() != EntityType.ITEM_FRAME) { + return; + } + + Player player = event.getPlayer(); + Entity entity = event.getRightClicked(); + + if (!FactionsBlockListener.playerCanBuildDestroyBlock(player, entity.getLocation(), "use item frames", false)) { + event.setCancelled(true); + } + } + + // For disabling interactions with armor stands in another faction's territory + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { + Entity entity = event.getRightClicked(); + + // only need to check for armor stand and item frames + if (entity.getType() != EntityType.ARMOR_STAND) { + return; + } + + if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), entity.getLocation(), "use armor stands", false)) { + event.setCancelled(true); + } + } + private boolean stopEndermanBlockManipulation(Location loc) { if (loc == null) { return false; diff --git a/src/main/java/com/massivecraft/factions/struct/Permission.java b/src/main/java/com/massivecraft/factions/struct/Permission.java index c26a8d6e..f33e2d9c 100644 --- a/src/main/java/com/massivecraft/factions/struct/Permission.java +++ b/src/main/java/com/massivecraft/factions/struct/Permission.java @@ -64,6 +64,7 @@ public enum Permission { SET_PERMANENT("setpermanent"), SET_PERMANENTPOWER("setpermanentpower"), SHOW_INVITES("showinvites"), + PAYPALSET("setpaypal"), PERMISSIONS("permissions"), POWERBOOST("powerboost"), POWER("power"), diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java index 5a03adde..19fabbbe 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -1046,9 +1046,9 @@ public boolean checkIfNearbyEnemies(){ if (eplayer == null) { continue; } FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer); if (efplayer == null) { continue; } - if (Conf.allowedStealthFactions != null && !efplayer.isStealthEnabled()) { - this.setFlying(false); - this.msg(TL.COMMAND_FLY_ENEMY_NEAR); + if (efplayer != null && this.getRelationTo(efplayer).equals(Relation.ENEMY) && !efplayer.isStealthEnabled()) { + setFlying(false); + msg(TL.COMMAND_FLY_ENEMY_NEAR); Bukkit.getServer().getPluginManager().callEvent(new FPlayerStoppedFlying(this)); return true; } diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java index 39e6f3f0..c72d6b39 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -51,6 +51,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { protected transient long lastPlayerLoggedOffTime; protected double money; protected double powerBoost; + protected String paypal; protected Map relationWish = new HashMap<>(); protected Map> claimOwnership = new ConcurrentHashMap<>(); protected transient Set fplayers = new HashSet<>(); @@ -164,6 +165,13 @@ public boolean removeWarp(String name) { public boolean isWarpPassword(String warp, String password) { return hasWarpPassword(warp) && warpPasswords.get(warp.toLowerCase()).equals(password); } + public String getPaypal() { + return this.paypal; + } + + public void paypalSet(String paypal) { + this.paypal = paypal; + } public boolean hasWarpPassword(String warp) { return warpPasswords.containsKey(warp.toLowerCase()); diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TL.java b/src/main/java/com/massivecraft/factions/zcore/util/TL.java index 3c68ae2e..343d8cd3 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -470,6 +470,14 @@ public enum TL { COMMAND_OWNERLIST_OWNERS("&c&l[!]&7 Current owner(s) of this land: %1$s"), COMMAND_OWNERLIST_DESCRIPTION("List owner(s) of this claimed land"), + COMMAND_PAYPALSET_DESCRIPTION("&c&l[!] &7Set the email of your faction to claim rewards."), + COMMAND_PAYPALSEE_DESCRIPTION("&c&l[!] &7View a specific factions paypal email with &b/f &b."), + COMMAND_PAYPALSET_CREATED("&c&l[!] &7Make sure to type &b/f &7!"), + COMMAND_PAYPALSET_SUCCESSFUL("&c&l[!] &7Successfully set your factions email - &b%1$s&7."), + COMMAND_PAYPALSEE_FACTION_PAYPAL("&c&l[!] &b%1$s's &7faction has their paypal set to &b%2$s&7."), + COMMAND_PAYPALSEE_FACTION_NOTSET("&c&l[!] &b%1$s's &7paypal has not yet been set!"), + COMMAND_PAYPALSEE_FACTION_NOFACTION("&c&l[!] &b%1$s &7does not have a faction!"), + COMMAND_PEACEFUL_DESCRIPTION("&c&l[!]&7Set a faction to peaceful"), COMMAND_PEACEFUL_YOURS("&c&l[!]&7%1$s has %2$s your faction"), COMMAND_PEACEFUL_OTHER("&c&l[!]&7%s has %s the faction '%s'."), diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 02f6675a..4a2f6e93 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -716,6 +716,14 @@ ftnt: Enabled: true Bank-Limit: 10000 +############################################################ +# +------------------------------------------------------+ # +# | Faction PayPal | # +# +------------------------------------------------------+ # +############################################################ +fpaypal: + Enabled: true + ############################################################ # +------------------------------------------------------+ # # | Faction Checkpoints | # diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c25bdf8c..ccf1ece0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -227,6 +227,8 @@ permissions: description: set permanent power for a faction factions.stuck: description: teleports player outside a faction + factions.setpaypal: + description: set paypal to faction factions.power: description: show player power info factions.power.any: