Added Corner Command, Spam Prevent System, Members Upgrade Redone
This commit is contained in:
parent
f8195caf06
commit
7dd071340f
@ -82,6 +82,7 @@ public class Conf {
|
|||||||
public static String truceChatFormat = ChatColor.DARK_PURPLE + "%s:" + ChatColor.WHITE + " %s";
|
public static String truceChatFormat = ChatColor.DARK_PURPLE + "%s:" + ChatColor.WHITE + " %s";
|
||||||
public static String modChatFormat = ChatColor.RED + "%s:" + ChatColor.WHITE + " %s";
|
public static String modChatFormat = ChatColor.RED + "%s:" + ChatColor.WHITE + " %s";
|
||||||
public static int stealthFlyCheckRadius = 32;
|
public static int stealthFlyCheckRadius = 32;
|
||||||
|
public static int factionBufferSize = 20;
|
||||||
public static boolean gracePeriod = false;
|
public static boolean gracePeriod = false;
|
||||||
public static boolean noEnderpearlsInFly = false;
|
public static boolean noEnderpearlsInFly = false;
|
||||||
public static boolean broadcastDescriptionChanges = false;
|
public static boolean broadcastDescriptionChanges = false;
|
||||||
|
@ -78,7 +78,6 @@ public class FLocation implements Serializable {
|
|||||||
public static int blockToChunk(int blockVal) { // 1 chunk is 16x16 blocks
|
public static int blockToChunk(int blockVal) { // 1 chunk is 16x16 blocks
|
||||||
return blockVal >> 4; // ">> 4" == "/ 16"
|
return blockVal >> 4; // ">> 4" == "/ 16"
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int blockToRegion(int blockVal) { // 1 region is 512x512 blocks
|
public static int blockToRegion(int blockVal) { // 1 region is 512x512 blocks
|
||||||
return blockVal >> 9; // ">> 9" == "/ 512"
|
return blockVal >> 9; // ">> 9" == "/ 512"
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ public class SavageFactions extends MPlugin {
|
|||||||
// Plugins can check this boolean while hooking in have
|
// Plugins can check this boolean while hooking in have
|
||||||
// a green light to use the api.
|
// a green light to use the api.
|
||||||
public static boolean startupFinished = false;
|
public static boolean startupFinished = false;
|
||||||
|
private FactionsPlayerListener factionsPlayerListener;
|
||||||
|
|
||||||
|
|
||||||
public boolean PlaceholderApi;
|
public boolean PlaceholderApi;
|
||||||
@ -238,10 +239,10 @@ public class SavageFactions extends MPlugin {
|
|||||||
log("Skript addon registered!");
|
log("Skript addon registered!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getServer().getPluginManager().registerEvents(factionsPlayerListener = new FactionsPlayerListener(), this);
|
||||||
|
|
||||||
// Register Event Handlers
|
// Register Event Handlers
|
||||||
eventsListener = new Listener[]{
|
eventsListener = new Listener[]{
|
||||||
new FactionsPlayerListener(),
|
|
||||||
new FactionsChatListener(),
|
new FactionsChatListener(),
|
||||||
new FactionsEntityListener(),
|
new FactionsEntityListener(),
|
||||||
new FactionsExploitListener(),
|
new FactionsExploitListener(),
|
||||||
@ -778,6 +779,9 @@ public class SavageFactions extends MPlugin {
|
|||||||
getLogger().log(level, s);
|
getLogger().log(level, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public FactionsPlayerListener getFactionsPlayerListener() {
|
||||||
|
return this.factionsPlayerListener;
|
||||||
|
}
|
||||||
|
|
||||||
public void debug(String s) {
|
public void debug(String s) {
|
||||||
debug(Level.INFO, s);
|
debug(Level.INFO, s);
|
||||||
|
64
src/main/java/com/massivecraft/factions/cmd/CmdCorner.java
Normal file
64
src/main/java/com/massivecraft/factions/cmd/CmdCorner.java
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package com.massivecraft.factions.cmd;
|
||||||
|
|
||||||
|
|
||||||
|
import com.massivecraft.factions.*;
|
||||||
|
import com.massivecraft.factions.struct.Permission;
|
||||||
|
import com.massivecraft.factions.util.CornerTask;
|
||||||
|
import com.massivecraft.factions.zcore.util.TL;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CmdCorner extends FCommand {
|
||||||
|
|
||||||
|
public CmdCorner() {
|
||||||
|
this.aliases.add("corner");
|
||||||
|
|
||||||
|
this.permission = Permission.CLAIM_RADIUS.node;
|
||||||
|
|
||||||
|
this.senderMustBePlayer = true;
|
||||||
|
this.senderMustBeMember = true;
|
||||||
|
this.senderMustBeModerator = false;
|
||||||
|
this.senderMustBeAdmin = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void perform() {
|
||||||
|
FLocation to = new FLocation(me.getLocation());
|
||||||
|
if (SavageFactions.plugin.getFactionsPlayerListener().getCorners().contains(to)) {
|
||||||
|
Faction cornerAt = Board.getInstance().getFactionAt(to);
|
||||||
|
if (cornerAt != null && cornerAt.isNormal() && !cornerAt.equals(fme.getFaction())) {
|
||||||
|
msg(TL.COMMAND_CORNER_CANT_CLAIM);
|
||||||
|
} else {
|
||||||
|
msg(TL.COMMAND_CORNER_ATTEMPTING_CLAIM);
|
||||||
|
List<FLocation> surrounding = new ArrayList<>(400);
|
||||||
|
for (int x = 0; x < Conf.factionBufferSize; ++x) {
|
||||||
|
for (int z = 0; z < Conf.factionBufferSize; ++z) {
|
||||||
|
int newX = (int) ((to.getX() > 0L) ? (to.getX() - x) : (to.getX() + x));
|
||||||
|
int newZ = (int) ((to.getZ() > 0L) ? (to.getZ() - z) : (to.getZ() + z));
|
||||||
|
FLocation location = new FLocation(me.getWorld().getName(), newX, newZ);
|
||||||
|
Faction at = Board.getInstance().getFactionAt(location);
|
||||||
|
if (at == null || !at.isNormal()) {
|
||||||
|
surrounding.add(location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
surrounding.sort(Comparator.comparingInt(fLocation -> (int) fLocation.getDistanceTo(to)));
|
||||||
|
if (surrounding.isEmpty()) {
|
||||||
|
msg(TL.COMMAND_CORNER_CANT_CLAIM);
|
||||||
|
} else {
|
||||||
|
new CornerTask(fme, surrounding).runTaskTimer(SavageFactions.plugin, 1L, 1L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
msg(TL.COMMAND_CORNER_NOT_CORNER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TL getUsageTranslation() {
|
||||||
|
return TL.COMMAND_CORNER_DESCRIPTION;
|
||||||
|
}
|
||||||
|
}
|
@ -109,6 +109,7 @@ public class FCmdRoot extends FCommand {
|
|||||||
public CmdStrikeSet cmdStrikeSet = new CmdStrikeSet();
|
public CmdStrikeSet cmdStrikeSet = new CmdStrikeSet();
|
||||||
public CmdAlts cmdAlts = new CmdAlts();
|
public CmdAlts cmdAlts = new CmdAlts();
|
||||||
public CmdSpam cmdSpam = new CmdSpam();
|
public CmdSpam cmdSpam = new CmdSpam();
|
||||||
|
public CmdCorner cmdCorner = new CmdCorner();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -224,6 +225,7 @@ public class FCmdRoot extends FCommand {
|
|||||||
this.addSubCommand(this.cmdSetBanner);
|
this.addSubCommand(this.cmdSetBanner);
|
||||||
this.addSubCommand(this.cmdStrikeSet);
|
this.addSubCommand(this.cmdStrikeSet);
|
||||||
this.addSubCommand(this.cmdSpam);
|
this.addSubCommand(this.cmdSpam);
|
||||||
|
this.addSubCommand(this.cmdCorner);
|
||||||
|
|
||||||
|
|
||||||
if(SavageFactions.plugin.getConfig().getBoolean("f-alts.Enabled")){
|
if(SavageFactions.plugin.getConfig().getBoolean("f-alts.Enabled")){
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.massivecraft.factions.listeners;
|
package com.massivecraft.factions.listeners;
|
||||||
|
|
||||||
import com.earth2me.essentials.User;
|
|
||||||
import com.massivecraft.factions.*;
|
import com.massivecraft.factions.*;
|
||||||
import com.massivecraft.factions.cmd.CmdFly;
|
import com.massivecraft.factions.cmd.CmdFly;
|
||||||
import com.massivecraft.factions.cmd.CmdSeeChunk;
|
import com.massivecraft.factions.cmd.CmdSeeChunk;
|
||||||
@ -24,10 +23,7 @@ import com.massivecraft.factions.zcore.util.TagUtil;
|
|||||||
import com.massivecraft.factions.zcore.util.TextUtil;
|
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||||
import net.coreprotect.CoreProtect;
|
import net.coreprotect.CoreProtect;
|
||||||
import net.coreprotect.CoreProtectAPI;
|
import net.coreprotect.CoreProtectAPI;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.*;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
@ -47,7 +43,7 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
public class FactionsPlayerListener implements Listener {
|
public class FactionsPlayerListener implements Listener {
|
||||||
|
|
||||||
|
private Set<FLocation> corners;
|
||||||
HashMap<Player, Boolean> fallMap = new HashMap<>();
|
HashMap<Player, Boolean> fallMap = new HashMap<>();
|
||||||
|
|
||||||
// Holds the next time a player can have a map shown.
|
// Holds the next time a player can have a map shown.
|
||||||
@ -56,9 +52,20 @@ public class FactionsPlayerListener implements Listener {
|
|||||||
private Map<String, InteractAttemptSpam> interactSpammers = new HashMap<>();
|
private Map<String, InteractAttemptSpam> interactSpammers = new HashMap<>();
|
||||||
|
|
||||||
public FactionsPlayerListener() {
|
public FactionsPlayerListener() {
|
||||||
|
this.corners = new HashSet<>();
|
||||||
for (Player player : SavageFactions.plugin.getServer().getOnlinePlayers()) {
|
for (Player player : SavageFactions.plugin.getServer().getOnlinePlayers()) {
|
||||||
initPlayer(player);
|
initPlayer(player);
|
||||||
}
|
}
|
||||||
|
for (World world : SavageFactions.plugin.getServer().getWorlds()) {
|
||||||
|
WorldBorder border = world.getWorldBorder();
|
||||||
|
if (border != null) {
|
||||||
|
int cornerCoord = (int) ((border.getSize() - 1.0) / 2.0);
|
||||||
|
this.corners.add(new FLocation(world.getName(), FLocation.blockToChunk(cornerCoord), FLocation.blockToChunk(cornerCoord)));
|
||||||
|
this.corners.add(new FLocation(world.getName(), FLocation.blockToChunk(cornerCoord), FLocation.blockToChunk(-cornerCoord)));
|
||||||
|
this.corners.add(new FLocation(world.getName(), FLocation.blockToChunk(-cornerCoord), FLocation.blockToChunk(cornerCoord)));
|
||||||
|
this.corners.add(new FLocation(world.getName(), FLocation.blockToChunk(-cornerCoord), FLocation.blockToChunk(-cornerCoord)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Boolean isSystemFaction(Faction faction) {
|
public static Boolean isSystemFaction(Faction faction) {
|
||||||
@ -778,6 +785,10 @@ public class FactionsPlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<FLocation> getCorners() {
|
||||||
|
return this.corners;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This checks if the current player can execute an action based on it's factions access and surroundings
|
/// This checks if the current player can execute an action based on it's factions access and surroundings
|
||||||
/// It will grant access in the following priorities:
|
/// It will grant access in the following priorities:
|
||||||
|
34
src/main/java/com/massivecraft/factions/util/CornerTask.java
Normal file
34
src/main/java/com/massivecraft/factions/util/CornerTask.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package com.massivecraft.factions.util;
|
||||||
|
|
||||||
|
import com.massivecraft.factions.FLocation;
|
||||||
|
import com.massivecraft.factions.FPlayer;
|
||||||
|
import com.massivecraft.factions.zcore.util.TL;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CornerTask extends BukkitRunnable {
|
||||||
|
private FPlayer fPlayer;
|
||||||
|
private List<FLocation> surrounding;
|
||||||
|
private int amount;
|
||||||
|
|
||||||
|
public CornerTask(FPlayer fPlayer, List<FLocation> surrounding) {
|
||||||
|
this.amount = 0;
|
||||||
|
this.fPlayer = fPlayer;
|
||||||
|
this.surrounding = surrounding;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
if (surrounding.isEmpty()) {
|
||||||
|
fPlayer.sendMessage(TL.COMMAND_CORNER_CLAIMED.format(amount));
|
||||||
|
cancel();
|
||||||
|
} else if (fPlayer.isOffline()) {
|
||||||
|
cancel();
|
||||||
|
} else {
|
||||||
|
FLocation fLocation = surrounding.remove(0);
|
||||||
|
if (fPlayer.attemptClaim(fPlayer.getFaction(), fLocation, true)) {
|
||||||
|
++amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -859,6 +859,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
|||||||
return attemptClaim(forFaction, new FLocation(location), notifyFailure);
|
return attemptClaim(forFaction, new FLocation(location), notifyFailure);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean shouldBeSaved() {
|
public boolean shouldBeSaved() {
|
||||||
return this.hasFaction() || (this.getPowerRounded() != this.getPowerMaxRounded() && this.getPowerRounded() != (int) Math.round(Conf.powerPlayerStarting));
|
return this.hasFaction() || (this.getPowerRounded() != this.getPowerMaxRounded() && this.getPowerRounded() != (int) Math.round(Conf.powerPlayerStarting));
|
||||||
}
|
}
|
||||||
@ -1173,7 +1174,6 @@ public abstract class MemoryFPlayer implements FPlayer {
|
|||||||
public boolean attemptClaim(Faction forFaction, FLocation flocation, boolean notifyFailure) {
|
public boolean attemptClaim(Faction forFaction, FLocation flocation, boolean notifyFailure) {
|
||||||
// notifyFailure is false if called by auto-claim; no need to notify on every failure for it
|
// notifyFailure is false if called by auto-claim; no need to notify on every failure for it
|
||||||
// return value is false on failure, true on success
|
// return value is false on failure, true on success
|
||||||
|
|
||||||
Faction currentFaction = Board.getInstance().getFactionAt(flocation);
|
Faction currentFaction = Board.getInstance().getFactionAt(flocation);
|
||||||
int ownedLand = forFaction.getLandRounded();
|
int ownedLand = forFaction.getLandRounded();
|
||||||
|
|
||||||
@ -1239,6 +1239,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRolePrefix() {
|
public String getRolePrefix() {
|
||||||
|
|
||||||
|
@ -114,6 +114,12 @@ public enum TL {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
COMMAND_UPGRADES_DESCRIPTION("&cOpen the Upgrades Menu"),
|
COMMAND_UPGRADES_DESCRIPTION("&cOpen the Upgrades Menu"),
|
||||||
|
COMMAND_CORNER_CANT_CLAIM("&c&l[!] &cYou may not claim this corner!"),
|
||||||
|
COMMAND_CORNER_CLAIMED("\n&2&l[!] &aYou have claimed the corner successfully, totalling in &b%1$d &achunks!\n"),
|
||||||
|
COMMAND_CORNER_ATTEMPTING_CLAIM("&c&l[!] &7Attempting to claim corner..."),
|
||||||
|
COMMAND_CORNER_NOT_CORNER("&c&l[!] &7You must be in a corner to use this command!"),
|
||||||
|
COMMAND_CORNER_DESCRIPTION("claim a corner at world border"),
|
||||||
|
COMMAND_CORNERLIST_DESCRIPTION("list of all corners"),
|
||||||
|
|
||||||
COMMAND_ADMIN_NOTMEMBER("&c&l[!] &7%1$s &cis not a member in your faction."),
|
COMMAND_ADMIN_NOTMEMBER("&c&l[!] &7%1$s &cis not a member in your faction."),
|
||||||
COMMAND_ADMIN_NOTADMIN("&c&l[!] &cYou are not the faction admin."),
|
COMMAND_ADMIN_NOTADMIN("&c&l[!] &cYou are not the faction admin."),
|
||||||
|
Loading…
Reference in New Issue
Block a user