Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit d8ff7a5

Browse files
committed
New Feature
Added an argument to the command that allows you to, basically, specify the lowest faction rank added to the region. For example, if you type officer, it adds only officers and leader to the region. if you type member, it adds members and up. If you type all, it allows recruits.
1 parent 9e4946e commit d8ff7a5

5 files changed

Lines changed: 80 additions & 10 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.github.pocketkid2</groupId>
55
<artifactId>WGFactions</artifactId>
6-
<version>0.1.0</version>
6+
<version>0.1.1</version>
77
<name>WGFactions</name>
88
<description>World Guard and Factions working together!</description>
99
<properties>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.github.pocketkid2.wgf;
2+
3+
public enum AddType {
4+
// Leader and officers in the faction
5+
OFFICERS,
6+
// All faction members except recruits
7+
MEMBERS,
8+
// All (including recruits)
9+
ALL;
10+
11+
@Override
12+
public String toString() {
13+
switch (this) {
14+
case ALL:
15+
return "all players";
16+
case MEMBERS:
17+
return "all players except recruits";
18+
case OFFICERS:
19+
return "leader and officer";
20+
default:
21+
return null;
22+
}
23+
}
24+
}

src/main/java/com/github/pocketkid2/wgf/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ public interface Messages {
1111
String INVALID_FACTION = ChatColor.RED + "Invalid faction!";
1212
String ADDED = ChatColor.AQUA + "Added all players from faction " + ChatColor.GREEN + "%s " + ChatColor.AQUA + "to region " + ChatColor.BLUE + "%s";
1313
String REMOVED = ChatColor.AQUA + "Removed all players from faction " + ChatColor.GREEN + "%s " + ChatColor.AQUA + "from region " + ChatColor.BLUE + "%s";
14+
String INVALID_MODE = ChatColor.RED + "Invalid add mode! Valid modes are OFFICER, MEMBER, or ALL";
1415

1516
}

src/main/java/com/github/pocketkid2/wgf/commands/WGFAddCommand.java

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.bukkit.command.CommandSender;
88
import org.bukkit.entity.Player;
99

10+
import com.github.pocketkid2.wgf.AddType;
1011
import com.github.pocketkid2.wgf.Messages;
1112
import com.github.pocketkid2.wgf.WGFPlugin;
1213
import com.massivecraft.factions.entity.Faction;
@@ -27,23 +28,23 @@ public WGFAddCommand(WGFPlugin pl) {
2728
@Override
2829
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
2930
// Check for not enough arguments
30-
if (args.length < 2) {
31+
if (args.length < 3) {
3132
sender.sendMessage(Messages.NOT_ENOUGH_ARGUMENTS);
3233
}
3334

3435
// Check for too many arguments
35-
if (args.length > 3) {
36+
if (args.length > 4) {
3637
sender.sendMessage(Messages.TOO_MANY_ARGUMENTS);
3738
return false;
3839
}
3940

4041
// World being used
4142
World world;
4243

43-
// Check for a third argument
44-
if (args.length == 3) {
44+
// Check for a fourth argument
45+
if (args.length == 4) {
4546
// Then get the world
46-
world = Bukkit.getWorld(args[2]);
47+
world = Bukkit.getWorld(args[3]);
4748

4849
// Check for null
4950
if (world == null) {
@@ -61,6 +62,23 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
6162
}
6263
}
6364

65+
// Get the mode
66+
AddType mode;
67+
switch (args[2].toLowerCase()) {
68+
case "officer":
69+
mode = AddType.OFFICERS;
70+
break;
71+
case "member":
72+
mode = AddType.MEMBERS;
73+
break;
74+
case "all":
75+
mode = AddType.ALL;
76+
break;
77+
default:
78+
sender.sendMessage(Messages.INVALID_MODE);
79+
return false;
80+
}
81+
6482
// Get the region
6583
RegionContainer container = plugin.getWorldGuard().getRegionContainer();
6684
RegionManager manager = container.get(world);
@@ -83,14 +101,41 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
83101

84102
// Showtime
85103
for (MPlayer player : faction.getMPlayers()) {
86-
region.getMembers().addPlayer(player.getUuid());
104+
105+
switch (player.getRole()) {
106+
// If it's a leader or officer, we add them automatically
107+
case LEADER:
108+
case OFFICER:
109+
add(region, player);
110+
break;
111+
// If it's a member, we only add if it's one of the other two modes
112+
case MEMBER:
113+
if (mode != AddType.OFFICERS) {
114+
add(region, player);
115+
}
116+
break;
117+
// Recruits are only added on the last mode
118+
case RECRUIT:
119+
if (mode == AddType.ALL) {
120+
add(region, player);
121+
}
122+
break;
123+
default:
124+
break;
125+
126+
}
87127
}
88128

89129
// Notify the sender
90-
sender.sendMessage(String.format(Messages.ADDED, faction.getName(), region.getId()));
130+
sender.sendMessage(String.format(Messages.ADDED, mode.toString(), faction.getName(), region.getId()));
91131

92132
// We're done
93133
return true;
94134
}
95135

136+
// This prevents code reuse
137+
private void add(ProtectedRegion region, MPlayer player) {
138+
region.getMembers().addPlayer(player.getUuid());
139+
}
140+
96141
}

src/main/resources/plugin.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name: WGFactions
22
main: com.github.pocketkid2.wgf.WGFPlugin
3-
version: 0.1.0
3+
version: 0.1.1
44
depend: [WorldGuard, Factions]
55
author: Pocketkid2
66
description: World Guard and Factions working together!
77
commands:
88
wgfadd:
99
description: Add all players from a faction to a region
10-
usage: /<command> <region> <faction> [world]
10+
usage: /<command> <region> <faction> <officer|member|all> [world]
1111
permission: wgf.add
1212
permisison-message: You don't have permission!
1313
wgfremove:

0 commit comments

Comments
 (0)