/
ConsoleCommandSender.java
108 lines (91 loc) · 2.81 KB
/
ConsoleCommandSender.java
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
package net.ME1312.Galaxi.Command;
import net.ME1312.Galaxi.Galaxi;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Map.ObjectMapValue;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Log.TextElement;
/**
* Console Command Sender Class
*/
public class ConsoleCommandSender implements CommandSender {
private final ObjectMap<String> extra = new ObjectMap<String>();
/**
* Get the Console Command Sender
*
* @return Console Command Sender
*/
public static ConsoleCommandSender get() {
return Galaxi.getInstance().getConsole();
}
protected ConsoleCommandSender() {}
@Override
public String getName() {
return "CONSOLE";
}
@Override
public boolean hasPermission(String permission) {
return true;
}
/**
* Open the Console Window
*/
public final void openWindow() {
Galaxi.getInstance().getCommandProcessor().openWindow(false);
}
/**
* Close the Console Window
*/
public final void closeWindow() {
Galaxi.getInstance().getCommandProcessor().closeWindow(false);
}
/**
* Send a message as Console
*
* @param message Message to send
* @throws UnsupportedOperationException when impossible
*/
public void chat(String message) {
throw new UnsupportedOperationException("No console chat handler for type: String");
}
/**
* Send a message as Console
*
* @param message Message to send
* @throws UnsupportedOperationException when impossible
*/
public void chat(TextElement message) {
throw new UnsupportedOperationException("No console chat handler for type: TextElement");
}
@Override
public void sendMessage(String... messages) {
Galaxi.getInstance().getAppInfo().getLogger().message.println(messages);
}
@Override
public void sendMessage(TextElement... messages) {
Galaxi.getInstance().getAppInfo().getLogger().message.println(messages);
}
@Override
public void addExtra(String handle, Object value) {
if (Util.isNull(handle, value)) throw new NullPointerException();
extra.set(handle, value);
}
@Override
public boolean hasExtra(String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
return extra.getKeys().contains(handle);
}
@Override
public ObjectMapValue<String> getExtra(String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
return extra.get(handle);
}
@Override
public ObjectMap<String> getExtra() {
return extra.clone();
}
@Override
public void removeExtra(String handle) {
if (Util.isNull(handle)) throw new NullPointerException();
extra.remove(handle);
}
}