Radius Claiming & Alt Limit Fix

This commit is contained in:
Driftay 2020-05-04 20:27:39 -04:00
parent e0d2e6b4db
commit 499d41dea0
14 changed files with 84 additions and 51 deletions

View File

@ -103,6 +103,9 @@ public class Conf {
public static boolean worldGuardChecking = false;
public static boolean worldGuardBuildPriority = false;
//RADIUS CLAIMING
public static boolean useRadiusClaimSystem = true;
//FRIENDLY FIRE
public static boolean friendlyFireFPlayersCommand = false;

View File

@ -66,6 +66,7 @@ public class FactionsPlugin extends MPlugin {
// Our single plugin instance.
// Single 4 life.
public static FactionsPlugin instance;
public static boolean cachedRadiusClaim;
public static Permission perms = null;
// This plugin sets the boolean true when fully enabled.
// Plugins can check this boolean while hooking in have
@ -248,6 +249,8 @@ public class FactionsPlugin extends MPlugin {
// start up task which runs the autoLeaveAfterDaysOfInactivity routine
startAutoLeaveTask(false);
cachedRadiusClaim = Conf.useRadiusClaimSystem;
if (version > 8) {
useNonPacketParticles = true;
log("Minecraft Version 1.9 or higher found, using non packet based particle API");
@ -452,7 +455,7 @@ public class FactionsPlugin extends MPlugin {
@Override
public void onDisable() {
// only save data if plugin actually completely loaded successfully
super.onDisable();
if (this.loadSuccessful) {
Conf.load();
Conf.saveSync();
@ -476,7 +479,6 @@ public class FactionsPlugin extends MPlugin {
e.printStackTrace();
}
}
this.getServer().getScheduler().cancelTasks(this);
super.onDisable();
}

View File

@ -81,7 +81,7 @@ public class CmdJoin extends FCommand {
int altLimit = Conf.factionAltMemberLimit;
if (altLimit > 0 && faction.getAltPlayers().size() >= altLimit && !faction.altInvited(context.fPlayer)) {
if (altLimit > 0 && faction.getAltPlayers().size() >= altLimit && faction.altInvited(context.fPlayer)) {
context.msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(context.fPlayer), altLimit, fplayer.describeTo(context.fPlayer, false));
return;
}

View File

@ -1,5 +1,6 @@
package com.massivecraft.factions.cmd.claim;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
@ -62,10 +63,14 @@ public class CmdAutoClaim extends FCommand {
return;
}
Faction at = Board.getInstance().getFactionAt(new FLocation(context.fPlayer.getPlayer().getLocation()));
context.fPlayer.setAutoClaimFor(forFaction);
FactionsPlugin.instance.logFactionEvent(forFaction, FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.GreenB + "CLAIMED", "1", new FLocation(context.fPlayer.getPlayer().getLocation()).formatXAndZ(","));
context.msg(TL.COMMAND_AUTOCLAIM_ENABLED, forFaction.describeTo(context.fPlayer));
if (FactionsPlugin.cachedRadiusClaim && context.fPlayer.attemptClaim(forFaction, context.player.getLocation(), true)) {
context.fPlayer.getFaction().getFPlayersWhereOnline(true).forEach(f -> f.msg(TL.CLAIM_CLAIMED, context.fPlayer.describeTo(f, true), context.fPlayer.getFaction().describeTo(f), at.describeTo(f)));
return;
}
context.fPlayer.attemptClaim(forFaction, context.fPlayer.getPlayer().getLocation(), true);
}

View File

@ -1,9 +1,6 @@
package com.massivecraft.factions.cmd.claim;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.*;
import com.massivecraft.factions.cmd.Aliases;
import com.massivecraft.factions.cmd.CommandContext;
import com.massivecraft.factions.cmd.CommandRequirements;
@ -59,8 +56,14 @@ public class CmdClaim extends FCommand {
return;
}
Faction at = Board.getInstance().getFactionAt(new FLocation(context.fPlayer.getPlayer().getLocation()));
if (radius < 2) {
// single chunk
if (FactionsPlugin.cachedRadiusClaim && context.fPlayer.attemptClaim(forFaction, context.player.getLocation(), true)) {
context.fPlayer.getFaction().getFPlayersWhereOnline(true).forEach(f -> f.msg(TL.CLAIM_CLAIMED, context.fPlayer.describeTo(f, true), context.fPlayer.getFaction().describeTo(f), at.describeTo(f)));
FactionsPlugin.instance.logFactionEvent(forFaction, FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.GreenB + "CLAIMED", "1", (new FLocation(context.fPlayer.getPlayer().getLocation())).formatXAndZ(","));
return;
}
context.fPlayer.attemptClaim(forFaction, context.player.getLocation(), true);
FactionsPlugin.instance.logFactionEvent(forFaction, FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.GreenB + "CLAIMED", "1", (new FLocation(context.fPlayer.getPlayer().getLocation())).formatXAndZ(","));
} else {
@ -68,16 +71,17 @@ public class CmdClaim extends FCommand {
if (!Permission.CLAIM_RADIUS.has(context.sender, true)) {
return;
}
new SpiralTask(new FLocation(context.player), radius) {
private final int limit = Conf.radiusClaimFailureLimit - 1;
private int failCount = 0;
private int successfulClaims = 0;
@Override
public boolean work() {
boolean success = context.fPlayer.attemptClaim(forFaction, this.currentLocation(), true);
if (success) {
failCount = 0;
successfulClaims++;
FactionsPlugin.instance.logFactionEvent(forFaction, FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.GreenB + "CLAIMED", "1", (new FLocation(context.fPlayer.getPlayer().getLocation())).formatXAndZ(","));
} else if (failCount++ >= limit) {
this.stop();
@ -85,6 +89,15 @@ public class CmdClaim extends FCommand {
}
return true;
}
public void finish() {
if (FactionsPlugin.cachedRadiusClaim) {
if (successfulClaims > 0) {
context.fPlayer.getFaction().getFPlayersWhereOnline(true).forEach(f -> f.msg(TL.CLAIM_RADIUS_CLAIM, context.fPlayer.describeTo(f, true), String.valueOf(successfulClaims), context.fPlayer.getPlayer().getLocation().getChunk().getX(), context.fPlayer.getPlayer().getLocation().getChunk().getZ()));
stop();
}
}
}
};
}
}

View File

@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd.claim;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.cmd.Aliases;
import com.massivecraft.factions.cmd.CommandContext;
@ -39,6 +40,15 @@ public class CmdClaimAt extends FCommand {
int x = context.argAsInt(1);
int z = context.argAsInt(2);
FLocation location = new FLocation(context.argAsString(0), x, z);
Faction at = Board.getInstance().getFactionAt(new FLocation(context.fPlayer.getPlayer().getLocation()));
if (FactionsPlugin.cachedRadiusClaim && context.fPlayer.attemptClaim(context.fPlayer.getFaction(), context.player.getLocation(), true)) {
context.fPlayer.getFaction().getFPlayersWhereOnline(true).forEach(f -> f.msg(TL.CLAIM_CLAIMED, context.fPlayer.describeTo(f, true), context.fPlayer.getFaction().describeTo(f), at.describeTo(f)));
FactionsPlugin.instance.logFactionEvent(context.fPlayer.getFaction(), FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.GreenB + "CLAIMED", "1", (new FLocation(context.fPlayer.getPlayer().getLocation())).formatXAndZ(","));
showMap(context);
return;
}
context.fPlayer.attemptClaim(context.faction, location, true);
FactionsPlugin.instance.logFactionEvent(context.fPlayer.getFaction(), FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.GreenB + "CLAIMED", "1", (location).formatXAndZ(","));
showMap(context);

View File

@ -1,9 +1,6 @@
package com.massivecraft.factions.cmd.claim;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.*;
import com.massivecraft.factions.cmd.Aliases;
import com.massivecraft.factions.cmd.CommandContext;
import com.massivecraft.factions.cmd.CommandRequirements;
@ -71,6 +68,7 @@ public class CmdClaimLine extends FCommand {
}
final Faction forFaction = context.argAsFaction(2, context.faction);
Faction at = Board.getInstance().getFactionAt(new FLocation(context.fPlayer.getPlayer().getLocation()));
if (forFaction != context.fPlayer.getFaction()) {
if (!context.fPlayer.isAdminBypassing()) {
@ -84,11 +82,18 @@ public class CmdClaimLine extends FCommand {
Location location = context.player.getLocation();
// TODO: make this a task like claiming a radius?
int claims = 0;
for (int i = 0; i < amount; i++) {
context.fPlayer.attemptClaim(forFaction, location, true);
if (FactionsPlugin.cachedRadiusClaim && context.fPlayer.attemptClaim(forFaction, context.player.getLocation(), true)) {
claims++;
} else {
context.fPlayer.attemptClaim(forFaction, location, true);
}
location = location.add(blockFace.getModX() * 16, 0, blockFace.getModZ() * 16);
FactionsPlugin.instance.logFactionEvent(forFaction, FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.GreenB + "CLAIMED", String.valueOf(i), new FLocation(context.player.getLocation()).formatXAndZ(","));
}
int cachedClaims = claims;
context.fPlayer.getFaction().getFPlayersWhereOnline(true).forEach(f -> f.msg(TL.CLAIM_RADIUS_CLAIM, context.fPlayer.describeTo(f, true), String.valueOf(cachedClaims), context.fPlayer.getPlayer().getLocation().getChunk().getX(), context.fPlayer.getPlayer().getLocation().getChunk().getZ()));
}
@Override

View File

@ -27,7 +27,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

View File

@ -327,7 +327,6 @@ public class FactionsEntityListener implements Listener {
public boolean isPlayerInSafeZone(Entity damagee) {
if (!(damagee instanceof Player)) return false;
return Board.getInstance().getFactionAt(new FLocation(damagee.getLocation())).isSafeZone();
}
@ -338,12 +337,8 @@ public class FactionsEntityListener implements Listener {
public boolean canDamagerHurtDamagee(EntityDamageByEntityEvent sub, boolean notify) {
Entity damager = sub.getDamager();
Entity damagee = sub.getEntity();
if (!(damagee instanceof Player)) return true;
FPlayer defender = FPlayers.getInstance().getByPlayer((Player) damagee);
if (damager instanceof Player) {
FPlayer attacker = FPlayers.getInstance().getByPlayer((Player) damager);
if (defender == null || defender.getPlayer() == null) return true;
@ -358,12 +353,8 @@ public class FactionsEntityListener implements Listener {
}
}
}
Location defenderLoc = defender.getPlayer().getLocation();
Faction defLocFaction = Board.getInstance().getFactionAt(new FLocation(defenderLoc));
// for damage caused by projectiles, getDamager() returns the projectile... what we need to know is the source
if (damager instanceof Projectile) {
Projectile projectile = (Projectile) damager;

View File

@ -730,9 +730,13 @@ public class FactionsPlayerListener implements Listener {
CmdFly.startParticles();
}
Faction at = Board.getInstance().getFactionAt(new FLocation(me.getPlayer().getLocation()));
if (me.getAutoClaimFor() != null) {
me.attemptClaim(me.getAutoClaimFor(), newLocation, true);
if (FactionsPlugin.cachedRadiusClaim && me.attemptClaim(me.getFaction(), me.getPlayer().getLocation(), true)) {
me.getFaction().getFPlayersWhereOnline(true).forEach(f -> f.msg(TL.CLAIM_CLAIMED, me.describeTo(f, true), me.getFaction().describeTo(f), at.describeTo(f)));
} else {
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);
} else if (me.isAutoSafeClaimEnabled()) {

View File

@ -2,6 +2,7 @@ package com.massivecraft.factions.util;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.scheduler.BukkitRunnable;
@ -26,7 +27,9 @@ public class CornerTask extends BukkitRunnable {
cancel();
} else {
FLocation fLocation = surrounding.remove(0);
if (fPlayer.attemptClaim(fPlayer.getFaction(), fLocation, true)) {
if (FactionsPlugin.cachedRadiusClaim && fPlayer.attemptClaim(fPlayer.getFaction(), fLocation, true)) {
++amount;
} else if (fPlayer.attemptClaim(fPlayer.getFaction(), fLocation, true)) {
++amount;
} else {
fPlayer.sendMessage(TL.COMMAND_CORNER_FAIL_WITH_FEEDBACK.toString().replace("&", "§") + amount);

View File

@ -3,10 +3,7 @@ package com.massivecraft.factions.zcore;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.*;
import com.massivecraft.factions.zcore.persist.SaveTask;
import com.massivecraft.factions.zcore.util.PermUtil;
import com.massivecraft.factions.zcore.util.Persist;
@ -15,7 +12,6 @@ import com.massivecraft.factions.zcore.util.TextUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.IllegalPluginAccessException;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.*;
@ -100,9 +96,7 @@ public abstract class MPlugin extends JavaPlugin {
long saveTicks = (long) (20 * 60 * Conf.saveToFileEveryXMinutes); // Approximately every 30 min by default
saveTask = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new SaveTask(this), saveTicks, saveTicks);
}
loadLang();
loadSuccessful = true;
return true;
}
@ -178,17 +172,18 @@ public abstract class MPlugin extends JavaPlugin {
}
public void onDisable() {
if (saveTask != null) {
this.getServer().getScheduler().cancelTask(saveTask);
saveTask = null;
}
// only save data if plugin actually loaded successfully
if (loadSuccessful) {
Factions.getInstance().forceSave();
FPlayers.getInstance().forceSave();
Board.getInstance().forceSave();
}
log("Disabled");
getServer().getScheduler().cancelTasks(this);
if (saveTask != null) {
this.getServer().getScheduler().cancelTask(saveTask);
saveTask = null;
}
// only save data if plugin actually loaded successfully
if (loadSuccessful) {
Factions.getInstance().forceSave();
FPlayers.getInstance().forceSave();
Board.getInstance().forceSave();
}
log("Disabled");
}
// -------------------------------------------- //

View File

@ -1288,11 +1288,13 @@ public abstract class MemoryFPlayer implements FPlayer {
// announce success
Set<FPlayer> informTheseFPlayers = new HashSet<>();
informTheseFPlayers.add(this);
informTheseFPlayers.addAll(forFaction.getFPlayersWhereOnline(true));
for (FPlayer fp : informTheseFPlayers) {
fp.msg(TL.CLAIM_CLAIMED, this.describeTo(fp, true), forFaction.describeTo(fp), currentFaction.describeTo(fp));
if(!FactionsPlugin.cachedRadiusClaim) {
Set<FPlayer> informTheseFPlayers = new HashSet<>();
informTheseFPlayers.add(this);
informTheseFPlayers.addAll(forFaction.getFPlayersWhereOnline(true));
for (FPlayer fp : informTheseFPlayers) {
fp.msg(TL.CLAIM_CLAIMED, this.describeTo(fp, true), forFaction.describeTo(fp), currentFaction.describeTo(fp));
}
}
Board.getInstance().setFactionAt(forFaction, flocation);

View File

@ -1067,6 +1067,7 @@ public enum TL {
CLAIM_FORCLAIM("for claiming this land"),
CLAIM_TOOVERCLAIM("to overclaim this land"),
CLAIM_FOROVERCLAIM("for over claiming this land"),
CLAIM_RADIUS_CLAIM("%1$s &eclaimed %2$s chunks &astarting from &e(X: %3$s, Z: %4$s)"),
CLAIM_CLAIMED("%s claimed land for %s from %s."),
CLAIM_CLAIMEDLOG("%s claimed land at (%s) for the faction: %s"),
CLAIM_OVERCLAIM_DISABLED("Over claiming is disabled on this server."),