SyncSaving and Persistence with Unclaiming and Disbanding With Fly Checks

This commit is contained in:
Driftay 2019-11-21 09:38:15 -05:00
parent 4f6329996f
commit 0b127cbe72
12 changed files with 45 additions and 52 deletions

View File

@ -550,6 +550,8 @@ public class Conf {
FactionsPlugin.getInstance().persist.save(i); FactionsPlugin.getInstance().persist.save(i);
} }
public static void saveSync() { FactionsPlugin.instance.persist.saveSync(i); }
public enum Backend { public enum Backend {
JSON, JSON,
//MYSQL, TODO add MySQL storage //MYSQL, TODO add MySQL storage

View File

@ -425,9 +425,7 @@ public class FactionsPlugin extends MPlugin {
public void onDisable() { public void onDisable() {
// only save data if plugin actually completely loaded successfully // only save data if plugin actually completely loaded successfully
if (this.loadSuccessful) { if (this.loadSuccessful) {
// Dont save, as this is kind of pointless, as the /f config command manually saves. Conf.saveSync();
// So any edits done are saved, this way manual edits to json can go through.
// Conf.save();
} }
if (AutoLeaveTask != null) { if (AutoLeaveTask != null) {

View File

@ -25,6 +25,10 @@ public class CmdAdmin extends FCommand {
@Override @Override
public void perform(CommandContext context) { public void perform(CommandContext context) {
if (context.player == null) {
context.msg(TL.GENERIC_PLAYERONLY);
return;
}
// Allows admins bypass this. // Allows admins bypass this.
if (!context.fPlayer.isAdminBypassing() && !context.fPlayer.getRole().equals(Role.LEADER)) { if (!context.fPlayer.isAdminBypassing() && !context.fPlayer.getRole().equals(Role.LEADER)) {
context.msg(TL.COMMAND_ADMIN_NOTADMIN); context.msg(TL.COMMAND_ADMIN_NOTADMIN);

View File

@ -78,18 +78,23 @@ public class CmdDisband extends FCommand {
if (FactionsPlugin.getInstance().getConfig().getBoolean("faction-disband-broadcast", true)) { if (FactionsPlugin.getInstance().getConfig().getBoolean("faction-disband-broadcast", true)) {
for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) { for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) {
String amountString = context.sender instanceof ConsoleCommandSender ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(follower); String amountString = context.sender instanceof ConsoleCommandSender ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(follower);
UtilFly.checkFly(context.fPlayer, Board.getInstance().getFactionAt(new FLocation(follower)));
if (follower.getFaction() == faction) { if (follower.getFaction() == faction) {
follower.msg(TL.COMMAND_DISBAND_BROADCAST_YOURS, amountString); follower.msg(TL.COMMAND_DISBAND_BROADCAST_YOURS, amountString);
if (!follower.canFlyAtLocation()) {
follower.setFFlying(false, false);
}
} else { } else {
follower.msg(TL.COMMAND_DISBAND_BROADCAST_NOTYOURS, amountString, faction.getTag(follower)); follower.msg(TL.COMMAND_DISBAND_BROADCAST_NOTYOURS, amountString, faction.getTag(follower));
} }
} }
faction.disband(context.player, PlayerDisbandReason.COMMAND); context.fPlayer.setFFlying(false, false);
} else { } else {
faction.disband(context.player, PlayerDisbandReason.COMMAND);
context.player.sendMessage(String.valueOf(TL.COMMAND_DISBAND_PLAYER)); context.player.sendMessage(String.valueOf(TL.COMMAND_DISBAND_PLAYER));
} }
faction.disband(context.player, PlayerDisbandReason.COMMAND);
if (!context.fPlayer.canFlyAtLocation()) {
context.fPlayer.setFFlying(false, false);
}
} }
} }

View File

@ -116,20 +116,15 @@ public class CmdFly extends FCommand {
return false; return false;
} }
if (!(me.hasPermission(Permission.FLY_NEUTRAL.node) || access == Access.ALLOW) && toFac.getRelationTo(fme.getFaction()) == Relation.NEUTRAL && !isSystemFaction(toFac)) { if (!(me.hasPermission(Permission.FLY_NEUTRAL.node) || access == Access.ALLOW) && toFac.getRelationTo(fme.getFaction()) == Relation.NEUTRAL && !toFac.isSystemFaction()) {
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme)); fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
return false; return false;
} }
return me.hasPermission(Permission.FLY.node) && (access != Access.DENY || toFac.isSystemFaction()); return me.hasPermission(Permission.FLY.node) && (access != Access.DENY || toFac.isSystemFaction());
} }
return true; return fme.canFlyAtLocation();
} }
public static Boolean isSystemFaction(Faction faction) {
return faction.isSafeZone() ||
faction.isWarZone() ||
faction.isWilderness();
}
public static void checkTaskState() { public static void checkTaskState() {
if (flyMap.isEmpty()) { if (flyMap.isEmpty()) {

View File

@ -52,6 +52,9 @@ public class CommandRequirements {
return false; return false;
} }
if (context.fPlayer.isAdminBypassing()) return true;
if (!FactionsPlugin.getInstance().perm.has(context.sender, permission.node, informIfNot)) return false; if (!FactionsPlugin.getInstance().perm.has(context.sender, permission.node, informIfNot)) return false;
// Permissable Action provided compute that before role // Permissable Action provided compute that before role

View File

@ -54,7 +54,9 @@ public class CmdUnclaim extends FCommand {
if (radius == 1) { if (radius == 1) {
// single chunk // single chunk
unClaim(new FLocation(context.player), context); boolean didUnClaim = unClaim(new FLocation(context.player), context);
if (didUnClaim && !context.fPlayer.canFlyAtLocation())
context.fPlayer.setFFlying(false, false);
} else { } else {
// radius claim // radius claim
if (!Permission.CLAIM_RADIUS.has(context.sender, false)) { if (!Permission.CLAIM_RADIUS.has(context.sender, false)) {

View File

@ -131,13 +131,14 @@ public class FactionsBlockListener implements Listener {
// special case for flint&steel, which should only be prevented by DenyUsage list // special case for flint&steel, which should only be prevented by DenyUsage list
if (event.getBlockPlaced().getType() == Material.FIRE) 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(), !isSpawner ? "build" : "mine spawners", false)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (event.getBlock().getType().equals(XMaterial.SPAWNER.parseMaterial())) { if (isSpawner) {
if (Conf.spawnerLock) { if (Conf.spawnerLock) {
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_SPAWNER_LOCK_CANNOT_PLACE.toString())); event.getPlayer().sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_SPAWNER_LOCK_CANNOT_PLACE.toString()));
@ -462,22 +463,11 @@ public class FactionsBlockListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) { boolean isSpawner = event.getBlock().getType() == XMaterial.SPAWNER.parseMaterial();
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), !isSpawner ? "destroy" : "mine spawners", false)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
FPlayer fme = FPlayers.getInstance().getByPlayer(event.getPlayer());
if (fme == null || !fme.hasFaction()) {
return;
}
if (event.getBlock().getType() == XMaterial.SPAWNER.parseMaterial()) {
if (!fme.isAdminBypassing()) {
Access access = fme.getFaction().getAccess(fme, PermissableAction.SPAWNER);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "mine spawners");
}
}
}
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)

View File

@ -555,6 +555,7 @@ public class FactionsPlayerListener implements Listener {
public void enableFly(FPlayer me) { public void enableFly(FPlayer me) {
if (!FactionsPlugin.instance.getConfig().getBoolean("ffly.AutoEnable")) return; // Looks prettier sorry if (!FactionsPlugin.instance.getConfig().getBoolean("ffly.AutoEnable")) return; // Looks prettier sorry
if (!me.canFlyAtLocation()) return;
me.setFFlying(true, false); me.setFFlying(true, false);
CmdFly.flyMap.put(me.getName(), true); CmdFly.flyMap.put(me.getName(), true);
if (CmdFly.particleTask == null) if (CmdFly.particleTask == null)
@ -728,21 +729,8 @@ public class FactionsPlayerListener implements Listener {
}, 5); }, 5);
} }
} }
if (!me.isFlying()) {
// enable fly :) enableFly(me);
if (FactionsPlugin.instance.factionsFlight && me.hasFaction() && !me.isFlying()) {
if (factionTo == me.getFaction()) enableFly(me);
// bypass checks
Relation relationTo = factionTo.getRelationTo(me);
if ((factionTo.isWilderness() && me.canflyinWilderness()) ||
(factionTo.isWarZone() && me.canflyinWarzone()) ||
(factionTo.isSafeZone() && me.canflyinSafezone()) ||
(relationTo == Relation.ENEMY && me.canflyinEnemy()) ||
(relationTo == Relation.ALLY && me.canflyinAlly()) ||
(relationTo == Relation.TRUCE && me.canflyinTruce()) ||
(relationTo == Relation.NEUTRAL && me.canflyinNeutral() && !isSystemFaction(factionTo))) {
Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> enableFly(me));
}
} }
if (me.getAutoClaimFor() != null) { if (me.getAutoClaimFor() != null) {

View File

@ -988,7 +988,7 @@ public abstract class MemoryFPlayer implements FPlayer {
return true; return true;
} }
if (faction.isWilderness() || faction.isSafeZone() || faction.isWarZone()){ if (faction.isSystemFaction()) {
return CmdFly.checkBypassPerms(this, this.getPlayer(), faction); return CmdFly.checkBypassPerms(this, this.getPlayer(), faction);
} }

View File

@ -870,13 +870,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
return Access.UNDEFINED; return Access.UNDEFINED;
} }
Permissable perm; Permissable perm = player.getFaction() == null ? player.getRole() : player.getFaction().getRelationTo(this);
if (player.getFaction() == this) {
perm = player.getRole();
} else {
perm = player.getFaction().getRelationTo(this);
}
Map<PermissableAction, Access> accessMap = permissions.get(perm); Map<PermissableAction, Access> accessMap = permissions.get(perm);
if (accessMap != null && accessMap.containsKey(permissableAction)) { if (accessMap != null && accessMap.containsKey(permissableAction)) {

View File

@ -103,6 +103,18 @@ public class Persist {
return DiscUtil.writeCatch(file, p.gson.toJson(instance), false); return DiscUtil.writeCatch(file, p.gson.toJson(instance), false);
} }
public boolean saveSync(Object instance) {
return saveSync(instance, getFile(instance));
}
public boolean saveSync(Object instance, String name) {
return saveSync(instance, getFile(name));
}
public boolean saveSync(Object instance, File file) {
return DiscUtil.writeCatch(file, p.gson.toJson(instance), true);
}
// LOAD BY CLASS // LOAD BY CLASS
public <T> T load(Class<T> clazz) { public <T> T load(Class<T> clazz) {