Skip to content

Commit 6471797

Browse files
committed
Final updates before 1.0 release!
1 parent 676ab31 commit 6471797

25 files changed

+775
-221
lines changed

MCNotify/src/org/zonex/ZoneX.java

+29
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
import org.zonex.config.EventRegistry;
1111
import org.zonex.config.Metrics;
1212
import org.zonex.datastore.Datastore;
13+
import org.zonex.subscriptions.Subscription;
1314
import org.zonex.subscriptions.SubscriptionManager;
1415
import org.zonex.config.ConfigurationManager;
1516
import org.zonex.communication.auth.RequestManager;
1617

1718
import java.sql.SQLException;
19+
import java.util.ArrayList;
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
import java.util.concurrent.Callable;
1823
import java.util.logging.Filter;
1924
import java.util.logging.LogManager;
2025
import java.util.logging.LogRecord;
@@ -73,6 +78,30 @@ public void onEnable(){
7378
new RegisterCommands();
7479

7580
Metrics metrics = new Metrics(this);
81+
metrics.addCustomChart(new Metrics.SingleLineChart("zone", new Callable<Integer>() {
82+
@Override
83+
public Integer call() throws Exception {
84+
return ZoneX.areaManager.countZones();
85+
}
86+
}));
87+
metrics.addCustomChart(new Metrics.SingleLineChart("subscriptions", new Callable<Integer>() {
88+
@Override
89+
public Integer call() throws Exception {
90+
return ZoneX.subscriptionManager.getSubscriptions().size();
91+
}
92+
}));
93+
metrics.addCustomChart(new Metrics.SingleLineChart("externalCommunications", new Callable<Integer>() {
94+
@Override
95+
public Integer call() throws Exception {
96+
return ZoneX.communicationManager.getTotalCommunicationMethods();
97+
}
98+
}));
99+
metrics.addCustomChart(new Metrics.SimplePie("storage_format", new Callable<String>() {
100+
@Override
101+
public String call() throws Exception {
102+
return ZoneX.datastore.isUsingDatabase() ? "Database" : "Flat file";
103+
}
104+
}));
76105

77106
System.out.println("[ZoneX] Plugin enabled.");
78107
}

