SyncSaving and Persistence with Unclaiming and Disbanding With Fly Checks
This commit is contained in:
parent
4f6329996f
commit
0b127cbe72
@ -550,6 +550,8 @@ public class Conf {
|
||||
FactionsPlugin.getInstance().persist.save(i);
|
||||
}
|
||||
|
||||
public static void saveSync() { FactionsPlugin.instance.persist.saveSync(i); }
|
||||
|
||||
public enum Backend {
|
||||
JSON,
|
||||
//MYSQL, TODO add MySQL storage
|
||||
|
@ -425,9 +425,7 @@ public class FactionsPlugin extends MPlugin {
|
||||
public void onDisable() {
|
||||
// only save data if plugin actually completely loaded successfully
|
||||
if (this.loadSuccessful) {
|
||||
// Dont save, as this is kind of pointless, as the /f config command manually saves.
|
||||
// So any edits done are saved, this way manual edits to json can go through.
|
||||
// Conf.save();
|
||||
Conf.saveSync();
|
||||
}
|
||||
|
||||
if (AutoLeaveTask != null) {
|
||||
|
@ -25,6 +25,10 @@ public class CmdAdmin extends FCommand {
|
||||
|
||||
@Override
|
||||
public void perform(CommandContext context) {
|
||||
if (context.player == null) {
|
||||
context.msg(TL.GENERIC_PLAYERONLY);
|
||||
return;
|
||||
}
|
||||
// Allows admins bypass this.
|
||||
if (!context.fPlayer.isAdminBypassing() && !context.fPlayer.getRole().equals(Role.LEADER)) {
|
||||
context.msg(TL.COMMAND_ADMIN_NOTADMIN);
|
||||
|
@ -78,18 +78,23 @@ public class CmdDisband extends FCommand {
|
||||
if (FactionsPlugin.getInstance().getConfig().getBoolean("faction-disband-broadcast", true)) {
|
||||
for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) {
|
||||
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) {
|
||||
follower.msg(TL.COMMAND_DISBAND_BROADCAST_YOURS, amountString);
|
||||
if (!follower.canFlyAtLocation()) {
|
||||
follower.setFFlying(false, false);
|
||||
}
|
||||
} else {
|
||||
follower.msg(TL.COMMAND_DISBAND_BROADCAST_NOTYOURS, amountString, faction.getTag(follower));
|
||||
}
|
||||
}
|
||||
faction.disband(context.player, PlayerDisbandReason.COMMAND);
|
||||
context.fPlayer.setFFlying(false, false);
|
||||
} else {
|
||||
faction.disband(context.player, PlayerDisbandReason.COMMAND);
|
||||
context.player.sendMessage(String.valueOf(TL.COMMAND_DISBAND_PLAYER));
|
||||
}
|
||||
faction.disband(context.player, PlayerDisbandReason.COMMAND);
|
||||
if (!context.fPlayer.canFlyAtLocation()) {
|
||||
context.fPlayer.setFFlying(false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,20 +116,15 @@ public class CmdFly extends FCommand {
|
||||
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));
|
||||
return false;
|
||||
}
|
||||
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() {
|
||||
if (flyMap.isEmpty()) {
|
||||
|
@ -52,6 +52,9 @@ public class CommandRequirements {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (context.fPlayer.isAdminBypassing()) return true;
|
||||
|
||||
|
||||
if (!FactionsPlugin.getInstance().perm.has(context.sender, permission.node, informIfNot)) return false;
|
||||
|
||||
// Permissable Action provided compute that before role
|
||||
|
@ -54,7 +54,9 @@ public class CmdUnclaim extends FCommand {
|
||||
|
||||
if (radius == 1) {
|
||||
// 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 {
|
||||
// radius claim
|
||||
if (!Permission.CLAIM_RADIUS.has(context.sender, false)) {
|
||||
|
@ -131,13 +131,14 @@ public class FactionsBlockListener implements Listener {
|
||||
|
||||
// special case for flint&steel, which should only be prevented by DenyUsage list
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getBlock().getType().equals(XMaterial.SPAWNER.parseMaterial())) {
|
||||
if (isSpawner) {
|
||||
if (Conf.spawnerLock) {
|
||||
event.setCancelled(true);
|
||||
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)
|
||||
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);
|
||||
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)
|
||||
|
@ -555,6 +555,7 @@ public class FactionsPlayerListener implements Listener {
|
||||
|
||||
public void enableFly(FPlayer me) {
|
||||
if (!FactionsPlugin.instance.getConfig().getBoolean("ffly.AutoEnable")) return; // Looks prettier sorry
|
||||
if (!me.canFlyAtLocation()) return;
|
||||
me.setFFlying(true, false);
|
||||
CmdFly.flyMap.put(me.getName(), true);
|
||||
if (CmdFly.particleTask == null)
|
||||
@ -728,21 +729,8 @@ public class FactionsPlayerListener implements Listener {
|
||||
}, 5);
|
||||
}
|
||||
}
|
||||
|
||||
// enable fly :)
|
||||
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.isFlying()) {
|
||||
enableFly(me);
|
||||
}
|
||||
|
||||
if (me.getAutoClaimFor() != null) {
|
||||
|
@ -988,7 +988,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (faction.isWilderness() || faction.isSafeZone() || faction.isWarZone()){
|
||||
if (faction.isSystemFaction()) {
|
||||
return CmdFly.checkBypassPerms(this, this.getPlayer(), faction);
|
||||
}
|
||||
|
||||
|
@ -870,13 +870,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
return Access.UNDEFINED;
|
||||
}
|
||||
|
||||
Permissable perm;
|
||||
|
||||
if (player.getFaction() == this) {
|
||||
perm = player.getRole();
|
||||
} else {
|
||||
perm = player.getFaction().getRelationTo(this);
|
||||
}
|
||||
Permissable perm = player.getFaction() == null ? player.getRole() : player.getFaction().getRelationTo(this);
|
||||
|
||||
Map<PermissableAction, Access> accessMap = permissions.get(perm);
|
||||
if (accessMap != null && accessMap.containsKey(permissableAction)) {
|
||||
|
@ -103,6 +103,18 @@ public class Persist {
|
||||
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
|
||||
|
||||
public <T> T load(Class<T> clazz) {
|
||||
|
Loading…
Reference in New Issue
Block a user