Adds per faction warps functionality from #72.
Default max warps per faction is 5. It can be changed in the config.yml. You can now use {warps} in the info board to show how many warps a faction has when you walk into their territory. Only faction mods+ can set faction warps.
This commit is contained in:
parent
35813c7210
commit
8b64b4bfe1
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
||||
|
||||
<groupId>com.massivecraft</groupId>
|
||||
<artifactId>Factions</artifactId>
|
||||
<version>1.6.9.5-U0.1.9</version>
|
||||
<version>1.6.9.5-U0.1.10-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Factions</name>
|
||||
|
@ -2,6 +2,7 @@ package com.massivecraft.factions;
|
||||
|
||||
import com.massivecraft.factions.util.MiscUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
@ -149,6 +150,14 @@ public class FLocation implements Serializable {
|
||||
return dx * dx + dz * dz;
|
||||
}
|
||||
|
||||
public boolean isInChunk(Location loc) {
|
||||
if (loc == null) {
|
||||
return false;
|
||||
}
|
||||
Chunk chunk = loc.getChunk();
|
||||
return loc.getWorld().getName().equalsIgnoreCase(getWorldName()) && chunk.getX() == x && chunk.getZ() == z;
|
||||
}
|
||||
|
||||
//----------------------------------------------//
|
||||
// Some Geometry
|
||||
//----------------------------------------------//
|
||||
|
@ -4,15 +4,29 @@ import com.massivecraft.factions.iface.EconomyParticipator;
|
||||
import com.massivecraft.factions.iface.RelationParticipator;
|
||||
import com.massivecraft.factions.struct.Relation;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.util.LazyLocation;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public interface Faction extends EconomyParticipator {
|
||||
public HashMap<String, List<String>> getAnnouncements();
|
||||
|
||||
public ConcurrentHashMap<String, LazyLocation> getWarps();
|
||||
|
||||
public LazyLocation getWarp(String name);
|
||||
|
||||
public void setWarp(String name, LazyLocation loc);
|
||||
|
||||
public boolean isWarp(String name);
|
||||
|
||||
public boolean removeWarp(String name);
|
||||
|
||||
public void clearWarps();
|
||||
|
||||
public void addAnnouncement(FPlayer fPlayer, String msg);
|
||||
|
||||
public void sendUnreadAnnouncements(FPlayer fPlayer);
|
||||
|
29
src/main/java/com/massivecraft/factions/cmd/CmdDelFWarp.java
Normal file
29
src/main/java/com/massivecraft/factions/cmd/CmdDelFWarp.java
Normal file
@ -0,0 +1,29 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
|
||||
public class CmdDelFWarp extends FCommand {
|
||||
|
||||
public CmdDelFWarp() {
|
||||
super();
|
||||
this.aliases.add("delwarp");
|
||||
this.aliases.add("dw");
|
||||
this.aliases.add("deletewarp");
|
||||
this.requiredArgs.add("warp name");
|
||||
this.senderMustBeMember = true;
|
||||
this.senderMustBeModerator = true;
|
||||
this.senderMustBePlayer = true;
|
||||
this.permission = Permission.SETWARP.node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
String warp = argAsString(0);
|
||||
if (myFaction.isWarp(warp)) {
|
||||
myFaction.removeWarp(warp);
|
||||
fme.msg("<i>Deleted warp <a>%s", warp);
|
||||
} else {
|
||||
fme.msg("<i>Couldn't find warp <a>%s", warp);
|
||||
}
|
||||
}
|
||||
}
|
39
src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java
Normal file
39
src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java
Normal file
@ -0,0 +1,39 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
|
||||
public class CmdFWarp extends FCommand {
|
||||
|
||||
public CmdFWarp() {
|
||||
super();
|
||||
this.aliases.add("warp");
|
||||
this.aliases.add("warps");
|
||||
this.optionalArgs.put("warpname", "warpname");
|
||||
|
||||
this.permission = Permission.WARP.node;
|
||||
this.senderMustBeMember = true;
|
||||
this.senderMustBeModerator = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
//TODO: check if in combat.
|
||||
if (args.size() == 0) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : myFaction.getWarps().keySet()) {
|
||||
sb.append(s + " ");
|
||||
}
|
||||
fme.msg("<i>Warps: <a>" + sb.toString().trim());
|
||||
} else if (args.size() > 1) {
|
||||
fme.msg("<i>/f warp <warpname>");
|
||||
} else {
|
||||
String warpName = argAsString(0);
|
||||
if (myFaction.isWarp(argAsString(0))) {
|
||||
fme.getPlayer().teleport(myFaction.getWarp(warpName).getLocation());
|
||||
fme.msg("<i>Warped to <a>%s", warpName);
|
||||
} else {
|
||||
fme.msg("<i>Couldn't find warp <a>%s", warpName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
39
src/main/java/com/massivecraft/factions/cmd/CmdSetFWarp.java
Normal file
39
src/main/java/com/massivecraft/factions/cmd/CmdSetFWarp.java
Normal file
@ -0,0 +1,39 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Relation;
|
||||
import com.massivecraft.factions.util.LazyLocation;
|
||||
|
||||
public class CmdSetFWarp extends FCommand {
|
||||
|
||||
public CmdSetFWarp() {
|
||||
super();
|
||||
this.aliases.add("setwarp");
|
||||
this.aliases.add("sw");
|
||||
this.requiredArgs.add("warp name");
|
||||
this.senderMustBeMember = true;
|
||||
this.senderMustBeModerator = true;
|
||||
this.senderMustBePlayer = true;
|
||||
this.permission = Permission.SETWARP.node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
if (!(fme.getRelationToLocation() == Relation.MEMBER)) {
|
||||
fme.msg("<i>You can only set warps in your faction territory.");
|
||||
return;
|
||||
}
|
||||
|
||||
int maxWarps = P.p.getConfig().getInt("max-warps", 5);
|
||||
if (maxWarps <= myFaction.getWarps().size()) {
|
||||
fme.msg("<i>Your Faction already has the max amount of warps set <a>(%d).", maxWarps);
|
||||
return;
|
||||
}
|
||||
|
||||
String warp = argAsString(0);
|
||||
LazyLocation loc = new LazyLocation(fme.getPlayer().getLocation());
|
||||
myFaction.setWarp(warp, loc);
|
||||
fme.msg("<i>Set warp <a>%s <i>to your location.", warp);
|
||||
}
|
||||
}
|
@ -57,6 +57,9 @@ public class FCmdRoot extends FCommand {
|
||||
public CmdAnnounce cmdAnnounce = new CmdAnnounce();
|
||||
public CmdSeeChunk cmdSeeChunk = new CmdSeeChunk();
|
||||
public CmdConvert cmdConvert = new CmdConvert();
|
||||
public CmdFWarp cmdFWarp = new CmdFWarp();
|
||||
public CmdSetFWarp cmdSetFWarp = new CmdSetFWarp();
|
||||
public CmdDelFWarp cmdDelFWarp = new CmdDelFWarp();
|
||||
|
||||
public FCmdRoot() {
|
||||
super();
|
||||
@ -130,6 +133,9 @@ public class FCmdRoot extends FCommand {
|
||||
this.addSubCommand(this.cmdAnnounce);
|
||||
this.addSubCommand(this.cmdSeeChunk);
|
||||
this.addSubCommand(this.cmdConvert);
|
||||
this.addSubCommand(this.cmdFWarp);
|
||||
this.addSubCommand(this.cmdSetFWarp);
|
||||
this.addSubCommand(this.cmdDelFWarp);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,7 +30,8 @@ public class FDefaultSidebar extends FSidebarProvider {
|
||||
|
||||
private String replace(FPlayer fplayer, String s) {
|
||||
String faction = !fplayer.getFaction().isNone() ? fplayer.getFaction().getTag() : "factionless";
|
||||
s = s.replace("{name}", fplayer.getName()).replace("{power}", String.valueOf(fplayer.getPowerRounded())).replace("{balance}", String.valueOf(Econ.getFriendlyBalance(fplayer.getPlayer().getUniqueId()))).replace("{faction}", faction).replace("{maxPower}", String.valueOf(fplayer.getPowerMaxRounded())).replace("{totalOnline}", String.valueOf(Bukkit.getServer().getOnlinePlayers().length));
|
||||
String powerBoost = String.valueOf((int) fplayer.getPowerBoost());
|
||||
s = s.replace("{name}", fplayer.getName()).replace("{power}", String.valueOf(fplayer.getPowerRounded())).replace("{balance}", String.valueOf(Econ.getFriendlyBalance(fplayer.getPlayer().getUniqueId()))).replace("{faction}", faction).replace("{maxPower}", String.valueOf(fplayer.getPowerMaxRounded())).replace("{totalOnline}", String.valueOf(Bukkit.getServer().getOnlinePlayers().length)).replace("{powerBoost}", powerBoost);
|
||||
return ChatColor.translateAlternateColorCodes('&', s);
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,6 @@ public class FInfoSidebar extends FSidebarProvider {
|
||||
boolean raidable = faction.getLandRounded() > faction.getPower();
|
||||
FPlayer fLeader = faction.getFPlayerAdmin();
|
||||
String leader = fLeader == null ? "Server" : fLeader.getName().substring(0, fLeader.getName().length() > 14 ? 13 : fLeader.getName().length());
|
||||
return ChatColor.translateAlternateColorCodes('&', s.replace("{power}", String.valueOf(faction.getPowerRounded())).replace("{online}", String.valueOf(faction.getOnlinePlayers().size())).replace("{members}", String.valueOf(faction.getFPlayers().size())).replace("{leader}", leader).replace("{chunks}", String.valueOf(faction.getLandRounded())).replace("{raidable}", String.valueOf(raidable)));
|
||||
return ChatColor.translateAlternateColorCodes('&', s.replace("{power}", String.valueOf(faction.getPowerRounded())).replace("{online}", String.valueOf(faction.getOnlinePlayers().size())).replace("{members}", String.valueOf(faction.getFPlayers().size())).replace("{leader}", leader).replace("{chunks}", String.valueOf(faction.getLandRounded())).replace("{raidable}", String.valueOf(raidable)).replace("{warps}", String.valueOf(faction.getWarps().size())));
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,9 @@ public enum Permission {
|
||||
UNCLAIM_ALL("unclaimall"),
|
||||
VERSION("version"),
|
||||
SCOREBOARD("scoreboard"),
|
||||
SEECHUNK("seechunk");
|
||||
SEECHUNK("seechunk"),
|
||||
SETWARP("setwarp"),
|
||||
WARP("warp");
|
||||
|
||||
public final String node;
|
||||
|
||||
|
@ -10,6 +10,7 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
public abstract class MemoryBoard extends Board {
|
||||
@ -45,6 +46,13 @@ public abstract class MemoryBoard extends Board {
|
||||
}
|
||||
|
||||
public void removeAt(FLocation flocation) {
|
||||
Faction faction = getFactionAt(flocation);
|
||||
for (String s : faction.getWarps().keySet()) {
|
||||
if (flocation.isInChunk(faction.getWarp(s).getLocation())) {
|
||||
faction.removeWarp(s);
|
||||
P.p.log(Level.INFO, "Removed warp %s from faction %s", s, faction.getTag());
|
||||
}
|
||||
}
|
||||
clearOwnershipAt(flocation);
|
||||
flocationIds.remove(flocation);
|
||||
}
|
||||
@ -62,6 +70,7 @@ public abstract class MemoryBoard extends Board {
|
||||
if (faction != null && faction.isNormal()) {
|
||||
faction.clearAllClaimOwnership();
|
||||
}
|
||||
faction.clearWarps();
|
||||
clean(factionId);
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
protected transient Set<FPlayer> fplayers = new HashSet<FPlayer>();
|
||||
protected Set<String> invites = new HashSet<String>();
|
||||
protected HashMap<String, List<String>> announcements = new HashMap<String, List<String>>();
|
||||
protected ConcurrentHashMap<String, LazyLocation> warps = new ConcurrentHashMap<String, LazyLocation>();
|
||||
|
||||
public HashMap<String, List<String>> getAnnouncements() {
|
||||
return this.announcements;
|
||||
@ -67,6 +68,34 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
||||
}
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<String, LazyLocation> getWarps() {
|
||||
return this.warps;
|
||||
}
|
||||
|
||||
public LazyLocation getWarp(String name) {
|
||||
return this.warps.get(name);
|
||||
}
|
||||
|
||||
public void setWarp(String name, LazyLocation loc) {
|
||||
this.warps.put(name, loc);
|
||||
}
|
||||
|
||||
public boolean isWarp(String name) {
|
||||
return this.warps.containsKey(name);
|
||||
}
|
||||
|
||||
public boolean removeWarp(String name) {
|
||||
if (warps.containsKey(name)) {
|
||||
warps.remove(name);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void clearWarps() {
|
||||
warps.clear();
|
||||
}
|
||||
|
||||
public Set<String> getInvites() {
|
||||
return invites;
|
||||
}
|
||||
|
@ -19,6 +19,10 @@ findfactionsexploit:
|
||||
cooldown: 2000 # in miliseconds. 2000 = 2 seconds.
|
||||
log: false
|
||||
|
||||
# Warps
|
||||
# What should be the max amount of warps that a Factoin can set?
|
||||
max-warps: 5
|
||||
|
||||
# Configuration section for Scoreboards
|
||||
# This will allow you to completely customize how your scoreboards look.
|
||||
# Make sure that no lines are duplicates of each other otherwise only the first will display.
|
||||
@ -34,6 +38,7 @@ scoreboard:
|
||||
# {power} - faction's power. {chunks} - total claimed chunks. {members} - total members.
|
||||
# {online} - online members. {leader} - faction's leader. {open} - shows either true or false if open.
|
||||
# {raidable} - true if the faction can be claimed over, otherwise false.
|
||||
# {warps} - the number of warps that a faction has set.
|
||||
# The title of the scoreboard will be the Faction's tag and colored according to the relation with the player's Faction.
|
||||
# Commenting this section out will cause the info to appear in chat as the plugin originally did.
|
||||
finfo-enabled: false # Default to false to keep original functionality.
|
||||
@ -52,6 +57,7 @@ scoreboard:
|
||||
# Replace {name} - player's name. {faction} - player's faction title, factionless if none.
|
||||
# {totalOnline} - total players on the server. {balance} - player's balance.
|
||||
# {maxPower} - player's max power.
|
||||
# {powerBoost} - player's powerboost.
|
||||
|
||||
default-enabled: false # Default to false to keep original functionality.
|
||||
default-title: "i love drt" # Can use any of the values from above but this won't update once it's set (so don't set {balance}).
|
||||
|
@ -234,3 +234,7 @@ permissions:
|
||||
description: show pending invites to your faction
|
||||
factions.seechunk:
|
||||
description: see the chunk you stand in
|
||||
factions.setwarp:
|
||||
description: set a warp for your faction
|
||||
factions.warp:
|
||||
description: access your faction warps
|
Loading…
Reference in New Issue
Block a user