Initial commit

This commit is contained in:
Scifi9902
2026-10-12 13:57:05 -03:00
commit 4bde3b176a
2576 changed files with 212659 additions and 0 deletions
Binary file not shown.
+229
View File
@@ -0,0 +1,229 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.massivecraft</groupId>
<artifactId>Factions-Legacy</artifactId>
<version>1.6.9.5-U0.5.18</version>
<packaging>jar</packaging>
<name>Factions Legacy Version Support</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<defaultGoal>clean package install</defaultGoal>
<finalName>${project.name}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bungeecord-chat</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>persistence-api</artifactId>
<groupId>javax.persistence</groupId>
</exclusion>
<exclusion>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>6.1.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bukkit</artifactId>
<groupId>org.bukkit</groupId>
</exclusion>
<exclusion>
<artifactId>bukkit-classloader-check</artifactId>
<groupId>com.sk89q.spigot</groupId>
</exclusion>
<exclusion>
<artifactId>commandbook</artifactId>
<groupId>com.sk89q</groupId>
</exclusion>
<exclusion>
<artifactId>jsr305</artifactId>
<groupId>com.google.code.findbugs</groupId>
</exclusion>
<exclusion>
<artifactId>js</artifactId>
<groupId>rhino</groupId>
</exclusion>
<exclusion>
<artifactId>truezip</artifactId>
<groupId>de.schlichtherle</groupId>
</exclusion>
<exclusion>
<artifactId>jchronic</artifactId>
<groupId>com.sk89q</groupId>
</exclusion>
<exclusion>
<artifactId>worldedit</artifactId>
<groupId>com.sk89q</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>6.1.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bukkit</artifactId>
<groupId>org.bukkit</groupId>
</exclusion>
<exclusion>
<artifactId>jsr305</artifactId>
<groupId>com.google.code.findbugs</groupId>
</exclusion>
<exclusion>
<artifactId>bukkit-classloader-check</artifactId>
<groupId>org.sk89q.bukkit</groupId>
</exclusion>
<exclusion>
<artifactId>dummypermscompat</artifactId>
<groupId>com.sk89q</groupId>
</exclusion>
<exclusion>
<artifactId>jchronic</artifactId>
<groupId>com.sk89q</groupId>
</exclusion>
<exclusion>
<artifactId>js</artifactId>
<groupId>rhino</groupId>
</exclusion>
<exclusion>
<artifactId>truezip</artifactId>
<groupId>de.schlichtherle</groupId>
</exclusion>
<exclusion>
<artifactId>jlibnoise</artifactId>
<groupId>com.sk89q.lib</groupId>
</exclusion>
<exclusion>
<artifactId>paranamer</artifactId>
<groupId>com.thoughtworks.paranamer</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
<exclusion>
<artifactId>snakeyaml</artifactId>
<groupId>org.yaml</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-core</artifactId>
<version>6.1.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bukkit</artifactId>
<groupId>org.bukkit</groupId>
</exclusion>
<exclusion>
<artifactId>jsr305</artifactId>
<groupId>com.google.code.findbugs</groupId>
</exclusion>
<exclusion>
<artifactId>bukkit-classloader-check</artifactId>
<groupId>org.sk89q.bukkit</groupId>
</exclusion>
<exclusion>
<artifactId>dummypermscompat</artifactId>
<groupId>com.sk89q</groupId>
</exclusion>
<exclusion>
<artifactId>jchronic</artifactId>
<groupId>com.sk89q</groupId>
</exclusion>
<exclusion>
<artifactId>js</artifactId>
<groupId>rhino</groupId>
</exclusion>
<exclusion>
<artifactId>truezip</artifactId>
<groupId>de.schlichtherle</groupId>
</exclusion>
<exclusion>
<artifactId>jlibnoise</artifactId>
<groupId>com.sk89q.lib</groupId>
</exclusion>
<exclusion>
<artifactId>paranamer</artifactId>
<groupId>com.thoughtworks.paranamer</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
<exclusion>
<artifactId>snakeyaml</artifactId>
<groupId>org.yaml</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<repositories>
<repository>
<id>enginehub-maven</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
</repositories>
</project>
@@ -0,0 +1,17 @@
package com.massivecraft.factions.integration;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public interface IWorldguard {
boolean isPVP(Player player);
boolean playerCanBuild(Player player, Location loc);
boolean checkForRegionsInChunk(Chunk chunk);
String getVersion();
}
@@ -0,0 +1,99 @@
package com.massivecraft.factions.integration;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
/**
* Worldguard Region Checking.
*
* @author Spathizilla
*/
public class Worldguard6 implements IWorldguard {
private WorldGuardPlugin wg;
public Worldguard6(Plugin wg) {
this.wg = (WorldGuardPlugin) wg;
}
// PVP Flag check
// Returns:
// True: PVP is allowed
// False: PVP is disallowed
public boolean isPVP(Player player) {
Location loc = player.getLocation();
World world = loc.getWorld();
Vector pt = toVector(loc);
RegionManager regionManager = wg.getRegionManager(world);
ApplicableRegionSet set = regionManager.getApplicableRegions(pt);
return set.allows(DefaultFlag.PVP);
}
// Check if player can build at location by worldguards rules.
// Returns:
// True: Player can build in the region.
// False: Player can not build in the region.
public boolean playerCanBuild(Player player, Location loc) {
World world = loc.getWorld();
Vector pt = toVector(loc);
return wg.getRegionManager(world).getApplicableRegions(pt).size() > 0 && wg.canBuild(player, loc);
}
// Check for Regions in chunk the chunk
// Returns:
// True: Regions found within chunk
// False: No regions found within chunk
public boolean checkForRegionsInChunk(Chunk chunk) {
World world = chunk.getWorld();
int minChunkX = chunk.getX() << 4;
int minChunkZ = chunk.getZ() << 4;
int maxChunkX = minChunkX + 15;
int maxChunkZ = minChunkZ + 15;
int worldHeight = world.getMaxHeight(); // Allow for heights other than default
BlockVector minChunk = new BlockVector(minChunkX, 0, minChunkZ);
BlockVector maxChunk = new BlockVector(maxChunkX, worldHeight, maxChunkZ);
RegionManager regionManager = wg.getRegionManager(world);
ProtectedCuboidRegion region = new ProtectedCuboidRegion("wgfactionoverlapcheck", minChunk, maxChunk);
Map<String, ProtectedRegion> allregions = regionManager.getRegions();
Collection<ProtectedRegion> allregionslist = new ArrayList<>(allregions.values());
List<ProtectedRegion> overlaps;
boolean foundregions = false;
try {
overlaps = region.getIntersectingRegions(allregionslist);
foundregions = overlaps != null && !overlaps.isEmpty();
} catch (Exception e) {
e.printStackTrace();
}
return foundregions;
}
@Override
public String getVersion() {
return wg.getDescription().getVersion();
}
}
@@ -0,0 +1,8 @@
package com.massivecraft.factions.listeners.versionspecific;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public interface PortalListenerBase {
boolean shouldCancel(Location location, Player player);
}
@@ -0,0 +1,29 @@
package com.massivecraft.factions.listeners.versionspecific;
import org.bukkit.TravelAgent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerPortalEvent;
/*
Supports versions older than 1.14 with TravelAgent.
*/
public class PortalListenerLegacy implements Listener {
private PortalListenerBase base;
public PortalListenerLegacy(PortalListenerBase base) {
this.base = base;
}
@EventHandler
public void onTravel(PlayerPortalEvent event) {
TravelAgent agent = event.getPortalTravelAgent();
// If they aren't able to find a portal, it'll try to create one.
if (event.useTravelAgent() && agent.getCanCreatePortal() && agent.findPortal(event.getTo()) == null) {
if (this.base.shouldCancel(event.getTo(), event.getPlayer())) {
event.setCancelled(true);
}
}
}
}
+510
View File
@@ -0,0 +1,510 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.massivecraft</groupId>
<artifactId>FactionsMain</artifactId>
<version>1.6.9.5-U0.5.18</version>
<packaging>jar</packaging>
<name>FactionsMain</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<defaultGoal>clean package install</defaultGoal>
<finalName>${project.name}</finalName>
<sourceDirectory>../../src/main/java</sourceDirectory>
<testSourceDirectory>../../src/test/java</testSourceDirectory>
<directory>../../target</directory>
<resources>
<resource>
<filtering>true</filtering>
<directory>../../src/main/resources/</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<excludes>
<exclude>com.mojang:brigadier</exclude>
<exclude>net.crankedpvp:Toggles</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<!-- Essentials is a separate Bukkit plugin and must use its own class loader. -->
<exclude>com/earth2me/essentials/**</exclude>
<exclude>net/ess3/**</exclude>
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>mkremins.fanciful</pattern>
<shadedPattern>moss.factions.shade.mkremins.fanciful</shadedPattern>
</relocation>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>moss.factions.shade.com.google</shadedPattern>
</relocation>
<relocation>
<pattern>com.darkblade12</pattern>
<shadedPattern>moss.factions.shade.com.darkblade12</shadedPattern>
</relocation>
<relocation>
<pattern>net.amoebaman.util</pattern>
<shadedPattern>moss.factions.shade.net.amoebaman.util</shadedPattern>
</relocation>
<relocation>
<pattern>me.lucko.commodore</pattern>
<shadedPattern>moss.factions.shade.me.lucko.commodore</shadedPattern>
</relocation>
<relocation>
<pattern>com.typesafe</pattern>
<shadedPattern>moss.factions.shade.com.typesafe</shadedPattern>
</relocation>
<relocation>
<pattern>ninja.leaping</pattern>
<shadedPattern>moss.factions.shade.ninja.leaping</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.http</pattern>
<shadedPattern>moss.factions.shade.org.apache.http</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons.codec</pattern>
<shadedPattern>moss.factions.shade.org.apache.commons.codec</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons.logging</pattern>
<shadedPattern>moss.factions.shade.org.apache.commons.logging</shadedPattern>
</relocation>
<relocation>
<pattern>org.kitteh</pattern>
<shadedPattern>moss.factions.shade.org.kitteh</shadedPattern>
</relocation>
<relocation>
<pattern>io.papermc.lib</pattern>
<shadedPattern>moss.factions.shade.io.paperlib</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.massivecraft</groupId>
<artifactId>Factions-Legacy</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bungeecord-chat</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>persistence-api</artifactId>
<groupId>javax.persistence</groupId>
</exclusion>
<exclusion>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bukkit</artifactId>
<groupId>org.bukkit</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-core</artifactId>
<version>7.0.0-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bukkit</artifactId>
<groupId>org.bukkit</groupId>
</exclusion>
<exclusion>
<artifactId>bukkit-classloader-check</artifactId>
<groupId>com.sk89q.spigot</groupId>
</exclusion>
<exclusion>
<artifactId>commandbook</artifactId>
<groupId>com.sk89q</groupId>
</exclusion>
<exclusion>
<artifactId>jsr305</artifactId>
<groupId>com.google.code.findbugs</groupId>
</exclusion>
<exclusion>
<artifactId>js</artifactId>
<groupId>rhino</groupId>
</exclusion>
<exclusion>
<artifactId>truezip</artifactId>
<groupId>de.schlichtherle</groupId>
</exclusion>
<exclusion>
<artifactId>jchronic</artifactId>
<groupId>com.sk89q</groupId>
</exclusion>
<exclusion>
<artifactId>worldedit</artifactId>
<groupId>com.sk89q</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-legacy</artifactId>
<version>7.0.0-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bukkit</artifactId>
<groupId>org.bukkit</groupId>
</exclusion>
<exclusion>
<artifactId>bukkit-classloader-check</artifactId>
<groupId>com.sk89q.spigot</groupId>
</exclusion>
<exclusion>
<artifactId>commandbook</artifactId>
<groupId>com.sk89q</groupId>
</exclusion>
<exclusion>
<artifactId>jsr305</artifactId>
<groupId>com.google.code.findbugs</groupId>
</exclusion>
<exclusion>
<artifactId>js</artifactId>
<groupId>rhino</groupId>
</exclusion>
<exclusion>
<artifactId>truezip</artifactId>
<groupId>de.schlichtherle</groupId>
</exclusion>
<exclusion>
<artifactId>jchronic</artifactId>
<groupId>com.sk89q</groupId>
</exclusion>
<exclusion>
<artifactId>worldedit</artifactId>
<groupId>com.sk89q</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.0.0-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bukkit</artifactId>
<groupId>org.bukkit</groupId>
</exclusion>
<exclusion>
<artifactId>jsr305</artifactId>
<groupId>com.google.code.findbugs</groupId>
</exclusion>
<exclusion>
<artifactId>bukkit-classloader-check</artifactId>
<groupId>org.sk89q.bukkit</groupId>
</exclusion>
<exclusion>
<artifactId>dummypermscompat</artifactId>
<groupId>com.sk89q</groupId>
</exclusion>
<exclusion>
<artifactId>jchronic</artifactId>
<groupId>com.sk89q</groupId>
</exclusion>
<exclusion>
<artifactId>js</artifactId>
<groupId>rhino</groupId>
</exclusion>
<exclusion>
<artifactId>truezip</artifactId>
<groupId>de.schlichtherle</groupId>
</exclusion>
<exclusion>
<artifactId>jlibnoise</artifactId>
<groupId>com.sk89q.lib</groupId>
</exclusion>
<exclusion>
<artifactId>paranamer</artifactId>
<groupId>com.thoughtworks.paranamer</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
<exclusion>
<artifactId>snakeyaml</artifactId>
<groupId>org.yaml</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>LunarAPI</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.ess3</groupId>
<artifactId>EssentialsX</artifactId>
<version>2.16.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mkremins</groupId>
<artifactId>fanciful</artifactId>
<version>0.4.0-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>jsr305</artifactId>
<groupId>com.google.code.findbugs</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.drtshock</groupId>
<artifactId>PlayerVaultsX</artifactId>
<version>4.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>taco</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/../../lib/taco.jar</systemPath>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>wine</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/../../../.lib/WineSpigot-V1.4.4.3.jar</systemPath>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>be.maximvdw</groupId>
<artifactId>MVdWPlaceholderAPI</artifactId>
<version>2.2.3-fuuid</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.darkblade12</groupId>
<artifactId>particleeffect</artifactId>
<version>1.8.0-fuuid</version>
</dependency>
<dependency>
<groupId>org.spongepowered</groupId>
<artifactId>configurate-hocon</artifactId>
<version>3.6.1</version>
<exclusions>
<exclusion>
<artifactId>checker-qual</artifactId>
<groupId>org.checkerframework</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.kitteh</groupId>
<artifactId>paste-gg-api</artifactId>
<version>0.9.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.luckperms</groupId>
<artifactId>api</artifactId>
<version>5.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.coreprotect</groupId>
<artifactId>coreprotect</artifactId>
<version>2.15.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dev.triumphteam</groupId>
<artifactId>triumph-gui</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>StorageUtilsShaded</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/../../../StorageUtils/target/StorageUtils-1.0-shaded.jar</systemPath>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>Toggles</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
<repository>
<id>fuuid-repo</id>
<url>https://github.com/factions-site/repo/raw/public</url>
</repository>
<repository>
<id>ess-repo</id>
<url>https://ci.ender.zone/plugin/repository/everything/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>enginehub-maven</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
<repository>
<id>repo.mikeprimm.com</id>
<url>https://repo.mikeprimm.com/</url>
</repository>
<repository>
<id>sponge</id>
<url>https://repo.spongepowered.org/maven</url>
</repository>
<repository>
<id>citizens-repo</id>
<url>https://repo.citizensnpcs.co</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>magic</id>
<url>https://maven.elmakers.com/repository/</url>
</repository>
<repository>
<id>minecraft-libraries</id>
<name>Minecraft Libraries</name>
<url>https://libraries.minecraft.net</url>
</repository>
<repository>
<id>net.coreprotect</id>
<url>https://maven.playpro.com/</url>
</repository>
</repositories>
</project>
+72
View File
@@ -0,0 +1,72 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.massivecraft</groupId>
<artifactId>CrankedFactions</artifactId>
<version>1.6.9.5-U0.5.18</version>
<packaging>pom</packaging>
<name>Factions</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<modules>
<module>modules/FactionsLegacy</module>
<module>modules/FactionsMain</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>persistence-api</artifactId>
<groupId>javax.persistence</groupId>
</exclusion>
<exclusion>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.gson</groupId>
</exclusion>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>taco</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/../.lib/WineSpigot-V1.4.4.3.jar</systemPath>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,90 @@
package com.massivecraft.factions;
import com.massivecraft.factions.data.json.JSONBoard;
import mkremins.fanciful.FancyMessage;
import org.bukkit.World;
import java.util.List;
import java.util.Map;
import java.util.Set;
public abstract class Board {
protected static Board instance = getBoardImpl();
//----------------------------------------------//
// Get and Set
//----------------------------------------------//
public abstract String getIdAt(FLocation flocation);
public static Board getBoardImpl() {
return new JSONBoard();
}
public static Board getInstance() {
return instance;
}
public abstract Faction getFactionAt(FLocation flocation);
public abstract Map<String, Map<String, String>> dumpAsSaveFormat();
public abstract void setIdAt(String id, FLocation flocation);
public abstract void setFactionAt(Faction faction, FLocation flocation);
public abstract void removeAt(FLocation flocation);
public abstract Set<FLocation> getAllClaims(String factionId);
public abstract Set<FLocation> getAllClaims(Faction faction);
// not to be confused with claims, ownership referring to further member-specific ownership of a claim
public abstract void clearOwnershipAt(FLocation flocation);
public abstract void unclaimAll(String factionId);
public abstract void unclaimAllInWorld(String factionId, World world);
// Is this coord NOT completely surrounded by coords claimed by the same faction?
// Simpler: Is there any nearby coord with a faction other than the faction here?
public abstract boolean isBorderLocation(FLocation flocation);
// Is this coord connected to any coord claimed by the specified faction?
public abstract boolean isConnectedLocation(FLocation flocation, Faction faction);
public abstract boolean hasFactionWithin(FLocation flocation, Faction faction, int radius);
//----------------------------------------------//
// Cleaner. Remove orphaned foreign keys
//----------------------------------------------//
public abstract void clean();
//----------------------------------------------//
// Coord count
//----------------------------------------------//
public abstract int getFactionCoordCount(String factionId);
public abstract int getFactionCoordCount(Faction faction);
public abstract int getFactionCoordCountInWorld(Faction faction, String worldName);
//----------------------------------------------//
// Map generation
//----------------------------------------------//
/**
* The map is relative to a coord and a faction north is in the direction of decreasing x east is in the direction
* of decreasing z
*/
public abstract List<FancyMessage> getMap(FPlayer fPlayer, FLocation flocation, double inDegrees);
public abstract void forceSave();
public abstract void forceSave(boolean sync);
public abstract int load();
}
@@ -0,0 +1,322 @@
package com.massivecraft.factions;
import com.massivecraft.factions.cmd.claim.CmdCorner;
import com.massivecraft.factions.util.MiscUtil;
import net.royawesome.jlibnoise.MathHelper;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import java.io.Serializable;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
public class FLocation implements Serializable {
private static final long serialVersionUID = -8292915234027387983L;
private static final boolean worldBorderSupport;
private String worldName = "world";
private int x = 0;
private int z = 0;
static {
boolean worldBorderClassPresent = false;
try {
Class.forName("org.bukkit.WorldBorder");
worldBorderClassPresent = true;
} catch (ClassNotFoundException ignored) {
}
worldBorderSupport = worldBorderClassPresent;
}
//----------------------------------------------//
// Constructors
//----------------------------------------------//
public FLocation() {
}
public FLocation(String worldName, int x, int z) {
this.worldName = worldName;
this.x = x;
this.z = z;
}
public FLocation(Location location) {
this(location.getWorld().getName(), blockToChunk(location.getBlockX()), blockToChunk(location.getBlockZ()));
}
public FLocation(Chunk chunk) {
this(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
}
public FLocation(Player player) {
this(player.getLocation());
}
public FLocation(FPlayer fplayer) {
this(fplayer.getPlayer());
}
public FLocation(Block block) {
this(block.getLocation());
}
//----------------------------------------------//
// Getters and Setters
//----------------------------------------------//
public String getWorldName() {
return worldName;
}
public World getWorld() {
return Bukkit.getWorld(worldName);
}
public void setWorldName(String worldName) {
this.worldName = worldName;
}
public long getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public void addX(int n) {
this.x = this.x + n;
}
public long getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
public void addZ(int n) {
this.z = this.z + n;
}
public String getCoordString() {
return "" + x + "," + z;
}
public Chunk getChunk() {
return new Location(getWorld(), chunkToBlock(x), 0, chunkToBlock(z)).getChunk();
}
@Override
public String toString() {
return "[" + this.getWorldName() + "," + this.getCoordString() + "]";
}
public static FLocation fromString(String string) {
int index = string.indexOf(',');
int start = 1;
String worldName = string.substring(start, index);
start = index + 1;
index = string.indexOf(',', start);
int x = Integer.parseInt(string.substring(start, index));
int y = Integer.parseInt(string.substring(index + 1, string.length() - 1));
return new FLocation(worldName, x, y);
}
//----------------------------------------------//
// Block/Chunk/Region Value Transformation
//----------------------------------------------//
// bit-shifting is used because it's much faster than standard division and multiplication
public static int blockToChunk(int blockVal) { // 1 chunk is 16x16 blocks
return blockVal >> 4; // ">> 4" == "/ 16"
}
public static int blockToRegion(int blockVal) { // 1 region is 512x512 blocks
return blockVal >> 9; // ">> 9" == "/ 512"
}
public static int chunkToRegion(int chunkVal) { // 1 region is 32x32 chunks
return chunkVal >> 5; // ">> 5" == "/ 32"
}
public static int chunkToBlock(int chunkVal) {
return chunkVal << 4; // "<< 4" == "* 16"
}
public static int regionToBlock(int regionVal) {
return regionVal << 9; // "<< 9" == "* 512"
}
public static int regionToChunk(int regionVal) {
return regionVal << 5; // "<< 5" == "* 32"
}
//----------------------------------------------//
// Misc Geometry
//----------------------------------------------//
public FLocation getRelative(int dx, int dz) {
return new FLocation(this.worldName, this.x + dx, this.z + dz);
}
public double getDistanceTo(FLocation that) {
double dx = that.x - this.x;
double dz = that.z - this.z;
return Math.sqrt(dx * dx + dz * dz);
}
public double getDistanceSquaredTo(FLocation that) {
double dx = that.x - this.x;
double dz = that.z - this.z;
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;
}
public boolean isInCorner() {
return getCorner() != null;
}
public enum EnumCorner{
POS_POS,
NEG_NEG,
POS_NEG,
NEG_POS
}
public EnumCorner getCorner() {
return getCorner(this.getChunk().getBlock(0, 0, 0).getLocation());
}
public EnumCorner getCorner(Location location){
int cx = location.getBlockX() >> 4;
int cz = location.getBlockZ() >> 4;
Location center = location.getWorld().getWorldBorder().getCenter();
int radius = (int) (location.getWorld().getWorldBorder().getSize() / 2D);
double maxX = MathHelper.floor((center.getX() + radius - 0.1) / 16.0D);
double maxZ = MathHelper.floor((center.getZ() + radius - 0.1) / 16.0D);
double minX = MathHelper.floor((center.getBlockX() - radius) / 16.0D);
double minZ = MathHelper.floor((center.getBlockZ() - radius) / 16.0D);
if(cx == maxX && cz == maxZ)return EnumCorner.POS_POS;
if(cx == maxX && cz == minZ)return EnumCorner.POS_NEG;
if(cx == minX && cz == maxZ)return EnumCorner.NEG_POS;
if(cx == minX && cz == minZ)return EnumCorner.NEG_NEG;
return null;
}
/**
* Checks if the chunk represented by this FLocation is outside the world border
*
* @param buffer the number of chunks from the border that will be treated as "outside"
* @return whether this location is outside of the border
*/
public boolean isOutsideWorldBorder(int buffer) {
if (!worldBorderSupport) {
return false;
}
WorldBorder border = getWorld().getWorldBorder();
Location center = border.getCenter();
double size = border.getSize();
int bufferBlocks = buffer << 4;
double borderMinX = (center.getX() - size / 2.0D) + bufferBlocks;
double borderMinZ = (center.getZ() - size / 2.0D) + bufferBlocks;
double borderMaxX = (center.getX() + size / 2.0D) - bufferBlocks;
double borderMaxZ = (center.getZ() + size / 2.0D) - bufferBlocks;
int chunkMinX = this.x << 4;
int chunkMaxX = chunkMinX | 15;
int chunkMinZ = this.z << 4;
int chunkMaxZ = chunkMinZ | 15;
return (chunkMinX >= borderMaxX) || (chunkMinZ >= borderMaxZ) || (chunkMaxX <= borderMinX) || (chunkMaxZ <= borderMinZ);
}
//----------------------------------------------//
// Some Geometry
//----------------------------------------------//
public Set<FLocation> getCircle(double radius) {
double radiusSquared = radius * radius;
Set<FLocation> ret = new LinkedHashSet<>();
if (radius <= 0) {
return ret;
}
int xfrom = (int) Math.floor(this.x - radius);
int xto = (int) Math.ceil(this.x + radius);
int zfrom = (int) Math.floor(this.z - radius);
int zto = (int) Math.ceil(this.z + radius);
for (int x = xfrom; x <= xto; x++) {
for (int z = zfrom; z <= zto; z++) {
FLocation potential = new FLocation(this.worldName, x, z);
if (this.getDistanceSquaredTo(potential) <= radiusSquared) {
ret.add(potential);
}
}
}
return ret;
}
public static HashSet<FLocation> getArea(FLocation from, FLocation to) {
HashSet<FLocation> ret = new HashSet<>();
for (long x : MiscUtil.range(from.getX(), to.getX())) {
for (long z : MiscUtil.range(from.getZ(), to.getZ())) {
ret.add(new FLocation(from.getWorldName(), (int) x, (int) z));
}
}
return ret;
}
//----------------------------------------------//
// Comparison
//----------------------------------------------//
@Override
public int hashCode() {
// should be fast, with good range and few hash collisions: (x * 512) + z + worldName.hashCode
return (this.x << 9) + this.z + (this.worldName != null ? this.worldName.hashCode() : 0);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof FLocation)) {
return false;
}
FLocation that = (FLocation) obj;
return this.x == that.x && this.z == that.z && (Objects.equals(this.worldName, that.worldName));
}
}
@@ -0,0 +1,306 @@
package com.massivecraft.factions;
import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.perms.Relation;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.util.SpiralTask;
import com.massivecraft.factions.util.WarmUpUtil;
import mkremins.fanciful.FancyMessage;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
/**
* Logged in players always have exactly one FPlayer instance. Logged out players may or may not have an FPlayer
* instance. They will always have one if they are part of a faction. This is because only players with a faction are
* saved to disk (in order to not waste disk space).
* <p/>
* The FPlayer is linked to a minecraft player using the player name.
* <p/>
* The same instance is always returned for the same player. This means you can use the == operator. No .equals method
* necessary.
*/
public interface FPlayer extends EconomyParticipator {
void login();
void logout();
Faction getFaction();
String getFactionId();
boolean hasFaction();
void setFaction(Faction faction);
boolean willAutoLeave();
boolean attemptRotateIn();
void setAutoLeave(boolean autoLeave);
long getLastFrostwalkerMessage();
void setLastFrostwalkerMessage();
void setMonitorJoins(boolean monitor);
boolean isMonitoringJoins();
Role getRole();
void setRole(Role role);
boolean shouldTakeFallDamage();
void setTakeFallDamage(boolean fallDamage);
double getPowerBoost();
void setPowerBoost(double powerBoost);
Faction getAutoClaimFor();
void setAutoClaimFor(Faction faction);
boolean isAutoSafeClaimEnabled();
void setIsAutoSafeClaimEnabled(boolean enabled);
boolean isAutoWarClaimEnabled();
void setIsAutoWarClaimEnabled(boolean enabled);
boolean isAdminBypassing();
boolean isVanished();
void setIsAdminBypassing(boolean val);
void setChatMode(ChatMode chatMode);
ChatMode getChatMode();
void setIgnoreAllianceChat(boolean ignore);
boolean isIgnoreAllianceChat();
void setSpyingChat(boolean chatSpying);
boolean isSpyingChat();
boolean showScoreboard();
void setShowScoreboard(boolean show);
void resetFactionData(boolean doSpoutUpdate);
void resetFactionData();
long getLastLoginTime();
void setLastLoginTime(long lastLoginTime);
boolean isMapAutoUpdating();
void setMapAutoUpdating(boolean mapAutoUpdating);
boolean hasLoginPvpDisabled();
FLocation getLastStoodAt();
void setLastStoodAt(FLocation flocation);
String getTitle();
void setTitle(CommandSender sender, String title);
String getName();
String getTag();
// Base concatenations:
String getNameAndSomething(String something);
String getNameAndTitle();
String getNameAndTag();
// Colored concatenations:
// These are used in information messages
String getNameAndTitle(Faction faction);
String getNameAndTitle(FPlayer fplayer);
// Chat Tag:
// These are injected into the format of global chat messages.
String getChatTag();
// Colored Chat Tag
String getChatTag(Faction faction);
String getChatTag(FPlayer fplayer);
int getKills();
int getDeaths();
boolean isStealth();
void setStealth(boolean stealth);
// -------------------------------
// Relation and relation colors
// -------------------------------
Relation getRelationToLocation();
//----------------------------------------------//
// Health
//----------------------------------------------//
void heal(int amnt);
//----------------------------------------------//
// Power
//----------------------------------------------//
double getPower();
void alterPower(double delta);
double getPowerMax();
double getPowerMin();
int getPowerRounded();
int getPowerMaxRounded();
int getPowerMinRounded();
void updatePower();
void losePowerFromBeingOffline();
void onDeath();
//----------------------------------------------//
// Territory
//----------------------------------------------//
boolean isInOwnTerritory();
boolean isInOthersTerritory();
boolean isInAllyTerritory();
boolean isInNeutralTerritory();
boolean isInEnemyTerritory();
void sendFactionHereMessage(Faction from);
// -------------------------------
// Actions
// -------------------------------
void leave(boolean makePay);
boolean canClaimForFaction(Faction forFaction);
boolean canClaimForFactionAtLocation(Faction forFaction, Location location, boolean notifyFailure);
boolean canClaimForFactionAtLocation(Faction forFaction, FLocation location, boolean notifyFailure);
boolean attemptClaim(Faction forFaction, Location location, boolean notifyFailure);
boolean attemptClaim(Faction forFaction, FLocation location, boolean notifyFailure);
boolean attemptClaim(Faction forFaction, FLocation location, boolean notifyFailure, SpiralTask spiralTask);
String getId();
Player getPlayer();
Location getLocation();
FLocation getFLocation();
boolean isOnline();
void sendMessage(String message);
void sendMessage(List<String> messages);
void sendFancyMessage(FancyMessage message);
void sendFancyMessage(List<FancyMessage> message);
int getMapHeight();
void setMapHeight(int height);
boolean isOnlineAndVisibleTo(Player me);
void remove();
boolean isOffline();
void setId(String id);
boolean isFlying();
void setFlying(boolean fly);
void setFlying(boolean fly, boolean damage);
boolean isAutoFlying();
void setAutoFlying(boolean autoFly);
boolean canFlyAtLocation();
boolean canFlyAtLocation(FLocation location);
boolean canFlyInFactionTerritory(Faction faction);
boolean isSeeingChunk();
void setSeeingChunk(boolean seeingChunk);
boolean isInspectMode();
void setInspectMode(boolean status);
boolean getFlyTrailsState();
void setFlyTrailsState(boolean state);
String getFlyTrailsEffect();
void setFlyTrailsEffect(String effect);
// -------------------------------
// Warmups
// -------------------------------
boolean isWarmingUp();
WarmUpUtil.Warmup getWarmupType();
void addWarmup(WarmUpUtil.Warmup warmup, int taskId);
void stopWarmup();
void clearWarmup();
void setOfflinePlayer(Player player);
}
@@ -0,0 +1,37 @@
package com.massivecraft.factions;
import com.massivecraft.factions.data.json.JSONFPlayers;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.Collection;
public abstract class FPlayers {
protected static FPlayers instance = getFPlayersImpl();
public abstract void clean();
public static FPlayers getInstance() {
return instance;
}
private static FPlayers getFPlayersImpl() {
return new JSONFPlayers();
}
public abstract Collection<FPlayer> getOnlinePlayers();
public abstract FPlayer getByPlayer(Player player);
public abstract Collection<FPlayer> getAllFPlayers();
public abstract void forceSave();
public abstract void forceSave(boolean sync);
public abstract FPlayer getByOfflinePlayer(OfflinePlayer player);
public abstract FPlayer getById(String string);
public abstract int load();
}
@@ -0,0 +1,324 @@
package com.massivecraft.factions;
import com.massivecraft.factions.iface.EconomyParticipator;
import com.massivecraft.factions.perms.Permissible;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.perms.Relation;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.BanInfo;
import com.massivecraft.factions.util.LazyLocation;
import com.massivecraft.factions.util.StrikeInfo;
import com.massivecraft.factions.util.UpgradeType;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface Faction extends EconomyParticipator {
Map<String, List<String>> getAnnouncements();
Map<String, LazyLocation> getWarps();
LazyLocation getWarp(String name);
void setWarp(String name, LazyLocation loc);
boolean isWarp(String name);
int getMaxWarps();
boolean hasWarpPassword(String warp);
boolean isWarpPassword(String warp, String password);
void setWarpPassword(String warp, String password);
boolean removeWarp(String name);
void clearWarps();
int getMaxVaults();
void setMaxVaults(int value);
void addAnnouncement(FPlayer fPlayer, String msg);
void sendUnreadAnnouncements(FPlayer fPlayer);
void removeAnnouncements(FPlayer fPlayer);
void setPayPal(String payPal);
String getPayPal();
String getAltJoinString();
String setAltOpen();
void setAltClosed();
Set<String> getInvites();
String getId();
void invite(FPlayer fplayer);
void deinvite(FPlayer fplayer);
boolean isInvited(FPlayer fplayer);
void ban(FPlayer target, FPlayer banner);
void unban(FPlayer player);
boolean isBanned(FPlayer player);
Set<BanInfo> getBannedPlayers();
boolean getOpen();
int getMaxTNT();
int getUpgrade(UpgradeType type);
void setOpen(boolean isOpen);
boolean isPeaceful();
void setPeaceful(boolean isPeaceful);
void setPeacefulExplosionsEnabled(boolean val);
boolean getPeacefulExplosionsEnabled();
boolean noExplosionsInTerritory();
boolean isPermanent();
void setPermanent(boolean isPermanent);
String getTag();
String getTag(String prefix);
String getTag(Faction otherFaction);
String getTag(FPlayer otherFplayer);
void setTag(String str);
String getComparisonTag();
String getDescription();
Inventory getChest();
void setDescription(String value);
void setHome(Location home);
void delHome();
boolean hasHome();
Location getHome();
long getFoundedDate();
void setFoundedDate(long newDate);
void confirmValidHome();
boolean noPvPInTerritory();
boolean noMonstersInTerritory();
boolean isNormal();
@Deprecated
boolean isNone();
boolean isWilderness();
boolean isSafeZone();
boolean isWarZone();
boolean isPlayerFreeType();
void setLastDeath(long time);
int getKills();
int getDeaths();
boolean hasAccess(boolean online, Permissible permissible, PermissibleAction permissibleAction);
boolean hasAccess(FPlayer player, PermissibleAction permissibleAction);
boolean isLocked(boolean online, Permissible permissible, PermissibleAction permissibleAction);
boolean setPermission(boolean online, Permissible permissible, PermissibleAction permissibleAction, boolean value);
void checkPerms();
void resetPerms();
Map<Permissible, Map<PermissibleAction, Boolean>> getPermissions();
int getLandRounded();
int getLandRoundedInWorld(String worldName);
int getTNTBank();
void setTNTBank(int amount);
// -------------------------------
// Relation and relation colors
// -------------------------------
Relation getRelationWish(Faction otherFaction);
void setRelationWish(Faction otherFaction, Relation relation);
int getRelationCount(Relation relation);
// ----------------------------------------------//
// DTR
// ----------------------------------------------//
double getDTR();
double getDTRWithoutUpdate();
void setDTR(double dtr);
long getLastDTRUpdateTime();
long getFrozenDTRUntilTime();
void setFrozenDTR(long time);
boolean isFrozenDTR();
// ----------------------------------------------//
// Power
// ----------------------------------------------//
double getPower();
double getPowerMax();
int getPowerRounded();
int getPowerMaxRounded();
Integer getPermanentPower();
void setPermanentPower(Integer permanentPower);
boolean hasPermanentPower();
double getPowerBoost();
void setPowerBoost(double powerBoost);
boolean hasLandInflation();
boolean isPowerFrozen();
// -------------------------------
// FPlayers
// -------------------------------
// maintain the reference list of FPlayers in this faction
void refreshFPlayers();
boolean addFPlayer(FPlayer fplayer);
boolean removeFPlayer(FPlayer fplayer);
List<StrikeInfo> getStrikes();
void addStrike(String reason, long time);
boolean takeStrike(int index);
int getSize();
Set<FPlayer> getFPlayers();
Set<FPlayer> getFPlayersWhereOnline(boolean online);
Set<FPlayer> getFPlayersWhereOnline(boolean online, FPlayer viewer);
FPlayer getFPlayerAdmin();
FPlayer getLeader();
List<FPlayer> getFPlayersWhereRole(Role role);
List<Player> getOnlinePlayers();
// slightly faster check than getOnlinePlayers() if you just want to see if
// there are any players online
boolean hasPlayersOnline();
void memberLoggedOff();
// used when current leader is about to be removed from the faction;
// promotes new leader, or disbands faction if no other members left
void promoteNewLeader();
Role getDefaultRole();
void setDefaultRole(Role role);
void sendMessage(String message);
void sendMessage(List<String> messages);
// ----------------------------------------------//
// Ownership of specific claims
// ----------------------------------------------//
Map<FLocation, Set<String>> getClaimOwnership();
void clearAllClaimOwnership();
void clearClaimOwnership(FLocation loc);
void clearClaimOwnership(FPlayer player);
int getCountOfClaimsWithOwners();
boolean doesLocationHaveOwnersSet(FLocation loc);
boolean isPlayerInOwnerList(FPlayer player, FLocation loc);
void setPlayerAsOwner(FPlayer player, FLocation loc);
void removePlayerAsOwner(FPlayer player, FLocation loc);
Set<String> getOwnerList(FLocation loc);
String getOwnerListString(FLocation loc);
boolean playerHasOwnershipRights(FPlayer fplayer, FLocation loc);
// ----------------------------------------------//
// Persistance and entity management
// ----------------------------------------------//
void remove();
Set<FLocation> getAllClaims();
void setId(String id);
OfflinePlayer getOfflinePlayer();
}
@@ -0,0 +1,51 @@
package com.massivecraft.factions;
import com.massivecraft.factions.data.json.JSONFactions;
import java.util.ArrayList;
import java.util.Set;
public abstract class Factions {
protected static Factions instance = getFactionsImpl();
public abstract Faction getFactionById(String id);
public abstract Faction getByTag(String str);
public abstract Faction getBestTagMatch(String start);
public abstract boolean isTagTaken(String str);
public abstract boolean isValidFactionId(String id);
public abstract Faction createFaction();
public abstract void removeFaction(String id);
public abstract Set<String> getFactionTags();
public abstract ArrayList<Faction> getAllFactions();
@Deprecated
public abstract Faction getNone();
public abstract Faction getWilderness();
public abstract Faction getSafeZone();
public abstract Faction getWarZone();
public abstract void forceSave();
public abstract void forceSave(boolean sync);
public static Factions getInstance() {
return instance;
}
private static Factions getFactionsImpl() {
return new JSONFactions();
}
public abstract int load();
}
@@ -0,0 +1,39 @@
package com.massivecraft.factions;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.Plugin;
import java.util.Set;
public interface FactionsAPI {
/**
* Gets the current API version.
*
* @return current API version
* @since API 5
*/
default int getAPIVersion() {
return 5;
}
boolean isAnotherPluginHandlingChat();
void setHandlingChat(Plugin plugin, boolean handling);
boolean shouldLetFactionsHandleThisChat(AsyncPlayerChatEvent event);
boolean isPlayerFactionChatting(Player player);
String getPlayerFactionTag(Player player);
String getPlayerFactionTagRelation(Player speaker, Player listener);
String getPlayerTitle(Player player);
Set<String> getFactionTags();
Set<String> getPlayersInFaction(String factionTag);
Set<String> getOnlinePlayersInFaction(String factionTag);
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,59 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.event.FPlayerTeleportEvent;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.Location;
public class CmdAHome extends FCommand {
public CmdAHome() {
super();
this.aliases.add("ahome");
this.requiredArgs.add("player");
this.requirements = new CommandRequirements.Builder(Permission.AHOME).noDisableOnLock().build();
}
@Override
public void perform(CommandContext context) {
FPlayer target = context.argAsBestFPlayerMatch(0);
if (target == null) {
context.msg(TL.GENERIC_NOPLAYERMATCH, context.argAsString(0));
return;
}
if (target.isOnline()) {
Faction faction = target.getFaction();
if (faction.hasHome()) {
Location destination = faction.getHome();
FPlayerTeleportEvent tpEvent = new FPlayerTeleportEvent(target, destination, FPlayerTeleportEvent.PlayerTeleportReason.AHOME);
Bukkit.getServer().getPluginManager().callEvent(tpEvent);
if (tpEvent.isCancelled()) {
return;
}
FactionsPlugin.getInstance().teleport(target.getPlayer(), destination).thenAccept(success -> {
if (success) {
context.msg(TL.COMMAND_AHOME_SUCCESS, target.getName());
target.msg(TL.COMMAND_AHOME_TARGET);
}
});
} else {
context.msg(TL.COMMAND_AHOME_NOHOME, target.getName());
}
} else {
context.msg(TL.COMMAND_AHOME_OFFLINE, target.getName());
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_AHOME_DESCRIPTION;
}
}
@@ -0,0 +1,92 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.event.FPlayerJoinEvent;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import org.bukkit.Bukkit;
public class CmdAdmin extends FCommand {
public CmdAdmin() {
super();
this.aliases.add("admin");
this.aliases.add("setadmin");
this.aliases.add("leader");
this.aliases.add("setleader");
this.requiredArgs.add("player");
this.requirements = new CommandRequirements.Builder(Permission.ADMIN).build();
}
@Override
public void perform(CommandContext context) {
FPlayer fyou = context.argAsBestFPlayerMatch(0);
if (fyou == null) {
return;
}
if(fyou.getRole() == Role.ALT){
context.msg(TL.COMMAND_PROMOTE_ISALT);
return;
}
boolean permAny = Permission.ADMIN_ANY.has(context.sender, false);
Faction targetFaction = fyou.getFaction();
if (targetFaction != context.faction && !permAny) {
context.msg(TL.COMMAND_ADMIN_NOTMEMBER, fyou.describeTo(context.fPlayer, true));
return;
}
if (context.fPlayer != null && context.fPlayer.getRole() != Role.ADMIN && !permAny) {
context.msg(TL.COMMAND_ADMIN_NOTADMIN);
return;
}
if (fyou == context.fPlayer && !permAny) {
context.msg(TL.COMMAND_ADMIN_TARGETSELF);
return;
}
// only perform a FPlayerJoinEvent when newLeader isn't actually in the faction
if (fyou.getFaction() != targetFaction) {
FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(context.player), targetFaction, FPlayerJoinEvent.PlayerJoinReason.LEADER);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
}
FPlayer admin = targetFaction.getFPlayerAdmin();
// if target player is currently admin, demote and replace him
if (fyou == admin) {
targetFaction.promoteNewLeader();
context.msg(TL.COMMAND_ADMIN_DEMOTES, fyou.describeTo(context.fPlayer, true));
fyou.msg(TL.COMMAND_ADMIN_DEMOTED, context.player == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fyou, true));
return;
}
// promote target player, and demote existing admin if one exists
if (admin != null) {
admin.setRole(Role.COLEADER);
}
fyou.setRole(Role.ADMIN);
context.msg(TL.COMMAND_ADMIN_PROMOTES, fyou.describeTo(context.fPlayer, true));
// Inform all players
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
fplayer.msg(TL.COMMAND_ADMIN_PROMOTED, context.player == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fplayer, true), fyou.describeTo(fplayer), targetFaction.describeTo(fplayer));
}
}
public TL getUsageTranslation() {
return TL.COMMAND_ADMIN_DESCRIPTION;
}
}
@@ -0,0 +1,45 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class CmdAnnounce extends FCommand {
public CmdAnnounce() {
super();
this.aliases.add("ann");
this.aliases.add("announce");
this.requiredArgs.add("message");
this.requirements = new CommandRequirements.Builder(Permission.ANNOUNCE).memberOnly().withRole(Role.MODERATOR)
.noErrorOnManyArgs()
.noDisableOnLock()
.build();
}
@Override
public void perform(CommandContext context) {
String prefix = ChatColor.GREEN + context.faction.getTag() + ChatColor.YELLOW + " [" + ChatColor.GRAY + context.player.getName() + ChatColor.YELLOW + "] " + ChatColor.RESET;
String message = StringUtils.join(context.args, " ");
for (Player player : context.faction.getOnlinePlayers()) {
player.sendMessage(prefix + message);
}
// Add for offline players.
for (FPlayer fp : context.faction.getFPlayersWhereOnline(false)) {
context.faction.addAnnouncement(fp, prefix + message);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_ANNOUNCE_DESCRIPTION;
}
}
@@ -0,0 +1,43 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.util.TL;
import java.util.ArrayList;
public class CmdAutoHelp extends FCommand {
public CmdAutoHelp() {
this.aliases.add("?");
this.aliases.add("h");
this.aliases.add("help");
this.setHelpShort("");
this.optionalArgs.put("page", "1");
}
@Override
public void perform(CommandContext context) {
if (context.commandChain.size() == 0) {
return;
}
FCommand pcmd = context.commandChain.get(context.commandChain.size() - 1);
ArrayList<String> lines = new ArrayList<>(pcmd.helpLong);
for (FCommand scmd : pcmd.subCommands) {
if (scmd.visibility == CommandVisibility.VISIBLE) {
lines.add(scmd.getUsageTemplate(context, true));
}
// TODO deal with other visibilities
}
context.sendMessage(FactionsPlugin.getInstance().txt().getPage(lines, context.argAsInt(0, 1), TL.COMMAND_AUTOHELP_HELPFOR.toString() + pcmd.aliases.get(0) + "\""));
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_HELP_DESCRIPTION;
}
}
@@ -0,0 +1,84 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.event.FPlayerLeaveEvent;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.struct.BanInfo;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import org.bukkit.Bukkit;
import java.util.logging.Level;
public class CmdBan extends FCommand {
public CmdBan() {
super();
this.aliases.add("ban");
this.requiredArgs.add("target");
this.requirements = new CommandRequirements.Builder(Permission.BAN)
.memberOnly()
.withAction(PermissibleAction.BAN)
.build();
}
@Override
public void perform(CommandContext context) {
// Good on permission checks. Now lets just ban the player.
FPlayer target = context.argAsFPlayer(0);
if (target == null) {
return; // the above method sends a message if fails to find someone.
}
if (context.fPlayer == target) {
// You may not ban yourself
context.msg(TL.COMMAND_BAN_SELF);
return;
} else if (target.getFaction() == context.faction && target.getRole().value >= context.fPlayer.getRole().value) {
// You may not ban someone that has same or higher faction rank
context.msg(TL.COMMAND_BAN_INSUFFICIENTRANK, target.getName());
return;
}
// Check if the user is already banned
for (BanInfo banInfo : context.faction.getBannedPlayers()) {
if (banInfo.getBanned().equals(target.getId())) {
context.msg(TL.COMMAND_BAN_ALREADYBANNED, target.getName());
return;
}
}
// Ban the user.
context.faction.ban(target, context.fPlayer);
context.faction.deinvite(target); // can't hurt
// If in same Faction, lets make sure to kick them and throw an event.
if (target.getFaction() == context.faction) {
FPlayerLeaveEvent event = new FPlayerLeaveEvent(target, context.faction, FPlayerLeaveEvent.PlayerLeaveReason.BANNED);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
// if someone cancels a ban, we'll get people complaining here. So lets log it.
FactionsPlugin.getInstance().log(Level.WARNING, "Attempted to ban {0} but someone cancelled the kick event. This isn't good.", target.getName());
return;
}
// Didn't get cancelled so remove them and reset their invite.
context.faction.removeFPlayer(target);
target.resetFactionData();
}
// Lets inform the people!
target.msg(TL.COMMAND_BAN_TARGET, context.faction.getTag(target.getFaction()));
context.faction.msg(TL.COMMAND_BAN_BANNED, context.fPlayer.getName(), target.getName());
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_BAN_DESCRIPTION;
}
}
@@ -0,0 +1,67 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.BanInfo;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import java.util.ArrayList;
import java.util.List;
public class CmdBanlist extends FCommand {
public CmdBanlist() {
super();
this.aliases.add("banlist");
this.aliases.add("bans");
this.aliases.add("banl");
this.optionalArgs.put("faction", "faction");
this.requirements = new CommandRequirements.Builder(Permission.BAN)
.playerOnly()
.build();
}
@Override
public void perform(CommandContext context) {
Faction target = context.faction;
if (!context.args.isEmpty()) {
target = context.argAsFaction(0);
}
if (target == null) {
context.msg(TL.COMMAND_BANLIST_INVALID.format(context.argAsString(0)));
return;
}
if (!target.isNormal()) {
context.msg(TL.COMMAND_BANLIST_NOFACTION);
return;
}
List<String> lines = new ArrayList<>();
lines.add(TL.COMMAND_BANLIST_HEADER.format(target.getBannedPlayers().size(), target.getTag(context.faction)));
int i = 1;
for (BanInfo info : target.getBannedPlayers()) {
FPlayer banned = FPlayers.getInstance().getById(info.getBanned());
FPlayer banner = FPlayers.getInstance().getById(info.getBanner());
String timestamp = TL.sdf.format(info.getTime());
lines.add(TL.COMMAND_BANLIST_ENTRY.format(i, banned.getName(), banner.getName(), timestamp));
i++;
}
for (String s : lines) {
context.fPlayer.sendMessage(s);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_BANLIST_DESCRIPTION;
}
}
@@ -0,0 +1,48 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdBoom extends FCommand {
public CmdBoom() {
super();
this.aliases.add("noboom");
this.aliases.add("explosions");
this.aliases.add("toggleexplosions");
this.optionalArgs.put("on/off", "flip");
this.requirements = new CommandRequirements.Builder(Permission.NO_BOOM)
.memberOnly()
.withRole(Role.MODERATOR)
.build();
}
@Override
public void perform(CommandContext context) {
if (!context.faction.isPeaceful()) {
context.msg(TL.COMMAND_BOOM_PEACEFULONLY);
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostNoBoom(), TL.COMMAND_BOOM_TOTOGGLE, TL.COMMAND_BOOM_FORTOGGLE)) {
return;
}
context.faction.setPeacefulExplosionsEnabled(context.argAsBool(0, !context.faction.getPeacefulExplosionsEnabled()));
String enabled = context.faction.noExplosionsInTerritory() ? TL.GENERIC_DISABLED.toString() : TL.GENERIC_ENABLED.toString();
// Inform
context.faction.msg(TL.COMMAND_BOOM_ENABLED, context.fPlayer.describeTo(context.faction), enabled);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_BOOM_DESCRIPTION;
}
}
@@ -0,0 +1,39 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdBypass extends FCommand {
public CmdBypass() {
super();
this.aliases.add("bypass");
this.optionalArgs.put("on/off", "flip");
this.requirements = new CommandRequirements.Builder(Permission.BYPASS)
.playerOnly()
.noDisableOnLock()
.build();
}
@Override
public void perform(CommandContext context) {
context.fPlayer.setIsAdminBypassing(context.argAsBool(0, !context.fPlayer.isAdminBypassing()));
// TODO: Move this to a transient field in the model??
if (context.fPlayer.isAdminBypassing()) {
context.fPlayer.msg(TL.COMMAND_BYPASS_ENABLE.toString());
FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_BYPASS_ENABLELOG.toString());
} else {
context.fPlayer.msg(TL.COMMAND_BYPASS_DISABLE.toString());
FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_BYPASS_DISABLELOG.toString());
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_BYPASS_DESCRIPTION;
}
}
@@ -0,0 +1,83 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdChat extends FCommand {
public CmdChat() {
super();
this.aliases.add("c");
this.aliases.add("chat");
this.optionalArgs.put("mode", "next");
this.requirements = new CommandRequirements.Builder(Permission.CHAT)
.memberOnly()
.noDisableOnLock()
.build();
}
@Override
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().conf().factions().chat().isFactionOnlyChat()) {
context.msg(TL.COMMAND_CHAT_DISABLED.toString());
return;
}
String modeString = context.argAsString(0);
ChatMode modeTarget = context.fPlayer.getChatMode().getNext();
// If player is cycling through chat modes
// and he is not atleast a moderator get next one
if (modeString == null && modeTarget == ChatMode.MOD) {
if (!context.fPlayer.getRole().isAtLeast(Role.MODERATOR)) {
modeTarget = modeTarget.getNext();
}
}
if (modeString != null) {
modeString = modeString.toLowerCase();
if (modeString.startsWith("m")) {
modeTarget = ChatMode.MOD;
if (!context.fPlayer.getRole().isAtLeast(Role.MODERATOR)) {
context.msg(TL.COMMAND_CHAT_INSUFFICIENTRANK);
return;
}
} else if (modeString.startsWith("p")) {
modeTarget = ChatMode.PUBLIC;
} else if (modeString.startsWith("a")) {
modeTarget = ChatMode.ALLIANCE;
} else if (modeString.startsWith("f")) {
modeTarget = ChatMode.FACTION;
} else if (modeString.startsWith("t")) {
modeTarget = ChatMode.TRUCE;
} else {
context.msg(TL.COMMAND_CHAT_INVALIDMODE);
return;
}
}
context.fPlayer.setChatMode(modeTarget);
if (context.fPlayer.getChatMode() == ChatMode.MOD) {
context.msg(TL.COMMAND_CHAT_MODE_MOD);
} else if (context.fPlayer.getChatMode() == ChatMode.PUBLIC) {
context.msg(TL.COMMAND_CHAT_MODE_PUBLIC);
} else if (context.fPlayer.getChatMode() == ChatMode.ALLIANCE) {
context.msg(TL.COMMAND_CHAT_MODE_ALLIANCE);
} else if (context.fPlayer.getChatMode() == ChatMode.TRUCE) {
context.msg(TL.COMMAND_CHAT_MODE_TRUCE);
} else {
context.msg(TL.COMMAND_CHAT_MODE_FACTION);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_CHAT_DESCRIPTION;
}
}
@@ -0,0 +1,38 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdChatSpy extends FCommand {
public CmdChatSpy() {
super();
this.aliases.add("chatspy");
this.optionalArgs.put("on/off", "flip");
this.requirements = new CommandRequirements.Builder(Permission.CHATSPY)
.playerOnly()
.noDisableOnLock()
.build();
}
@Override
public void perform(CommandContext context) {
context.fPlayer.setSpyingChat(context.argAsBool(0, !context.fPlayer.isSpyingChat()));
if (context.fPlayer.isSpyingChat()) {
context.fPlayer.msg(TL.COMMAND_CHATSPY_ENABLE);
FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_CHATSPY_ENABLELOG.toString());
} else {
context.fPlayer.msg(TL.COMMAND_CHATSPY_DISABLE);
FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_CHATSPY_DISABLELOG.toString());
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_CHATSPY_DESCRIPTION;
}
}
@@ -0,0 +1,99 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.ChatColor;
public class CmdColeader extends FCommand {
public CmdColeader() {
super();
this.aliases.add("coleader");
this.aliases.add("setcoleader");
this.aliases.add("cl");
this.aliases.add("setcl");
this.requiredArgs.add("player");
this.requirements = new CommandRequirements.Builder(Permission.COLEADER)
.memberOnly()
.withRole(Role.ADMIN)
.build();
}
@Override
public void perform(CommandContext context) {
FPlayer target = context.argAsBestFPlayerMatch(0);
if (target == null) {
FancyMessage msg = new FancyMessage(TL.COMMAND_COLEADER_CANDIDATES.toString()).color(ChatColor.GOLD);
for (FPlayer player : context.faction.getFPlayersWhereRole(Role.MODERATOR)) {
String s = player.getName();
msg.then(s + " ").color(ChatColor.WHITE)
.tooltip(TL.COMMAND_COLEADER_CLICKTOPROMOTE.toString() + s)
.command("/" + FactionsPlugin.getInstance().conf().getCommandBase().get(0) + " coleader " + s);
}
context.sendFancyMessage(msg);
return;
}
if(target.getRole() == Role.ALT){
context.msg(TL.COMMAND_PROMOTE_ISALT);
return;
}
boolean permAny = Permission.COLEADER_ANY.has(context.sender, false);
Faction targetFaction = target.getFaction();
if (targetFaction != context.faction && !permAny) {
context.msg(TL.COMMAND_COLEADER_NOTMEMBER, target.describeTo(context.fPlayer, true));
return;
}
if (context.fPlayer != null && context.fPlayer.getRole() != Role.ADMIN && !permAny) {
context.msg(TL.COMMAND_COLEADER_NOTADMIN);
return;
}
if (target == context.fPlayer && !permAny) {
context.msg(TL.COMMAND_COLEADER_SELF);
return;
}
if (target.getRole() == Role.ADMIN) {
context.msg(TL.COMMAND_COLEADER_TARGETISADMIN);
return;
}
if (target.getRole() == Role.COLEADER) {
// Revoke
target.setRole(Role.MODERATOR);
targetFaction.msg(TL.COMMAND_COLEADER_REVOKED, target.describeTo(targetFaction, true));
context.msg(TL.COMMAND_COLEADER_REVOKES, target.describeTo(context.fPlayer, true));
return;
}
// Check to see if we should allow multiple coleaders or not.
if (!FactionsPlugin.getInstance().conf().factions().other().isAllowMultipleColeaders() && !targetFaction.getFPlayersWhereRole(Role.COLEADER).isEmpty()) {
context.msg(TL.COMMAND_COLEADER_ALREADY_COLEADER);
return;
}
// Give
target.setRole(Role.COLEADER);
targetFaction.msg(TL.COMMAND_COLEADER_PROMOTED, target.describeTo(targetFaction, true));
context.msg(TL.COMMAND_COLEADER_PROMOTES, target.describeTo(context.fPlayer, true));
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_COLEADER_DESCRIPTION;
}
}
@@ -0,0 +1,34 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import org.bukkit.Location;
public class CmdCoords extends FCommand {
public CmdCoords() {
super();
this.aliases.add("coords");
this.aliases.add("coord");
this.requirements = new CommandRequirements.Builder(Permission.COORDS)
.memberOnly()
.build();
}
@Override
public void perform(CommandContext context) {
Location location = context.player.getLocation();
String message = TL.COMMAND_COORDS_MESSAGE.format(context.player.getDisplayName(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), location.getWorld().getName());
for (FPlayer fPlayer : context.faction.getFPlayers()) {
fPlayer.sendMessage(message);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_COORDS_DESCRIPTION;
}
}
@@ -0,0 +1,109 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.event.FPlayerJoinEvent;
import com.massivecraft.factions.event.FactionAttemptCreateEvent;
import com.massivecraft.factions.event.FactionCreateEvent;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.factions.util.TL;
import org.bukkit.Bukkit;
import java.util.ArrayList;
public class CmdCreate extends FCommand {
public CmdCreate() {
super();
this.aliases.add("create");
this.requiredArgs.add("faction tag");
this.requirements = new CommandRequirements.Builder(Permission.CREATE)
.playerOnly()
.build();
}
@Override
public void perform(CommandContext context) {
String tag = context.argAsString(0);
if (context.fPlayer.hasFaction()) {
context.msg(TL.COMMAND_CREATE_MUSTLEAVE);
return;
}
if (Factions.getInstance().isTagTaken(tag)) {
context.msg(TL.COMMAND_CREATE_INUSE);
return;
}
ArrayList<String> tagValidationErrors = MiscUtil.validateTag(tag);
if (tagValidationErrors.size() > 0) {
context.sendMessage(tagValidationErrors);
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
if (!context.canAffordCommand(FactionsPlugin.getInstance().conf().economy().getCostCreate(), TL.COMMAND_CREATE_TOCREATE.toString())) {
return;
}
FactionAttemptCreateEvent attemptEvent = new FactionAttemptCreateEvent(context.player, tag);
Bukkit.getServer().getPluginManager().callEvent(attemptEvent);
if (attemptEvent.isCancelled()) {
return;
}
// then make 'em pay (if applicable)
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostCreate(), TL.COMMAND_CREATE_TOCREATE, TL.COMMAND_CREATE_FORCREATE)) {
return;
}
Faction faction = Factions.getInstance().createFaction();
// TODO: Why would this even happen??? Auto increment clash??
if (faction == null) {
context.msg(TL.COMMAND_CREATE_ERROR);
return;
}
// finish setting up the Faction
faction.setTag(tag);
// trigger the faction join event for the creator
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(context.player), faction, FPlayerJoinEvent.PlayerJoinReason.CREATE);
Bukkit.getServer().getPluginManager().callEvent(joinEvent);
// join event cannot be cancelled or you'll have an empty faction
// finish setting up the FPlayer
context.fPlayer.setRole(Role.ADMIN);
context.fPlayer.setFaction(faction);
// trigger the faction creation event
FactionCreateEvent createEvent = new FactionCreateEvent(context.player, tag, faction);
Bukkit.getServer().getPluginManager().callEvent(createEvent);
for (FPlayer follower : FPlayers.getInstance().getOnlinePlayers()) {
//follower.msg(TL.COMMAND_CREATE_CREATED, context.fPlayer.describeTo(follower, true), faction.getTag(follower));
}
context.msg(TL.COMMAND_CREATE_YOUSHOULD, FCmdRoot.getInstance().cmdDescription.getUsageTemplate(context));
if (FactionsPlugin.getInstance().conf().logging().isFactionCreate()) {
FactionsPlugin.getInstance().log(context.fPlayer.getName() + TL.COMMAND_CREATE_CREATEDLOG + tag);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_CREATE_DESCRIPTION;
}
}
@@ -0,0 +1,34 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.cmd.dtr.CmdDTRGet;
import com.massivecraft.factions.cmd.dtr.CmdDTRModify;
import com.massivecraft.factions.cmd.dtr.CmdDTRResetAll;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdDTR extends FCommand {
private final CmdDTRGet cmdDTRGet;
public CmdDTR() {
super();
this.aliases.add("dtr");
this.aliases.add("deathstilraidable"); // YOLO
this.addSubCommand(this.cmdDTRGet = new CmdDTRGet());
this.addSubCommand(new CmdDTRModify());
this.addSubCommand(new CmdDTRResetAll());
this.requirements = new CommandRequirements.Builder(Permission.DTR).noDisableOnLock().build();
}
@Override
public void perform(CommandContext context) {
context.commandChain.add(this);
this.cmdDTRGet.execute(context);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_DTR_DESCRIPTION;
}
}
@@ -0,0 +1,139 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.kitteh.pastegg.PasteBuilder;
import org.kitteh.pastegg.PasteContent;
import org.kitteh.pastegg.PasteFile;
import org.kitteh.pastegg.Visibility;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.logging.Level;
public class CmdDebug extends FCommand {
public CmdDebug() {
super();
this.aliases.add("debug");
this.aliases.add("helpme");
this.optionalArgs.put("mini/full", "full");
this.requirements = new CommandRequirements.Builder(Permission.DEBUG).build();
}
@Override
public void perform(CommandContext context) {
StringBuilder mainInfo = new StringBuilder();
mainInfo.append(Bukkit.getName()).append(" version: ").append(Bukkit.getServer().getVersion()).append('\n');
mainInfo.append("Server ID: ").append(FactionsPlugin.getInstance().getServerUUID()).append('\n');
mainInfo.append("Plugin version: ").append(FactionsPlugin.getInstance().getDescription().getVersion()).append('\n');
mainInfo.append("Java version: ").append(System.getProperty("java.version")).append('\n');
if (!context.args.isEmpty() && context.argAsString(0).equalsIgnoreCase("mini")) {
for (String string : mainInfo.toString().split("\n")) {
context.msg(string);
}
return;
}
mainInfo.append('\n');
mainInfo.append("Plugins:\n");
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
mainInfo.append(' ').append(plugin.getName()).append(" - ").append(plugin.getDescription().getVersion()).append('\n');
mainInfo.append(" ").append(plugin.getDescription().getAuthors()).append('\n');
}
StringBuilder permInfo = new StringBuilder();
for (Player player : Bukkit.getOnlinePlayers()) {
permInfo.append(player.getName()).append('\n');
for (Permission permission : Permission.values()) {
permInfo.append(' ');
if (player.hasPermission(permission.toString())) {
permInfo.append('\u2713');
} else {
permInfo.append('\u2715');
}
permInfo.append(permission.toString()).append('\n');
}
permInfo.append('\n');
}
new BukkitRunnable() {
private final PasteBuilder builder = new PasteBuilder().name("FactionsUUID Debug")
.visibility(Visibility.UNLISTED)
.expires(ZonedDateTime.now(ZoneOffset.UTC).plusDays(3));
private int i = 0;
private void add(String name, String content) {
builder.addFile(new PasteFile(i++ + name, new PasteContent(PasteContent.ContentType.TEXT, content)));
}
private String getFile(Path file) {
try {
return new String(Files.readAllBytes(file), StandardCharsets.UTF_8);
} catch (IOException e) {
return ExceptionUtils.getFullStackTrace(e);
}
}
@Override
public void run() {
try {
Path dataPath = FactionsPlugin.getInstance().getDataFolder().toPath();
add("info.txt", mainInfo.toString());
add("startup.txt", plugin.getStartupLog());
if (!plugin.getStartupExceptionLog().isEmpty()) {
add("startupexceptions.txt", plugin.getStartupExceptionLog());
}
add("server.properties", getFile(Paths.get("server.properties")).replaceAll("(?:(?:server-ip=)|(?:server-port=)|(?:rcon\\.port=)|(?:rcon\\.password=)|(?:query.port=))[^\n]*[\r\n]*", ""));
add("main.conf", getFile(dataPath.resolve("config/main.conf")));
add("spigot.yml", getFile(Paths.get("spigot.yml")));
if (permInfo.length() > 0) {
add("perms.txt", permInfo.toString());
}
PasteBuilder.PasteResult result = builder.build();
new BukkitRunnable() {
@Override
public void run() {
if (result.getPaste().isPresent()) {
String delKey = result.getPaste().get().getDeletionKey().orElse("No deletion key");
context.msg(TL.COMMAND_DEBUG_COMPLETE, "https://paste.gg/anonymous/" + result.getPaste().get().getId());
context.msg(TL.COMMAND_DEBUG_DELETIONKEY, delKey);
if (context.sender instanceof Player) {
FactionsPlugin.getInstance().getLogger().info(TL.COMMAND_DEBUG_COMPLETE.format("https://paste.gg/anonymous/" + result.getPaste().get().getId()));
FactionsPlugin.getInstance().getLogger().info(TL.COMMAND_DEBUG_DELETIONKEY.format(delKey));
}
} else {
context.msg(TL.COMMAND_DEBUG_FAIL);
FactionsPlugin.getInstance().getLogger().warning("Received: " + result.getMessage());
}
}
}.runTask(FactionsPlugin.getInstance());
} catch (Exception e) {
FactionsPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to execute debug command", e);
new BukkitRunnable() {
@Override
public void run() {
context.msg(TL.COMMAND_DEBUG_FAIL);
}
}.runTask(FactionsPlugin.getInstance());
}
}
}.runTaskAsynchronously(FactionsPlugin.getInstance());
context.msg(TL.COMMAND_DEBUG_RUNNING);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_DEBUG_DESCRIPTION;
}
}
@@ -0,0 +1,60 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.ChatColor;
public class CmdDeinvite extends FCommand {
public CmdDeinvite() {
super();
this.aliases.add("deinvite");
this.aliases.add("deinv");
this.optionalArgs.put("player", "player");
//this.optionalArgs.put("", "");
this.requirements = new CommandRequirements.Builder(Permission.DEINVITE)
.memberOnly()
.withAction(PermissibleAction.INVITE)
.build();
}
@Override
public void perform(CommandContext context) {
FPlayer you = context.argAsBestFPlayerMatch(0);
if (you == null) {
FancyMessage msg = new FancyMessage(TL.COMMAND_DEINVITE_CANDEINVITE.toString()).color(ChatColor.GOLD);
for (String id : context.faction.getInvites()) {
FPlayer fp = FPlayers.getInstance().getById(id);
String name = fp != null ? fp.getName() : id;
msg.then(name + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_DEINVITE_CLICKTODEINVITE.format(name)).command("/" + FactionsPlugin.getInstance().conf().getCommandBase().get(0) + " deinvite " + name);
}
context.sendFancyMessage(msg);
return;
}
if (you.getFaction() == context.faction) {
context.msg(TL.COMMAND_DEINVITE_ALREADYMEMBER, you.getName(), context.faction.getTag());
context.msg(TL.COMMAND_DEINVITE_MIGHTWANT, FCmdRoot.getInstance().cmdKick.getUsageTemplate(context));
return;
}
context.faction.deinvite(you);
you.msg(TL.COMMAND_DEINVITE_REVOKED, context.fPlayer.describeTo(you), context.faction.describeTo(you));
context.faction.msg(TL.COMMAND_DEINVITE_REVOKES, context.fPlayer.describeTo(context.faction), you.describeTo(context.faction));
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_DEINVITE_DESCRIPTION;
}
}
@@ -0,0 +1,47 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdDelWarp extends FCommand {
public CmdDelWarp() {
super();
this.aliases.add("delwarp");
this.aliases.add("dw");
this.aliases.add("deletewarp");
this.requiredArgs.add("warp");
this.requirements = new CommandRequirements.Builder(Permission.SETWARP)
.memberOnly()
.withAction(PermissibleAction.SETWARP)
.build();
}
@Override
public void perform(CommandContext context) {
String warp = context.argAsString(0);
if (context.faction.isWarp(warp)) {
if (!transact(context.fPlayer, context)) {
return;
}
context.faction.removeWarp(warp);
context.msg(TL.COMMAND_DELFWARP_DELETED, warp);
} else {
context.msg(TL.COMMAND_DELFWARP_INVALID, warp);
}
}
private boolean transact(FPlayer player, CommandContext context) {
return player.isAdminBypassing() || context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostDelWarp(), TL.COMMAND_DELFWARP_TODELETE.toString(), TL.COMMAND_DELFWARP_FORDELETE.toString());
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_DELFWARP_DESCRIPTION;
}
}
@@ -0,0 +1,47 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdDelhome extends FCommand {
public CmdDelhome() {
this.aliases.add("delhome");
this.requirements = new CommandRequirements.Builder(Permission.DELHOME)
.memberOnly()
.withAction(PermissibleAction.SETHOME)
.build();
}
@Override
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().conf().factions().homes().isEnabled()) {
context.msg(TL.COMMAND_SETHOME_DISABLED);
return;
}
if (!context.faction.hasHome()) {
context.msg(TL.COMMAND_HOME_NOHOME.toString() + (context.fPlayer.getRole().value < Role.MODERATOR.value ? TL.GENERIC_ASKYOURLEADER.toString() : TL.GENERIC_YOUSHOULD.toString()));
context.sendMessage(FCmdRoot.getInstance().cmdSethome.getUsageTemplate(context));
return;
}
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostDelhome(), TL.COMMAND_DELHOME_TOSET, TL.COMMAND_DELHOME_FORSET)) {
return;
}
context.faction.delHome();
context.faction.msg(TL.COMMAND_DELHOME_DEL, context.fPlayer.describeTo(context.faction, true));
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_DELHOME_DESCRIPTION;
}
}
@@ -0,0 +1,56 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import com.massivecraft.factions.util.TextUtil;
public class CmdDescription extends FCommand {
public CmdDescription() {
super();
this.aliases.add("desc");
this.aliases.add("description");
this.requiredArgs.add("desc");
this.requirements = new CommandRequirements.Builder(Permission.DESCRIPTION)
.memberOnly()
.withRole(Role.MODERATOR)
.noErrorOnManyArgs()
.build();
}
@Override
public void perform(CommandContext context) {
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostDesc(), TL.COMMAND_DESCRIPTION_TOCHANGE, TL.COMMAND_DESCRIPTION_FORCHANGE)) {
return;
}
// since "&" color tags seem to work even through plain old FPlayer.sendMessage() for some reason, we need to break those up
// And replace all the % because it messes with string formatting and this is easy way around that.
context.faction.setDescription(TextUtil.implode(context.args, " ").replaceAll("%", "").replaceAll("(&([a-f0-9klmnor]))", "& $2"));
if (!FactionsPlugin.getInstance().conf().factions().chat().isBroadcastDescriptionChanges()) {
context.fPlayer.msg(TL.COMMAND_DESCRIPTION_CHANGED, context.faction.describeTo(context.fPlayer));
context.fPlayer.sendMessage(context.faction.getDescription());
return;
}
// Broadcast the description to everyone
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
fplayer.msg(TL.COMMAND_DESCRIPTION_CHANGES, context.faction.describeTo(fplayer));
fplayer.sendMessage(context.faction.getDescription()); // players can inject "&" or "`" or "<i>" or whatever in their description; &k is particularly interesting looking
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_DESCRIPTION_DESCRIPTION;
}
}
@@ -0,0 +1,125 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.event.FPlayerLeaveEvent;
import com.massivecraft.factions.event.FactionDisbandEvent;
import com.massivecraft.factions.gui.FDisbandConfirmGUI;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.scoreboards.FTeamWrapper;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import org.bukkit.Bukkit;
import java.util.concurrent.TimeUnit;
public class CmdDisband extends FCommand {
public CmdDisband() {
super();
this.aliases.add("disband");
this.optionalArgs.put("faction", "yours");
this.requirements = new CommandRequirements.Builder(Permission.DISBAND).build();
}
@Override
public void perform(CommandContext context) {
// The faction, default to your own.. but null if console sender.
Faction faction = context.argAsFaction(0, context.fPlayer == null ? null : context.faction);
if (faction == null) {
return;
}
boolean isfaction = context.fPlayer != null && faction == context.faction;
long time;
if (isfaction) {
if (!context.fPlayer.isAdminBypassing() && !faction.hasAccess(context.fPlayer, PermissibleAction.DISBAND)) {
context.msg(TL.GENERIC_NOPERMISSION.format(PermissibleAction.DISBAND));
return;
}
} else {
if (!Permission.DISBAND_ANY.has(context.sender, true)) {
return;
}
}
if (!faction.isNormal()) {
context.msg(TL.COMMAND_DISBAND_IMMUTABLE.toString());
return;
}
if (faction.isPermanent()) {
context.msg(TL.COMMAND_DISBAND_MARKEDPERMANENT.toString());
return;
}
boolean access = false;
if (context.player.hasMetadata("disband_confirm") && (time = context.player.getMetadata("disband_confirm").get(0).asLong()) != 0L && System.currentTimeMillis() - time <= TimeUnit.SECONDS.toMillis(3L)) {
access = true;
}
if (!access) {
context.player.playSound(context.player.getLocation(), "ANVIL_LAND", 1.0f, 1.4f);
FDisbandConfirmGUI fDisbandConfirmGUI = new FDisbandConfirmGUI(context.player, faction);
fDisbandConfirmGUI.getConfirmGUI().open(context.player);
return;
}
if (!FactionsPlugin.getInstance().getLandRaidControl().canDisbandFaction(faction, context)) {
return;
}
FactionDisbandEvent disbandEvent = new FactionDisbandEvent(context.player, faction.getId());
Bukkit.getServer().getPluginManager().callEvent(disbandEvent);
if (disbandEvent.isCancelled()) {
return;
}
// Send FPlayerLeaveEvent for each player in the faction
for (FPlayer fplayer : faction.getFPlayers()) {
Bukkit.getServer().getPluginManager().callEvent(new FPlayerLeaveEvent(fplayer, faction, FPlayerLeaveEvent.PlayerLeaveReason.DISBAND));
}
// Inform all players
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
String who = context.player == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fplayer);
if (fplayer.getFaction() == faction) {
fplayer.msg(TL.COMMAND_DISBAND_BROADCAST_YOURS, who);
} else {
//fplayer.msg(TL.COMMAND_DISBAND_BROADCAST_NOTYOURS, who, faction.getTag(fplayer));
}
}
if (FactionsPlugin.getInstance().conf().logging().isFactionDisband()) {
//TODO: Format this correctly and translate.
FactionsPlugin.getInstance().log("The faction " + faction.getTag() + " (" + faction.getId() + ") was disbanded by " + (context.player == null ? "console command" : context.fPlayer.getName()) + ".");
}
if (Econ.shouldBeUsed() && context.player != null) {
//Give all the faction's money to the disbander
double amount = Econ.getBalance(faction);
Econ.transferMoney(context.fPlayer, faction, context.fPlayer, amount, false);
if (amount > 0.0) {
String amountString = Econ.moneyString(amount);
context.msg(TL.COMMAND_DISBAND_HOLDINGS, amountString);
//TODO: Format this correctly and translate
FactionsPlugin.getInstance().log(context.fPlayer.getName() + " has been given bank holdings of " + amountString + " from disbanding " + faction.getTag() + ".");
}
}
Factions.getInstance().removeFaction(faction.getId());
FTeamWrapper.applyUpdates(faction);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_DISBAND_DESCRIPTION;
}
}
@@ -0,0 +1,101 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.FlightUtil;
import com.massivecraft.factions.util.TL;
import com.massivecraft.factions.util.WarmUpUtil;
public class CmdFly extends FCommand {
public CmdFly() {
super();
this.aliases.add("fly");
this.optionalArgs.put("on/off/auto", "flip");
this.requirements = new CommandRequirements.Builder(Permission.FLY)
.memberOnly()
.build();
}
@Override
public void perform(CommandContext context) {
if (context.args.size() == 0) {
if(FactionsPlugin.getInstance().isSOTW() && !Permission.SOTW.has(context.sender)){
context.fPlayer.msg(TL.PLAYER_SOTW_NOFLY);
return;
}
if (Permission.FLY_AUTO.has(context.player, false)) {
boolean did = toggleFlight(context, !context.fPlayer.isAutoFlying(), true);
if(did){
//context.fPlayer.setAutoFlying(!context.fPlayer.isAutoFlying());
}
}else{
//toggleFlight(context, !context.fPlayer.isFlying(), true);
}
} else if (context.args.size() == 1) {
if(FactionsPlugin.getInstance().isSOTW() && !Permission.SOTW.has(context.sender)){
context.fPlayer.msg(TL.PLAYER_SOTW_NOFLY);
return;
}
if (context.argAsString(0).equalsIgnoreCase("auto")) {
// Player Wants to AutoFly
if (Permission.FLY_AUTO.has(context.player, true)) {
//context.fPlayer.setAutoFlying(!context.fPlayer.isAutoFlying());
//toggleFlight(context, context.fPlayer.isAutoFlying(), false);
}
} else {
//toggleFlight(context, context.argAsBool(0), true);
}
}
}
private boolean toggleFlight(final CommandContext context, final boolean toggle, boolean notify) {
// If false do nothing besides set
if (!toggle) {
//context.fPlayer.setFlying(false);
return true;
}
// Do checks if true
if (!flyTest(context, notify)) {
return false;
}
context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> {
if (flyTest(context, notify)) {
if(FactionsPlugin.getInstance().isSOTW() && !Permission.SOTW.has(context.sender)){
context.fPlayer.msg(TL.PLAYER_SOTW_NOFLY);
}else{
//context.fPlayer.setFlying(true);
}
}
}, this.plugin.conf().commands().fly().getDelay());
return true;
}
private boolean flyTest(final CommandContext context, boolean notify) {
if (!context.fPlayer.canFlyAtLocation()) {
if (notify) {
Faction factionAtLocation = Board.getInstance().getFactionAt(context.fPlayer.getLastStoodAt());
context.msg(TL.COMMAND_FLY_NO_ACCESS, factionAtLocation.getTag(context.fPlayer));
}
return false;
} else if (FlightUtil.instance().enemiesNearby(context.fPlayer, FactionsPlugin.getInstance().conf().commands().fly().getEnemyRadius())) {
if (notify) {
context.msg(TL.COMMAND_FLY_ENEMY_NEARBY);
}
return false;
}
return true;
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_FLY_DESCRIPTION;
}
}
@@ -0,0 +1,202 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class CmdHelp extends FCommand {
public CmdHelp() {
super();
this.aliases.add("help");
this.aliases.add("h");
//this.requiredArgs.add("");
this.optionalArgs.put("page", "1");
this.requirements = new CommandRequirements.Builder(Permission.HELP).noDisableOnLock().build();
}
@Override
public void perform(CommandContext context) {
if (FactionsPlugin.getInstance().conf().commands().help().isUseOldHelp()) {
if (helpPages == null) {
updateHelp(context);
}
int page = context.argAsInt(0, 1);
context.sendMessage(plugin.txt().titleize("Factions Help (" + page + "/" + helpPages.size() + ")"));
page -= 1;
if (page < 0 || page >= helpPages.size()) {
context.msg(TL.COMMAND_HELP_404.format(String.valueOf(page)));
return;
}
context.sendMessage(helpPages.get(page));
return;
}
Map<String, List<String>> help = FactionsPlugin.getInstance().conf().commands().help().getEntries();
String pageArg = context.argAsString(0, "1");
List<String> page = help.get(pageArg);
if (page == null || page.isEmpty()) {
context.msg(TL.COMMAND_HELP_404.format(pageArg));
return;
}
for (String helpLine : page) {
context.sendMessage(FactionsPlugin.getInstance().txt().parse(helpLine));
}
}
//----------------------------------------------//
// Build the help pages
//----------------------------------------------//
public ArrayList<ArrayList<String>> helpPages;
public void updateHelp(CommandContext context) {
helpPages = new ArrayList<>();
ArrayList<String> pageLines;
pageLines = new ArrayList<>();
pageLines.add(FCmdRoot.getInstance().cmdHelp.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdList.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdShow.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdPower.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdJoin.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdLeave.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdChat.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdToggleAllianceChat.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdHome.getUsageTemplate(context, true));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_NEXTCREATE.toString()));
helpPages.add(pageLines);
pageLines = new ArrayList<>();
pageLines.add(FCmdRoot.getInstance().cmdCreate.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdDescription.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdTag.getUsageTemplate(context, true));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_INVITATIONS.toString()));
pageLines.add(FCmdRoot.getInstance().cmdOpen.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdInvite.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdDeinvite.getUsageTemplate(context, true));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_HOME.toString()));
pageLines.add(FCmdRoot.getInstance().cmdSethome.getUsageTemplate(context, true));
helpPages.add(pageLines);
if (Econ.isSetup() && FactionsPlugin.getInstance().conf().economy().isEnabled() && FactionsPlugin.getInstance().conf().economy().isBankEnabled()) {
pageLines = new ArrayList<>();
pageLines.add("");
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_BANK_1.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_BANK_2.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_BANK_3.toString()));
pageLines.add("");
pageLines.add(FCmdRoot.getInstance().cmdMoney.getUsageTemplate(context, true));
pageLines.add("");
pageLines.add("");
pageLines.add("");
helpPages.add(pageLines);
}
pageLines = new ArrayList<>();
pageLines.add(FCmdRoot.getInstance().cmdClaim.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdAutoClaim.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdUnclaim.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdUnclaimall.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdKick.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdMod.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdAdmin.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdTitle.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdSB.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdSeeChunk.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdStatus.getUsageTemplate(context, true));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_PLAYERTITLES.toString()));
helpPages.add(pageLines);
pageLines = new ArrayList<>();
pageLines.add(FCmdRoot.getInstance().cmdMap.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdBoom.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdOwner.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdOwnerList.getUsageTemplate(context, true));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_OWNERSHIP_1.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_OWNERSHIP_2.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_OWNERSHIP_3.toString()));
helpPages.add(pageLines);
pageLines = new ArrayList<>();
pageLines.add(FCmdRoot.getInstance().cmdDisband.getUsageTemplate(context, true));
pageLines.add("");
pageLines.add(FCmdRoot.getInstance().cmdRelationAlly.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdRelationNeutral.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdRelationEnemy.getUsageTemplate(context, true));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_RELATIONS_1.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_RELATIONS_2.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_RELATIONS_3.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_RELATIONS_4.toString()));
helpPages.add(pageLines);
pageLines = new ArrayList<>();
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_RELATIONS_5.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_RELATIONS_6.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_RELATIONS_7.toString()));
pageLines.add(TL.COMMAND_HELP_RELATIONS_8.toString());
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_RELATIONS_9.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_RELATIONS_10.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_RELATIONS_11.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_RELATIONS_12.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_RELATIONS_13.toString()));
helpPages.add(pageLines);
pageLines = new ArrayList<>();
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_PERMISSIONS_1.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_PERMISSIONS_2.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_PERMISSIONS_3.toString()));
pageLines.add(TL.COMMAND_HELP_PERMISSIONS_4.toString());
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_PERMISSIONS_5.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_PERMISSIONS_6.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_PERMISSIONS_7.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_PERMISSIONS_8.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_PERMISSIONS_9.toString()));
helpPages.add(pageLines);
pageLines = new ArrayList<>();
pageLines.add(TL.COMMAND_HELP_MOAR_1.toString());
pageLines.add(FCmdRoot.getInstance().cmdBypass.getUsageTemplate(context, true));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_ADMIN_1.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_ADMIN_2.toString()));
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_ADMIN_3.toString()));
pageLines.add(FCmdRoot.getInstance().cmdSafeunclaimall.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdWarunclaimall.getUsageTemplate(context, true));
//TODO:TL
pageLines.add(plugin.txt().parse("<i>Note: " + FCmdRoot.getInstance().cmdUnclaim.getUsageTemplate(context, false) + FactionsPlugin.getInstance().txt().parse("<i>") + " works on safe/war zones as well."));
pageLines.add(FCmdRoot.getInstance().cmdPeaceful.getUsageTemplate(context, true));
helpPages.add(pageLines);
pageLines = new ArrayList<>();
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_MOAR_2.toString()));
pageLines.add(FCmdRoot.getInstance().cmdChatSpy.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdPermanent.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdPermanentPower.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdPowerBoost.getUsageTemplate(context, true));
helpPages.add(pageLines);
pageLines = new ArrayList<>();
pageLines.add(plugin.txt().parse(TL.COMMAND_HELP_MOAR_3.toString()));
pageLines.add(FCmdRoot.getInstance().cmdLock.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdReload.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdSaveAll.getUsageTemplate(context, true));
pageLines.add(FCmdRoot.getInstance().cmdVersion.getUsageTemplate(context, true));
helpPages.add(pageLines);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_HELP_DESCRIPTION;
}
}
@@ -0,0 +1,169 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.event.FPlayerTeleportEvent;
import com.massivecraft.factions.integration.Essentials;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.perms.Relation;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.SmokeUtil;
import com.massivecraft.factions.util.TL;
import com.massivecraft.factions.util.WarmUpUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class CmdHome extends FCommand {
public CmdHome() {
super();
this.aliases.add("home");
this.optionalArgs.put("faction", "yours");
this.requirements = new CommandRequirements.Builder(Permission.HOME)
.playerOnly()
.noDisableOnLock()
.build();
}
@Override
public void perform(final CommandContext context) {
// TODO: Hide this command on help also.
Faction targetFaction = context.argAsFaction(0, context.fPlayer == null ? null : context.faction);
if (targetFaction != context.faction && context.fPlayer.isAdminBypassing()) {
if (targetFaction.hasHome()) {
FactionsPlugin.getInstance().teleport(context.player, targetFaction.getHome());
} else {
context.fPlayer.msg(TL.COMMAND_HOME_NOHOME.toString());
}
return;
}
if (!FactionsPlugin.getInstance().conf().factions().homes().isEnabled()) {
context.fPlayer.msg(TL.COMMAND_HOME_DISABLED);
return;
}
if (!FactionsPlugin.getInstance().conf().factions().homes().isTeleportCommandEnabled()) {
context.fPlayer.msg(TL.COMMAND_HOME_TELEPORTDISABLED);
return;
}
if (!targetFaction.hasHome()) {
if (targetFaction == context.faction) {
if (context.faction.hasAccess(context.fPlayer, PermissibleAction.SETHOME)) {
context.fPlayer.msg(TL.COMMAND_HOME_NOHOME.toString() + TL.GENERIC_YOUSHOULD.toString());
} else {
context.fPlayer.msg(TL.COMMAND_HOME_NOHOME.toString() + TL.GENERIC_ASKYOURLEADER.toString());
}
context.fPlayer.sendMessage(FCmdRoot.getInstance().cmdSethome.getUsageTemplate(context));
} else {
context.fPlayer.msg(TL.COMMAND_HOME_NOHOME.toString());
}
return;
}
if (!targetFaction.hasAccess(context.fPlayer, PermissibleAction.HOME)) {
context.fPlayer.msg(TL.COMMAND_HOME_DENIED, targetFaction.getTag(context.fPlayer));
return;
}
if (!FactionsPlugin.getInstance().conf().factions().homes().isTeleportAllowedFromEnemyTerritory() && context.fPlayer.isInEnemyTerritory()) {
context.fPlayer.msg(TL.COMMAND_HOME_INENEMY);
return;
}
if (!FactionsPlugin.getInstance().conf().factions().homes().isTeleportAllowedFromDifferentWorld() && context.player.getWorld().getUID() != targetFaction.getHome().getWorld().getUID()) {
context.fPlayer.msg(TL.COMMAND_HOME_WRONGWORLD);
return;
}
Faction faction = Board.getInstance().getFactionAt(new FLocation(context.player.getLocation()));
final Location loc = context.player.getLocation().clone();
// if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby
if (FactionsPlugin.getInstance().conf().factions().homes().getTeleportAllowedEnemyDistance() > 0 &&
!faction.isSafeZone() &&
(!context.fPlayer.isInOwnTerritory() || !FactionsPlugin.getInstance().conf().factions().homes().isTeleportIgnoreEnemiesIfInOwnTerritory())) {
World w = loc.getWorld();
double x = loc.getX();
double y = loc.getY();
double z = loc.getZ();
for (Player p : context.player.getServer().getOnlinePlayers()) {
if (p == null || !p.isOnline() || p.isDead() || p == context.player || p.getWorld() != w) {
continue;
}
FPlayer fp = FPlayers.getInstance().getByPlayer(p);
if (context.fPlayer.getRelationTo(fp) != Relation.ENEMY || fp.isVanished()) {
continue;
}
Location l = p.getLocation();
double dx = Math.abs(x - l.getX());
double dy = Math.abs(y - l.getY());
double dz = Math.abs(z - l.getZ());
double max = FactionsPlugin.getInstance().conf().factions().homes().getTeleportAllowedEnemyDistance();
// box-shaped distance check
if (dx > max || dy > max || dz > max) {
continue;
}
context.fPlayer.msg(TL.COMMAND_HOME_ENEMYNEAR, String.valueOf(FactionsPlugin.getInstance().conf().factions().homes().getTeleportAllowedEnemyDistance()));
return;
}
}
Location destination = targetFaction.getHome();
FPlayerTeleportEvent tpEvent = new FPlayerTeleportEvent(context.fPlayer, destination, FPlayerTeleportEvent.PlayerTeleportReason.HOME);
Bukkit.getServer().getPluginManager().callEvent(tpEvent);
if (tpEvent.isCancelled()) {
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostHome(), TL.COMMAND_HOME_TOTELEPORT.toString(), TL.COMMAND_HOME_FORTELEPORT.toString())) {
return;
}
// if Essentials teleport handling is enabled and available, pass the teleport off to it (for delay and cooldown)
if (Essentials.handleTeleport(context.player, destination)) {
return;
}
context.doWarmUp(WarmUpUtil.Warmup.HOME, TL.WARMUPS_NOTIFY_TELEPORT, "Home", () -> {
// Create a smoke effect
if (FactionsPlugin.getInstance().conf().factions().homes().isTeleportCommandSmokeEffectEnabled()) {
List<Location> smokeLocations = new ArrayList<>();
smokeLocations.add(loc);
smokeLocations.add(loc.add(0, 1, 0));
smokeLocations.add(destination);
smokeLocations.add(destination.clone().add(0, 1, 0));
SmokeUtil.spawnCloudRandom(smokeLocations, FactionsPlugin.getInstance().conf().factions().homes().getTeleportCommandSmokeEffectThickness());
}
FactionsPlugin.getInstance().teleport(context.player, destination);
}, this.plugin.conf().commands().home().getDelay());
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_HOME_DESCRIPTION;
}
}
@@ -0,0 +1,36 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdInspect extends FCommand {
public CmdInspect() {
super();
this.aliases.add("inspect");
this.aliases.add("ins");
this.requirements = new CommandRequirements.Builder(Permission.STEALTH)
.playerOnly()
.memberOnly()
.build();
}
@Override
public void perform(CommandContext context) {
if (context.fPlayer.isInspectMode()) {
context.fPlayer.setInspectMode(false);
context.msg(TL.COMMAND_INSPECT_DISABLED_MSG);
} else {
context.fPlayer.setInspectMode(true);
context.msg(TL.COMMAND_INSPECT_ENABLED);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_INSPECT_DESCRIPTION;
}
}
@@ -0,0 +1,76 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.ChatColor;
public class CmdInvite extends FCommand {
public CmdInvite() {
super();
this.aliases.add("invite");
this.aliases.add("inv");
this.requiredArgs.add("player");
this.requirements = new CommandRequirements.Builder(Permission.INVITE)
.memberOnly()
.withAction(PermissibleAction.INVITE)
.build();
}
@Override
public void perform(CommandContext context) {
FPlayer target = context.argAsBestFPlayerMatch(0);
if (target == null) {
return;
}
if (target.getFaction() == context.faction) {
context.msg(TL.COMMAND_INVITE_ALREADYMEMBER, target.getName(), context.faction.getTag());
context.msg(TL.GENERIC_YOUMAYWANT.toString() + FCmdRoot.getInstance().cmdKick.getUsageTemplate(context));
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostInvite(), TL.COMMAND_INVITE_TOINVITE.toString(), TL.COMMAND_INVITE_FORINVITE.toString())) {
return;
}
if (context.faction.isBanned(target)) {
context.msg(TL.COMMAND_INVITE_BANNED, target.getName());
return;
}
context.faction.invite(target);
if (!target.isOnline()) {
return;
}
// Tooltips, colors, and commands only apply to the string immediately before it.
FancyMessage message = new FancyMessage(context.fPlayer.describeTo(target, true))
.tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString())
.command("/" + FactionsPlugin.getInstance().conf().getCommandBase().get(0) + " join " + context.faction.getTag())
.then(TL.COMMAND_INVITE_INVITEDYOU.toString())
.color(ChatColor.YELLOW)
.tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString())
.command("/" + FactionsPlugin.getInstance().conf().getCommandBase().get(0) + " join " + context.faction.getTag())
.then(context.faction.describeTo(target)).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString())
.command("/" + FactionsPlugin.getInstance().conf().getCommandBase().get(0) + " join " + context.faction.getTag());
message.send(target.getPlayer());
//you.msg("%s<i> invited you to %s",context.fPlayer.describeTo(you, true), context.faction.describeTo(you));
context.faction.msg(TL.COMMAND_INVITE_INVITED, context.fPlayer.describeTo(context.faction, true), target.describeTo(context.faction));
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_INVITE_DESCRIPTION;
}
}
@@ -0,0 +1,134 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.event.FPlayerJoinEvent;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.CC;
import com.massivecraft.factions.util.TL;
import org.bukkit.Bukkit;
public class CmdJoin extends FCommand {
public CmdJoin() {
super();
this.aliases.add("join");
this.requiredArgs.add("faction");
this.optionalArgs.put("player", "you");
this.requirements = new CommandRequirements.Builder(Permission.JOIN)
.playerOnly()
.build();
}
@Override
public void perform(CommandContext context) {
Faction faction = context.argAsFaction(0);
if (faction == null) {
return;
}
FPlayer fplayer = context.argAsBestFPlayerMatch(1, context.fPlayer, false);
boolean samePlayer = fplayer == context.fPlayer;
if (!samePlayer && !Permission.JOIN_OTHERS.has(context.sender, false)) {
context.msg(TL.COMMAND_JOIN_CANNOTFORCE);
return;
}
if (fplayer.getRole() == Role.ALT && !faction.isInvited(fplayer)) {
fplayer.getPlayer().sendMessage(CC.translate("&c&l(!)&c You are not invited to this faction!"));
return;
}
if (!faction.isNormal()) {
context.msg(TL.COMMAND_JOIN_SYSTEMFACTION);
return;
}
if (faction == fplayer.getFaction()) {
//TODO:TL
context.msg(TL.COMMAND_JOIN_ALREADYMEMBER, fplayer.describeTo(context.fPlayer, true), (samePlayer ? "are" : "is"), faction.getTag(context.fPlayer));
return;
}
if (fplayer.hasFaction()) {
//TODO:TL
context.msg(TL.COMMAND_JOIN_INOTHERFACTION, fplayer.describeTo(context.fPlayer, true), (samePlayer ? "your" : "their"));
return;
}
if (!FactionsPlugin.getInstance().getLandRaidControl().canJoinFaction(faction, fplayer, context)) {
return;
}
final int memberLimit = FactionsPlugin.getInstance().conf().factions().other().getFactionMemberLimit();
if(!fplayer.isAdminBypassing()){
if (faction.getSize() >= memberLimit) {
context.msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(context.fPlayer), memberLimit, fplayer.describeTo(context.fPlayer, false));
return;
}
}
if (!(faction.getOpen() || faction.isInvited(fplayer) || context.fPlayer.isAdminBypassing() || Permission.JOIN_ANY.has(context.sender, false))) {
context.msg(TL.COMMAND_JOIN_REQUIRESINVITATION);
if (samePlayer) {
faction.msg(TL.COMMAND_JOIN_ATTEMPTEDJOIN, fplayer.describeTo(faction, true));
}
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
if (samePlayer && !context.canAffordCommand(FactionsPlugin.getInstance().conf().economy().getCostJoin(), TL.COMMAND_JOIN_TOJOIN.toString())) {
return;
}
// Check for ban
if (!context.fPlayer.isAdminBypassing() && faction.isBanned(context.fPlayer)) {
context.fPlayer.msg(TL.COMMAND_JOIN_BANNED, faction.getTag(context.fPlayer));
return;
}
// trigger the join event (cancellable)
FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.getInstance().getByPlayer(context.player), faction, FPlayerJoinEvent.PlayerJoinReason.COMMAND);
Bukkit.getServer().getPluginManager().callEvent(joinEvent);
if (joinEvent.isCancelled()) {
return;
}
// then make 'em pay (if applicable)
if (samePlayer && !context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostJoin(), TL.COMMAND_JOIN_TOJOIN.toString(), TL.COMMAND_JOIN_FORJOIN.toString())) {
return;
}
context.fPlayer.msg(TL.COMMAND_JOIN_SUCCESS, fplayer.describeTo(context.fPlayer, true), faction.getTag(context.fPlayer));
if (!samePlayer) {
fplayer.msg(TL.COMMAND_JOIN_MOVED, context.fPlayer.describeTo(fplayer, true), faction.getTag(fplayer));
}
faction.msg(TL.COMMAND_JOIN_JOINED, fplayer.describeTo(faction, true));
fplayer.resetFactionData();
fplayer.setFaction(faction);
faction.deinvite(fplayer);
fplayer.setRole(faction.getDefaultRole());
if (FactionsPlugin.getInstance().conf().logging().isFactionJoin()) {
if (samePlayer) {
FactionsPlugin.getInstance().log(TL.COMMAND_JOIN_JOINEDLOG.toString(), fplayer.getName(), faction.getTag());
} else {
FactionsPlugin.getInstance().log(TL.COMMAND_JOIN_MOVEDLOG.toString(), context.fPlayer.getName(), fplayer.getName(), faction.getTag());
}
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_JOIN_DESCRIPTION;
}
}
@@ -0,0 +1,133 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.event.FPlayerLeaveEvent;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
public class CmdKick extends FCommand {
public CmdKick() {
super();
this.aliases.add("kick");
this.optionalArgs.put("player", "player");
this.requirements = new CommandRequirements.Builder(Permission.KICK)
.memberOnly()
.withAction(PermissibleAction.KICK)
.noDisableOnLock()
.build();
}
@Override
public void perform(CommandContext context) {
FPlayer toKick = context.argIsSet(0) ? context.argAsBestFPlayerMatch(0) : null;
if (toKick == null) {
FancyMessage msg = new FancyMessage(TL.COMMAND_KICK_CANDIDATES.toString()).color(ChatColor.GOLD);
for (FPlayer player : context.faction.getFPlayersWhereRole(Role.NORMAL)) {
String s = player.getName();
msg.then(s + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_KICK_CLICKTOKICK.toString() + s).command("/" + FactionsPlugin.getInstance().conf().getCommandBase().get(0) + " kick " + s);
}
if (context.fPlayer.getRole().isAtLeast(Role.COLEADER)) {
// For both coleader and admin, add mods.
for (FPlayer player : context.faction.getFPlayersWhereRole(Role.MODERATOR)) {
String s = player.getName();
msg.then(s + " ").color(ChatColor.GRAY).tooltip(TL.COMMAND_KICK_CLICKTOKICK.toString() + s).command("/" + FactionsPlugin.getInstance().conf().getCommandBase().get(0) + " kick " + s);
}
if (context.fPlayer.getRole() == Role.ADMIN) {
// Only add coleader to this for the leader.
for (FPlayer player : context.faction.getFPlayersWhereRole(Role.COLEADER)) {
String s = player.getName();
msg.then(s + " ").color(ChatColor.RED).tooltip(TL.COMMAND_KICK_CLICKTOKICK.toString() + s).command("/" + FactionsPlugin.getInstance().conf().getCommandBase().get(0) + " kick " + s);
}
}
}
context.sendFancyMessage(msg);
return;
}
if (context.fPlayer == toKick) {
context.msg(TL.COMMAND_KICK_SELF);
context.msg(TL.GENERIC_YOUMAYWANT.toString() + FCmdRoot.getInstance().cmdLeave.getUsageTemplate(context));
return;
}
Faction toKickFaction = toKick.getFaction();
// players with admin-level "disband" permission can bypass these requirements
if (!Permission.KICK_ANY.has(context.sender)) {
if (toKickFaction != context.faction) {
context.msg(TL.COMMAND_KICK_NOTMEMBER, toKick.describeTo(context.fPlayer, true), context.faction.describeTo(context.fPlayer));
return;
}
if (toKick.getRole().value >= context.fPlayer.getRole().value) {
context.msg(TL.COMMAND_KICK_INSUFFICIENTRANK);
return;
}
if (toKick.getRole().value == context.fPlayer.getRole().value) {
context.msg(TL.COMMAND_KICK_INSUFFICIENTRANK);
return;
}
if (!FactionsPlugin.getInstance().getLandRaidControl().canKick(toKick, context)) {
return;
}
}
if (toKickFaction.isWilderness()) {
context.sender.sendMessage(TL.COMMAND_KICK_NONE.toString());
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
if (!context.canAffordCommand(FactionsPlugin.getInstance().conf().economy().getCostKick(), TL.COMMAND_KICK_TOKICK.toString())) {
return;
}
// trigger the leave event (cancellable) [reason:kicked]
FPlayerLeaveEvent event = new FPlayerLeaveEvent(toKick, toKick.getFaction(), FPlayerLeaveEvent.PlayerLeaveReason.KICKED);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
// then make 'em pay (if applicable)
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostKick(), TL.COMMAND_KICK_TOKICK.toString(), TL.COMMAND_KICK_FORKICK.toString())) {
return;
}
toKickFaction.msg(TL.COMMAND_KICK_FACTION, context.fPlayer.describeTo(toKickFaction, true), toKick.describeTo(toKickFaction, true));
toKick.msg(TL.COMMAND_KICK_KICKED, context.fPlayer.describeTo(toKick, true), toKickFaction.describeTo(toKick));
if (toKickFaction != context.faction) {
context.msg(TL.COMMAND_KICK_KICKS, toKick.describeTo(context.fPlayer), toKickFaction.describeTo(context.fPlayer));
}
if (FactionsPlugin.getInstance().conf().logging().isFactionKick()) {
FactionsPlugin.getInstance().log((context.player == null ? "A console command" : context.fPlayer.getName()) + " kicked " + toKick.getName() + " from the faction: " + toKickFaction.getTag());
}
if (toKick.getRole() == Role.ADMIN) {
toKickFaction.promoteNewLeader();
}
toKickFaction.deinvite(toKick);
toKick.resetFactionData();
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_KICK_DESCRIPTION;
}
}
@@ -0,0 +1,33 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import java.util.*;
public class CmdLeave extends FCommand {
public CmdLeave() {
super();
this.aliases.add("leave");
this.requirements = new CommandRequirements.Builder(Permission.LEAVE)
.memberOnly()
.build();
}
private Map<UUID, Long> confirm = new HashMap<>();
@Override
public void perform(CommandContext context) {
context.fPlayer.leave(true);
}
@Override
public TL getUsageTranslation() {
return TL.LEAVE_DESCRIPTION;
}
}
@@ -0,0 +1,118 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.tag.Tag;
import com.massivecraft.factions.util.TL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
public class CmdList extends FCommand {
public CmdList() {
super();
this.aliases.add("list");
this.aliases.add("ls");
this.optionalArgs.put("page", "1");
this.requirements = new CommandRequirements.Builder(Permission.LIST).build();
}
@Override
public void perform(CommandContext context) {
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostList(), "to list the factions", "for listing the factions")) {
return;
}
ArrayList<Faction> factionList = Factions.getInstance().getAllFactions();
factionList.remove(Factions.getInstance().getWilderness());
factionList.remove(Factions.getInstance().getSafeZone());
factionList.remove(Factions.getInstance().getWarZone());
// remove exempt factions
if (!context.sender.hasPermission(Permission.SHOW_BYPASS_EXEMPT.toString())) {
List<String> exemptFactions = FactionsPlugin.getInstance().conf().commands().show().getExempt();
factionList.removeIf(next -> exemptFactions.contains(next.getTag()));
}
// Sort by total followers first
factionList.sort(this.compare(Faction::getFPlayers));
// Then sort by how many members are online now
factionList.sort(this.compare(f -> f.getFPlayersWhereOnline(true)));
ArrayList<String> lines = new ArrayList<>();
factionList.add(0, Factions.getInstance().getWilderness());
final int pageheight = 9;
int pagenumber = context.argAsInt(0, 1);
int pagecount = (factionList.size() / pageheight) + 1;
if (pagenumber > pagecount) {
pagenumber = pagecount;
} else if (pagenumber < 1) {
pagenumber = 1;
}
int start = (pagenumber - 1) * pageheight;
int end = start + pageheight;
if (end > factionList.size()) {
end = factionList.size();
}
String header = plugin.conf().commands().list().getHeader();
String footer = plugin.conf().commands().list().getFooter();
if (!header.isEmpty()) {
header = header.replace("{pagenumber}", String.valueOf(pagenumber)).replace("{pagecount}", String.valueOf(pagecount));
lines.add(plugin.txt().parse(header));
}
for (Faction faction : factionList.subList(start, end)) {
if (faction.isWilderness()) {
continue;
}
String entry = plugin.conf().commands().list().getEntry();
if(context.fPlayer != null && context.fPlayer.getFaction() != faction && !Permission.CLAIM_SEEALL.has(context.sender)){
entry = entry.replace("{chunks}", "???");
}
lines.add(plugin.txt().parse(Tag.parsePlain(faction, context.fPlayer, entry)));
}
if (!footer.isEmpty()) {
footer = footer.replace("{pagenumber}", String.valueOf(pagenumber)).replace("{pagecount}", String.valueOf(pagecount));
lines.add(plugin.txt().parse(footer));
}
context.sendMessage(lines);
}
private Comparator<Faction> compare(Function<Faction, ? extends Collection<?>> func) {
return (f1, f2) -> {
int f1Size = func.apply(f1).size();
int f2Size = func.apply(f2).size();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
};
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_LIST_DESCRIPTION;
}
}
@@ -0,0 +1,165 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.World;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
import java.util.Set;
public class CmdListClaims extends FCommand {
public CmdListClaims() {
super();
this.aliases.add("listclaims");
this.aliases.add("listclaim");
this.optionalArgs.put("world", "currentworld");
this.optionalArgs.put("faction", "yours");
this.requirements = new CommandRequirements.Builder(Permission.LISTCLAIMS)
.withAction(PermissibleAction.LISTCLAIMS)
.memberOnly()
.build();
}
@Override
public void perform(CommandContext context) {
World world = context.player.getWorld();
if (context.argIsSet(0)) {
world = Bukkit.getWorld(context.argAsString(0));
}
if (world == null) {
context.msg(TL.COMMAND_LISTCLAIMS_INVALIDWORLD, context.argAsString(0));
return;
}
Faction faction = context.faction;
if (context.argIsSet(1)) {
if (Permission.LISTCLAIMS_OTHER.has(context.sender, true)) {
faction = context.argAsFaction(1);
} else {
return;
}
}
if (faction == null) {
context.msg(TL.GENERIC_NOFACTIONMATCH, context.argAsString(1));
return;
}
Map<Long, FLoc> worldClaims = new HashMap<>();
for (FLocation loc : Board.getInstance().getAllClaims(faction)) {
if (loc.getWorld().equals(world)) {
worldClaims.put(getLong(loc.getX(), (int) loc.getZ()), new FLoc(loc.getX(), loc.getZ()));
}
}
if (worldClaims.isEmpty()) {
context.msg(TL.COMMAND_LISTCLAIMS_NOCLAIMS, faction.getTag(), world.getName());
return;
}
Set<FLoc> set;
Queue<FLoc> queue;
FLoc cur;
List<FLoc> displayList = new ArrayList<>();
for (FLoc activeLoc : worldClaims.values()) {
if (activeLoc.processed) {
continue;
}
set = new HashSet<>();
set.add(activeLoc);
queue = new LinkedList<>();
queue.add(activeLoc);
while (!queue.isEmpty()) {
cur = queue.poll();
cur.processed = true;
addIf(set, queue, worldClaims.get(getLong(cur.x, cur.z + 1)));
addIf(set, queue, worldClaims.get(getLong(cur.x, cur.z - 1)));
addIf(set, queue, worldClaims.get(getLong(cur.x + 1, cur.z)));
addIf(set, queue, worldClaims.get(getLong(cur.x - 1, cur.z)));
}
if (set.size() == 1) {
displayList.add(activeLoc);
} else {
long tX = 0;
long tZ = 0;
for (FLoc loc : set) {
tX += loc.x;
tZ += loc.z;
}
cur = new FLoc((int) (((double) tX) / set.size() + 0.5), (int) (((double) tZ) / set.size() + 0.5));
cur.total = set.size();
displayList.add(cur);
}
}
context.msg(TL.COMMAND_LISTCLAIMS_MESSAGE, faction.getTag(), world.getName());
StringBuilder builder = new StringBuilder();
String str;
final String separator = " ";
for (FLoc loc : displayList) {
str = (loc.x << 4 | 8) + "," + (loc.z << 4 | 8) + (loc.total > 1 ? (" (" + loc.total + ")") : "");
if (builder.length() + separator.length() + str.length() > 75) {
context.msg(builder.toString());
builder.setLength(0);
} else if (builder.length() > 0) {
builder.append(separator);
}
builder.append(str);
}
if (builder.length() > 0) {
context.msg(builder.toString());
}
}
private void addIf(Set<FLoc> set, Queue<FLoc> queue, FLoc loc) {
if (loc != null && !set.contains(loc)) {
set.add(loc);
queue.add(loc);
}
}
private long getLong(long x, int z) {
return (x << 32) | z;
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_LISTCLAIMS_DESCRIPTION;
}
private class FLoc {
private int x;
private int z;
private boolean processed;
private int total = 1;
public FLoc(long x, long z) {
this.x = (int) x;
this.z = (int) z;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FLoc fLoc = (FLoc) o;
return x == fLoc.x && z == fLoc.z;
}
@Override
public int hashCode() {
return Objects.hash(x, z);
}
}
}
@@ -0,0 +1,35 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdLock extends FCommand {
// TODO: This solution needs refactoring.
/*
factions.lock:
description: use the /f lock [on/off] command to temporarily lock the data files from being overwritten
default: op
*/
public CmdLock() {
super();
this.aliases.add("lock");
this.optionalArgs.put("on/off", "flip");
this.requirements = new CommandRequirements.Builder(Permission.LOCK).noDisableOnLock().build();
}
@Override
public void perform(CommandContext context) {
plugin.setLocked(context.argAsBool(0, !plugin.getLocked()));
context.msg(plugin.getLocked() ? TL.COMMAND_LOCK_LOCKED : TL.COMMAND_LOCK_UNLOCKED);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_LOCK_DESCRIPTION;
}
}
@@ -0,0 +1,31 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdLogins extends FCommand {
public CmdLogins() {
super();
this.aliases.add("login");
this.aliases.add("logins");
this.aliases.add("logout");
this.aliases.add("logouts");
this.requirements = new CommandRequirements.Builder(Permission.MONITOR_LOGINS)
.memberOnly()
.build();
}
@Override
public void perform(CommandContext context) {
boolean monitor = context.fPlayer.isMonitoringJoins();
context.msg(TL.COMMAND_LOGINS_TOGGLE, String.valueOf(!monitor));
context.fPlayer.setMonitorJoins(!monitor);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_LOGINS_DESCRIPTION;
}
}
@@ -0,0 +1,64 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdMap extends FCommand {
public CmdMap() {
super();
this.aliases.add("map");
this.optionalArgs.put("on/off", "once");
this.requirements = new CommandRequirements.Builder(Permission.MAP)
.playerOnly()
.noDisableOnLock()
.build();
}
@Override
public void perform(CommandContext context) {
if (context.argIsSet(0)) {
if (context.argAsBool(0, !context.fPlayer.isMapAutoUpdating())) {
// Turn on
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostMap(), "to show the map", "for showing the map")) {
return;
}
context.fPlayer.setMapAutoUpdating(true);
context.msg(TL.COMMAND_MAP_UPDATE_ENABLED);
// And show the map once
showMap(context);
} else {
// Turn off
context.fPlayer.setMapAutoUpdating(false);
context.msg(TL.COMMAND_MAP_UPDATE_DISABLED);
}
} else {
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostMap(), TL.COMMAND_MAP_TOSHOW, TL.COMMAND_MAP_FORSHOW)) {
return;
}
showMap(context);
}
}
public void showMap(CommandContext context) {
context.sendFancyMessage(Board.getInstance().getMap(context.fPlayer, new FLocation(context.fPlayer), context.fPlayer.getPlayer().getLocation().getYaw()));
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_MAP_DESCRIPTION;
}
}
@@ -0,0 +1,39 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdMapHeight extends FCommand {
public CmdMapHeight() {
super();
this.aliases.add("mapheight");
this.aliases.add("mh");
this.optionalArgs.put("height", "height");
this.requirements = new CommandRequirements.Builder(Permission.MAPHEIGHT)
.playerOnly()
.build();
}
@Override
public void perform(CommandContext context) {
if (context.args.size() == 0) {
context.fPlayer.sendMessage(TL.COMMAND_MAPHEIGHT_CURRENT.format(context.fPlayer.getMapHeight()));
return;
}
int height = context.argAsInt(0);
context.fPlayer.setMapHeight(height);
context.fPlayer.sendMessage(TL.COMMAND_MAPHEIGHT_SET.format(context.fPlayer.getMapHeight()));
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_MAPHEIGHT_DESCRIPTION;
}
}
@@ -0,0 +1,89 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.ChatColor;
public class CmdMod extends FCommand {
public CmdMod() {
super();
this.aliases.add("mod");
this.aliases.add("setmod");
this.aliases.add("officer");
this.aliases.add("setofficer");
this.optionalArgs.put("player", "player");
this.requirements = new CommandRequirements.Builder(Permission.MOD)
.memberOnly()
.withRole(Role.COLEADER)
.build();
}
@Override
public void perform(CommandContext context) {
FPlayer you = context.argAsBestFPlayerMatch(0);
if (you == null) {
FancyMessage msg = new FancyMessage(TL.COMMAND_MOD_CANDIDATES.toString()).color(ChatColor.GOLD);
for (FPlayer player : context.faction.getFPlayersWhereRole(Role.NORMAL)) {
String s = player.getName();
msg.then(s + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_MOD_CLICKTOPROMOTE.toString() + s).command("/" + FactionsPlugin.getInstance().conf().getCommandBase().get(0) + " mod " + s);
}
context.sendFancyMessage(msg);
return;
}
if(you.getRole() == Role.ALT){
context.msg(TL.COMMAND_PROMOTE_ISALT);
return;
}
boolean permAny = Permission.MOD_ANY.has(context.sender, false);
Faction targetFaction = you.getFaction();
if (targetFaction != context.faction && !permAny) {
context.msg(TL.COMMAND_MOD_NOTMEMBER, you.describeTo(context.fPlayer, true));
return;
}
if (context.fPlayer != null && context.fPlayer.getRole() != Role.ADMIN && !permAny) {
context.msg(TL.COMMAND_MOD_NOTADMIN);
return;
}
if (you == context.fPlayer && !permAny) {
context.msg(TL.COMMAND_MOD_SELF);
return;
}
if (you.getRole() == Role.ADMIN) {
context.msg(TL.COMMAND_MOD_TARGETISADMIN);
return;
}
if (you.getRole() == Role.MODERATOR) {
// Revoke
you.setRole(Role.NORMAL);
targetFaction.msg(TL.COMMAND_MOD_REVOKED, you.describeTo(targetFaction, true));
context.msg(TL.COMMAND_MOD_REVOKES, you.describeTo(context.fPlayer, true));
} else {
// Give
you.setRole(Role.MODERATOR);
targetFaction.msg(TL.COMMAND_MOD_PROMOTED, you.describeTo(targetFaction, true));
context.msg(TL.COMMAND_MOD_PROMOTES, you.describeTo(context.fPlayer, true));
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_MOD_DESCRIPTION;
}
}
@@ -0,0 +1,43 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdModifyPower extends FCommand {
public CmdModifyPower() {
super();
this.aliases.add("pm");
this.aliases.add("mp");
this.aliases.add("modifypower");
this.aliases.add("modpower");
this.requiredArgs.add("name");
this.requiredArgs.add("power");
this.requirements = new CommandRequirements.Builder(Permission.MODIFY_POWER).build();
}
@Override
public void perform(CommandContext context) {
// /f modify <name> #
FPlayer player = context.argAsBestFPlayerMatch(0);
Double number = context.argAsDouble(1); // returns null if not a Double.
if (player == null || number == null) {
context.sender.sendMessage(getHelpShort());
return;
}
player.alterPower(number);
int newPower = player.getPowerRounded(); // int so we don't have super long doubles.
context.msg(TL.COMMAND_MODIFYPOWER_ADDED, number, player.getName(), newPower);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_MODIFYPOWER_DESCRIPTION;
}
}
@@ -0,0 +1,76 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.tag.Tag;
import com.massivecraft.factions.util.TL;
import org.bukkit.Location;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class CmdNear extends FCommand {
public CmdNear() {
super();
this.aliases.add("near");
this.requirements = new CommandRequirements.Builder(Permission.NEAR)
.memberOnly()
.build();
}
@Override
public void perform(CommandContext context) {
int radius = FactionsPlugin.getInstance().conf().commands().near().getRadius();
Set<FPlayer> onlineMembers = context.faction.getFPlayersWhereOnline(true, context.fPlayer);
List<FPlayer> nearbyMembers = new ArrayList<>();
int radiusSquared = radius * radius;
Location loc = context.player.getLocation();
Location cur = new Location(loc.getWorld(), 0, 0, 0);
for (FPlayer player : onlineMembers) {
if (player == context.fPlayer) {
continue;
}
player.getPlayer().getLocation(cur);
if (cur.getWorld().getUID().equals(loc.getWorld().getUID()) && cur.distanceSquared(loc) <= radiusSquared) {
nearbyMembers.add(player);
}
}
StringBuilder playerMessageBuilder = new StringBuilder();
String playerMessage = TL.COMMAND_NEAR_PLAYER.toString();
for (FPlayer member : nearbyMembers) {
playerMessageBuilder.append(parsePlaceholders(context.fPlayer, member, playerMessage));
}
// Append none text if no players where found
if (playerMessageBuilder.toString().isEmpty()) {
playerMessageBuilder.append(TL.COMMAND_NEAR_NONE);
}
context.msg(TL.COMMAND_NEAR_PLAYERLIST.toString().replace("{players-nearby}", playerMessageBuilder.toString()));
}
private String parsePlaceholders(FPlayer user, FPlayer target, String string) {
string = Tag.parsePlain(target, string);
string = Tag.parsePlaceholders(target.getPlayer(), string);
string = string.replace("{role}", target.getRole().toString());
string = string.replace("{role-prefix}", target.getRole().getPrefix());
// Only run distance calculation if needed
if (string.contains("{distance}")) {
double distance = Math.round(user.getPlayer().getLocation().distance(target.getPlayer().getLocation()));
string = string.replace("{distance}", distance + "");
}
return string;
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_NEAR_DESCRIPTION;
}
}
@@ -0,0 +1,50 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdOpen extends FCommand {
public CmdOpen() {
super();
this.aliases.add("open");
this.optionalArgs.put("yes/no", "flip");
this.requirements = new CommandRequirements.Builder(Permission.OPEN)
.playerOnly()
.noDisableOnLock()
.withRole(Role.MODERATOR)
.build();
}
@Override
public void perform(CommandContext context) {
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostOpen(), TL.COMMAND_OPEN_TOOPEN, TL.COMMAND_OPEN_FOROPEN)) {
return;
}
context.faction.setOpen(context.argAsBool(0, !context.faction.getOpen()));
String open = context.faction.getOpen() ? TL.COMMAND_OPEN_OPEN.toString() : TL.COMMAND_OPEN_CLOSED.toString();
// Inform
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
if (fplayer.getFactionId().equals(context.faction.getId())) {
fplayer.msg(TL.COMMAND_OPEN_CHANGES, context.fPlayer.getName(), open);
}
//fplayer.msg(TL.COMMAND_OPEN_CHANGED, context.faction.getTag(fplayer.getFaction()), open);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_OPEN_DESCRIPTION;
}
}
@@ -0,0 +1,102 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdOwner extends FCommand {
public CmdOwner() {
super();
this.aliases.add("owner");
this.optionalArgs.put("player", "you");
this.requirements = new CommandRequirements.Builder(Permission.OWNER)
.withAction(PermissibleAction.OWNER)
.playerOnly()
.build();
}
// TODO: Fix colors!
@Override
public void perform(CommandContext context) {
boolean hasBypass = context.fPlayer.isAdminBypassing();
if (!hasBypass && !context.assertHasFaction()) {
return;
}
if (!FactionsPlugin.getInstance().conf().factions().ownedArea().isEnabled()) {
context.msg(TL.COMMAND_OWNER_DISABLED);
return;
}
if (!hasBypass && FactionsPlugin.getInstance().conf().factions().ownedArea().getLimitPerFaction() > 0 && context.faction.getCountOfClaimsWithOwners() >= FactionsPlugin.getInstance().conf().factions().ownedArea().getLimitPerFaction()) {
context.msg(TL.COMMAND_OWNER_LIMIT, FactionsPlugin.getInstance().conf().factions().ownedArea().getLimitPerFaction());
return;
}
FLocation flocation = new FLocation(context.fPlayer);
Faction factionHere = Board.getInstance().getFactionAt(flocation);
if (factionHere != context.faction) {
if (!factionHere.isNormal()) {
context.msg(TL.COMMAND_OWNER_NOTCLAIMED);
return;
}
if (!hasBypass) {
context.msg(TL.COMMAND_OWNER_WRONGFACTION);
return;
}
}
FPlayer target = context.argAsBestFPlayerMatch(0, context.fPlayer);
if (target == null) {
return;
}
String playerName = target.getName();
if (target.getFaction() != context.faction) {
context.msg(TL.COMMAND_OWNER_NOTMEMBER, playerName);
return;
}
// if no player name was passed, and this claim does already have owners set, clear them
if (context.args.isEmpty() && context.faction.doesLocationHaveOwnersSet(flocation)) {
context.faction.clearClaimOwnership(flocation);
context.msg(TL.COMMAND_OWNER_CLEARED);
return;
}
if (context.faction.isPlayerInOwnerList(target, flocation)) {
context.faction.removePlayerAsOwner(target, flocation);
context.msg(TL.COMMAND_OWNER_REMOVED, playerName);
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostOwner(), TL.COMMAND_OWNER_TOSET, TL.COMMAND_OWNER_FORSET)) {
return;
}
context.faction.setPlayerAsOwner(target, flocation);
context.msg(TL.COMMAND_OWNER_ADDED, playerName);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_OWNER_DESCRIPTION;
}
}
@@ -0,0 +1,64 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdOwnerList extends FCommand {
public CmdOwnerList() {
super();
this.aliases.add("ownerlist");
this.requirements = new CommandRequirements.Builder(Permission.OWNERLIST)
.playerOnly()
.noDisableOnLock()
.build();
}
@Override
public void perform(CommandContext context) {
boolean hasBypass = context.fPlayer.isAdminBypassing();
if (!hasBypass && !context.assertHasFaction()) {
return;
}
if (!FactionsPlugin.getInstance().conf().factions().ownedArea().isEnabled()) {
context.msg(TL.COMMAND_OWNERLIST_DISABLED);
return;
}
FLocation flocation = new FLocation(context.fPlayer);
if (Board.getInstance().getFactionAt(flocation) != context.faction) {
if (!hasBypass) {
context.msg(TL.COMMAND_OWNERLIST_WRONGFACTION);
return;
}
//TODO: This code won't ever be called.
context.faction = Board.getInstance().getFactionAt(flocation);
if (!context.faction.isNormal()) {
context.msg(TL.COMMAND_OWNERLIST_NOTCLAIMED);
return;
}
}
String owners = context.faction.getOwnerListString(flocation);
if (owners == null || owners.isEmpty()) {
context.msg(TL.COMMAND_OWNERLIST_NONE);
return;
}
context.msg(TL.COMMAND_OWNERLIST_OWNERS, owners);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_OWNERLIST_DESCRIPTION;
}
}
@@ -0,0 +1,53 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdPeaceful extends FCommand {
public CmdPeaceful() {
super();
this.aliases.add("peaceful");
this.requiredArgs.add("faction");
this.requirements = new CommandRequirements.Builder(Permission.SET_PEACEFUL).build();
}
@Override
public void perform(CommandContext context) {
Faction faction = context.argAsFaction(0);
if (faction == null) {
return;
}
String change;
if (faction.isPeaceful()) {
change = TL.COMMAND_PEACEFUL_REVOKE.toString();
faction.setPeaceful(false);
} else {
change = TL.COMMAND_PEACEFUL_GRANT.toString();
faction.setPeaceful(true);
}
// Inform all players
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
String blame = (context.fPlayer == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fplayer, true));
if (fplayer.getFaction() == faction) {
fplayer.msg(TL.COMMAND_PEACEFUL_YOURS, blame, change);
} else {
fplayer.msg(TL.COMMAND_PEACEFUL_OTHER, blame, change, faction.getTag(fplayer));
}
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_PEACEFUL_DESCRIPTION;
}
}
@@ -0,0 +1,129 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.gui.PermissibleActionGUI;
import com.massivecraft.factions.gui.PermissibleRelationGUI;
import com.massivecraft.factions.perms.Permissible;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.perms.Relation;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class CmdPerm extends FCommand {
public CmdPerm() {
super();
this.aliases.add("perm");
this.aliases.add("perms");
this.aliases.add("permission");
this.aliases.add("permissions");
this.optionalArgs.put("relation", "relation");
this.optionalArgs.put("action", "action");
this.optionalArgs.put("access", "access");
this.requirements = new CommandRequirements.Builder(Permission.PERMISSIONS)
.memberOnly()
.withRole(Role.ADMIN)
.build();
}
@Override
public void perform(CommandContext context) {
if (context.args.size() == 0) {
PermissibleRelationGUI ui = new PermissibleRelationGUI(true, context.fPlayer);
ui.open();
return;
} else if (context.args.size() == 1 && getPermissible(context.argAsString(0)) != null) {
PermissibleActionGUI ui = new PermissibleActionGUI(true, context.fPlayer, getPermissible(context.argAsString(0)));
ui.open();
return;
}
// If not opening GUI, then setting the permission manually.
if (context.args.size() < 3) {
context.fPlayer.msg(TL.COMMAND_PERM_DESCRIPTION);
return;
}
Set<Permissible> permissibles = new HashSet<>();
Set<PermissibleAction> permissibleActions = new HashSet<>();
boolean allRelations = context.argAsString(0).equalsIgnoreCase("all");
boolean allActions = context.argAsString(1).equalsIgnoreCase("all");
boolean online = true;
if (FactionsPlugin.getInstance().conf().factions().other().isSeparateOfflinePerms() && context.args.size() == 4 && "offline".equalsIgnoreCase(context.argAsString(3))) {
online = false;
}
if (allRelations) {
permissibles.addAll(context.faction.getPermissions().keySet());
} else {
Permissible permissible = getPermissible(context.argAsString(0));
if (permissible == null) {
context.fPlayer.msg(TL.COMMAND_PERM_INVALID_RELATION);
return;
}
permissibles.add(permissible);
}
if (allActions) {
permissibleActions.addAll(Arrays.asList(PermissibleAction.values()));
} else {
PermissibleAction permissibleAction = PermissibleAction.fromString(context.argAsString(1));
if (permissibleAction == null) {
context.fPlayer.msg(TL.COMMAND_PERM_INVALID_ACTION);
return;
}
permissibleActions.add(permissibleAction);
}
boolean access;
switch (context.argAsString(2).toLowerCase()) {
case "allow":
case "true":
access = true;
break;
case "deny":
case "false":
access = false;
break;
default:
context.fPlayer.msg(TL.COMMAND_PERM_INVALID_ACCESS);
return;
}
for (Permissible permissible : permissibles) {
for (PermissibleAction permissibleAction : permissibleActions) {
context.fPlayer.getFaction().setPermission(online, permissible, permissibleAction, access);
}
}
context.fPlayer.msg(TL.COMMAND_PERM_SET, context.argAsString(1), access, context.argAsString(0));
FactionsPlugin.getInstance().log(String.format(TL.COMMAND_PERM_SET.toString(), context.argAsString(1), access, context.argAsString(0)) + " for faction " + context.fPlayer.getTag());
}
private Permissible getPermissible(String name) {
if (Role.fromString(name.toUpperCase()) != null) {
return Role.fromString(name.toUpperCase());
} else if (Relation.fromString(name.toUpperCase()) != null) {
return Relation.fromString(name.toUpperCase());
} else {
return null;
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_PERM_DESCRIPTION;
}
}
@@ -0,0 +1,55 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdPermanent extends FCommand {
public CmdPermanent() {
super();
this.aliases.add("permanent");
this.requiredArgs.add("faction");
this.requirements = new CommandRequirements.Builder(Permission.SET_PERMANENT).build();
}
@Override
public void perform(CommandContext context) {
Faction faction = context.argAsFaction(0);
if (faction == null) {
return;
}
String change;
if (faction.isPermanent()) {
change = TL.COMMAND_PERMANENT_REVOKE.toString();
faction.setPermanent(false);
} else {
change = TL.COMMAND_PERMANENT_GRANT.toString();
faction.setPermanent(true);
}
FactionsPlugin.getInstance().log((context.fPlayer == null ? "A server admin" : context.fPlayer.getName()) + " " + change + " the faction \"" + faction.getTag() + "\".");
// Inform all players
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
String blame = (context.fPlayer == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fplayer, true));
if (fplayer.getFaction() == faction) {
fplayer.msg(TL.COMMAND_PERMANENT_YOURS, blame, change);
} else {
fplayer.msg(TL.COMMAND_PERMANENT_OTHER, blame, change, faction.getTag(fplayer));
}
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_PERMANENT_DESCRIPTION;
}
}
@@ -0,0 +1,52 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdPermanentPower extends FCommand {
public CmdPermanentPower() {
super();
this.aliases.add("permanentpower");
this.requiredArgs.add("faction");
this.requiredArgs.add("power");
this.requirements = new CommandRequirements.Builder(Permission.SET_PERMANENTPOWER).build();
}
@Override
public void perform(CommandContext context) {
Faction targetFaction = context.argAsFaction(0);
if (targetFaction == null) {
return;
}
Integer targetPower = context.argAsInt(1);
targetFaction.setPermanentPower(targetPower);
String change = TL.COMMAND_PERMANENTPOWER_REVOKE.toString();
if (targetFaction.hasPermanentPower()) {
change = TL.COMMAND_PERMANENTPOWER_GRANT.toString();
}
// Inform sender
context.msg(TL.COMMAND_PERMANENTPOWER_SUCCESS, change, targetFaction.describeTo(context.fPlayer));
// Inform all other players
for (FPlayer fplayer : targetFaction.getFPlayersWhereOnline(true)) {
if (fplayer == context.fPlayer) {
continue;
}
String blame = (context.fPlayer == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fplayer, true));
fplayer.msg(TL.COMMAND_PERMANENTPOWER_FACTION, blame, change);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_PERMANENTPOWER_DESCRIPTION;
}
}
@@ -0,0 +1,46 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdPower extends FCommand {
public CmdPower() {
super();
this.aliases.add("power");
this.aliases.add("pow");
this.optionalArgs.put("player", "you");
this.requirements = new CommandRequirements.Builder(Permission.POWER).noDisableOnLock().build();
}
@Override
public void perform(CommandContext context) {
FPlayer target = context.argAsBestFPlayerMatch(0, context.fPlayer);
if (target == null) {
return;
}
if (target != context.fPlayer && !Permission.POWER_ANY.has(context.sender, true)) {
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostPower(), TL.COMMAND_POWER_TOSHOW, TL.COMMAND_POWER_FORSHOW)) {
return;
}
double powerBoost = target.getPowerBoost();
String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? TL.COMMAND_POWER_BONUS.toString() : TL.COMMAND_POWER_PENALTY.toString()) + powerBoost + ")";
context.msg(TL.COMMAND_POWER_POWER, target.describeTo(context.fPlayer, true), target.getPowerRounded(), target.getPowerMaxRounded(), boost);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_POWER_DESCRIPTION;
}
}
@@ -0,0 +1,81 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdPowerBoost extends FCommand {
public CmdPowerBoost() {
super();
this.aliases.add("powerboost");
this.requiredArgs.add("p/f/player/faction");
this.requiredArgs.add("name");
this.requiredArgs.add("#/reset");
this.requirements = new CommandRequirements.Builder(Permission.POWERBOOST).build();
}
@Override
public void perform(CommandContext context) {
String type = context.argAsString(0).toLowerCase();
boolean doPlayer = true;
if (type.equals("f") || type.equals("faction")) {
doPlayer = false;
} else if (!type.equals("p") && !type.equals("player")) {
context.msg(TL.COMMAND_POWERBOOST_HELP_1);
context.msg(TL.COMMAND_POWERBOOST_HELP_2);
return;
}
Double targetPower = context.argAsDouble(2);
if (targetPower == null) {
if (context.argAsString(2).equalsIgnoreCase("reset")) {
targetPower = 0D;
} else {
context.msg(TL.COMMAND_POWERBOOST_INVALIDNUM);
return;
}
}
String target;
if (doPlayer) {
FPlayer targetPlayer = context.argAsBestFPlayerMatch(1);
if (targetPlayer == null) {
return;
}
if (targetPower != 0) {
targetPower += targetPlayer.getPowerBoost();
}
targetPlayer.setPowerBoost(targetPower);
target = TL.COMMAND_POWERBOOST_PLAYER.format(targetPlayer.getName());
} else {
Faction targetFaction = context.argAsFaction(1);
if (targetFaction == null) {
return;
}
if (targetPower != 0) {
targetPower += targetFaction.getPowerBoost();
}
targetFaction.setPowerBoost(targetPower);
target = TL.COMMAND_POWERBOOST_FACTION.format(targetFaction.getTag());
}
int roundedPower = (int) Math.round(targetPower);
context.msg(TL.COMMAND_POWERBOOST_BOOST, target, roundedPower);
if (context.player != null) {
FactionsPlugin.getInstance().log(TL.COMMAND_POWERBOOST_BOOSTLOG.toString(), context.fPlayer.getName(), target, roundedPower);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_POWERBOOST_DESCRIPTION;
}
}
@@ -0,0 +1,105 @@
package com.massivecraft.factions.cmd;
import com.lunarclient.bukkitapi.LunarClientAPI;
import com.lunarclient.bukkitapi.object.LCWaypoint;
import com.massivecraft.factions.struct.RallyWaypoint;
import com.massivecraft.factions.util.CC;
import com.massivecraft.factions.util.TL;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
public class CmdRally extends FCommand {
private final Map<Player, Long> cooldownMap;
private final Map<Player, RallyWaypoint> rallyWaypointMap;
public CmdRally() {
super();
this.aliases.add("rally");
this.cooldownMap = new HashMap<>();
this.rallyWaypointMap = new HashMap<>();
}
private boolean isOnCooldown(Player player) {
if(!this.cooldownMap.containsKey(player)) return false;
return (cooldownMap.get(player) + 7000) > System.currentTimeMillis();
}
private String getFormattedCooldown(Player player) {
if(!isOnCooldown(player)) return "error";
return (((cooldownMap.get(player) + 7000) - System.currentTimeMillis()) / 1000) + "s";
}
@Override
public void perform(CommandContext context) {
CommandSender commandSender = context.sender;
if(!(commandSender instanceof Player)) return;
Player player = (Player)commandSender;
if(!context.faction.isNormal()) {
commandSender.sendMessage(CC.translate("&cYou must be in a faction to use /f rally."));
player.playSound(player.getLocation(), "ANVIL_LAND", 2.0f, 2.0f);
return;
}
/*
if(!LunarClientAPI.getInstance().isRunningLunarClient(player)) {
player.sendMessage(CC.translate("&cYou must be running lunar client to use f rally!"));
player.playSound(player.getLocation(), "ANVIL_LAND", 2.0f, 2.0f);
return;
} */
if(isOnCooldown(player)) {
player.sendMessage(CC.translate("&cYou cannot use /f rally for " + getFormattedCooldown(player)));
player.playSound(player.getLocation(), "ANVIL_LAND", 2.0f, 2.0f);
return;
}
if(this.rallyWaypointMap.containsKey(player)) {
RallyWaypoint rallyWaypoint = this.rallyWaypointMap.get(player);
for(Player whoSee : rallyWaypoint.getPlayersSentTo()) {
if(!whoSee.isOnline()) continue;
if(!LunarClientAPI.getInstance().isRunningLunarClient(whoSee)) continue;
LunarClientAPI.getInstance().removeWaypoint(whoSee, rallyWaypoint.getLcWaypoint());
}
}
this.cooldownMap.put(player, System.currentTimeMillis());
LCWaypoint waypoint = new LCWaypoint(player.getName() + "'s Rally", player.getLocation(), 20, true);
RallyWaypoint rallyWaypoint = new RallyWaypoint(waypoint, context.faction.getOnlinePlayers());
this.removeAfterThirtySeconds(rallyWaypoint);
this.rallyWaypointMap.put(player, rallyWaypoint);
for(Player loopPlayer : context.faction.getOnlinePlayers()) {
String message = (TL.RALLY_COORDS_MESSAGE.toString()).replace("%player%", player.getName())
.replace("%x%", String.valueOf(waypoint.getX()))
.replace("%y%", String.valueOf(waypoint.getY()))
.replace("%z%", String.valueOf(waypoint.getZ()))
.replace("%world%", String.valueOf(waypoint.getWorld()))
;
loopPlayer.sendMessage(CC.translate(message));
if(!LunarClientAPI.getInstance().isRunningLunarClient(loopPlayer)) continue;
loopPlayer.playSound(loopPlayer.getLocation(), "CHICKEN_EGG_POP", 2.0f, 2.0f);
System.out.println("send waypoint to " + loopPlayer);
LunarClientAPI.getInstance().sendWaypoint(loopPlayer, waypoint);
}
}
private void removeAfterThirtySeconds(RallyWaypoint rallyWaypoint) {
super.plugin.getServer().getScheduler().runTaskLater(super.plugin, () -> {
for(Player playersSentTo : rallyWaypoint.getPlayersSentTo()) {
LunarClientAPI.getInstance().removeWaypoint(playersSentTo, rallyWaypoint.getLcWaypoint());
}
}, 30 * 20L);
}
@Override
public TL getUsageTranslation() {
return TL.RALLY_DESCRIPTION;
}
}
@@ -0,0 +1,31 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdReload extends FCommand {
public CmdReload() {
super();
this.aliases.add("reload");
this.requirements = new CommandRequirements.Builder(Permission.RELOAD).noDisableOnLock().build();
}
@Override
public void perform(CommandContext context) {
long timeInitStart = System.currentTimeMillis();
FactionsPlugin.getInstance().getConfigManager().loadConfigs();
FactionsPlugin.getInstance().reloadConfig();
FactionsPlugin.getInstance().loadLang();
long timeReload = (System.currentTimeMillis() - timeInitStart);
context.msg(TL.COMMAND_RELOAD_TIME, timeReload);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_RELOAD_DESCRIPTION;
}
}
@@ -0,0 +1,35 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.scoreboards.FScoreboard;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdSB extends FCommand {
public CmdSB() {
this.aliases.add("sb");
this.aliases.add("scoreboard");
this.requirements = new CommandRequirements.Builder(Permission.SCOREBOARD)
.playerOnly()
.build();
}
@Override
public void perform(CommandContext context) {
boolean toggleTo = !context.fPlayer.showScoreboard();
FScoreboard board = FScoreboard.get(context.fPlayer);
if (board == null) {
context.player.sendMessage(TL.COMMAND_TOGGLESB_DISABLED.toString());
} else {
context.player.sendMessage(TL.TOGGLE_SB.toString().replace("{value}", String.valueOf(toggleTo)));
board.setSidebarVisibility(toggleTo);
}
context.fPlayer.setShowScoreboard(toggleTo);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SCOREBOARD_DESCRIPTION;
}
}
@@ -0,0 +1,32 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdSaveAll extends FCommand {
public CmdSaveAll() {
super();
this.aliases.add("saveall");
this.aliases.add("save");
this.requirements = new CommandRequirements.Builder(Permission.SAVE).noDisableOnLock().build();
}
@Override
public void perform(CommandContext context) {
FPlayers.getInstance().forceSave(false);
Factions.getInstance().forceSave(false);
Board.getInstance().forceSave(false);
context.msg(TL.COMMAND_SAVEALL_SUCCESS);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SAVEALL_DESCRIPTION;
}
}
@@ -0,0 +1,45 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.SeeChunkUtil;
import com.massivecraft.factions.util.TL;
public class CmdSeeChunk extends FCommand {
private final boolean useParticles;
public CmdSeeChunk() {
super();
this.aliases.add("seechunk");
this.aliases.add("sc");
this.requirements = new CommandRequirements.Builder(Permission.SEECHUNK)
.playerOnly()
.build();
useParticles = FactionsPlugin.getInstance().conf().commands().seeChunk().isParticles();
}
@Override
public void perform(CommandContext context) {
if (useParticles) {
boolean toggle = false;
if (context.args.size() == 0) {
toggle = !context.fPlayer.isSeeingChunk();
} else if (context.args.size() == 1) {
toggle = context.argAsBool(0);
}
context.fPlayer.setSeeingChunk(toggle);
context.msg(TL.COMMAND_SEECHUNK_TOGGLE, toggle ? "enabled" : "disabled");
} else {
SeeChunkUtil.showPillars(context.player, context.fPlayer, null, false);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SEECHUNK_DESCRIPTION;
}
}
@@ -0,0 +1,37 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdSeePaypal extends FCommand{
public CmdSeePaypal(){
super();
this.aliases.add("seepaypal");
this.requiredArgs.add("faction");
this.requirements = new CommandRequirements.Builder(Permission.SEEPAYPAL).playerOnly().build();
}
@Override
public void perform(CommandContext context) {
Faction faction = context.argAsFaction(0);
if(faction == null){
return;
}
if(faction.getPayPal() == null || faction.getPayPal().isEmpty()){
context.fPlayer.msg(TL.COMMAND_SEEPAYPAL_ISNTSET, faction.describeTo(context.fPlayer));
return;
}
context.fPlayer.msg(TL.COMMAND_SEEPAYPAL_SEE, faction.describeTo(context.fPlayer), faction.getPayPal());
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SEEPAYPAL_DESCRIPTION;
}
}
@@ -0,0 +1,45 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdSetDefaultRole extends FCommand {
public CmdSetDefaultRole() {
super();
this.aliases.add("defaultrole");
this.aliases.add("defaultrank");
this.aliases.add("default");
this.aliases.add("def");
this.requiredArgs.add("role");
this.requirements = new CommandRequirements.Builder(Permission.DEFAULTRANK)
.memberOnly()
.withRole(Role.ADMIN)
.build();
}
@Override
public void perform(CommandContext context) {
Role target = Role.fromString(context.argAsString(0).toUpperCase());
if (target == null) {
context.msg(TL.COMMAND_SETDEFAULTROLE_INVALIDROLE, context.argAsString(0));
return;
}
if (target == Role.ADMIN) {
context.msg(TL.COMMAND_SETDEFAULTROLE_NOTTHATROLE, context.argAsString(0));
return;
}
context.faction.setDefaultRole(target);
context.msg(TL.COMMAND_SETDEFAULTROLE_SUCCESS, target.nicename);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SETDEFAULTROLE_DESCRIPTION;
}
}
@@ -0,0 +1,45 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import org.bukkit.ChatColor;
public class CmdSetMaxVaults extends FCommand {
public CmdSetMaxVaults() {
this.aliases.add("setmaxvaults");
this.aliases.add("smv");
this.requiredArgs.add("faction");
this.requiredArgs.add("number");
this.requirements = new CommandRequirements.Builder(Permission.SETMAXVAULTS)
.noDisableOnLock()
.build();
}
@Override
public void perform(CommandContext context) {
Faction targetFaction = context.argAsFaction(0);
int value = context.argAsInt(1, -1);
if (value < 0) {
context.sender.sendMessage(ChatColor.RED + "Number must be greater than 0.");
return;
}
if (targetFaction == null) {
context.sender
.sendMessage(ChatColor.RED + "Couldn't find Faction: " + ChatColor.YELLOW + context.argAsString(0));
return;
}
targetFaction.setMaxVaults(value);
context.sender.sendMessage(TL.COMMAND_SETMAXVAULTS_SUCCESS.format(targetFaction.getTag(), value));
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SETMAXVAULTS_DESCRIPTION;
}
}
@@ -0,0 +1,46 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdSetPaypal extends FCommand{
public CmdSetPaypal(){
super();
this.aliases.add("setpaypal");
this.requiredArgs.add("paypal link");
this.requirements = new CommandRequirements.Builder(Permission.SETPAYPAL).memberOnly().build();
}
@Override
public void perform(CommandContext context) {
if(context.fPlayer.getRole() != Role.ADMIN && !context.fPlayer.isAdminBypassing()){
context.fPlayer.msg(TL.COMMAND_SETPAYPAL_NOTADMIN);
return;
}
String payPalLink = context.argAsString(0);
if(payPalLink == null || payPalLink.isEmpty()){
context.fPlayer.msg(TL.COMMAND_SETPAYPAL_NOTVALID, "null");
return;
}
if(!payPalLink.contains("@") || !payPalLink.contains(".")){
context.fPlayer.msg(TL.COMMAND_SETPAYPAL_NOTVALID, payPalLink);
return;
}
context.fPlayer.getFaction().setPayPal(payPalLink);
context.fPlayer.msg(TL.COMMAND_SETPAYPAL_SUCCESS, payPalLink);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SETPAYPAL_DESCRIPTION;
}
}
@@ -0,0 +1,64 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.perms.Relation;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.LazyLocation;
import com.massivecraft.factions.util.TL;
public class CmdSetWarp extends FCommand {
public CmdSetWarp() {
super();
this.aliases.add("setwarp");
this.aliases.add("sw");
this.requiredArgs.add("warp");
this.optionalArgs.put("password", "password");
this.requirements = new CommandRequirements.Builder(Permission.SETWARP)
.memberOnly()
.withAction(PermissibleAction.SETWARP)
.build();
}
@Override
public void perform(CommandContext context) {
if (!(context.fPlayer.getRelationToLocation() == Relation.MEMBER)) {
context.fPlayer.msg(TL.COMMAND_SETFWARP_NOTCLAIMED);
return;
}
int maxWarps = context.faction.getMaxWarps();
if (maxWarps <= context.faction.getWarps().size()) {
context.fPlayer.msg(TL.COMMAND_SETFWARP_LIMIT, maxWarps);
return;
}
if (!transact(context.fPlayer, context)) {
return;
}
String warp = context.argAsString(0);
String password = context.argAsString(1);
LazyLocation loc = new LazyLocation(context.fPlayer.getPlayer().getLocation());
context.faction.setWarp(warp, loc);
if (password != null) {
context.faction.setWarpPassword(warp, password);
}
context.fPlayer.msg(TL.COMMAND_SETFWARP_SET, warp, password != null ? password : "");
}
private boolean transact(FPlayer player, CommandContext context) {
return player.isAdminBypassing() || context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostSetWarp(), TL.COMMAND_SETFWARP_TOSET.toString(), TL.COMMAND_SETFWARP_FORSET.toString());
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SETFWARP_DESCRIPTION;
}
}
@@ -0,0 +1,56 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdSethome extends FCommand {
public CmdSethome() {
this.aliases.add("sethome");
this.requirements = new CommandRequirements.Builder(Permission.SETHOME)
.memberOnly()
.withAction(PermissibleAction.SETHOME)
.build();
}
@Override
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().conf().factions().homes().isEnabled()) {
context.msg(TL.COMMAND_SETHOME_DISABLED);
return;
}
// Can the player set the faction home HERE?
if (!Permission.BYPASS.has(context.player) &&
FactionsPlugin.getInstance().conf().factions().homes().isMustBeInClaimedTerritory() &&
Board.getInstance().getFactionAt(new FLocation(context.player)) != context.faction) {
context.msg(TL.COMMAND_SETHOME_NOTCLAIMED);
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostSethome(), TL.COMMAND_SETHOME_TOSET, TL.COMMAND_SETHOME_FORSET)) {
return;
}
context.faction.setHome(context.player.getLocation());
context.faction.msg(TL.COMMAND_SETHOME_SET, context.fPlayer.describeTo(context.faction, true));
context.faction.sendMessage(FCmdRoot.getInstance().cmdHome.getUsageTemplate(context));
/*
if (faction != context.faction) {
context.msg(TL.COMMAND_SETHOME_SETOTHER, faction.getTag(context.fPlayer));
}*/
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SETHOME_DESCRIPTION;
}
}
@@ -0,0 +1,276 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.perms.Relation;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.tag.FactionTag;
import com.massivecraft.factions.tag.FancyTag;
import com.massivecraft.factions.tag.Tag;
import com.massivecraft.factions.util.CC;
import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.factions.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
public class CmdShow extends FCommand {
List<String> defaults = new ArrayList<>();
public CmdShow() {
this.aliases.add("show");
this.aliases.add("who");
this.aliases.add("f");
// add defaults to /f show in case config doesnt have it
defaults.add("{header}");
defaults.add("<a>Description: <i>{description}");
defaults.add("<a>Joining: <i>{joining} {peaceful}");
defaults.add("<a>Land / Power / Maxpower: <i> {chunks} / {power} / {maxPower}");
defaults.add("<a>Raidable: {raidable}");
defaults.add("<a>Founded: <i>{create-date}");
defaults.add("<a>This faction is permanent, remaining even with no members.");
defaults.add("<a>Land value: <i>{land-value} {land-refund}");
defaults.add("<a>Balance: <i>{faction-balance}");
defaults.add("<a>Bans: <i>{faction-bancount}");
defaults.add("<a>Allies(<i>{allies}<a>/<i>{max-allies}<a>): {allies-list}");
defaults.add("<a>Online: (<i>{online}<a>/<i>{members}<a>): {online-list}");
defaults.add("<a>Offline: (<i>{offline}<a>/<i>{members}<a>): {offline-list}");
defaults.add("<a>Alts: (<i>{alts}<a>): {alt-list}");
this.optionalArgs.put("faction tag", "yours");
this.requirements = new CommandRequirements.Builder(Permission.SHOW).noDisableOnLock().build();
}
@Override
public void perform(CommandContext context) {
Faction faction = context.faction;
if (context.argIsSet(0)) {
faction = context.argAsFaction(0);
}
if (faction == null) {
return;
}
if (context.fPlayer != null && !context.player.hasPermission(Permission.SHOW_BYPASS_EXEMPT.toString())
&& FactionsPlugin.getInstance().conf().commands().show().getExempt().contains(faction.getTag())) {
context.msg(TL.COMMAND_SHOW_EXEMPT);
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostShow(), TL.COMMAND_SHOW_TOSHOW, TL.COMMAND_SHOW_FORSHOW)) {
return;
}
List<String> show = FactionsPlugin.getInstance().conf().commands().show().getFormat();
if (show == null || show.isEmpty()) {
show = defaults;
}
if (!faction.isNormal()) {
String tag = faction.getTag(context.fPlayer);
// send header and that's all
String header = show.get(0);
if (FactionTag.HEADER.foundInString(header)) {
context.msg(plugin.txt().titleize(tag));
} else {
String message = header.replace(FactionTag.FACTION.getTag(), tag);
message = Tag.parsePlain(faction, context.fPlayer, message);
context.msg(plugin.txt().parse(message));
}
return; // we only show header for non-normal factions
}
List<String> messageList = new ArrayList<>();
for (String raw : show) {
if(context.fPlayer != null && faction != context.fPlayer.getFaction() && !Permission.CLAIM_SEEALL.has(context.sender)){
raw = raw.replace("{chunks}", "???");
}
String parsed = Tag.parsePlain(faction, context.fPlayer, raw); // use relations
if (parsed == null) {
continue; // Due to minimal f show.
}
if (context.fPlayer != null) {
parsed = Tag.parsePlaceholders(context.fPlayer.getPlayer(), parsed);
}
if (!parsed.contains("{notFrozen}") && !parsed.contains("{notPermanent}")) {
if (parsed.contains("{ig}")) {
// replaces all variables with no home TL
parsed = parsed.substring(0, parsed.indexOf("{ig}")) + TL.COMMAND_SHOW_NOHOME.toString();
}
parsed = parsed.replace("%", ""); // Just in case it got in there before we disallowed it.
messageList.add(parsed);
}
}
//messageList.add(CC.translate("&6 * &eKoth Wins: &f" + CosmicKOTHAPI.getFactionKothWins(faction)));
//messageList.add(CC.translate("&6 * &eFtop: &f#" + FactionsTopAPI.getFactionTop(faction)));
messageList.add(CC.translate("&8&m---------------------------------"));
if (context.fPlayer != null && this.groupPresent()) {
new GroupGetter(messageList, context.fPlayer, faction).runTaskAsynchronously(FactionsPlugin.getInstance());
} else {
this.sendMessages(messageList, context.sender, faction, context.fPlayer);
}
}
private void sendMessages(List<String> messageList, CommandSender recipient, Faction faction, FPlayer player) {
this.sendMessages(messageList, recipient, faction, player, null);
}
private void sendMessages(List<String> messageList, CommandSender recipient, Faction faction, FPlayer player, Map<UUID, String> groupMap) {
FancyTag tag;
for (String parsed : messageList) {
if ((tag = FancyTag.getMatch(parsed)) != null) {
if (player != null) {
List<FancyMessage> fancy = FancyTag.parse(parsed, faction, player, groupMap);
if (fancy != null) {
for (FancyMessage fancyMessage : fancy) {
fancyMessage.send(recipient);
}
}
} else {
StringBuilder builder = new StringBuilder();
builder.append(parsed.replace(tag.getTag(), ""));
switch (tag) {
case ALT_LIST:
this.onAltMessage(builder, recipient, faction);
break;
case ONLINE_LIST:
this.onOffLineMessage(builder, recipient, faction, true);
break;
case OFFLINE_LIST:
this.onOffLineMessage(builder, recipient, faction, false);
break;
case ALLIES_LIST:
this.relationMessage(builder, recipient, faction, Relation.ALLY);
break;
case ENEMIES_LIST:
this.relationMessage(builder, recipient, faction, Relation.ENEMY);
break;
case TRUCES_LIST:
this.relationMessage(builder, recipient, faction, Relation.TRUCE);
break;
default:
// NO
}
}
} else {
recipient.sendMessage(FactionsPlugin.getInstance().txt().parse(parsed));
}
}
}
private void onOffLineMessage(StringBuilder builder, CommandSender recipient, Faction faction, boolean online) {
boolean first = true;
for (FPlayer p : MiscUtil.rankOrder(faction.getFPlayersWhereOnline(online))) {
String name = p.getNameAndTitle();
builder.append(first ? name : ", " + name);
first = false;
}
recipient.sendMessage(FactionsPlugin.getInstance().txt().parse(builder.toString()));
}
private void onAltMessage(StringBuilder builder, CommandSender recipient, Faction faction) {
boolean first = true;
for (FPlayer p : MiscUtil.rankOrder(faction.getFPlayersWhereRole(Role.ALT))) {
String name = p.getNameAndTitle();
builder.append(first ? name : ", " + name);
first = false;
}
recipient.sendMessage(FactionsPlugin.getInstance().txt().parse(builder.toString()));
}
private void relationMessage(StringBuilder builder, CommandSender recipient, Faction faction, Relation relation) {
boolean first = true;
for (Faction otherFaction : Factions.getInstance().getAllFactions()) {
if (otherFaction != faction && otherFaction.getRelationTo(faction) == relation) {
String s = otherFaction.getTag();
builder.append(first ? s : ", " + s);
first = false;
}
}
recipient.sendMessage(FactionsPlugin.getInstance().txt().parse(builder.toString()));
}
private boolean groupPresent() {
for (String line : FactionsPlugin.getInstance().conf().commands().toolTips().getPlayer()) {
if (line.contains("{group}")) {
return true;
}
}
return false;
}
private class GroupGetter extends BukkitRunnable {
private final List<String> messageList;
private final FPlayer sender;
private final Faction faction;
private final Set<OfflinePlayer> players;
private GroupGetter(List<String> messageList, FPlayer sender, Faction faction) {
this.messageList = messageList;
this.sender = sender;
this.faction = faction;
this.players = faction.getFPlayers().stream().map(fp -> Bukkit.getOfflinePlayer(UUID.fromString(fp.getId()))).collect(Collectors.toSet());
}
@Override
public void run() {
Map<UUID, String> map = new HashMap<>();
for (OfflinePlayer player : this.players) {
map.put(player.getUniqueId(), FactionsPlugin.getInstance().getPrimaryGroup(player));
}
new Sender(this.messageList, this.sender, this.faction, map).runTask(FactionsPlugin.getInstance());
}
}
private class Sender extends BukkitRunnable {
private final List<String> messageList;
private final FPlayer sender;
private final Faction faction;
private final Map<UUID, String> map;
private Sender(List<String> messageList, FPlayer sender, Faction faction, Map<UUID, String> map) {
this.messageList = messageList;
this.sender = sender;
this.faction = faction;
this.map = map;
}
@Override
public void run() {
Player player = Bukkit.getPlayerExact(sender.getName());
if (player != null) {
CmdShow.this.sendMessages(messageList, player, faction, sender, map);
}
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SHOW_COMMANDDESCRIPTION;
}
}
@@ -0,0 +1,40 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.ChatColor;
public class CmdShowInvites extends FCommand {
public CmdShowInvites() {
super();
this.aliases.add("showinvites");
this.requirements = new CommandRequirements.Builder(Permission.SHOW_INVITES)
.memberOnly()
.build();
}
@Override
public void perform(CommandContext context) {
FancyMessage msg = new FancyMessage(TL.COMMAND_SHOWINVITES_PENDING.toString()).color(ChatColor.GOLD);
for (String id : context.faction.getInvites()) {
FPlayer fp = FPlayers.getInstance().getById(id);
String name = fp != null ? fp.getName() : id;
msg.then(name + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_SHOWINVITES_CLICKTOREVOKE.format(name)).command("/" + FactionsPlugin.getInstance().conf().getCommandBase().get(0) + " deinvite " + name);
}
context.sendFancyMessage(msg);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SHOWINVITES_DESCRIPTION;
}
}
@@ -0,0 +1,43 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import org.bukkit.ChatColor;
public class CmdSotw extends FCommand {
public CmdSotw() {
super();
this.aliases.add("sotw");
this.requirements = new CommandRequirements.Builder(Permission.SOTW).build();
}
@Override
public void perform(CommandContext context) {
boolean on = !FactionsPlugin.getInstance().isSOTW();
FactionsPlugin.getInstance().setSOTW(on);
if (on) {
context.sender.sendMessage(ChatColor.GREEN + "Turned on SOTW.");
for (FPlayer fPlayer : FPlayers.getInstance().getOnlinePlayers()) {
if (Permission.SOTW.has(fPlayer.getPlayer())) continue;
fPlayer.msg(TL.PLAYER_SOTW_NOFLY);
//fPlayer.setFlying(false, false);
//fPlayer.setAutoFlying(false);
}
} else {
context.sender.sendMessage(ChatColor.RED + "Turned off SOTW");
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SOTW_DESCRIPTION;
}
}
@@ -0,0 +1,47 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.landraidcontrol.PowerControl;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.bukkit.ChatColor;
import java.util.ArrayList;
public class CmdStatus extends FCommand {
public CmdStatus() {
super();
this.aliases.add("status");
this.aliases.add("s");
this.requirements = new CommandRequirements.Builder(Permission.STATUS)
.memberOnly()
.build();
}
@Override
public void perform(CommandContext context) {
ArrayList<String> ret = new ArrayList<>();
for (FPlayer fp : context.faction.getFPlayers()) {
String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - fp.getLastLoginTime(), true, true) + TL.COMMAND_STATUS_AGOSUFFIX;
String last = fp.isOnline() ? ChatColor.GREEN + TL.COMMAND_STATUS_ONLINE.toString() : (System.currentTimeMillis() - fp.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized);
String power = "";
if (FactionsPlugin.getInstance().getLandRaidControl() instanceof PowerControl) {
power = ChatColor.YELLOW + String.valueOf(fp.getPowerRounded()) + " / " + fp.getPowerMaxRounded() + ChatColor.RESET;
} else {
power = "n/a";
}
ret.add(String.format(TL.COMMAND_STATUS_FORMAT.toString(), ChatColor.GOLD + fp.getRole().getPrefix() + fp.getName() + ChatColor.RESET, power, last).trim());
}
context.fPlayer.sendMessage(ret);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_STATUS_DESCRIPTION;
}
}
@@ -0,0 +1,32 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import org.bukkit.ChatColor;
public class CmdStealth extends FCommand {
public CmdStealth() {
super();
this.aliases.add("stealth");
this.requirements = new CommandRequirements.Builder(Permission.STEALTH)
.memberOnly()
.build();
}
@Override
public void perform(CommandContext context) {
FPlayer fPlayer = context.fPlayer;
fPlayer.setStealth(!fPlayer.isStealth());
fPlayer.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8(&a!&8) &7Stealth mode has been " + (fPlayer.isStealth() ? "&aenabled" : "&cdisabled")));
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_STEALTH_DESCRIPTION;
}
}
@@ -0,0 +1,120 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.event.FPlayerTeleportEvent;
import com.massivecraft.factions.integration.Essentials;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.SpiralTask;
import com.massivecraft.factions.util.TL;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class CmdStuck extends FCommand {
public CmdStuck() {
super();
this.aliases.add("stuck");
this.aliases.add("halp!"); // halp! c:
this.requirements = new CommandRequirements.Builder(Permission.STUCK).build();
}
@Override
public void perform(final CommandContext context) {
final Player player = context.fPlayer.getPlayer();
final Location sentAt = player.getLocation();
final FLocation chunk = context.fPlayer.getLastStoodAt();
// TODO handle delay 0
final long delay = FactionsPlugin.getInstance().conf().commands().stuck().getDelay();
final int radius = FactionsPlugin.getInstance().conf().commands().stuck().getRadius();
if (FactionsPlugin.getInstance().getStuckMap().containsKey(player.getUniqueId())) {
long wait = FactionsPlugin.getInstance().getTimers().get(player.getUniqueId()) - System.currentTimeMillis();
String time = DurationFormatUtils.formatDuration(wait, TL.COMMAND_STUCK_TIMEFORMAT.toString(), true);
context.msg(TL.COMMAND_STUCK_EXISTS, time);
} else {
FPlayerTeleportEvent tpEvent = new FPlayerTeleportEvent(context.fPlayer, null, FPlayerTeleportEvent.PlayerTeleportReason.STUCK);
Bukkit.getServer().getPluginManager().callEvent(tpEvent);
if (tpEvent.isCancelled()) {
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostStuck(), TL.COMMAND_STUCK_TOSTUCK.format(context.fPlayer.getName()), TL.COMMAND_STUCK_FORSTUCK.format(context.fPlayer.getName()))) {
return;
}
final int id = new BukkitRunnable() {
@Override
public void run() {
if (!FactionsPlugin.getInstance().getStuckMap().containsKey(player.getUniqueId())) {
return;
}
// check for world difference or radius exceeding
final World world = chunk.getWorld();
if (world.getUID() != player.getWorld().getUID() || sentAt.distance(player.getLocation()) > radius) {
context.msg(TL.COMMAND_STUCK_OUTSIDE.format(radius));
FactionsPlugin.getInstance().getTimers().remove(player.getUniqueId());
FactionsPlugin.getInstance().getStuckMap().remove(player.getUniqueId());
return;
}
final Board board = Board.getInstance();
// spiral task to find nearest wilderness chunk
new SpiralTask(new FLocation(context.player), radius * 2) {
final int buffer = FactionsPlugin.getInstance().conf().worldBorder().getBuffer();
@Override
public boolean work() {
FLocation chunk = currentFLocation();
if (chunk.isOutsideWorldBorder(buffer)) {
return true;
}
Faction faction = board.getFactionAt(chunk);
if (faction.isWilderness()) {
int cx = FLocation.chunkToBlock((int) chunk.getX());
int cz = FLocation.chunkToBlock((int) chunk.getZ());
int y = world.getHighestBlockYAt(cx, cz);
Location tp = new Location(world, cx, y, cz);
context.msg(TL.COMMAND_STUCK_TELEPORT, tp.getBlockX(), tp.getBlockY(), tp.getBlockZ());
FactionsPlugin.getInstance().getTimers().remove(player.getUniqueId());
FactionsPlugin.getInstance().getStuckMap().remove(player.getUniqueId());
if (!Essentials.handleTeleport(player, tp)) {
FactionsPlugin.getInstance().teleport(player, tp);
FactionsPlugin.getInstance().debug("/f stuck used regular teleport, not essentials!");
}
this.stop();
return false;
}
return true;
}
};
}
}.runTaskLater(FactionsPlugin.getInstance(), delay * 20).getTaskId();
FactionsPlugin.getInstance().getTimers().put(player.getUniqueId(), System.currentTimeMillis() + (delay * 1000));
long wait = FactionsPlugin.getInstance().getTimers().get(player.getUniqueId()) - System.currentTimeMillis();
String time = DurationFormatUtils.formatDuration(wait, TL.COMMAND_STUCK_TIMEFORMAT.toString(), true);
context.msg(TL.COMMAND_STUCK_START, time);
FactionsPlugin.getInstance().getStuckMap().put(player.getUniqueId(), id);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_STUCK_DESCRIPTION;
}
}
@@ -0,0 +1,34 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.cmd.tnt.*;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdTNT extends FCommand {
private final CmdTNTInfo infoCmd;
public CmdTNT() {
super();
this.aliases.add("tnt");
this.addSubCommand(this.infoCmd = new CmdTNTInfo());
this.addSubCommand(new CmdTNTFill());
this.addSubCommand(new CmdTNTDeposit());
this.addSubCommand(new CmdTNTWithdraw());
this.addSubCommand(new CmdTNTSiphon());
this.addSubCommand(new CmdTNTAdminSet());
this.requirements = new CommandRequirements.Builder(Permission.TNT_INFO).memberOnly().build();
}
@Override
public void perform(CommandContext context) {
context.commandChain.add(this);
FCmdRoot.getInstance().cmdAutoHelp.execute(context);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_TNT_INFO_DESCRIPTION;
}
}
@@ -0,0 +1,90 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.event.FactionRenameEvent;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.scoreboards.FTeamWrapper;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.factions.util.TL;
import org.bukkit.Bukkit;
import java.util.ArrayList;
public class CmdTag extends FCommand {
public CmdTag() {
this.aliases.add("tag");
this.aliases.add("rename");
this.requiredArgs.add("faction tag");
this.requirements = new CommandRequirements.Builder(Permission.TAG)
.memberOnly()
.withRole(Role.MODERATOR)
.build();
}
@Override
public void perform(CommandContext context) {
String tag = context.argAsString(0);
// TODO does not first shouldCancel cover selfcase?
if (Factions.getInstance().isTagTaken(tag) && !MiscUtil.getComparisonString(tag).equals(context.faction.getComparisonTag())) {
context.msg(TL.COMMAND_TAG_TAKEN);
return;
}
ArrayList<String> errors = MiscUtil.validateTag(tag);
if (errors.size() > 0) {
context.sendMessage(errors);
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
if (!context.canAffordCommand(FactionsPlugin.getInstance().conf().economy().getCostTag(), TL.COMMAND_TAG_TOCHANGE.toString())) {
return;
}
// trigger the faction rename event (cancellable)
FactionRenameEvent renameEvent = new FactionRenameEvent(context.fPlayer, tag);
Bukkit.getServer().getPluginManager().callEvent(renameEvent);
if (renameEvent.isCancelled()) {
return;
}
// then make 'em pay (if applicable)
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostTag(), TL.COMMAND_TAG_TOCHANGE, TL.COMMAND_TAG_FORCHANGE)) {
return;
}
String oldtag = context.faction.getTag();
context.faction.setTag(tag);
// Inform
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
if (fplayer.getFactionId().equals(context.faction.getId())) {
fplayer.msg(TL.COMMAND_TAG_FACTION, context.fPlayer.describeTo(context.faction, true), context.faction.getTag(context.faction));
continue;
}
// Broadcast the tag change (if applicable)
if (FactionsPlugin.getInstance().conf().factions().chat().isBroadcastTagChanges()) {
Faction faction = fplayer.getFaction();
fplayer.msg(TL.COMMAND_TAG_CHANGED, context.fPlayer.getColorTo(faction) + oldtag, context.faction.getTag(faction));
}
}
FTeamWrapper.updatePrefixes(context.faction);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_TAG_DESCRIPTION;
}
}
@@ -0,0 +1,56 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import com.massivecraft.factions.util.TextUtil;
public class CmdTitle extends FCommand {
public CmdTitle() {
this.aliases.add("title");
this.requiredArgs.add("player");
this.optionalArgs.put("title", "title");
this.requirements = new CommandRequirements.Builder(Permission.TITLE)
.memberOnly()
.withRole(Role.MODERATOR)
.build();
}
@Override
public void perform(CommandContext context) {
FPlayer you = context.argAsBestFPlayerMatch(0);
if (you == null) {
return;
}
context.args.remove(0);
String title = TextUtil.implode(context.args, " ");
title = title.replaceAll(",", "");
if (!context.canIAdministerYou(context.fPlayer, you)) {
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostTitle(), TL.COMMAND_TITLE_TOCHANGE, TL.COMMAND_TITLE_FORCHANGE)) {
return;
}
you.setTitle(context.sender, title);
// Inform
context.faction.msg(TL.COMMAND_TITLE_CHANGED, context.fPlayer.describeTo(context.faction, true), you.describeTo(context.faction, true));
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_TITLE_DESCRIPTION;
}
}
@@ -0,0 +1,38 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdToggleAllianceChat extends FCommand {
public CmdToggleAllianceChat() {
super();
this.aliases.add("tac");
this.aliases.add("togglealliancechat");
this.aliases.add("ac");
this.requirements = new CommandRequirements.Builder(Permission.TOGGLE_ALLIANCE_CHAT)
.memberOnly()
.noDisableOnLock()
.build();
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_TOGGLEALLIANCECHAT_DESCRIPTION;
}
@Override
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().conf().factions().chat().isFactionOnlyChat()) {
context.msg(TL.COMMAND_CHAT_DISABLED.toString());
return;
}
boolean ignoring = context.fPlayer.isIgnoreAllianceChat();
context.msg(ignoring ? TL.COMMAND_TOGGLEALLIANCECHAT_UNIGNORE : TL.COMMAND_TOGGLEALLIANCECHAT_IGNORE);
context.fPlayer.setIgnoreAllianceChat(!ignoring);
}
}
@@ -0,0 +1,172 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.landraidcontrol.PowerControl;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import org.bukkit.entity.Player;
import java.util.ArrayList;
public class CmdTop extends FCommand {
public CmdTop() {
super();
this.aliases.add("top");
this.aliases.add("t");
this.requiredArgs.add("criteria");
this.optionalArgs.put("page", "1");
this.requirements = new CommandRequirements.Builder(Permission.TOP).noDisableOnLock().build();
}
@Override
public void perform(CommandContext context) {
// Can sort by: money, members, online, allies, enemies, power, land.
// Get all Factions and remove non player ones.
ArrayList<Faction> factionList = Factions.getInstance().getAllFactions();
factionList.remove(Factions.getInstance().getWilderness());
factionList.remove(Factions.getInstance().getSafeZone());
factionList.remove(Factions.getInstance().getWarZone());
String criteria = context.argAsString(0);
// TODO: Better way to sort?
if (criteria.equalsIgnoreCase("members")) {
factionList.sort((f1, f2) -> {
int f1Size = f1.getFPlayers().size();
int f2Size = f2.getFPlayers().size();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
});
} else if (criteria.equalsIgnoreCase("start")) {
factionList.sort((f1, f2) -> {
long f1start = f1.getFoundedDate();
long f2start = f2.getFoundedDate();
// flip signs because a smaller date is farther in the past
if (f1start > f2start) {
return 1;
} else if (f1start < f2start) {
return -1;
}
return 0;
});
} else if (FactionsPlugin.getInstance().getLandRaidControl() instanceof PowerControl && criteria.equalsIgnoreCase("power")) {
factionList.sort((f1, f2) -> {
int f1Size = f1.getPowerRounded();
int f2Size = f2.getPowerRounded();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
});
} else if (criteria.equalsIgnoreCase("land")) {
factionList.sort((f1, f2) -> {
int f1Size = f1.getLandRounded();
int f2Size = f2.getLandRounded();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
});
} else if (criteria.equalsIgnoreCase("online")) {
factionList.sort((f1, f2) -> {
int f1Size = f1.getFPlayersWhereOnline(true).size();
int f2Size = f2.getFPlayersWhereOnline(true).size();
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
});
} else if (criteria.equalsIgnoreCase("money") || criteria.equalsIgnoreCase("balance") || criteria.equalsIgnoreCase("bal")) {
factionList.sort((f1, f2) -> {
double f1Size = Econ.getBalance(f1);
// Lets get the balance of /all/ the players in the Faction.
for (FPlayer fp : f1.getFPlayers()) {
f1Size = f1Size + Econ.getBalance(fp);
}
double f2Size = Econ.getBalance(f2);
for (FPlayer fp : f2.getFPlayers()) {
f2Size = f2Size + Econ.getBalance(fp);
}
if (f1Size < f2Size) {
return 1;
} else if (f1Size > f2Size) {
return -1;
}
return 0;
});
} else {
context.msg(TL.COMMAND_TOP_INVALID, criteria);
return;
}
ArrayList<String> lines = new ArrayList<>();
final int pageheight = 9;
int pagenumber = context.argAsInt(1, 1);
int pagecount = (factionList.size() / pageheight) + 1;
if (pagenumber > pagecount) {
pagenumber = pagecount;
} else if (pagenumber < 1) {
pagenumber = 1;
}
int start = (pagenumber - 1) * pageheight;
int end = start + pageheight;
if (end > factionList.size()) {
end = factionList.size();
}
lines.add(TL.COMMAND_TOP_TOP.format(criteria.toUpperCase(), pagenumber, pagecount));
int rank = 1;
for (Faction faction : factionList.subList(start, end)) {
// Get the relation color if player is executing this.
String fac = context.sender instanceof Player ? faction.getRelationTo(context.fPlayer).getColor() + faction.getTag() : faction.getTag();
lines.add(TL.COMMAND_TOP_LINE.format(rank, fac, getValue(faction, criteria)));
rank++;
}
context.sendMessage(lines);
}
private String getValue(Faction faction, String criteria) {
if (criteria.equalsIgnoreCase("online")) {
return String.valueOf(faction.getFPlayersWhereOnline(true).size());
} else if (criteria.equalsIgnoreCase("start")) {
return TL.sdf.format(faction.getFoundedDate());
} else if (criteria.equalsIgnoreCase("members")) {
return String.valueOf(faction.getFPlayers().size());
} else if (criteria.equalsIgnoreCase("land")) {
return String.valueOf(faction.getLandRounded());
} else if (FactionsPlugin.getInstance().getLandRaidControl() instanceof PowerControl && criteria.equalsIgnoreCase("power")) {
return String.valueOf(faction.getPowerRounded());
} else { // Last one is balance, and it has 3 different things it could be.
double balance = Econ.getBalance(faction);
for (FPlayer fp : faction.getFPlayers()) {
balance = balance + Econ.getBalance(fp);
}
return String.valueOf(balance);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_TOP_DESCRIPTION;
}
}
@@ -0,0 +1,55 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdTrail extends FCommand {
public CmdTrail() {
super();
this.aliases.add("trail");
this.aliases.add("trails");
this.optionalArgs.put("on/off/effect", "flip");
this.optionalArgs.put("particle", "particle");
this.requirements = new CommandRequirements.Builder(Permission.FLY_TRAILS).memberOnly().build();
}
@Override
public void perform(CommandContext context) {
// Let's flip it
if (!context.argIsSet(0)) {
context.fPlayer.setFlyTrailsState(!context.fPlayer.getFlyTrailsState());
} else {
// They are setting a particle type
if (context.argAsString(0).equalsIgnoreCase("effect")) {
if (context.argIsSet(1)) {
String effectName = context.argAsString(1);
Object particleEffect = plugin.getParticleProvider().effectFromString(effectName);
if (particleEffect == null) {
context.fPlayer.msg(TL.COMMAND_FLYTRAILS_PARTICLE_INVALID);
return;
}
if (context.player.hasPermission(Permission.FLY_TRAILS.node + "." + effectName)) {
context.fPlayer.setFlyTrailsEffect(effectName);
} else {
context.fPlayer.msg(TL.COMMAND_FLYTRAILS_PARTICLE_PERMS, effectName);
}
} else {
context.msg(getUsageTranslation());
}
} else {
boolean state = context.argAsBool(0);
context.fPlayer.setFlyTrailsState(state);
}
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_FLY_DESCRIPTION;
}
}
@@ -0,0 +1,46 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdUnban extends FCommand {
public CmdUnban() {
super();
this.aliases.add("unban");
this.requiredArgs.add("target");
this.requirements = new CommandRequirements.Builder(Permission.BAN)
.memberOnly()
.withAction(PermissibleAction.BAN)
.withRole(Role.MODERATOR)
.build();
}
@Override
public void perform(CommandContext context) {
FPlayer target = context.argAsFPlayer(0);
if (target == null) {
return; // the above method sends a message if fails to find someone.
}
if (!context.faction.isBanned(target)) {
context.msg(TL.COMMAND_UNBAN_NOTBANNED, target.getName());
return;
}
context.faction.unban(target);
context.faction.msg(TL.COMMAND_UNBAN_UNBANNED, context.fPlayer.getName(), target.getName());
target.msg(TL.COMMAND_UNBAN_TARGET, context.faction.getTag(target));
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_UNBAN_DESCRIPTION;
}
}
@@ -0,0 +1,28 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.gui.UpgradeGUI;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdUpgrade extends FCommand{
public CmdUpgrade() {
super();
this.aliases.add("upgrade");
this.requirements = new CommandRequirements.Builder(Permission.UPGRADE).memberOnly().playerOnly().build();
}
@Override
public void perform(CommandContext context) {
UpgradeGUI upgradeGUI = new UpgradeGUI(context.fPlayer);
upgradeGUI.open();
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_UPGRADE_DESCRIPTION;
}
}
@@ -0,0 +1,39 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
public class CmdVault extends FCommand {
public CmdVault() {
this.aliases.add("vault");
this.aliases.add("chest");
this.requirements = new CommandRequirements.Builder(Permission.VAULT)
.memberOnly()
.noDisableOnLock()
.build();
}
@Override
public void perform(CommandContext context) {
/*
/f vault <number>
*/
Player player = context.player;
if(context.faction.isWilderness())return;
Inventory inventory = context.faction.getChest();
player.openInventory(inventory);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_VAULT_DESCRIPTION;
}
}
@@ -0,0 +1,26 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdVersion extends FCommand {
public CmdVersion() {
this.aliases.add("version");
this.aliases.add("ver");
this.requirements = new CommandRequirements.Builder(Permission.VERSION).noDisableOnLock().build();
}
@Override
public void perform(CommandContext context) {
context.msg(TL.COMMAND_VERSION_VERSION, FactionsPlugin.getInstance().getDescription().getFullName());
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_VERSION_DESCRIPTION;
}
}
@@ -0,0 +1,90 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.event.FPlayerTeleportEvent;
import com.massivecraft.factions.gui.WarpGUI;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import com.massivecraft.factions.util.WarmUpUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.UUID;
public class CmdWarp extends FCommand {
public CmdWarp() {
super();
this.aliases.add("warp");
this.aliases.add("warps");
this.optionalArgs.put("warp", "warp");
this.optionalArgs.put("password", "password");
this.requirements = new CommandRequirements.Builder(Permission.WARP)
.memberOnly()
.withAction(PermissibleAction.WARP)
.build();
}
@Override
public void perform(CommandContext context) {
// TODO: check if in combat.
if (!context.faction.hasAccess(context.fPlayer, PermissibleAction.WARP)) {
context.msg(TL.COMMAND_FWARP_NOACCESS, context.faction.getTag(context.fPlayer));
return;
}
if (context.args.size() == 0) {
WarpGUI ui = new WarpGUI(context.fPlayer, context.faction);
ui.open();
} else if (context.args.size() > 2) {
context.msg(TL.COMMAND_FWARP_COMMANDFORMAT);
} else {
final String warpName = context.argAsString(0);
final String passwordAttempt = context.argAsString(1);
if (context.faction.isWarp(context.argAsString(0))) {
// Check if requires password and if so, check if valid. CASE SENSITIVE
if (!context.fPlayer.isAdminBypassing() && context.faction.hasWarpPassword(warpName) && !context.faction.isWarpPassword(warpName, passwordAttempt)) {
context.fPlayer.msg(TL.COMMAND_FWARP_INVALID_PASSWORD);
return;
}
FPlayerTeleportEvent tpEvent = new FPlayerTeleportEvent(context.fPlayer, context.fPlayer.getFaction().getWarp(warpName).getLocation(), FPlayerTeleportEvent.PlayerTeleportReason.WARP);
Bukkit.getServer().getPluginManager().callEvent(tpEvent);
if (tpEvent.isCancelled()) {
return;
}
// Check transaction AFTER password check.
if (!transact(context.fPlayer, context)) {
return;
}
final FPlayer fPlayer = context.fPlayer;
final UUID uuid = context.fPlayer.getPlayer().getUniqueId();
context.doWarmUp(WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warpName, () -> {
Player player = Bukkit.getPlayer(uuid);
if (player != null) {
FactionsPlugin.getInstance().teleport(player, fPlayer.getFaction().getWarp(warpName).getLocation()).thenAccept(success -> {
if (success) {
fPlayer.msg(TL.COMMAND_FWARP_WARPED, warpName);
}
});
}
}, this.plugin.conf().commands().warp().getDelay());
} else {
context.fPlayer.msg(TL.COMMAND_FWARP_INVALID_WARP, warpName);
}
}
}
private boolean transact(FPlayer player, CommandContext context) {
return player.isAdminBypassing() || context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostWarp(), TL.COMMAND_FWARP_TOWARP.toString(), TL.COMMAND_FWARP_FORWARPING.toString());
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_FWARP_DESCRIPTION;
}
}
@@ -0,0 +1,97 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.event.FPlayerTeleportEvent;
import com.massivecraft.factions.gui.WarpGUI;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
import com.massivecraft.factions.util.WarmUpUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.UUID;
public class CmdWarpOther extends FCommand {
public CmdWarpOther() {
super();
this.aliases.add("warpother");
this.requiredArgs.add("faction");
this.optionalArgs.put("warp", "warp");
this.optionalArgs.put("password", "password");
this.requirements = new CommandRequirements.Builder(Permission.WARP)
.memberOnly()
.build();
}
@Override
public void perform(CommandContext context) {
// TODO: check if in combat.
if (context.args.size() < 1) {
context.msg(TL.COMMAND_WARPOTHER_COMMANDFORMAT);
return;
}
Faction faction = context.argAsFaction(0);
if (faction == null) {
context.msg(TL.GENERIC_NOFACTIONMATCH, context.argAsString(0));
return;
}
if (!context.fPlayer.isAdminBypassing() && !faction.hasAccess(context.fPlayer, PermissibleAction.WARP)) {
context.msg(TL.COMMAND_FWARP_NOACCESS, faction.getTag(context.fPlayer));
return;
}
if (context.args.size() == 1) {
WarpGUI ui = new WarpGUI(context.fPlayer, faction);
ui.open();
} else {
final String warpName = context.argAsString(1);
final String passwordAttempt = context.argAsString(2);
if (faction.isWarp(warpName)) {
// Check if requires password and if so, check if valid. CASE SENSITIVE
if (!context.fPlayer.isAdminBypassing() && faction.hasWarpPassword(warpName) && !faction.isWarpPassword(warpName, passwordAttempt)) {
context.fPlayer.msg(TL.COMMAND_FWARP_INVALID_PASSWORD);
return;
}
FPlayerTeleportEvent tpEvent = new FPlayerTeleportEvent(context.fPlayer, faction.getWarp(warpName).getLocation(), FPlayerTeleportEvent.PlayerTeleportReason.WARP);
Bukkit.getServer().getPluginManager().callEvent(tpEvent);
if (tpEvent.isCancelled()) {
return;
}
// Check transaction AFTER password check.
if (!transact(context.fPlayer, context)) {
return;
}
final FPlayer fPlayer = context.fPlayer;
final UUID uuid = context.fPlayer.getPlayer().getUniqueId();
context.doWarmUp(WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warpName, () -> {
Player player = Bukkit.getPlayer(uuid);
if (player != null) {
FactionsPlugin.getInstance().teleport(player, faction.getWarp(warpName).getLocation()).thenAccept(success -> {
if (success) {
fPlayer.msg(TL.COMMAND_FWARP_WARPED, warpName);
}
});
}
}, this.plugin.conf().commands().warp().getDelay());
} else {
context.fPlayer.msg(TL.COMMAND_FWARP_INVALID_WARP, warpName);
}
}
}
private boolean transact(FPlayer player, CommandContext context) {
return player.isAdminBypassing() || context.payForCommand(FactionsPlugin.getInstance().conf().economy().getCostWarp(), TL.COMMAND_FWARP_TOWARP.toString(), TL.COMMAND_FWARP_FORWARPING.toString());
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_FWARP_DESCRIPTION;
}
}
@@ -0,0 +1,418 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.util.TL;
import com.massivecraft.factions.util.WarmUpUtil;
import mkremins.fanciful.FancyMessage;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
/*
Object that contains information about a command being executed,
args, player, faction
*/
public class CommandContext {
public CommandSender sender;
public Player player;
public FPlayer fPlayer;
public Faction faction;
public List<String> args;
public String alias;
public List<FCommand> commandChain = new ArrayList<>(); // The command chain used to execute this command
public CommandContext(CommandSender sender, List<String> args, String alias) {
this.sender = sender;
this.args = args;
this.alias = alias;
if (sender instanceof Player) {
this.player = (Player) sender;
this.fPlayer = FPlayers.getInstance().getByPlayer(player);
this.faction = fPlayer.getFaction();
}
}
// -------------------------------------------- //
// Message Sending Helpers
// -------------------------------------------- //
public void msg(String str, Object... args) {
sender.sendMessage(FactionsPlugin.getInstance().txt().parse(str, args));
}
public void msg(TL translation, Object... args) {
sender.sendMessage(FactionsPlugin.getInstance().txt().parse(translation.toString(), args));
}
public void sendMessage(String msg) {
sender.sendMessage(msg);
}
public void sendMessage(List<String> msgs) {
for (String msg : msgs) {
this.sendMessage(msg);
}
}
public void sendFancyMessage(FancyMessage message) {
message.send(sender);
}
public void sendFancyMessage(List<FancyMessage> messages) {
for (FancyMessage m : messages) {
sendFancyMessage(m);
}
}
// TODO: Clean this UP
// -------------------------------------------- //
// Argument Readers
// -------------------------------------------- //
// Is set? ======================
public boolean argIsSet(int idx) {
return args.size() >= idx + 1;
}
// STRING ======================
public String argAsString(int idx, String def) {
if (args.size() < idx + 1) {
return def;
}
return args.get(idx);
}
public String argAsString(int idx) {
return argAsString(idx, null);
}
// INT ======================
public Integer strAsInt(String str, Integer def) {
if (str == null) {
return def;
}
try {
return Integer.parseInt(str);
} catch (Exception e) {
return def;
}
}
public Integer argAsInt(int idx, Integer def) {
return strAsInt(argAsString(idx), def);
}
public Integer argAsInt(int idx) {
return argAsInt(idx, null);
}
// Double ======================
public Double strAsDouble(String str, Double def) {
if (str == null) {
return def;
}
try {
return Double.parseDouble(str);
} catch (Exception e) {
return def;
}
}
public Double argAsDouble(int idx, Double def) {
return strAsDouble(argAsString(idx), def);
}
public Double argAsDouble(int idx) {
return argAsDouble(idx, null);
}
// TODO: Go through the str conversion for the other arg-readers as well.
// Boolean ======================
public Boolean strAsBool(String str) {
str = str.toLowerCase();
return str.startsWith("y") || str.startsWith("t") || str.startsWith("on") || str.startsWith("+") || str.startsWith("1");
}
public Boolean argAsBool(int idx, boolean def) {
String str = argAsString(idx);
if (str == null) {
return def;
}
return strAsBool(str);
}
public Boolean argAsBool(int idx) {
return argAsBool(idx, false);
}
// PLAYER ======================
public Player strAsPlayer(String name, Player def, boolean msg) {
Player ret = def;
if (name != null) {
Player player = Bukkit.getServer().getPlayer(name);
if (player != null) {
ret = player;
}
}
if (msg && ret == null) {
sender.sendMessage(TL.GENERIC_NOPLAYERFOUND.format(name));
}
return ret;
}
public Player argAsPlayer(int idx, Player def, boolean msg) {
return this.strAsPlayer(argAsString(idx), def, msg);
}
public Player argAsPlayer(int idx, Player def) {
return argAsPlayer(idx, def, true);
}
public Player argAsPlayer(int idx) {
return argAsPlayer(idx, null);
}
// BEST PLAYER MATCH ======================
public Player strAsBestPlayerMatch(String name, Player def, boolean msg) {
Player ret = def;
if (name != null) {
List<Player> players = Bukkit.getServer().matchPlayer(name);
if (players.size() > 0) {
ret = players.get(0);
}
}
if (msg && ret == null) {
sender.sendMessage(TL.GENERIC_NOPLAYERMATCH.format(name));
}
return ret;
}
public Player argAsBestPlayerMatch(int idx, Player def, boolean msg) {
return this.strAsBestPlayerMatch(argAsString(idx), def, msg);
}
public Player argAsBestPlayerMatch(int idx, Player def) {
return argAsBestPlayerMatch(idx, def, true);
}
public Player argAsBestPlayerMatch(int idx) {
return argAsPlayer(idx, null);
}
// -------------------------------------------- //
// Faction Argument Readers
// -------------------------------------------- //
// FPLAYER ======================
public FPlayer strAsFPlayer(String name, FPlayer def, boolean msg) {
FPlayer ret = def;
if (name != null) {
for (FPlayer fplayer : FPlayers.getInstance().getAllFPlayers()) {
if (fplayer.getName().equalsIgnoreCase(name)) {
ret = fplayer;
break;
}
}
}
if (msg && ret == null) {
sender.sendMessage(TL.GENERIC_NOPLAYERFOUND.format(name));
}
return ret;
}
public FPlayer argAsFPlayer(int idx, FPlayer def, boolean msg) {
return this.strAsFPlayer(argAsString(idx), def, msg);
}
public FPlayer argAsFPlayer(int idx, FPlayer def) {
return argAsFPlayer(idx, def, true);
}
public FPlayer argAsFPlayer(int idx) {
return argAsFPlayer(idx, null);
}
// BEST FPLAYER MATCH ======================
public FPlayer strAsBestFPlayerMatch(String name, FPlayer def, boolean msg) {
return strAsFPlayer(name, def, msg);
}
public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def, boolean msg) {
return this.strAsBestFPlayerMatch(argAsString(idx), def, msg);
}
public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def) {
return argAsBestFPlayerMatch(idx, def, true);
}
public FPlayer argAsBestFPlayerMatch(int idx) {
return argAsBestFPlayerMatch(idx, null);
}
// FACTION ======================
public Faction strAsFaction(String name, Faction def, boolean msg) {
Faction ret = def;
if (name != null) {
// First we try an exact match
Faction faction = Factions.getInstance().getByTag(name); // Checks for faction name match.
// Now lets try for warzone / safezone. Helpful for custom warzone / safezone names.
// Do this after we check for an exact match in case they rename the warzone / safezone
// and a player created faction took one of the names.
if (faction == null) {
if (name.equalsIgnoreCase("warzone")) {
faction = Factions.getInstance().getWarZone();
} else if (name.equalsIgnoreCase("safezone")) {
faction = Factions.getInstance().getSafeZone();
}
}
// Next we match faction tags
if (faction == null) {
faction = Factions.getInstance().getBestTagMatch(name);
}
// Next we match player names
if (faction == null) {
FPlayer fplayer = strAsFPlayer(name, null, false);
if (fplayer != null) {
faction = fplayer.getFaction();
}
}
if (faction != null) {
ret = faction;
}
}
if (msg && ret == null) {
sender.sendMessage(TL.GENERIC_NOFACTIONMATCH.format(name));
}
return ret;
}
public Faction argAsFaction(int idx, Faction def, boolean msg) {
return this.strAsFaction(argAsString(idx), def, msg);
}
public Faction argAsFaction(int idx, Faction def) {
return argAsFaction(idx, def, true);
}
public Faction argAsFaction(int idx) {
return argAsFaction(idx, null);
}
/*
Assertions
*/
public boolean assertHasFaction() {
if (player == null) {
return true;
}
if (!fPlayer.hasFaction()) {
sendMessage("You are not member of any faction.");
return false;
}
return true;
}
public boolean assertMinRole(Role role) {
if (player == null) {
return true;
}
if (fPlayer.getRole().value < role.value) {
msg("<b>You <h>must be " + role);
return false;
}
return true;
}
/*
Common Methods
*/
public boolean canIAdministerYou(FPlayer i, FPlayer you) {
if (!i.getFaction().equals(you.getFaction())) {
i.sendMessage(FactionsPlugin.getInstance().txt().parse("%s <b>is not in the same faction as you.", you.describeTo(i, true)));
return false;
}
if (i.getRole().value >= you.getRole().value || i.getRole() == Role.ADMIN) {
return true;
}
i.sendMessage(FactionsPlugin.getInstance().txt().parse("%s <b>has a higher rank than you.", you.describeTo(i, true)));
return false;
}
// if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost
public boolean payForCommand(double cost, String toDoThis, String forDoingThis) {
if (!Econ.shouldBeUsed() || this.fPlayer == null || cost == 0.0 || fPlayer.isAdminBypassing()) {
return true;
}
if (FactionsPlugin.getInstance().conf().economy().isBankEnabled() && FactionsPlugin.getInstance().conf().economy().isBankFactionPaysCosts() && fPlayer.hasFaction() && fPlayer.getFaction().hasAccess(fPlayer, PermissibleAction.ECONOMY)) {
return Econ.modifyMoney(faction, -cost, toDoThis, forDoingThis);
} else {
return Econ.modifyMoney(fPlayer, -cost, toDoThis, forDoingThis);
}
}
public boolean payForCommand(double cost, TL toDoThis, TL forDoingThis) {
return payForCommand(cost, toDoThis.toString(), forDoingThis.toString());
}
// like above, but just make sure they can pay; returns true unless person can't afford the cost
public boolean canAffordCommand(double cost, String toDoThis) {
if (!Econ.shouldBeUsed() || fPlayer == null || cost == 0.0 || fPlayer.isAdminBypassing()) {
return true;
}
if (FactionsPlugin.getInstance().conf().economy().isBankEnabled() && FactionsPlugin.getInstance().conf().economy().isBankFactionPaysCosts() && fPlayer.hasFaction()) {
return Econ.hasAtLeast(faction, cost, toDoThis);
} else {
return Econ.hasAtLeast(fPlayer, cost, toDoThis);
}
}
public void doWarmUp(WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) {
this.doWarmUp(fPlayer, warmup, translationKey, action, runnable, delay);
}
public void doWarmUp(FPlayer player, WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) {
WarmUpUtil.process(player, warmup, translationKey, action, runnable, delay);
}
}
@@ -0,0 +1,149 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CommandRequirements {
// Permission required to execute command
private final Permission permission;
// Must be player
private final boolean playerOnly;
// Must be member of faction
private final boolean memberOnly;
// Must be at least this role
private final Role role;
// PermissibleAction check if the player has allow for this before checking the role
private final PermissibleAction action;
// Edge case handling
private boolean errorOnManyArgs;
private boolean disableOnLock;
private CommandRequirements(Permission permission, boolean playerOnly, boolean memberOnly, Role role, PermissibleAction action) {
this.permission = permission;
this.playerOnly = playerOnly;
this.memberOnly = memberOnly;
this.role = role;
this.action = action;
}
public boolean computeRequirements(CommandContext context, boolean informIfNot) {
// Did not modify CommandRequirements return true
if (permission == null) {
return true;
}
if (context.player != null) {
// Is Player
if (!context.fPlayer.hasFaction() && memberOnly) {
if (informIfNot) {
context.msg(TL.GENERIC_MEMBERONLY);
}
return false;
}
if (!FactionsPlugin.getInstance().getPermUtil().has(context.sender, permission.node, informIfNot)) {
return false;
}
// Permissible Action provided compute that before role
if (action != null) {
boolean access = context.faction.hasAccess(context.fPlayer, action);
if (!access) {
if (informIfNot) {
context.msg(TL.GENERIC_NOPERMISSION, action.name());
}
return false;
}
// They have been explicitly allowed
return true;
} else {
if ((role != null && !context.fPlayer.getRole().isAtLeast(role)) && informIfNot) {
context.msg(TL.GENERIC_YOUMUSTBE, role.translation);
}
return role == null || context.fPlayer.getRole().isAtLeast(role);
}
} else {
if (playerOnly) {
if (informIfNot) {
context.sender.sendMessage(TL.GENERIC_PLAYERONLY.toString());
}
return false;
}
return context.sender.hasPermission(permission.node);
}
}
public boolean isErrorOnManyArgs() {
return errorOnManyArgs;
}
public boolean isDisableOnLock() {
return disableOnLock;
}
public static class Builder {
private final Permission permission;
private boolean playerOnly = false;
private boolean memberOnly = false;
private Role role = null;
private PermissibleAction action;
private boolean errorOnManyArgs = true;
private boolean disableOnLock = true;
public Builder(Permission permission) {
this.permission = permission;
}
public Builder playerOnly() {
playerOnly = true;
return this;
}
public Builder memberOnly() {
playerOnly = true;
memberOnly = true;
return this;
}
public Builder withRole(Role role) {
this.role = role;
return this;
}
public Builder withAction(PermissibleAction action) {
this.action = action;
return this;
}
public CommandRequirements build() {
CommandRequirements requirements = new CommandRequirements(permission, playerOnly, memberOnly, role, action);
requirements.errorOnManyArgs = errorOnManyArgs;
requirements.disableOnLock = disableOnLock;
return requirements;
}
public Builder noErrorOnManyArgs() {
errorOnManyArgs = false;
return this;
}
public Builder noDisableOnLock() {
disableOnLock = false;
return this;
}
}
}
@@ -0,0 +1,286 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.cmd.alts.CmdAlts;
import com.massivecraft.factions.cmd.claim.*;
import com.massivecraft.factions.cmd.money.CmdMoney;
import com.massivecraft.factions.cmd.relations.CmdRelationAlly;
import com.massivecraft.factions.cmd.relations.CmdRelationEnemy;
import com.massivecraft.factions.cmd.relations.CmdRelationNeutral;
import com.massivecraft.factions.cmd.relations.CmdRelationTruce;
import com.massivecraft.factions.cmd.role.CmdDemote;
import com.massivecraft.factions.cmd.role.CmdPromote;
import com.massivecraft.factions.cmd.strikes.CmdStrike;
import com.massivecraft.factions.landraidcontrol.DTRControl;
import com.massivecraft.factions.landraidcontrol.PowerControl;
import com.massivecraft.factions.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class FCmdRoot extends FCommand implements CommandExecutor {
private static FCmdRoot cmdBase;
public static FCmdRoot getInstance() {
return cmdBase;
}
public CmdAutoHelp cmdAutoHelp = new CmdAutoHelp();
public CmdAdmin cmdAdmin = new CmdAdmin();
public CmdAutoClaim cmdAutoClaim = new CmdAutoClaim();
public CmdBoom cmdBoom = new CmdBoom();
public CmdBypass cmdBypass = new CmdBypass();
public CmdChat cmdChat = new CmdChat();
public CmdChatSpy cmdChatSpy = new CmdChatSpy();
public CmdClaim cmdClaim = new CmdClaim();
public CmdCoords cmdCoords = new CmdCoords();
public CmdCreate cmdCreate = new CmdCreate();
public CmdDeinvite cmdDeinvite = new CmdDeinvite();
public CmdDescription cmdDescription = new CmdDescription();
public CmdDisband cmdDisband = new CmdDisband();
public CmdFly cmdFly = new CmdFly();
public CmdHelp cmdHelp = new CmdHelp();
public CmdHome cmdHome = new CmdHome();
public CmdInvite cmdInvite = new CmdInvite();
public CmdJoin cmdJoin = new CmdJoin();
public CmdKick cmdKick = new CmdKick();
public CmdLeave cmdLeave = new CmdLeave();
public CmdList cmdList = new CmdList();
public CmdLock cmdLock = new CmdLock();
public CmdMap cmdMap = new CmdMap();
public CmdMod cmdMod = new CmdMod();
public CmdMoney cmdMoney = new CmdMoney();
public CmdOpen cmdOpen = new CmdOpen();
public CmdOwner cmdOwner = new CmdOwner();
public CmdOwnerList cmdOwnerList = new CmdOwnerList();
public CmdPeaceful cmdPeaceful = new CmdPeaceful();
public CmdPermanent cmdPermanent = new CmdPermanent();
public CmdPermanentPower cmdPermanentPower = new CmdPermanentPower();
public CmdPowerBoost cmdPowerBoost = new CmdPowerBoost();
public CmdRally cmdRally = new CmdRally();
public CmdPower cmdPower = new CmdPower();
public CmdDTR cmdDTR = new CmdDTR();
public CmdRelationAlly cmdRelationAlly = new CmdRelationAlly();
public CmdRelationEnemy cmdRelationEnemy = new CmdRelationEnemy();
public CmdRelationNeutral cmdRelationNeutral = new CmdRelationNeutral();
public CmdRelationTruce cmdRelationTruce = new CmdRelationTruce();
public CmdReload cmdReload = new CmdReload();
public CmdSafeunclaimall cmdSafeunclaimall = new CmdSafeunclaimall();
public CmdSaveAll cmdSaveAll = new CmdSaveAll();
public CmdSethome cmdSethome = new CmdSethome();
public CmdDelhome cmdDelhome = new CmdDelhome();
public CmdShow cmdShow = new CmdShow();
public CmdStatus cmdStatus = new CmdStatus();
public CmdStuck cmdStuck = new CmdStuck();
public CmdTag cmdTag = new CmdTag();
public CmdTitle cmdTitle = new CmdTitle();
public CmdToggleAllianceChat cmdToggleAllianceChat = new CmdToggleAllianceChat();
public CmdUnclaim cmdUnclaim = new CmdUnclaim();
public CmdUnclaimall cmdUnclaimall = new CmdUnclaimall();
public CmdVersion cmdVersion = new CmdVersion();
public CmdWarunclaimall cmdWarunclaimall = new CmdWarunclaimall();
public CmdSB cmdSB = new CmdSB();
public CmdShowInvites cmdShowInvites = new CmdShowInvites();
public CmdAnnounce cmdAnnounce = new CmdAnnounce();
public CmdSeeChunk cmdSeeChunk = new CmdSeeChunk();
public CmdWarp cmdWarp = new CmdWarp();
public CmdWarpOther cmdWarpOther = new CmdWarpOther();
public CmdSetWarp cmdSetWarp = new CmdSetWarp();
public CmdDelWarp cmdDelWarp = new CmdDelWarp();
public CmdModifyPower cmdModifyPower = new CmdModifyPower();
public CmdLogins cmdLogins = new CmdLogins();
public CmdClaimLine cmdClaimLine = new CmdClaimLine();
public CmdClaimFill cmdClaimFill = new CmdClaimFill();
public CmdTop cmdTop = new CmdTop();
public CmdAHome cmdAHome = new CmdAHome();
public CmdPerm cmdPerm = new CmdPerm();
public CmdPromote cmdPromote = new CmdPromote();
public CmdDemote cmdDemote = new CmdDemote();
public CmdSetDefaultRole cmdSetDefaultRole = new CmdSetDefaultRole();
public CmdMapHeight cmdMapHeight = new CmdMapHeight();
public CmdClaimAt cmdClaimAt = new CmdClaimAt();
public CmdBan cmdban = new CmdBan();
public CmdUnban cmdUnban = new CmdUnban();
public CmdBanlist cmdbanlist = new CmdBanlist();
public CmdColeader cmdColeader = new CmdColeader();
public CmdNear cmdNear = new CmdNear();
public CmdTrail cmdTrail = new CmdTrail();
public CmdDebug cmdDebug = new CmdDebug();
public CmdTNT cmdTNT = new CmdTNT();
public CmdUpgrade cmdUpgrade = new CmdUpgrade();
public CmdListClaims cmdListClaims = new CmdListClaims();
public CmdStrike cmdStrike = new CmdStrike();
public CmdStealth cmdStealth = new CmdStealth();
public CmdCorner cmdCorner = new CmdCorner();
public CmdInspect cmdInspect = new CmdInspect();
public CmdRaidClaim cmdRaidClaim = new CmdRaidClaim();
public CmdSotw cmdSotw = new CmdSotw();
public CmdAlts cmdAlts = new CmdAlts();
public CmdSeePaypal cmdSeePaypal = new CmdSeePaypal();
public CmdSetPaypal cmdSetPaypal = new CmdSetPaypal();
public FCmdRoot() {
super();
cmdBase = this;
this.aliases.addAll(FactionsPlugin.getInstance().conf().getCommandBase());
this.aliases.removeAll(Collections.<String>singletonList(null)); // remove any nulls from extra commas
this.setHelpShort("The faction base command");
this.helpLong.add(FactionsPlugin.getInstance().txt().parseTags("<i>This command contains all faction stuff."));
this.addSubCommand(this.cmdRally);
this.addSubCommand(this.cmdAlts);
this.addSubCommand(this.cmdAdmin);
this.addSubCommand(this.cmdAutoClaim);
this.addSubCommand(this.cmdBoom);
this.addSubCommand(this.cmdSetPaypal);
this.addSubCommand(this.cmdSeePaypal);
this.addSubCommand(this.cmdBypass);
this.addSubCommand(this.cmdChat);
this.addSubCommand(this.cmdToggleAllianceChat);
this.addSubCommand(this.cmdChatSpy);
this.addSubCommand(this.cmdClaim);
this.addSubCommand(this.cmdCoords);
this.addSubCommand(this.cmdCreate);
this.addSubCommand(this.cmdDeinvite);
this.addSubCommand(this.cmdDescription);
this.addSubCommand(this.cmdDisband);
this.addSubCommand(this.cmdHelp);
this.addSubCommand(this.cmdHome);
this.addSubCommand(this.cmdInvite);
this.addSubCommand(this.cmdJoin);
this.addSubCommand(this.cmdKick);
this.addSubCommand(this.cmdLeave);
this.addSubCommand(this.cmdList);
this.addSubCommand(this.cmdLock);
this.addSubCommand(this.cmdMap);
this.addSubCommand(this.cmdMod);
this.addSubCommand(this.cmdMoney);
this.addSubCommand(this.cmdOpen);
this.addSubCommand(this.cmdOwner);
this.addSubCommand(this.cmdOwnerList);
this.addSubCommand(this.cmdPeaceful);
this.addSubCommand(this.cmdPermanent);
this.addSubCommand(this.cmdRelationAlly);
this.addSubCommand(this.cmdRelationEnemy);
this.addSubCommand(this.cmdRelationNeutral);
this.addSubCommand(this.cmdRelationTruce);
this.addSubCommand(this.cmdReload);
this.addSubCommand(this.cmdSafeunclaimall);
this.addSubCommand(this.cmdSaveAll);
this.addSubCommand(this.cmdSethome);
this.addSubCommand(this.cmdDelhome);
this.addSubCommand(this.cmdShow);
this.addSubCommand(this.cmdStatus);
this.addSubCommand(this.cmdStuck);
this.addSubCommand(this.cmdTag);
this.addSubCommand(this.cmdTitle);
this.addSubCommand(this.cmdUnclaim);
this.addSubCommand(this.cmdUnclaimall);
this.addSubCommand(this.cmdVersion);
this.addSubCommand(this.cmdWarunclaimall);
this.addSubCommand(this.cmdSB);
this.addSubCommand(this.cmdShowInvites);
this.addSubCommand(this.cmdAnnounce);
this.addSubCommand(this.cmdSeeChunk);
this.addSubCommand(this.cmdWarp);
this.addSubCommand(this.cmdWarpOther);
this.addSubCommand(this.cmdSetWarp);
this.addSubCommand(this.cmdDelWarp);
this.addSubCommand(this.cmdLogins);
this.addSubCommand(this.cmdClaimLine);
this.addSubCommand(this.cmdClaimFill);
this.addSubCommand(this.cmdAHome);
this.addSubCommand(this.cmdPerm);
this.addSubCommand(this.cmdPromote);
this.addSubCommand(this.cmdDemote);
this.addSubCommand(this.cmdSetDefaultRole);
this.addSubCommand(this.cmdMapHeight);
this.addSubCommand(this.cmdClaimAt);
this.addSubCommand(this.cmdban);
this.addSubCommand(this.cmdUnban);
this.addSubCommand(this.cmdbanlist);
this.addSubCommand(this.cmdColeader);
this.addSubCommand(this.cmdNear);
this.addSubCommand(this.cmdDebug);
this.addSubCommand(this.cmdListClaims);
this.addSubCommand(this.cmdUpgrade);
this.addSubCommand(this.cmdStrike);
this.addSubCommand(this.cmdSotw);
this.addSubCommand(this.cmdStealth);
this.addSubCommand(this.cmdCorner);
this.addSubCommand(this.cmdInspect);
this.addSubCommand(this.cmdRaidClaim);
if (FactionsPlugin.getInstance().getLandRaidControl() instanceof PowerControl) {
FactionsPlugin.getInstance().getLogger().info("Using POWER for land/raid control. Enabling power commands.");
this.addSubCommand(this.cmdPermanentPower);
this.addSubCommand(this.cmdPower);
this.addSubCommand(this.cmdPowerBoost);
this.addSubCommand(this.cmdModifyPower);
} else if (FactionsPlugin.getInstance().getLandRaidControl() instanceof DTRControl) {
FactionsPlugin.getInstance().getLogger().info("Using DTR for land/raid control. Enabling DTR commands.");
this.addSubCommand(this.cmdDTR);
}
if (FactionsPlugin.getInstance().conf().commands().tnt().isEnable()) {
this.addSubCommand(this.cmdTNT);
FactionsPlugin.getInstance().getLogger().info("Enabling TNT bank management");
}
if (FactionsPlugin.getInstance().conf().commands().fly().isEnable()) {
this.addSubCommand(this.cmdFly);
this.addSubCommand(this.cmdTrail);
FactionsPlugin.getInstance().getLogger().info("Enabling /f fly command");
} else {
FactionsPlugin.getInstance().getLogger().info("Faction flight set to false in main.conf. Not enabling /f fly command.");
}
}
public void done() {
if (Bukkit.getServer().getPluginManager().isPluginEnabled("FactionsTop")) {
FactionsPlugin.getInstance().getLogger().info("Found FactionsTop plugin. Disabling our own /f top command.");
} else {
this.addSubCommand(this.cmdTop);
}
}
@Override
public void perform(CommandContext context) {
context.commandChain.add(this);
this.cmdHelp.execute(context);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!plugin.worldUtil().isEnabled(sender)) {
sender.sendMessage(TL.GENERIC_DISABLEDWORLD.toString());
return false;
}
this.execute(new CommandContext(sender, new ArrayList<>(Arrays.asList(args)), label));
return true;
}
@Override
public void addSubCommand(FCommand subCommand) {
super.addSubCommand(subCommand);
}
@Override
public TL getUsageTranslation() {
return TL.GENERIC_PLACEHOLDER;
}
}
@@ -0,0 +1,211 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.tag.Tag;
import com.massivecraft.factions.util.TL;
import com.massivecraft.factions.util.TextUtil;
import org.bukkit.ChatColor;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public abstract class FCommand {
public enum CommandVisibility {
VISIBLE, // Visible commands are visible to anyone. Even those who don't have permission to use it or is of invalid sender type.
SECRET, // Secret commands are visible only to those who can use the command. These commands are usually some kind of admin commands.
INVISIBLE // Invisible commands are invisible to everyone, even those who can use the command.
}
public FactionsPlugin plugin;
public SimpleDateFormat sdf = new SimpleDateFormat(TL.DATE_FORMAT.toString());
// Command Aliases
public List<String> aliases;
// Information on the args
public List<String> requiredArgs;
public LinkedHashMap<String, String> optionalArgs;
// Requirements to execute this command
public CommandRequirements requirements;
public FCommand() {
plugin = FactionsPlugin.getInstance();
requirements = new CommandRequirements.Builder(null).build();
this.subCommands = new ArrayList<>();
this.aliases = new ArrayList<>();
this.requiredArgs = new ArrayList<>();
this.optionalArgs = new LinkedHashMap<>();
this.helpShort = null;
this.helpLong = new ArrayList<>();
this.visibility = CommandVisibility.VISIBLE;
}
public abstract void perform(CommandContext context);
public void execute(CommandContext context) {
// Is there a matching sub command?
if (context.args.size() > 0) {
for (FCommand subCommand : this.subCommands) {
if (subCommand.aliases.contains(context.args.get(0).toLowerCase())) {
context.args.remove(0);
context.commandChain.add(this);
subCommand.execute(context);
return;
}
}
}
if (!validCall(context)) {
return;
}
if (!this.isEnabled(context)) {
return;
}
perform(context);
}
public boolean validCall(CommandContext context) {
return requirements.computeRequirements(context, true) && validArgs(context);
}
public boolean isEnabled(CommandContext context) {
if (FactionsPlugin.getInstance().getLocked() && requirements.isDisableOnLock()) {
context.msg("<b>Factions was locked by an admin. Please try again later.");
return false;
}
return true;
}
public boolean validArgs(CommandContext context) {
if (context.args.size() < this.requiredArgs.size()) {
if (context.sender != null) {
context.msg(TL.GENERIC_ARGS_TOOFEW);
context.sender.sendMessage(this.getUsageTemplate(context));
}
return false;
}
if (context.args.size() > this.requiredArgs.size() + this.optionalArgs.size() && this.requirements.isErrorOnManyArgs()) {
if (context.sender != null) {
// Get the to many string slice
List<String> theToMany = context.args.subList(this.requiredArgs.size() + this.optionalArgs.size(), context.args.size());
context.msg(TL.GENERIC_ARGS_TOOMANY, TextUtil.implode(theToMany, " "));
context.sender.sendMessage(this.getUsageTemplate(context));
}
return false;
}
return true;
}
/*
Subcommands
*/
public List<FCommand> subCommands;
public void addSubCommand(FCommand subCommand) {
this.subCommands.add(subCommand);
}
/*
Help
*/
public List<String> helpLong;
public CommandVisibility visibility;
private String helpShort;
public void setHelpShort(String val) {
this.helpShort = val;
}
public String getHelpShort() {
if (this.helpShort == null) {
return getUsageTranslation().toString();
}
return this.helpShort;
}
public abstract TL getUsageTranslation();
/*
Common Logic
*/
public List<String> getToolTips(FPlayer player) {
List<String> lines = new ArrayList<>();
for (String s : FactionsPlugin.getInstance().conf().commands().toolTips().getPlayer()) {
lines.add(ChatColor.translateAlternateColorCodes('&', Tag.parsePlain(player, s)));
}
return lines;
}
public List<String> getToolTips(Faction faction) {
List<String> lines = new ArrayList<>();
for (String s : FactionsPlugin.getInstance().conf().commands().toolTips().getFaction()) {
lines.add(ChatColor.translateAlternateColorCodes('&', Tag.parsePlain(faction, s)));
}
return lines;
}
/*
Help and Usage information
*/
public String getUsageTemplate(CommandContext context, boolean addShortHelp) {
StringBuilder ret = new StringBuilder();
ret.append(FactionsPlugin.getInstance().txt().parseTags("<g>"));
ret.append('/');
for (FCommand fc : context.commandChain) {
ret.append(TextUtil.implode(fc.aliases, ","));
ret.append(' ');
}
ret.append(TextUtil.implode(this.aliases, ","));
List<String> args = new ArrayList<>();
for (String requiredArg : this.requiredArgs) {
args.add("<" + requiredArg + ">");
}
for (Map.Entry<String, String> optionalArg : this.optionalArgs.entrySet()) {
String val = optionalArg.getValue();
if (val == null) {
val = "";
} else {
val = "=" + val;
}
args.add("[" + optionalArg.getKey() + val + "]");
}
if (args.size() > 0) {
ret.append(FactionsPlugin.getInstance().txt().parseTags("<l> "));
ret.append(TextUtil.implode(args, " "));
}
if (addShortHelp) {
ret.append(FactionsPlugin.getInstance().txt().parseTags(" <n>"));
ret.append(this.getHelpShort());
}
return ret.toString();
}
public String getUsageTemplate(CommandContext context) {
return getUsageTemplate(context, false);
}
}
@@ -0,0 +1,46 @@
package com.massivecraft.factions.cmd.alts;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.cmd.CommandContext;
import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.CC;
import com.massivecraft.factions.util.TL;
public class CmdAltClear extends FCommand {
public CmdAltClear() {
super();
this.aliases.add("clear");
this.requirements = new CommandRequirements.Builder(Permission.ALTS).withAction(PermissibleAction.INVITE).memberOnly().build();
}
@Override
public void perform(CommandContext context) {
Faction faction = context.faction;
int amountKicked = 0;
for (FPlayer fPlayer : faction.getFPlayersWhereRole(Role.ALT)) {
faction.removeFPlayer(fPlayer);
amountKicked++;
}
if (amountKicked == 0) {
context.fPlayer.sendMessage(CC.translate("&6&lFactions &8⎜ &cError&8: &eThere are no alts in your faction"));
} else {
context.fPlayer.sendMessage(CC.translate("&6&lFactions &8⎜ &cError&8: &eRemoved a total of &7" + amountKicked + " &ealts from your faction"));
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_ALT_OPENUSAGE;
}
}
@@ -0,0 +1,38 @@
package com.massivecraft.factions.cmd.alts;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.cmd.CommandContext;
import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdAltClose extends FCommand {
public CmdAltClose(){
super();
this.aliases.add("close");
this.requirements = new CommandRequirements.Builder(Permission.ALTS).withAction(PermissibleAction.INVITE).memberOnly().build();
}
@Override
public void perform(CommandContext context) {
Faction faction = context.faction;
if(faction.getAltJoinString().equals("-1")){
context.msg(TL.COMMAND_ALT_ALREADYCLOSED, faction.describeTo(context.fPlayer));
return;
}
faction.setAltClosed();
context.msg(TL.COMMAND_ALT_CLOSE, faction.describeTo(context.fPlayer));
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_ALT_CLOSEUSAGE;
}
}
@@ -0,0 +1,72 @@
package com.massivecraft.factions.cmd.alts;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.cmd.CommandContext;
import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.perms.Role;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdAltJoin extends FCommand {
public CmdAltJoin(){
super();
this.aliases.add("join");
this.requiredArgs.add("faction");
this.requiredArgs.add("joinString");
this.requirements = new CommandRequirements.Builder(Permission.ALTS).build();
}
@Override
public void perform(CommandContext context) {
Faction faction = context.argAsFaction(0);
String other = context.argAsString(1);
if(faction == null)return;
if(other == null)return;
if (context.fPlayer.hasFaction()) {
context.msg(TL.COMMAND_JOIN_INOTHERFACTION, context.fPlayer.describeTo(context.fPlayer, true), "your");
return;
}
if (FactionsPlugin.getInstance().conf().factions().other().maxAlts() > 0 && faction.getFPlayersWhereRole(Role.ALT).size() >= FactionsPlugin.getInstance().conf().factions().other().maxAlts()) {
context.msg(TL.COMMAND_JOIN_ATLIMIT, faction.getTag(context.fPlayer), FactionsPlugin.getInstance().conf().factions().other().maxAlts(), context.fPlayer.describeTo(context.fPlayer, false));
return;
}
if(faction == context.fPlayer.getFaction()){
context.msg(TL.COMMAND_JOIN_ALREADYMEMBER, context.fPlayer.describeTo(context.fPlayer, true), "are", faction.getTag(context.fPlayer));
return;
}
if(faction.getAltJoinString().equals("-1")){
context.msg(TL.COMMAND_ALT_NOTOPEN, faction.describeTo(context.fPlayer));
return;
}
if(!faction.getAltJoinString().equals(other)){
context.msg(TL.COMMAND_ALT_WRONGCODE, other, faction.describeTo(context.fPlayer));
return;
}
context.fPlayer.resetFactionData();
context.fPlayer.setFaction(faction);
context.msg(TL.COMMAND_JOIN_SUCCESS, context.fPlayer.describeTo(context.fPlayer, true), faction.getTag(context.fPlayer));
context.fPlayer.setRole(Role.ALT);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_ALT_JOINUSAGE;
}
}
@@ -0,0 +1,38 @@
package com.massivecraft.factions.cmd.alts;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.cmd.CommandContext;
import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.perms.PermissibleAction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdAltOpen extends FCommand {
public CmdAltOpen(){
super();
this.aliases.add("open");
this.requirements = new CommandRequirements.Builder(Permission.ALTS).withAction(PermissibleAction.INVITE).memberOnly().build();
}
@Override
public void perform(CommandContext context) {
Faction faction = context.faction;
if(!faction.getAltJoinString().equals("-1")){
context.msg(TL.COMMAND_ALT_ALREADYOPEN, faction.describeTo(context.fPlayer), faction.getAltJoinString());
return;
}
String string = faction.setAltOpen();
context.msg(TL.COMMAND_ALT_OPEN, faction.describeTo(context.fPlayer), string);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_ALT_OPENUSAGE;
}
}
@@ -0,0 +1,37 @@
package com.massivecraft.factions.cmd.alts;
import com.massivecraft.factions.cmd.CommandContext;
import com.massivecraft.factions.cmd.CommandRequirements;
import com.massivecraft.factions.cmd.FCmdRoot;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.TL;
public class CmdAlts extends FCommand {
public CmdAlts(){
super();
this.aliases.add("alts");
this.aliases.add("alt");
this.addSubCommand(new CmdAltJoin());
this.addSubCommand(new CmdAltOpen());
this.addSubCommand(new CmdAltClose());
this.addSubCommand(new CmdAltClear());
this.requirements = new CommandRequirements.Builder(Permission.ALTS).build();
}
@Override
public void perform(CommandContext context) {
context.commandChain.add(this);
FCmdRoot.getInstance().cmdAutoHelp.execute(context);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_ALT_USAGE;
}
}

Some files were not shown because too many files have changed in this diff Show More