-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFactionSubCommand.java
More file actions
131 lines (111 loc) · 4.02 KB
/
Copy pathFactionSubCommand.java
File metadata and controls
131 lines (111 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package com.hyperfactions.command;
import com.hyperfactions.HyperFactions;
import com.hyperfactions.command.util.CommandUtil;
import com.hyperfactions.data.Faction;
import com.hyperfactions.platform.HyperFactionsPlugin;
import com.hyperfactions.util.CommonKeys;
import com.hyperfactions.util.MessageUtil;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import java.util.UUID;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Base class for faction subcommands.
* Provides common functionality and access to HyperFactions services.
*/
public abstract class FactionSubCommand extends AbstractPlayerCommand {
protected final HyperFactions hyperFactions;
protected final HyperFactionsPlugin plugin;
/**
* Creates a new faction subcommand.
*
* @param name the command name
* @param description the command description
* @param hyperFactions the HyperFactions instance
* @param plugin the plugin instance
*/
protected FactionSubCommand(@NotNull String name,
@NotNull String description,
@NotNull HyperFactions hyperFactions,
@NotNull HyperFactionsPlugin plugin) {
super(name, description);
this.hyperFactions = hyperFactions;
this.plugin = plugin;
setAllowsExtraArguments(true);
}
/**
* Disable Hytale's auto-generated permissions for subcommands.
* We use our own permission system via hasPermission() checks in execute().
*/
@Override
protected boolean canGeneratePermission() {
return false;
}
// ==================== Utility Methods ====================
/**
* Creates the standard HyperFactions message prefix.
*/
protected Message prefix() {
return CommandUtil.prefix();
}
/**
* Creates a colored message.
*/
protected Message msg(String text, String color) {
return CommandUtil.msg(text, color);
}
/**
* Checks if a player has a specific permission.
*/
protected boolean hasPermission(PlayerRef player, String permission) {
return CommandUtil.hasPermission(player, permission);
}
/**
* Finds an online player by name.
*/
protected PlayerRef findOnlinePlayer(String name) {
return CommandUtil.findOnlinePlayer(plugin, name);
}
/**
* Broadcasts a message to all online members of a faction.
*/
protected void broadcastToFaction(UUID factionId, Message message) {
CommandUtil.broadcastToFaction(hyperFactions, plugin, factionId, message);
}
/**
* Parses FactionCommandContext from remaining arguments.
* This handles the --text flag extraction from args.
*
* @param args the raw command arguments
* @return the parsed context
*/
protected FactionCommandContext parseContext(String[] args) {
return FactionCommandContext.parse(args);
}
/**
* Gets the player's faction, sending an error message if they aren't in one.
*
* @param ctx the command context (for sending error message)
* @param player the player to check
* @return the player's faction, or null if not in a faction
*/
@Nullable
protected Faction requireFaction(@NotNull CommandContext ctx, @NotNull PlayerRef player) {
Faction faction = hyperFactions.getFactionManager().getPlayerFaction(player.getUuid());
if (faction == null) {
ctx.sendMessage(MessageUtil.error(player, CommonKeys.Common.NOT_IN_FACTION));
return null;
}
return faction;
}
// Color constants for convenience
protected static final String COLOR_CYAN = CommandUtil.COLOR_CYAN;
protected static final String COLOR_GREEN = CommandUtil.COLOR_GREEN;
protected static final String COLOR_RED = CommandUtil.COLOR_RED;
protected static final String COLOR_YELLOW = CommandUtil.COLOR_YELLOW;
protected static final String COLOR_GRAY = CommandUtil.COLOR_GRAY;
protected static final String COLOR_WHITE = CommandUtil.COLOR_WHITE;
}