Merge pull request #127 from Juniormunk/1.6.x

Fix Bugs
This commit is contained in:
Driftay 2020-05-25 20:38:35 -04:00 committed by GitHub
commit 14776b8877
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 2232 additions and 1416 deletions

View File

@ -2,25 +2,27 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.*;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
public class CmdCheckpoint extends FCommand {
public class CmdCheckpoint extends FCommand
{
/**
* @author Illyria Team
*/
public CmdCheckpoint() {
public CmdCheckpoint()
{
super();
this.aliases.addAll(Aliases.checkpoint);
this.optionalArgs.put("set", "");
this.requirements = new CommandRequirements.Builder(Permission.CHECKPOINT)
.playerOnly()
.memberOnly()
.build();
this.requirements = new CommandRequirements.Builder(Permission.CHECKPOINT).playerOnly().memberOnly().build();
}
@Override
@ -29,7 +31,29 @@ public class CmdCheckpoint extends FCommand {
context.msg(TL.COMMAND_CHECKPOINT_DISABLED);
return;
}
if (context.args.size() == 1) {
if (context.args.size() == 1 && context.args.get(0).equalsIgnoreCase("set")) {
if (context.fPlayer.getRole() == Role.LEADER)
{
FLocation myLocation = new FLocation(context.player.getLocation());
Faction myLocFaction = Board.getInstance().getFactionAt(myLocation);
if (myLocFaction == Factions.getInstance().getWilderness() || myLocFaction == context.faction) {
context.faction.setCheckpoint(context.player.getLocation());
context.msg(TL.COMMAND_CHECKPOINT_SET);
return;
}
} else {
context.msg(TL.COMMAND_CHECKPOINT_INVALIDLOCATION);
return;
}
PermissableAction action = PermissableAction.SETWARP;
Access access = context.faction.getAccess(context.fPlayer, action);
if (access == Access.DENY) {
context.msg(TL.GENERIC_FPERM_NOPERMISSION, action.getName());
return;
}
else
{
FLocation myLocation = new FLocation(context.player.getLocation());
Faction myLocFaction = Board.getInstance().getFactionAt(myLocation);
if (myLocFaction == Factions.getInstance().getWilderness() || myLocFaction == context.faction) {
@ -41,6 +65,8 @@ public class CmdCheckpoint extends FCommand {
return;
}
}
}
if (context.faction.getCheckpoint() == null) {
context.msg(TL.COMMAND_CHECKPOINT_NOT_SET);
return;
@ -57,12 +83,11 @@ public class CmdCheckpoint extends FCommand {
} else {
context.msg(TL.COMMAND_CHECKPOINT_CLAIMED);
}
}
@Override
public TL getUsageTranslation() {
public TL getUsageTranslation()
{
return TL.COMMAND_CHECKPOINT_DESCRIPTION;
}
}

View File

@ -26,6 +26,7 @@ import com.massivecraft.factions.discord.CmdInviteBot;
import com.massivecraft.factions.discord.CmdSetGuild;
import com.massivecraft.factions.missions.CmdMissions;
import com.massivecraft.factions.shop.CmdShop;
import com.massivecraft.factions.shop.ShopGUIFrame;
import com.massivecraft.factions.zcore.util.TL;
import me.lucko.commodore.CommodoreProvider;
import org.bukkit.Bukkit;
@ -377,6 +378,7 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
}
if (FactionsPlugin.getInstance().getConfig().getBoolean("F-Shop.Enabled", false) && !fShopEnabled) {
this.addSubCommand(this.cmdShop);
new ShopGUIFrame(null).checkShopConfig();
fShopEnabled = true;
}
if (FactionsPlugin.getInstance().getConfig().getBoolean("f-inventory-see.Enabled", false) && !invSeeEnabled) {

View File

@ -1,9 +1,14 @@
package com.massivecraft.factions.integration.dynmap;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import org.dynmap.markers.AreaMarker;
import org.dynmap.markers.MarkerSet;
public class TempAreaMarker {
public class TempAreaMarker
{
/**
* @author FactionsUUID Team
@ -17,6 +22,9 @@ public class TempAreaMarker {
public String world;
public double[] x;
public double[] z;
private List<List<Point>> polyLine = new ArrayList<List<Point>>();
public String description;
public int lineColor;
@ -32,21 +40,27 @@ public class TempAreaMarker {
// CREATE
// -------------------------------------------- //
public static boolean equals(AreaMarker marker, double[] x, double[] z) {
public static boolean equals(AreaMarker marker, double[] x, double[] z)
{
int length = marker.getCornerCount();
if (x.length != length) {
if (x.length != length)
{
return false;
}
if (z.length != length) {
if (z.length != length)
{
return false;
}
for (int i = 0; i < length; i++) {
if (marker.getCornerX(i) != x[i]) {
for (int i = 0; i < length; i++)
{
if (marker.getCornerX(i) != x[i])
{
return false;
}
if (marker.getCornerZ(i) != z[i]) {
if (marker.getCornerZ(i) != z[i])
{
return false;
}
}
@ -54,23 +68,37 @@ public class TempAreaMarker {
return true;
}
public void setPolyLine(List<List<Point>> points)
{
polyLine.clear();
polyLine.addAll(points);
}
public List<List<Point>> getPolyLine()
{
return polyLine;
}
// -------------------------------------------- //
// UPDATE
// -------------------------------------------- //
public AreaMarker create(MarkerSet markerset, String markerId) {
public AreaMarker create(MarkerSet markerset, String markerId)
{
AreaMarker ret = markerset.createAreaMarker(markerId, this.label, false, this.world, this.x, this.z, false // not persistent
);
if (ret == null) {
if (ret == null)
{
return null;
}
int counter = 0;
// Description
ret.setDescription(this.description);
// Line Style
ret.setLineStyle(this.lineWeight, this.lineOpacity, this.lineColor);
ret.setLineStyle(0, 0, 0);
// Fill Style
ret.setFillStyle(this.fillOpacity, this.fillColor);
@ -80,40 +108,42 @@ public class TempAreaMarker {
return ret;
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
public void update(AreaMarker marker) {
public void update(AreaMarker marker)
{
// Corner Locations
if (!equals(marker, this.x, this.z)) {
if (!equals(marker, this.x, this.z))
{
marker.setCornerLocations(this.x, this.z);
}
// Label
if (!marker.getLabel().equals(this.label)) {
if (!marker.getLabel().equals(this.label))
{
marker.setLabel(this.label);
}
// Description
if (!marker.getDescription().equals(this.description)) {
if (!marker.getDescription().equals(this.description))
{
marker.setDescription(this.description);
}
// Line Style
if (marker.getLineWeight() != this.lineWeight ||
marker.getLineOpacity() != this.lineOpacity ||
marker.getLineColor() != this.lineColor) {
marker.setLineStyle(this.lineWeight, this.lineOpacity, this.lineColor);
}
// // Line Style
// if (marker.getLineWeight() != this.lineWeight || marker.getLineOpacity() != this.lineOpacity || marker.getLineColor() != this.lineColor)
// {
// marker.setLineStyle(this.lineWeight, this.lineOpacity, this.lineColor);
// }
// Fill Style
if ((marker.getFillOpacity() != this.fillOpacity) || (marker.getFillColor() != this.fillColor)) {
if ((marker.getFillOpacity() != this.fillOpacity) || (marker.getFillColor() != this.fillColor))
{
marker.setFillStyle(this.fillOpacity, this.fillColor);
}
// Boost Flag
if (marker.getBoostFlag() != this.boost) {
if (marker.getBoostFlag() != this.boost)
{
marker.setBoostFlag(this.boost);
}
}

View File

@ -0,0 +1,62 @@
package com.massivecraft.factions.integration.dynmap;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
public class TempLine
{
private Point p1;
private Point p2;
private List<TempLine> connectedLines = new ArrayList<TempLine>();
TempLine(Point p1, Point p2)
{
this.p1 = p1;
this.p2 = p2;
}
public Point getP1()
{
return p1;
}
public Point getP2()
{
return p2;
}
public void addAdditionLines(List<TempLine> connectedLines)
{
this.connectedLines = connectedLines;
}
public List<TempLine> getConnectedLines()
{
return connectedLines;
}
@Override
public boolean equals(Object o)
{
TempLine line = (TempLine) o;
if (line.p1.x == this.p1.x && line.p2.x == this.p2.x && line.p1.y == this.p1.y && line.p2.y == this.p2.y)
{
return true;
}
if (line.p1.x == this.p2.x && line.p2.x == this.p1.x && line.p1.y == this.p2.y && line.p2.y == this.p1.y)
{
return true;
}
return false;
}
@Override
public int hashCode()
{
String test = "" + (p1.x + p2.x);
test += " " + (p1.y + p2.y);
return test.hashCode();
}
}

View File

@ -0,0 +1,111 @@
package com.massivecraft.factions.integration.dynmap;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import org.dynmap.markers.MarkerSet;
import org.dynmap.markers.PolyLineMarker;
public class TempPolyLineMarker
{
/**
* @author FactionsUUID Team
*/
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
public String world;
public List<Point> polyLine = new ArrayList<Point>();
public int lineColor;
public double lineOpacity;
public int lineWeight;
// -------------------------------------------- //
// CREATE
// -------------------------------------------- //
public static boolean equals(PolyLineMarker marker, List<Point> points)
{
int length = marker.getCornerCount();
if (points.size() != length)
{
return false;
}
for (int i = 0; i < length; i++)
{
if (marker.getCornerX(i) != points.get(i).x)
{
return false;
}
if (marker.getCornerZ(i) != points.get(i).y)
{
return false;
}
}
return true;
}
// -------------------------------------------- //
// UPDATE
// -------------------------------------------- //
public PolyLineMarker create(MarkerSet markerset, String markerId)
{
double[] polyX = new double[polyLine.size()];
double[] polyY = new double[polyLine.size()];
double[] polyZ = new double[polyLine.size()];
for (int i = 0; i < polyLine.size(); i++)
{
Point p = polyLine.get(i);
polyX[i] = p.getX();
polyY[i] = 64;
polyZ[i] = p.getY();
}
PolyLineMarker poly = markerset.createPolyLineMarker(markerId, "", false, this.world, polyX, polyY, polyZ, false);
// Poly Line Style
if (poly != null)
{
poly.setLineStyle(this.lineWeight, this.lineOpacity, this.lineColor);
}
return poly;
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
public void update(PolyLineMarker marker)
{
// Corner Locations
if (!equals(marker, polyLine))
{
double[] polyX = new double[polyLine.size()];
double[] polyY = new double[polyLine.size()];
double[] polyZ = new double[polyLine.size()];
for (int i = 0; i < polyLine.size(); i++)
{
Point p = polyLine.get(i);
polyX[i] = p.getX();
polyY[i] = 64;
polyZ[i] = p.getY();
}
marker.setCornerLocations(polyX, polyY, polyZ);
marker.setLineStyle(this.lineWeight, this.lineOpacity, this.lineColor);
}
// Line Style
if (marker.getLineWeight() != this.lineWeight || marker.getLineOpacity() != this.lineOpacity || marker.getLineColor() != this.lineColor)
{
marker.setLineStyle(this.lineWeight, this.lineOpacity, this.lineColor);
}
}
}

View File

@ -42,115 +42,155 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
public class FactionsBlockListener implements Listener {
public class FactionsBlockListener implements Listener
{
public static HashMap<String, Location> bannerLocations = new HashMap<>();
private HashMap<String, Boolean> bannerCooldownMap = new HashMap<>();
private long placeTimer = TimeUnit.SECONDS.toMillis(15L);
public static boolean playerCanBuildDestroyBlock(Player player, Location location, String action, boolean justCheck) {
if (Conf.playersWhoBypassAllProtection.contains(player.getName())) return true;
public static boolean playerCanBuildDestroyBlock(Player player, Location location, PermissableAction action, boolean justCheck)
{
if (Conf.playersWhoBypassAllProtection.contains(player.getName()))
return true;
FPlayer me = FPlayers.getInstance().getById(player.getUniqueId().toString());
if (me.isAdminBypassing()) return true;
if (me.isAdminBypassing())
return true;
FLocation loc = new FLocation(location);
Faction otherFaction = Board.getInstance().getFactionAt(loc);
Faction myFaction = me.getFaction();
if (otherFaction.isWilderness()) {
if (Conf.worldGuardBuildPriority && Worldguard.getInstance().playerCanBuild(player, location)) return true;
if (location.getWorld() != null) {
if (otherFaction.isWilderness())
{
if (Conf.worldGuardBuildPriority && Worldguard.getInstance().playerCanBuild(player, location))
return true;
if (location.getWorld() != null)
{
if (!Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName()))
return true;
}
if (!justCheck) me.msg(TL.ACTION_DENIED_WILDERNESS, action);
if (!justCheck)
me.msg(TL.ACTION_DENIED_WILDERNESS, action.toString());
return false;
} else if (otherFaction.isSafeZone()) {
if (Conf.worldGuardBuildPriority && Worldguard.getInstance().playerCanBuild(player, location)) return true;
if (!Conf.safeZoneDenyBuild || Permission.MANAGE_SAFE_ZONE.has(player)) return true;
if (!justCheck) me.msg(TL.ACTION_DENIED_SAFEZONE, action);
}
else if (otherFaction.isSafeZone())
{
if (Conf.worldGuardBuildPriority && Worldguard.getInstance().playerCanBuild(player, location))
return true;
if (!Conf.safeZoneDenyBuild || Permission.MANAGE_SAFE_ZONE.has(player))
return true;
if (!justCheck)
me.msg(TL.ACTION_DENIED_SAFEZONE, action.toString());
return false;
} else if (otherFaction.isWarZone()) {
if (Conf.worldGuardBuildPriority && Worldguard.getInstance().playerCanBuild(player, location)) return true;
if (!Conf.warZoneDenyBuild || Permission.MANAGE_WAR_ZONE.has(player)) return true;
if (!justCheck) me.msg(TL.ACTION_DENIED_WARZONE, action);
}
else if (otherFaction.isWarZone())
{
if (Conf.worldGuardBuildPriority && Worldguard.getInstance().playerCanBuild(player, location))
return true;
if (!Conf.warZoneDenyBuild || Permission.MANAGE_WAR_ZONE.has(player))
return true;
if (!justCheck)
me.msg(TL.ACTION_DENIED_WARZONE, action.toString());
return false;
} else if (!otherFaction.getId().equals(myFaction.getId())) { // If the faction target is not my own
}
else if (!otherFaction.getId().equals(myFaction.getId()))
{ // If the faction target is not my own
if (FactionsPlugin.getInstance().getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded())
return true;
boolean pain = !justCheck && otherFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW;
return CheckActionState(otherFaction, loc, me, PermissableAction.fromString(action), pain);
} else if (otherFaction.getId().equals(myFaction.getId())) {
return CheckActionState(otherFaction, loc, me, action, pain, justCheck);
}
else if (otherFaction.getId().equals(myFaction.getId()))
{
boolean pain = !justCheck && myFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW;
return CheckActionState(myFaction, loc, me, PermissableAction.fromString(action), pain);
return CheckActionState(myFaction, loc, me, action, pain, justCheck);
}
return false;
}
private static boolean CheckPlayerAccess(Player player, FPlayer me, FLocation loc, Faction myFaction, Access access, PermissableAction action, boolean shouldHurt) {
private static boolean CheckPlayerAccess(Player player, FPlayer me, FLocation loc, Faction myFaction, Access access, PermissableAction action, boolean shouldHurt, boolean justCheck)
{
boolean landOwned = (myFaction.doesLocationHaveOwnersSet(loc) && !myFaction.getOwnerList(loc).isEmpty());
if ((landOwned && myFaction.getOwnerListString(loc).contains(player.getName())) || (me.getRole() == Role.LEADER && me.getFactionId().equals(myFaction.getId())))
return true;
else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) {
else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName()))
{
me.msg(TL.ACTIONS_OWNEDTERRITORYDENY.toString().replace("{owners}", myFaction.getOwnerListString(loc)));
if (shouldHurt) {
if (shouldHurt)
{
player.damage(Conf.actionDeniedPainAmount);
me.msg(TL.ACTIONS_NOPERMISSIONPAIN.toString().replace("{action}", action.toString()).replace("{faction}", Board.getInstance().getFactionAt(loc).getTag(myFaction)));
}
return false;
} else if (!landOwned && access == Access.DENY) { // If land is not owned but access is set to DENY anyway
if (shouldHurt) {
}
else if (!landOwned && access == Access.DENY)
{ // If land is not owned but access is set to DENY anyway
if (shouldHurt)
{
player.damage(Conf.actionDeniedPainAmount);
if ((Board.getInstance().getFactionAt(loc).getTag(myFaction)) != null)
me.msg(TL.ACTIONS_NOPERMISSIONPAIN.toString().replace("{action}", action.toString()).replace("{faction}", Board.getInstance().getFactionAt(loc).getTag(myFaction)));
}
if (myFaction.getTag(me.getFaction()) != null && action != null)
me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", action.toString()));
return false;
} else if (access == Access.ALLOW) return true;
if (myFaction.getTag(me.getFaction()) != null && action != null && !justCheck)
me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", action.toString()));
return false;
}
else if (access == Access.ALLOW)
return true;
private static boolean CheckActionState(Faction target, FLocation location, FPlayer me, PermissableAction action, boolean pain) {
if (Conf.ownedAreasEnabled && target.doesLocationHaveOwnersSet(location) && !target.playerHasOwnershipRights(me, location)) {
if (!justCheck)
me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", me.getFaction().getTag()).replace("{action}", action.toString()));
return false;
}
private static boolean CheckActionState(Faction target, FLocation location, FPlayer me, PermissableAction action, boolean pain, boolean justCheck)
{
if (Conf.ownedAreasEnabled && target.doesLocationHaveOwnersSet(location) && !target.playerHasOwnershipRights(me, location))
{
// If pain should be applied
if (pain && Conf.ownedAreaPainBuild)
me.msg(TL.ACTIONS_OWNEDTERRITORYPAINDENY.toString().replace("{action}", action.toString()).replace("{faction}", target.getOwnerListString(location)));
if (Conf.ownedAreaDenyBuild && pain) return false;
else if (Conf.ownedAreaDenyBuild) {
if (Conf.ownedAreaDenyBuild && pain)
return false;
else if (Conf.ownedAreaDenyBuild)
{
if(!justCheck)
me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", target.getTag(me.getFaction())).replace("{action}", action.toString()));
return false;
}
}
return CheckPlayerAccess(me.getPlayer(), me, location, target, target.getAccess(me, action), action, pain);
return CheckPlayerAccess(me.getPlayer(), me, location, target, target.getAccess(me, action), action, pain, justCheck);
}
public void handleSpawnerUpdate(Faction at, Player player, ItemStack spawnerItem, LogTimer.TimerSubType subType) {
public void handleSpawnerUpdate(Faction at, Player player, ItemStack spawnerItem, LogTimer.TimerSubType subType)
{
FLogManager manager = FactionsPlugin.instance.getFlogManager();
LogTimer logTimer = manager.getLogTimers().computeIfAbsent(player.getUniqueId(), e -> new LogTimer(player.getName(), at.getId()));
LogTimer.Timer timer = logTimer.attemptLog(LogTimer.TimerType.SPAWNER_EDIT, subType, 0L);
Map<MaterialData, AtomicInteger> currentCounts = (timer.getExtraData() == null) ? new HashMap<>() : ((Map) timer.getExtraData());
currentCounts.computeIfAbsent(spawnerItem.getData(), e -> new AtomicInteger(0)).addAndGet(1);
timer.setExtraData(currentCounts);
if (timer.isReadyToLog(this.placeTimer)) {
if (timer.isReadyToLog(this.placeTimer))
{
logTimer.pushLogs(at, LogTimer.TimerType.SPAWNER_EDIT);
}
}
@EventHandler(
priority = EventPriority.HIGH,
ignoreCancelled = true
)
public void onPlayerPlace(BlockPlaceEvent event) {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerPlace(BlockPlaceEvent event)
{
ItemStack item = event.getItemInHand();
if (item != null && item.getType() == XMaterial.SPAWNER.parseMaterial()) {
if (item != null && item.getType() == XMaterial.SPAWNER.parseMaterial())
{
Faction at = Board.getInstance().getFactionAt(new FLocation(event.getBlockPlaced()));
if (at != null && at.isNormal()) {
if (at != null && at.isNormal())
{
FPlayer fplayer = FPlayers.getInstance().getByPlayer(event.getPlayer());
if (fplayer != null && at.getRelationTo(fplayer.getFaction()).isAtLeast(Relation.TRUCE)) {
if (fplayer != null && at.getRelationTo(fplayer.getFaction()).isAtLeast(Relation.TRUCE))
{
this.handleSpawnerUpdate(at, event.getPlayer(), item, LogTimer.TimerSubType.SPAWNER_PLACE);
}
}
@ -158,18 +198,24 @@ public class FactionsBlockListener implements Listener {
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
public void onBlockPlace(BlockPlaceEvent event)
{
if (!event.canBuild()) return;
if (event.getBlockPlaced().getType() == Material.FIRE) return;
if (!event.canBuild())
return;
if (event.getBlockPlaced().getType() == Material.FIRE)
return;
boolean isSpawner = event.getBlock().getType().equals(XMaterial.SPAWNER.parseMaterial());
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "build", false)) {
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), PermissableAction.BUILD, false))
{
event.setCancelled(true);
return;
}
if (isSpawner) {
if (Conf.spawnerLock) {
if (isSpawner)
{
if (Conf.spawnerLock)
{
event.setCancelled(true);
event.getPlayer().sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_SPAWNER_LOCK_CANNOT_PLACE.toString()));
}
@ -177,22 +223,30 @@ public class FactionsBlockListener implements Listener {
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockFromTo(BlockFromToEvent event) {
if (!Conf.handleExploitLiquidFlow) return;
public void onBlockFromTo(BlockFromToEvent event)
{
if (!Conf.handleExploitLiquidFlow)
return;
if (event.getBlock().isLiquid()) {
if (event.getToBlock().isEmpty()) {
if (event.getBlock().isLiquid())
{
if (event.getToBlock().isEmpty())
{
Faction from = Board.getInstance().getFactionAt(new FLocation(event.getBlock()));
Faction to = Board.getInstance().getFactionAt(new FLocation(event.getToBlock()));
if (from == to) return;
if (from == to)
return;
// from faction != to faction
if(to.isSystemFaction()) {
if (to.isSystemFaction())
{
event.setCancelled(true);
return;
}
if (to.isNormal()) {
if (from.isNormal() && from.getRelationTo(to).isAlly()) {
if (to.isNormal())
{
if (from.isNormal() && from.getRelationTo(to).isAlly())
{
return;
}
event.setCancelled(true);
@ -202,15 +256,19 @@ public class FactionsBlockListener implements Listener {
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockDamage(BlockDamageEvent event) {
if (event.getInstaBreak() && !playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) {
public void onBlockDamage(BlockDamageEvent event)
{
if (event.getInstaBreak() && !playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), PermissableAction.DESTROY, false))
{
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
if (!Conf.pistonProtectionThroughDenyBuild) return;
public void onBlockPistonExtend(BlockPistonExtendEvent event)
{
if (!Conf.pistonProtectionThroughDenyBuild)
return;
Faction pistonFaction = Board.getInstance().getFactionAt(new FLocation(event.getBlock()));
// target end-of-the-line empty (air) block which is being pushed into, including if piston itself would extend into air
@ -221,40 +279,46 @@ public class FactionsBlockListener implements Listener {
event.setCancelled(true);
}
@EventHandler
public void onVaultPlace(BlockPlaceEvent e) {
if (e.getItemInHand().getType() == Material.CHEST) {
public void onVaultPlace(BlockPlaceEvent e)
{
if (e.getItemInHand().getType() == Material.CHEST)
{
ItemStack vault = new ItemBuilder(Material.CHEST)
.amount(1).name(FactionsPlugin.instance.getConfig().getString("fvault.Item.Name"))
.lore(FactionsPlugin.instance.getConfig().getStringList("fvault.Item.Lore"))
.build();
ItemStack vault = new ItemBuilder(Material.CHEST).amount(1).name(FactionsPlugin.instance.getConfig().getString("fvault.Item.Name")).lore(FactionsPlugin.instance.getConfig().getStringList("fvault.Item.Lore")).build();
if (e.getItemInHand().isSimilar(vault)) {
if (e.getItemInHand().isSimilar(vault))
{
FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer());
if (fme.getFaction().getVault() != null) {
if (fme.getFaction().getVault() != null)
{
fme.msg(TL.COMMAND_GETVAULT_ALREADYSET);
e.setCancelled(true);
return;
}
FLocation flocation = new FLocation(e.getBlockPlaced().getLocation());
if (Board.getInstance().getFactionAt(flocation) != fme.getFaction()) {
if (Board.getInstance().getFactionAt(flocation) != fme.getFaction())
{
fme.msg(TL.COMMAND_GETVAULT_INVALIDLOCATION);
e.setCancelled(true);
return;
}
Block start = e.getBlockPlaced();
int radius = 1;
for (double x = start.getLocation().getX() - radius; x <= start.getLocation().getX() + radius; x++) {
for (double y = start.getLocation().getY() - radius; y <= start.getLocation().getY() + radius; y++) {
for (double z = start.getLocation().getZ() - radius; z <= start.getLocation().getZ() + radius; z++) {
for (double x = start.getLocation().getX() - radius; x <= start.getLocation().getX() + radius; x++)
{
for (double y = start.getLocation().getY() - radius; y <= start.getLocation().getY() + radius; y++)
{
for (double z = start.getLocation().getZ() - radius; z <= start.getLocation().getZ() + radius; z++)
{
Location blockLoc = new Location(e.getPlayer().getWorld(), x, y, z);
if (blockLoc.getX() == start.getLocation().getX() && blockLoc.getY() == start.getLocation().getY() && blockLoc.getZ() == start.getLocation().getZ()) {
if (blockLoc.getX() == start.getLocation().getX() && blockLoc.getY() == start.getLocation().getY() && blockLoc.getZ() == start.getLocation().getZ())
{
continue;
}
Material blockMaterial = blockLoc.getBlock().getType();
if (blockMaterial == Material.CHEST || (FactionsPlugin.instance.getConfig().getBoolean("fvault.No-Hoppers-near-vault") && blockMaterial == Material.HOPPER)) {
if (blockMaterial == Material.CHEST || (FactionsPlugin.instance.getConfig().getBoolean("fvault.No-Hoppers-near-vault") && blockMaterial == Material.HOPPER))
{
e.setCancelled(true);
fme.msg(TL.COMMAND_GETVAULT_CHESTNEAR);
return;
@ -270,24 +334,32 @@ public class FactionsBlockListener implements Listener {
}
@EventHandler
public void onHopperPlace(BlockPlaceEvent e) {
public void onHopperPlace(BlockPlaceEvent e)
{
if (e.getItemInHand().getType() != Material.HOPPER && !FactionsPlugin.instance.getConfig().getBoolean("fvault.No-Hoppers-near-vault"))
return;
Faction factionAt = Board.getInstance().getFactionAt(new FLocation(e.getBlockPlaced().getLocation()));
if (factionAt.isWilderness() || factionAt.getVault() == null) return;
if (factionAt.isWilderness() || factionAt.getVault() == null)
return;
FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer());
Block start = e.getBlockPlaced();
int radius = 1;
for (double x = start.getLocation().getX() - radius; x <= start.getLocation().getX() + radius; x++) {
for (double y = start.getLocation().getY() - radius; y <= start.getLocation().getY() + radius; y++) {
for (double z = start.getLocation().getZ() - radius; z <= start.getLocation().getZ() + radius; z++) {
for (double x = start.getLocation().getX() - radius; x <= start.getLocation().getX() + radius; x++)
{
for (double y = start.getLocation().getY() - radius; y <= start.getLocation().getY() + radius; y++)
{
for (double z = start.getLocation().getZ() - radius; z <= start.getLocation().getZ() + radius; z++)
{
Location blockLoc = new Location(e.getPlayer().getWorld(), x, y, z);
if (blockLoc.getX() == start.getLocation().getX() && blockLoc.getY() == start.getLocation().getY() && blockLoc.getZ() == start.getLocation().getZ()) {
if (blockLoc.getX() == start.getLocation().getX() && blockLoc.getY() == start.getLocation().getY() && blockLoc.getZ() == start.getLocation().getZ())
{
continue;
}
if (blockLoc.getBlock().getType() == XMaterial.CHEST.parseMaterial()) {
if (factionAt.getVault().equals(blockLoc)) {
if (blockLoc.getBlock().getType() == XMaterial.CHEST.parseMaterial())
{
if (factionAt.getVault().equals(blockLoc))
{
e.setCancelled(true);
fme.msg(TL.COMMAND_VAULT_NO_HOPPER);
return;
@ -300,34 +372,43 @@ public class FactionsBlockListener implements Listener {
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
public void onBlockPistonRetract(BlockPistonRetractEvent event)
{
// if not a sticky piston, retraction should be fine
if (!event.isSticky() || !Conf.pistonProtectionThroughDenyBuild) return;
if (!event.isSticky() || !Conf.pistonProtectionThroughDenyBuild)
return;
Location targetLoc = event.getRetractLocation();
Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(targetLoc));
// Check if the piston is moving in a faction's territory. This disables pistons entirely in faction territory.
if (otherFaction.isNormal() && FactionsPlugin.instance.getConfig().getBoolean("disable-pistons-in-territory", false)) {
if (otherFaction.isNormal() && FactionsPlugin.instance.getConfig().getBoolean("disable-pistons-in-territory", false))
{
event.setCancelled(true);
return;
}
// if potentially retracted block is just air/water/lava, no worries
if (targetLoc.getBlock().isEmpty() || targetLoc.getBlock().isLiquid()) return;
if (targetLoc.getBlock().isEmpty() || targetLoc.getBlock().isLiquid())
return;
Faction pistonFaction = Board.getInstance().getFactionAt(new FLocation(event.getBlock()));
if (!canPistonMoveBlock(pistonFaction, targetLoc)) event.setCancelled(true);
if (!canPistonMoveBlock(pistonFaction, targetLoc))
event.setCancelled(true);
}
@EventHandler
public void onBannerBreak(BlockBreakEvent e) {
public void onBannerBreak(BlockBreakEvent e)
{
FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer());
if (FactionsPlugin.getInstance().mc17) {
if (FactionsPlugin.getInstance().mc17)
{
return;
}
if (bannerLocations.containsValue(e.getBlock().getLocation())) {
if (e.getBlock().getType().name().contains("BANNER")) {
if (bannerLocations.containsValue(e.getBlock().getLocation()))
{
if (e.getBlock().getType().name().contains("BANNER"))
{
e.setCancelled(true);
fme.msg(TL.BANNER_CANNOT_BREAK);
}
@ -335,20 +416,26 @@ public class FactionsBlockListener implements Listener {
}
@EventHandler
public void onBannerPlace(BlockPlaceEvent e) {
if (FactionsPlugin.getInstance().mc17) return;
public void onBannerPlace(BlockPlaceEvent e)
{
if (FactionsPlugin.getInstance().mc17)
return;
if (e.getItemInHand().getType().name().contains("BANNER")) {
if (e.getItemInHand().getType().name().contains("BANNER"))
{
ItemStack bannerInHand = e.getItemInHand();
FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer());
ItemStack warBanner = fme.getFaction().getBanner();
if (warBanner == null) return;
if (warBanner == null)
return;
ItemMeta warmeta = warBanner.getItemMeta();
warmeta.setDisplayName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name")));
warmeta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore")));
warBanner.setItemMeta(warmeta);
if (warBanner.isSimilar(bannerInHand)) {
if (fme.getFaction().isWilderness()) {
if (warBanner.isSimilar(bannerInHand))
{
if (fme.getFaction().isWilderness())
{
fme.msg(TL.WARBANNER_NOFACTION);
e.setCancelled(true);
return;
@ -356,13 +443,17 @@ public class FactionsBlockListener implements Listener {
int bannerTime = FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Time") * 20;
Location placedLoc = e.getBlockPlaced().getLocation();
FLocation fplacedLoc = new FLocation(placedLoc);
if ((Board.getInstance().getFactionAt(fplacedLoc).isWarZone() && FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Placeable.Warzone")) || (fme.getFaction().getRelationTo(Board.getInstance().getFactionAt(fplacedLoc)) == Relation.ENEMY && FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Placeable.Enemy"))) {
if (bannerCooldownMap.containsKey(fme.getTag())) {
if ((Board.getInstance().getFactionAt(fplacedLoc).isWarZone() && FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Placeable.Warzone"))
|| (fme.getFaction().getRelationTo(Board.getInstance().getFactionAt(fplacedLoc)) == Relation.ENEMY && FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Placeable.Enemy")))
{
if (bannerCooldownMap.containsKey(fme.getTag()))
{
fme.msg(TL.WARBANNER_COOLDOWN);
e.setCancelled(true);
return;
}
for (FPlayer fplayer : fme.getFaction().getFPlayers()) {
for (FPlayer fplayer : fme.getFaction().getFPlayers())
{
fplayer.getPlayer().sendTitle(FactionsPlugin.getInstance().color(fme.getTag() + " Placed A WarBanner!"), FactionsPlugin.getInstance().color("&7use &c/f tpbanner&7 to tp to the banner!"));
}
bannerCooldownMap.put(fme.getTag(), true);
@ -382,33 +473,42 @@ public class FactionsBlockListener implements Listener {
banner.getWorld().strikeLightningEffect(banner.getLocation());
int radius = FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Effect-Radius");
List<String> effects = FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Effects");
int affectorTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> {
for (Entity e1 : Objects.requireNonNull(banner.getLocation().getWorld()).getNearbyEntities(banner.getLocation(), radius, 255.0, radius)) {
if (e1 instanceof Player) {
int affectorTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () ->
{
for (Entity e1 : Objects.requireNonNull(banner.getLocation().getWorld()).getNearbyEntities(banner.getLocation(), radius, 255.0, radius))
{
if (e1 instanceof Player)
{
Player player = (Player) e1;
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
if (fplayer.getFaction() != bannerFaction) {
if (fplayer.getFaction() != bannerFaction)
{
continue;
}
for (String effect : effects) {
for (String effect : effects)
{
String[] components = effect.split(":");
player.addPotionEffect(new PotionEffect(Objects.requireNonNull(PotionEffectType.getByName(components[0])), 100, Integer.parseInt(components[1])));
}
if (banner.getType() == bannerType) {
if (banner.getType() == bannerType)
{
continue;
}
banner.setType(bannerType);
}
}
}, 0L, 20L);
Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.getInstance(), () -> {
Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.getInstance(), () ->
{
banner.setType(Material.AIR);
as.remove();
banner.getWorld().strikeLightningEffect(banner.getLocation());
Bukkit.getScheduler().cancelTask(affectorTask);
FactionsBlockListener.bannerLocations.remove(bannerFaction.getTag());
}, Long.parseLong(bannerTime + ""));
} else {
}
else
{
fme.msg(TL.WARBANNER_INVALIDLOC);
e.setCancelled(true);
}
@ -417,78 +517,102 @@ public class FactionsBlockListener implements Listener {
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onFrostWalker(EntityBlockFormEvent event) {
public void onFrostWalker(EntityBlockFormEvent event)
{
if (event.getEntity() == null || event.getEntity().getType() != EntityType.PLAYER || event.getBlock() == null)
return;
Player player = (Player) event.getEntity();
Location location = event.getBlock().getLocation();
if (!event.getBlock().getType().equals(Material.WATER))
{
// If we are not replacing water then this is clearly not a frostwalker event.
return;
}
// only notify every 10 seconds
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
boolean justCheck = fPlayer.getLastFrostwalkerMessage() + 10000 > System.currentTimeMillis();
if (!justCheck) fPlayer.setLastFrostwalkerMessage();
if (!justCheck)
fPlayer.setLastFrostwalkerMessage();
// Check if they have build permissions here. If not, block this from happening.
if (!playerCanBuildDestroyBlock(player, location, PermissableAction.FROST_WALK.toString(), justCheck)) event.setCancelled(true);
if (!playerCanBuildDestroyBlock(player, location, PermissableAction.FROST_WALK, justCheck))
event.setCancelled(true);
}
@EventHandler
public void onFallingBlock(EntityChangeBlockEvent event) {
public void onFallingBlock(EntityChangeBlockEvent event)
{
if (!FactionsPlugin.getInstance().getConfig().getBoolean("Falling-Block-Fix.Enabled"))
return;
Faction faction = Board.getInstance().getFactionAt(new FLocation(event.getBlock()));
if (faction.isWarZone() || faction.isSafeZone()) {
if (faction.isWarZone() || faction.isSafeZone())
{
event.getBlock().setType(Material.AIR);
event.setCancelled(true);
}
}
private boolean canPistonMoveBlock(Faction pistonFaction, Location target) {
private boolean canPistonMoveBlock(Faction pistonFaction, Location target)
{
Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(target));
if (pistonFaction == otherFaction) return true;
if (pistonFaction == otherFaction)
return true;
if (otherFaction.isWilderness())
return !Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(target.getWorld().getName());
else if (otherFaction.isSafeZone()) return !Conf.safeZoneDenyBuild;
else if (otherFaction.isWarZone()) return !Conf.warZoneDenyBuild;
else if (otherFaction.isSafeZone())
return !Conf.safeZoneDenyBuild;
else if (otherFaction.isWarZone())
return !Conf.warZoneDenyBuild;
Relation rel = pistonFaction.getRelationTo(otherFaction);
return !rel.confDenyBuild(otherFaction.hasPlayersOnline());
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
public void onBlockBreak(BlockBreakEvent event)
{
// If there is an error its much safer to not allow the block to be broken
try {
try
{
Block block = event.getBlock();
Faction at = Board.getInstance().getFactionAt(new FLocation(block));
boolean isSpawner = event.getBlock().getType().equals(XMaterial.SPAWNER.parseMaterial());
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) {
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), PermissableAction.DESTROY, false))
{
event.setCancelled(true);
return;
}
FPlayer fme = FPlayers.getInstance().getByPlayer(event.getPlayer());
if (fme == null || !fme.hasFaction()) return;
if (fme == null || !fme.hasFaction())
return;
if (isSpawner) {
if (isSpawner)
{
Access access = fme.getFaction().getAccess(fme, PermissableAction.SPAWNER);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
if (access != Access.ALLOW && fme.getRole() != Role.LEADER)
{
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "mine spawners");
}
}
if (isSpawner && !fme.isAdminBypassing()) {
if (isSpawner && !fme.isAdminBypassing())
{
ItemStack item = new ItemStack(block.getType(), 1, block.getData());
if (at != null && at.isNormal()) {
if (at != null && at.isNormal())
{
FPlayer fplayer = FPlayers.getInstance().getByPlayer(event.getPlayer());
if (fplayer != null) {
if (fplayer != null)
{
BlockState state = block.getState();
if (state instanceof CreatureSpawner) {
if (state instanceof CreatureSpawner)
{
CreatureSpawner spawner = (CreatureSpawner) state;
item.setDurability(spawner.getSpawnedType().getTypeId());
}
@ -496,20 +620,26 @@ public class FactionsBlockListener implements Listener {
}
}
}
} catch (Exception e) {
}
catch (Exception e)
{
event.setCancelled(true);
e.printStackTrace();
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void FrameRemove(HangingBreakByEntityEvent event) {
if (event.getRemover() == null) return;
if ((event.getRemover() instanceof Player)) {
if (event.getEntity().getType().equals(EntityType.ITEM_FRAME)) {
public void FrameRemove(HangingBreakByEntityEvent event)
{
if (event.getRemover() == null)
return;
if ((event.getRemover() instanceof Player))
{
if (event.getEntity().getType().equals(EntityType.ITEM_FRAME))
{
Player p = (Player) event.getRemover();
if (!playerCanBuildDestroyBlock(p, event.getEntity().getLocation(), "destroy", true)) {
if (!playerCanBuildDestroyBlock(p, event.getEntity().getLocation(), PermissableAction.DESTROY, true))
{
event.setCancelled(true);
return;
}
@ -518,10 +648,13 @@ public class FactionsBlockListener implements Listener {
}
@EventHandler
public void onFarmLandDamage(EntityChangeBlockEvent event) {
if (event.getEntity() instanceof Player) {
public void onFarmLandDamage(EntityChangeBlockEvent event)
{
if (event.getEntity() instanceof Player)
{
Player player = (Player) event.getEntity();
if (!playerCanBuildDestroyBlock(player, event.getBlock().getLocation(), PermissableAction.DESTROY.name(), true)) {
if (!playerCanBuildDestroyBlock(player, event.getBlock().getLocation(), PermissableAction.DESTROY, true))
{
FPlayer me = FPlayers.getInstance().getByPlayer(player);
Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(event.getBlock().getLocation()));
me.msg(TL.ACTION_DENIED_OTHER, otherFaction.getTag(), "trample crops");

View File

@ -5,6 +5,7 @@ import com.massivecraft.factions.event.PowerLossEvent;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.factions.util.timer.type.GraceTimer;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -138,7 +139,7 @@ public class FactionsEntityListener implements Listener {
// Run the check for a player
if (damager instanceof Player) {
if (!FactionsBlockListener.playerCanBuildDestroyBlock((Player) damager, damagee.getLocation(), "destroy", false))
if (!FactionsBlockListener.playerCanBuildDestroyBlock((Player) damager, damagee.getLocation(), PermissableAction.DESTROY, false))
event.setCancelled(true);
} else {
@ -508,7 +509,7 @@ public class FactionsEntityListener implements Listener {
Player p = (Player) e.getRemover();
if (e.getEntity().getType() == EntityType.PAINTING || e.getEntity().getType() == EntityType.ITEM_FRAME) {
if (!FactionsBlockListener.playerCanBuildDestroyBlock(p, e.getEntity().getLocation(), "destroy", false)) {
if (!FactionsBlockListener.playerCanBuildDestroyBlock(p, e.getEntity().getLocation(), PermissableAction.DESTROY, false)) {
e.setCancelled(true);
}
}
@ -519,7 +520,7 @@ public class FactionsEntityListener implements Listener {
if (e.getPlayer() == null) return;
if (e.getEntity().getType() == EntityType.PAINTING || e.getEntity().getType() == EntityType.ITEM_FRAME) {
if (!FactionsBlockListener.playerCanBuildDestroyBlock(e.getPlayer(), e.getBlock().getLocation(), "build", false)) {
if (!FactionsBlockListener.playerCanBuildDestroyBlock(e.getPlayer(), e.getBlock().getLocation(), PermissableAction.BUILD, false)) {
e.setCancelled(true);
e.getPlayer().updateInventory();
}
@ -626,7 +627,7 @@ public class FactionsEntityListener implements Listener {
if (event.getRightClicked() == null) return;
if (!event.getRightClicked().getType().equals(EntityType.ITEM_FRAME)) return;
if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), event.getRightClicked().getLocation(), "build", false)) {
if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), event.getRightClicked().getLocation(), PermissableAction.BUILD, false)) {
event.setCancelled(true);
}
}

View File

@ -741,7 +741,8 @@ public class FactionsPlayerListener implements Listener {
me.attemptClaim(me.getAutoClaimFor(), newLocation, true);
}
FactionsPlugin.instance.logFactionEvent(me.getAutoClaimFor(), FLogType.CHUNK_CLAIMS, me.getName(), CC.GreenB + "CLAIMED", String.valueOf(1), (new FLocation(player.getLocation())).formatXAndZ(","));
if (Conf.disableFlightOnFactionClaimChange) CmdFly.disableFlight(me);
if (Conf.disableFlightOnFactionClaimChange && FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight")) CmdFly.disableFlight(me);
} else if (me.isAutoSafeClaimEnabled()) {
if (!Permission.MANAGE_SAFE_ZONE.has(player)) {
me.setIsAutoSafeClaimEnabled(false);
@ -863,7 +864,7 @@ public class FactionsPlayerListener implements Listener {
Block block = event.getClickedBlock();
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && block.getType() == XMaterial.GRASS_BLOCK.parseMaterial()
&& event.hasItem() && event.getItem().getType() == XMaterial.BONE_MEAL.parseMaterial()) {
if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), block.getLocation(), PermissableAction.BUILD.name(), true)) {
if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), block.getLocation(), PermissableAction.BUILD, true)) {
FPlayer me = FPlayers.getInstance().getById(event.getPlayer().getUniqueId().toString());
Faction myFaction = me.getFaction();

View File

@ -11,6 +11,7 @@ import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
@ -20,9 +21,13 @@ import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class ShopGUIFrame {
public class ShopGUIFrame
{
/**
* @author Driftay
@ -30,21 +35,27 @@ public class ShopGUIFrame {
private Gui gui;
public ShopGUIFrame(Faction f) {
gui = new Gui(FactionsPlugin.getInstance(),
FactionsPlugin.getInstance().getConfig().getInt("F-Shop.GUI.Rows", 4),
FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("F-Shop.GUI.Name")));
public ShopGUIFrame(Faction f)
{
gui = new Gui(FactionsPlugin.getInstance(), FactionsPlugin.getInstance().getConfig().getInt("F-Shop.GUI.Rows", 4), FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("F-Shop.GUI.Name")));
}
public void buildGUI(FPlayer fplayer) {
public void buildGUI(FPlayer fplayer)
{
PaginatedPane pane = new PaginatedPane(0, 0, 9, gui.getRows());
List<GuiItem> GUIItems = new ArrayList<>();
ItemStack dummy = buildDummyItem(fplayer.getFaction());
for (int x = 0; x <= (gui.getRows() * 9) - 1; x++) GUIItems.add(new GuiItem(dummy, e -> e.setCancelled(true)));
for (int x = 0; x <= (gui.getRows() * 9) - 1; x++)
GUIItems.add(new GuiItem(dummy, e -> e.setCancelled(true)));
Set<String> items = FactionsPlugin.getInstance().getFileManager().getShop().getConfig().getConfigurationSection("items").getKeys(false);
for (String s : items)
{
if (!checkShopConfig(s))
{
continue;
}
int items = FactionsPlugin.getInstance().getFileManager().getShop().getConfig().getConfigurationSection("items").getKeys(false).size();
for (int a = 1; a <= items; a++) {
String s = a + "";
int slot = FactionsPlugin.getInstance().getFileManager().getShop().fetchInt("items." + s + ".slot");
ItemStack item = XMaterial.matchXMaterial(FactionsPlugin.getInstance().getFileManager().getShop().fetchString("items." + s + ".block")).get().parseItem();
int cost = FactionsPlugin.getInstance().getFileManager().getShop().fetchInt("items." + s + ".cost");
@ -52,33 +63,43 @@ public class ShopGUIFrame {
boolean glowing = FactionsPlugin.getInstance().getFileManager().getShop().fetchBoolean("items." + s + ".glowing");
List<String> lore = FactionsPlugin.getInstance().getFileManager().getShop().fetchStringList("items." + s + ".lore");
assert item != null;
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(FactionsPlugin.instance.color(name));
meta.addItemFlags();
if (glowing) {
if (glowing)
{
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.addEnchant(Enchantment.DURABILITY, 1, true);
}
if (!glowing) meta.removeEnchant(Enchantment.DURABILITY);
if (!glowing)
meta.removeEnchant(Enchantment.DURABILITY);
List<String> replacedLore = lore.stream().map(t -> t.replace("{cost}", cost + "")).collect(Collectors.toList());
meta.setLore(FactionsPlugin.instance.colorList(replacedLore));
item.setItemMeta(meta);
GUIItems.set(slot, new GuiItem(item, e -> {
GUIItems.set(slot, new GuiItem(item, e ->
{
e.setCancelled(true);
FPlayer fme = FPlayers.getInstance().getByPlayer((Player) e.getWhoClicked());
if (fplayer.getFaction().getPoints() >= cost) {
if (fplayer.getFaction().getPoints() >= cost)
{
if (runCommands(FactionsPlugin.getInstance().getFileManager().getShop().fetchStringList("items." + s + ".cmds"), fplayer.getPlayer()))
{
fplayer.getFaction().setPoints(fplayer.getFaction().getPoints() - cost);
runCommands(FactionsPlugin.getInstance().getFileManager().getShop().fetchStringList("items." + s + ".cmds"), fplayer.getPlayer());
for (FPlayer fplayerBuy : fplayer.getFaction().getFPlayers()) {
fplayerBuy.getPlayer().sendMessage(TL.SHOP_BOUGHT_BROADCAST_FACTION.toString()
.replace("{player}", fplayer.getPlayer().getName())
.replace("{item}", ChatColor.stripColor(FactionsPlugin.getInstance().color(name)))
for (FPlayer fplayerBuy : fplayer.getFaction().getFPlayers())
{
fplayerBuy.getPlayer().sendMessage(TL.SHOP_BOUGHT_BROADCAST_FACTION.toString().replace("{player}", fplayer.getPlayer().getName()).replace("{item}", ChatColor.stripColor(FactionsPlugin.getInstance().color(name)))
.replace("{cost}", cost + ""));
}
buildGUI(fme);
} else {
}
else
{
fplayer.msg(TL.SHOP_ERROR_DURING_PURCHASE);
}
}
else
{
fplayer.msg(TL.SHOP_NOT_ENOUGH_POINTS);
}
}));
@ -89,12 +110,13 @@ public class ShopGUIFrame {
}
}
private ItemStack buildDummyItem(Faction f) {
private ItemStack buildDummyItem(Faction f)
{
ConfigurationSection config = FactionsPlugin.getInstance().getConfig().getConfigurationSection("F-Shop.GUI.dummy-item");
ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).get().parseItem();
ItemMeta meta = item.getItemMeta();
if (meta != null) {
if (meta != null)
{
meta.setLore(FactionsPlugin.getInstance().colorList(config.getStringList("Lore")));
meta.setDisplayName(FactionsPlugin.getInstance().color(config.getString("Name").replace("{points}", f.getPoints() + "")));
item.setItemMeta(meta);
@ -102,10 +124,107 @@ public class ShopGUIFrame {
return item;
}
public void runCommands(List<String> list, Player p) {
for (String cmd : list) {
public boolean checkShopConfig()
{
boolean ret = true;
Set<String> items = FactionsPlugin.getInstance().getFileManager().getShop().getConfig().getConfigurationSection("items").getKeys(false);
for (String s : items)
{
if (checkShopConfig(s) == false)
{
ret = false;
}
}
return ret;
}
public boolean checkShopConfig(String s)
{
boolean ret = true;
if (!FactionsPlugin.getInstance().getFileManager().getShop().containsKey("items." + s + ".slot"))
{
FactionsPlugin.getInstance().log(Level.WARNING, "Problem with config item \'" + s + "\' missing slot variable");
ret = false;
}
if (!FactionsPlugin.getInstance().getFileManager().getShop().containsKey("items." + s + ".block"))
{
FactionsPlugin.getInstance().log(Level.WARNING, "Problem with config item \'" + s + "\' missing block variable");
ret = false;
}
if (!FactionsPlugin.getInstance().getFileManager().getShop().containsKey("items." + s + ".cmds"))
{
FactionsPlugin.getInstance().log(Level.WARNING, "Problee with config item \'" + s + "\' missing cmds variable");
ret = false;
}
if (!FactionsPlugin.getInstance().getFileManager().getShop().containsKey("items." + s + ".cost"))
{
FactionsPlugin.getInstance().log(Level.WARNING, "Problem with config item \'" + s + "\' missing cost variable this item will cost 0");
}
if (!FactionsPlugin.getInstance().getFileManager().getShop().containsKey("items." + s + ".name"))
{
FactionsPlugin.getInstance().log(Level.WARNING, "Problem with config item \'" + s + "\' missing name variable");
ret = false;
}
return ret;
}
/**
*
* @param list
* The list of commands to be ran.
* @param p
* The player that is using the shop
* @return if all commands are able to be ran or if they did run.
*/
public boolean runCommands(List<String> list, Player p)
{
for (String cmd : list)
{
cmd = cmd.replace("%player%", p.getName());
if (cmd.toLowerCase().startsWith("give"))
{
String[] args = cmd.split(" ");
if (args.length == 4)
{
Material material = Material.matchMaterial(args[2]);
int amount = Integer.parseInt(args[3]);
Player player = Bukkit.getPlayer(args[1]);
if (!player.isOnline())
{
return false;
}
// See if the player has this item in their inventory;
if (player.getInventory().contains(material) && player.getInventory().firstEmpty() < 0)
{
int spacesAvailable = 0;
Map<Integer, ? extends ItemStack> contents = player.getInventory().all(material);
for (ItemStack stack : contents.values())
{
spacesAvailable += stack.getMaxStackSize() - stack.getAmount();
}
if (spacesAvailable < amount)
{
return false;
}
}
else
{
if (player.getInventory().firstEmpty() < 0)
{
return false;
}
}
}
}
}
for (String cmd : list)
{
cmd = cmd.replace("%player%", p.getName());
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
}
return true;
}
}

View File

@ -56,6 +56,10 @@ public class CustomFile {
}
}
public boolean containsKey(String key) {
return getCachedObjects().containsKey(key)|| getConfig().contains(key);
}
public String fetchString(String key) {
return (String) getObj(key, dataTypes.STRING);
}

View File

@ -972,6 +972,8 @@ public abstract class MemoryFPlayer implements FPlayer {
}
public void setFFlying(boolean fly, boolean damage) {
if(FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight"))
{
Player player = getPlayer();
if (player == null) return;
@ -1003,6 +1005,7 @@ public abstract class MemoryFPlayer implements FPlayer {
isFlying = fly;
}
}
public boolean isInFactionsChest() {
return inChest;

View File

@ -824,6 +824,7 @@ public enum TL {
COMMAND_STRIKESINFO_DESCRIPTION("Get a faction's strikes"),
SHOP_NOT_ENOUGH_POINTS("&c&l[!] &7Your faction does not have enough points to purchase this!"),
SHOP_ERROR_DURING_PURCHASE("&c&l[!] &7There was an error while trying to give items please check your inventory! Purchase was not completed!"),
SHOP_BOUGHT_BROADCAST_FACTION("\n&c&l[!] &e&lFactionShop » &b{player} &7bought &b{item}&7 for &b{cost} &7points!\n"),