MCNotify/src/org/zonex/areas/AreaManager.java

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
public class AreaManager {
1313

1414
HashMap<UUID, ArrayList<Area>> areaList = new HashMap<>();
15+
private int areaCount = 0;
1516

1617
public AreaManager(){
1718

@@ -25,6 +26,7 @@ public void loadDatabase() throws SQLException {
2526
ArrayList<Area> areaList = ZoneX.datastore.areaTable().selectAll();
2627

2728
for(Area area : areaList){
29+
areaCount++;
2830
this.addOldArea(area);
2931
}
3032

@@ -53,6 +55,7 @@ public boolean addNewArea(Area area){
5355
if(this.areaList.get(area.getOwner().getUniqueId()) == null){
5456
playerAreas = new ArrayList<Area>();
5557
this.areaList.put(area.getOwner().getUniqueId(), playerAreas);
58+
areaCount++;
5659
} else {
5760
playerAreas = this.areaList.get(area.getOwner().getUniqueId());
5861
}
@@ -80,6 +83,7 @@ public boolean removeArea(UUID uuid, String areaName){
8083

8184
if(ZoneX.datastore.areaTable().delete(area)){
8285
playerAreas.remove(area);
86+
areaCount--;
8387
return true;
8488
}
8589

@@ -121,4 +125,8 @@ public Area getAreaAtLocation(Location location){
121125
return null;
122126
}
123127

128+
public int countZones(){
129+
return areaCount;
130+
}
131+
124132
}

MCNotify/src/org/zonex/areas/protection/Protection.java

+18-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
package org.zonex.areas.protection;
22

33
import org.zonex.config.Configuration;
4+
import org.zonex.config.Permission;
45

56
import java.util.ArrayList;
67

78
public enum Protection {
89

9-
PROTECT("Protect", "Players cannot place or destroy blocks", "protect", Configuration.AREA_DEFAULT_PROTECT, "Players cannot build or place blocks unless allowed", "Players can place and destroy blocks", "zx.member.protect.protect"),
10-
MOB_PROTECT("Mob Protect", "Players cannot damage peaceful mobs", "mobProtect", Configuration.AREA_DEFAULT_MOBPROTECT, "Players cannot harm peaceful mobs unless allowed", "Players can harm peaceful mobs", "zx.member.protect.mobProtect"),
11-
STOP_LIQUID("Stop Liquid", "Liquid cannot flow into area", "stopLiquid", Configuration.AREA_DEFAULT_STOPLIQUID, "Water and lava cannot flow into the area", "Water and lava can flow into the area", "zx.member.protect.stopLiquid"),
12-
CHEST_LOCK("Chest Lock", "Prevents players from opening your chests, shulkers, hoppers, etc.", "chestLock", Configuration.AREA_DEFAULT_CHESTLOCK, "Players cannot access inventories unless allowed", "Players can access inventories", "zx.member.protect.chestLock"),
13-
NO_REDSTONE("No Redstone", "Prevents players using redstone devices (buttons, levers, pressure plates)", "noRedstone", Configuration.AREA_DEFAULT_NOREDSTONE, "Players cannot use redstone devices unless allowed", "Players can use redstone devices", "zx.member.protect.noRedstone"),
14-
NO_FIRE("No Fire", "Prevents fire from starting", "noFire", Configuration.AREA_DEFAULT_NOFIRE, "Fire cannot be started unless allowed", "Fire can be started", "zx.member.protect.noFire"),
15-
DOOR_LOCK("Door Lock", "Prevents doors and trapdoors from being opened", "doorLock", Configuration.AREA_DEFAULT_DOORLOCK, "Doors cannot be used unless allowed", "Doors can be used", "zx.member.protect.doorLock"),
16-
NO_ENTER("No Enter", "Prevents players being able to walk into the area", "noEnter", Configuration.AREA_DEFAULT_NOENTER, "Players cannot enter the area unless allowed", "Players can enter the area", "zx.member.protect.noEnter"),
17-
NO_INTERACT("No Interact", "Prevents players interacting with furnaces, brewing stands, etc.", "noInteract", Configuration.AREA_DEFAULT_NOINTERACT, "Players cannot interact with furnaces, etc. unless allowed", "Players can interact with furnaces, etc.", "zx.member.protect.noInteract"),
18-
NO_PVP("No PvP", "Prevents other players from being able to attack players.", "noPvP", Configuration.AREA_DEFAULT_NOPVP, "Players cannot attack other players in the area.", "Players can attack players in the area.", "zx.member.protect.noPvp");
10+
PROTECT("Protect", "Players cannot place or destroy blocks", "protect", Configuration.AREA_DEFAULT_PROTECT, "Players cannot build or place blocks unless allowed", "Players can place and destroy blocks", Permission.PROTECTION_PROTECT),
11+
MOB_PROTECT("Mob Protect", "Players cannot damage peaceful mobs", "mobProtect", Configuration.AREA_DEFAULT_MOBPROTECT, "Players cannot harm peaceful mobs unless allowed", "Players can harm peaceful mobs", Permission.PROTECTION_MOB_PROTECT),
12+
STOP_LIQUID("Stop Liquid", "Liquid cannot flow into area", "stopLiquid", Configuration.AREA_DEFAULT_STOPLIQUID, "Water and lava cannot flow into the area", "Water and lava can flow into the area", Permission.PROTECTION_STOP_LIQUID),
13+
CHEST_LOCK("Chest Lock", "Prevents players from opening your chests, shulkers, hoppers, etc.", "chestLock", Configuration.AREA_DEFAULT_CHESTLOCK, "Players cannot access inventories unless allowed", "Players can access inventories", Permission.PROTECTION_CHEST_LOCK),
14+
NO_REDSTONE("No Redstone", "Prevents players using redstone devices (buttons, levers, pressure plates)", "noRedstone", Configuration.AREA_DEFAULT_NOREDSTONE, "Players cannot use redstone devices unless allowed", "Players can use redstone devices", Permission.PROTECTION_NO_REDSTONE),
15+
NO_FIRE("No Fire", "Prevents fire from starting", "noFire", Configuration.AREA_DEFAULT_NOFIRE, "Fire cannot be started unless allowed", "Fire can be started", Permission.PROTECTION_NO_FIRE),
16+
DOOR_LOCK("Door Lock", "Prevents doors and trapdoors from being opened", "doorLock", Configuration.AREA_DEFAULT_DOORLOCK, "Doors cannot be used unless allowed", "Doors can be used", Permission.PROTECTION_DOOR_LOCK),
17+
NO_ENTER("No Enter", "Prevents players being able to walk into the area", "noEnter", Configuration.AREA_DEFAULT_NOENTER, "Players cannot enter the area unless allowed", "Players can enter the area", Permission.PROTECTION_NO_ENTER),
18+
NO_INTERACT("No Interact", "Prevents players interacting with furnaces, brewing stands, etc.", "noInteract", Configuration.AREA_DEFAULT_NOINTERACT, "Players cannot interact with furnaces, etc. unless allowed", "Players can interact with furnaces, etc.", Permission.PROTECTION_NO_INTERACT),
19+
NO_PVP("No PvP", "Prevents other players from being able to attack players.", "noPvP", Configuration.AREA_DEFAULT_NOPVP, "Players cannot attack other players in the area.", "Players can attack players in the area.", Permission.PROTECTION_NO_PVP);
1920

2021

2122
private String name;
@@ -24,16 +25,16 @@ public enum Protection {
2425
private Configuration defaultConfig;
2526
private String enabledMessage;
2627
private String disabledMessage;
27-
private String permissionString;
28+
private Permission permissionNode;
2829

29-
Protection(String name, String description, String command, Configuration defaultConfig, String enabledMessage, String disabledMessage, String permissionString){
30+
Protection(String name, String description, String command, Configuration defaultConfig, String enabledMessage, String disabledMessage, Permission permissionString){
3031
this.name = name;
3132
this.description = description;
3233
this.command = command;
3334
this.defaultConfig = defaultConfig;
3435
this.enabledMessage = enabledMessage;
3536
this.disabledMessage = disabledMessage;
36-
this.permissionString = permissionString;
37+
this.permissionNode = permissionString;
3738
}
3839

3940
public String toString(){
@@ -56,8 +57,8 @@ public Configuration getDefaultConfig(){
5657
return this.defaultConfig;
5758
}
5859

59-
public String getPermissionString(){
60-
return this.permissionString;
60+
public Permission getPermissionNode(){
61+
return this.permissionNode;
6162
}
6263

6364
public static ArrayList<Protection> getDefaultProtections(){
@@ -73,7 +74,7 @@ public static ArrayList<Protection> getDefaultProtections(){
7374
public static ArrayList<Protection> fromString(String protectionString){
7475
ArrayList<Protection> protections = new ArrayList<>();
7576
for(Protection p : Protection.values()){
76-
if(protectionString.toLowerCase().contains(p.command.toLowerCase())){
77+
if(protectionString.toLowerCase().equals(p.command.toLowerCase())){
7778
protections.add(p);
7879
}
7980
}
@@ -82,7 +83,7 @@ public static ArrayList<Protection> fromString(String protectionString){
8283

8384
public static Protection fromCommand(String commandName){
8485
for(Protection p : Protection.values()){
85-
if(commandName.toLowerCase().contains(p.command.toLowerCase())){
86+
if(commandName.toLowerCase().equals(p.command.toLowerCase())){
8687
return p;
8788
}
8889
}

MCNotify/src/org/zonex/commands/AbstractCommand.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
import org.bukkit.command.TabCompleter;
99
import org.bukkit.entity.Player;
1010
import org.zonex.ZoneX;
11+
import org.zonex.commands.autocomplete.AutoCompleter;
1112

1213
import java.util.List;
1314

1415
public abstract class AbstractCommand extends AsyncCommandExecutor implements TabCompleter {
1516

1617
private final String commandString;
1718
private final boolean canConsoleUse;
19+
private AutoCompleter autoCompleter;
1820

1921
public AbstractCommand(String commandString, boolean canConsoleUse){
2022
this.commandString = commandString;
@@ -23,6 +25,10 @@ public AbstractCommand(String commandString, boolean canConsoleUse){
2325
ZoneX.plugin.getCommand(this.commandString).setTabCompleter(this);
2426
}
2527

28+
public void setAutoCompleter(AutoCompleter autoCompleter){
29+
this.autoCompleter = autoCompleter;
30+
}
31+
2632
@Override
2733
public void doAsyncCommand(CommandSender sender, Command cmd, String str, String[] args) {
2834
if(!cmd.getLabel().equalsIgnoreCase(this.commandString))
@@ -35,16 +41,13 @@ public void doAsyncCommand(CommandSender sender, Command cmd, String str, String
3541
}
3642

3743
public abstract void execute(CommandSender sender, String[] args);
38-
public abstract List<String> tabComplete(CommandSender sender, String[] args);
3944

4045
@Override
4146
public List<String> onTabComplete(CommandSender sender, Command cmd, String str, String[] args){
42-
if(!cmd.getLabel().equalsIgnoreCase(this.commandString))
43-
return null;
44-
if(sender instanceof Player)
45-
return this.tabComplete(sender, args);
46-
else
47-
return null;
47+
if(this.autoCompleter != null) {
48+
return this.autoCompleter.getSuggestions((Player)sender, args);
49+
}
50+
return null;
4851
}
4952

5053
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.zonex.commands.autocomplete;
2+
3+
import org.bukkit.entity.Player;
4+
import org.zonex.config.Permission;
5+
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
9+
public abstract class AutoCompleteNode {
10+
11+
protected Permission permissionNode = null;
12+
protected ArrayList<AutoCompleteNode> children = new ArrayList<>();
13+
14+
public abstract boolean matches(String s);
15+
16+
17+
public AutoCompleteNode addChild(AutoCompleteNode node){
18+
this.children.add(node);
19+
return this;
20+
}
21+
22+
public ArrayList<AutoCompleteNode> getChildren(){
23+
return this.children;
24+
}
25+
26+
public boolean hasChildren(){
27+
return this.children.size() > 0;
28+
}
29+
30+
public AutoCompleteNode requiresPermissionNode(Permission permissionNode){
31+
this.permissionNode = permissionNode;
32+
return this;
33+
}
34+
35+
public boolean hasPermission(Player player){
36+
if(this.permissionNode == null){
37+
return true;
38+
} else {
39+
return this.permissionNode.hasPermission(player);
40+
}
41+
}
42+
43+
public abstract List<String> getSuggestedCommands(Player player, String s);
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.zonex.commands.autocomplete;
2+
3+
import org.bukkit.entity.Player;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public class AutoCompleter {
9+
10+
private ArrayList<AutoCompleteNode> commands = new ArrayList<>();
11+
private int depth;
12+
13+
public AutoCompleter(){
14+
this.depth = 0;
15+
}
16+
17+
public void addNode(AutoCompleteNode node){
18+
this.commands.add(node);
19+
}
20+
21+
private AutoCompleter(ArrayList<AutoCompleteNode> autoCompleteTree, int depth){
22+
this.commands = autoCompleteTree;
23+
this.depth = depth;
24+
}
25+
26+
public List<String> getSuggestions(Player player, String[] args){
27+
List<String> commands = new ArrayList<>();
28+
if(args.length - 1 > depth) {
29+
for (AutoCompleteNode commandNode : this.commands) {
30+
if (commandNode.matches(args[depth])){
31+
if(commandNode.hasChildren()) {
32+
commands.addAll(new AutoCompleter(commandNode.getChildren(), depth + 1).getSuggestions(player, args));
33+
} else {
34+
continue;
35+
}
36+
}
37+
}
38+
return commands;
39+
} else {
40+
for (AutoCompleteNode commandNode : this.commands) {
41+
commands.addAll(commandNode.getSuggestedCommands(player, args[depth]));
42+
}
43+
return commands;
44+
}
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.zonex.commands.autocomplete;
2+
3+
import org.bukkit.entity.Player;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
public class CommandAutoCompleteNode extends AutoCompleteNode {
9+
10+
private String nodeName;
11+
12+
public CommandAutoCompleteNode(String s){
13+
this.nodeName = s;
14+
}
15+
16+
public boolean matches(String s){
17+
return this.nodeName.startsWith(s.toLowerCase());
18+
}
19+
20+
public List<String> getSuggestedCommands(Player player, String s){
21+
ArrayList<String> commands = new ArrayList<>();
22+
if(hasPermission(player)) {
23+
if(this.matches(s)) {
24+
commands.add(this.nodeName);
25+
return commands;
26+
}
27+
}
28+
return commands;
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.zonex.commands.autocomplete;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.OfflinePlayer;
5+
import org.bukkit.entity.Player;
6+
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
public class PlayerNameAutoCompleteNode extends AutoCompleteNode {
11+
12+
13+
@Override
14+
public boolean matches(String s) {
15+
return true;
16+
}
17+
18+
@Override
19+
public List<String> getSuggestedCommands(Player player, String s) {
20+
// Get potential list of players.
21+
List<String> players = new ArrayList<>();
22+
for(Player p : Bukkit.getOnlinePlayers()){
23+
if(p.getName().startsWith(s)){
24+
players.add(p.getName());
25+
}
26+
}
27+
for(OfflinePlayer p : Bukkit.getOfflinePlayers()){
28+
if(p.getName().startsWith(s)){
29+
players.add(p.getName());
30+
}
31+
}
32+
return players;
33+
}
34+
}

0 commit comments

Comments
 (0)