Skip to content

Commit 62ad3e6

Browse files
[+] Added Respawn Command for respawning the bot.
[+] Added command usages for reload command. [+] Added Command Menu for tab completing. [#] Improved Logging system. [+] Added Reconnect Command for reconnecting to the server. [+] Added Exception Detection in Event Manager. [-] Removed setting of Disabling READ_TIMEOUT. [#] Improved Terminal Command Completer. [#] Fixed bug that players' skins duplicates when property.isEmpty() is true. [#] Fixed Terminal Command Completer Not Working when command starting with "/". [#] Improved code quality. [#] Updated submodule `DolphinStudio` in project.
1 parent 4b9f5ac commit 62ad3e6

15 files changed

Lines changed: 105 additions & 37 deletions

DolphinStudio

Submodule DolphinStudio updated 32 files

src/main/java/org/angellock/impl/AbstractRobot.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ public String getPassword(){
150150

151151
public void connect(){
152152
onPreLogin();
153-
String serverIP = this.infoHelper.getServer(); // != null ? this.infoHelper.getServer() : this.config().getServer();
154-
int serverPort = this.infoHelper.getPort(); // != 0 ? this.infoHelper.getPort() : this.config().getPort();
153+
String serverIP = this.infoHelper.getServer();
154+
int serverPort = this.infoHelper.getPort();
155155

156156
if (this.proxyInfo != null) {
157157
this.serverSession = new TcpClientSession(serverIP, serverPort, minecraftProtocol, this.proxyInfo);
@@ -168,7 +168,6 @@ public void connect(){
168168
this.serverSession.addListener(new PlayerEmergeHandler(this));
169169
this.serverSession.addListener(new PlayerPositionPacket((RobotPlayer) this));
170170
if (this.config().getDebugSettings().isEnablePacketDebug()) { this.serverSession.addListener(new PacketDebugger()); }
171-
//this.serverSession.setFlag(BuiltinFlags.READ_TIMEOUT, -1);
172171
this.serverSession.setFlag(BuiltinFlags.WRITE_TIMEOUT, -1);
173172
this.serverSession.connect(true, false);
174173

@@ -197,9 +196,11 @@ public void connect(){
197196
}
198197
}
199198
catch (InterruptedException e){
200-
throw new RuntimeException(e);
199+
continue;
201200
} catch (IllegalArgumentException e) {
202201
TranslatableUtil.warnTranslatableOf(EnumSystemEvents.PACKET_ERROR, e);
202+
} catch (Exception e) {
203+
TranslatableUtil.warnTranslatableOf(EnumSystemEvents.PLUGIN_ERROR, e);
203204
}
204205
}
205206
} finally {

src/main/java/org/angellock/impl/ChatMessageManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void putMessage(String msg){
4444
this.chatMessageQueue.offer(msg);
4545
}
4646

47-
public boolean pollMessage() {
47+
public boolean pollMessage() throws Exception{
4848
String removal = this.chatMessageQueue.poll();
4949
if(removal != null) {
5050
this.sendMessagePacket(removal);

src/main/java/org/angellock/impl/EnumSystemEvents.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public enum EnumSystemEvents {
3737
PACKET_ERROR("packet.error"),
3838
DOLPHIN_TIMING_RESET("dolphin.timing.reset"),
3939
SERVER_PLAYER_GAMEMODE("server.player.gamemode"),
40-
40+
PLUGIN_ERROR("plugin.error"),
4141
SERVER_WORLD_JOIN("server.world.join"),
4242
CHAT_MESSAGE_SEND("chat.message.send"),
4343
CHAT_COMMAND_SEND("chat.command.send"),

src/main/java/org/angellock/impl/api/events/MessageBroadcastEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class MessageBroadcastEvent extends AbstractEvent {
2525
private static final HandlerMapper HANDLERS = new HandlerMapper();
2626
@Override
2727
public HandlerMapper getMapper() {
28-
return null;
28+
return HANDLERS;
2929
}
3030
private final BotMessage message;
3131
public MessageBroadcastEvent(BotMessage message){

src/main/java/org/angellock/impl/events/EventDispatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void registerListeners(IListener listener, Plugin plugin) {
6161
}
6262
}
6363

64-
public void callEvent(AbstractEvent event) {
64+
public void callEvent(AbstractEvent event) throws Exception{
6565
HandlerMapper list = event.getMapper();
6666
for (ActiveListener registeredListener : list.getRegisteredListenersInOrder()) {
6767
try {

src/main/java/org/angellock/impl/managers/EventManager.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
package org.angellock.impl.managers;
1818

19+
import org.angellock.impl.EnumSystemEvents;
1920
import org.angellock.impl.events.EventDispatcher;
2021
import org.angellock.impl.events.bukkit.AbstractEvent;
22+
import org.angellock.impl.util.TranslatableUtil;
2123

2224
public class EventManager {
2325
private final EventDispatcher dispatcher = new EventDispatcher();
@@ -27,6 +29,10 @@ public EventDispatcher dispatcher(){
2729
}
2830

2931
public void broadcastEvent(AbstractEvent event){
30-
this.dispatcher.callEvent(event);
32+
try {
33+
this.dispatcher.callEvent(event);
34+
} catch (Exception e) {
35+
TranslatableUtil.errorTranslatableOf(EnumSystemEvents.PLUGIN_ERROR, e);
36+
}
3137
}
3238
}

src/main/java/org/angellock/impl/plugin/AbstractPlugin.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.angellock.impl.managers.TerminalCommandManager;
2323
import org.angellock.impl.managers.utils.Manager;
2424
import org.angellock.impl.util.ConsoleTokens;
25+
import org.angellock.impl.util.wrapper.LoggerWrapper;
2526
import org.geysermc.mcprotocollib.network.event.session.SessionListener;
2627
import org.jetbrains.annotations.Nullable;
2728
import org.slf4j.Logger;
@@ -35,12 +36,11 @@
3536
public abstract class AbstractPlugin extends Manager implements Plugin {
3637
private Path dataPath;
3738
private String simpleName;
38-
private Manifest manifest;
39-
private boolean enabled = false;
4039
private Manifest pluginManifest;
40+
private boolean enabled = false;
4141
private final List<SessionListener> listeners = new ArrayList<>();
4242
private AbstractRobot targetBot;
43-
private static final Logger log = LoggerFactory.getLogger(ConsoleTokens.colorizeText("&6&lPlugins"));
43+
private final LoggerWrapper log = new LoggerWrapper();
4444
protected Thread schedulerThread;
4545
private ClassLoader classLoader;
4646

@@ -58,6 +58,7 @@ public AbstractPlugin(){
5858
String path = getBaseConfigRoot();
5959
this.dataPath = Path.of(path);
6060
this.simpleName = this.getClass().getSimpleName();
61+
log.setLoggerName(this.simpleName);
6162
}
6263

6364
public EventDispatcher getEvents(){
@@ -68,11 +69,11 @@ public String getSimpleName() {
6869
return simpleName;
6970
}
7071

71-
public Manifest getManifest(){
72+
public Manifest getPluginManifest(){
7273
return this.pluginManifest;
7374
}
7475

75-
public static Logger getLogger(){
76+
public LoggerWrapper getLogger(){
7677
return log;
7778
}
7879

@@ -100,6 +101,7 @@ public ClassLoader getClassLoader() {
100101
@Override
101102
public void onEnables(AbstractRobot targetBot){
102103
this.targetBot = targetBot;
104+
this.log.setBot(targetBot);
103105
if (this.listeners.isEmpty()) {
104106
try {
105107
onEnable(this.targetBot);
@@ -117,7 +119,7 @@ public String getName(){
117119
return this.getPluginName();
118120
}
119121
else {
120-
String pluginName = getManifest().getPluginName();
122+
String pluginName = getPluginManifest().getPluginName();
121123
if(!pluginName.isEmpty()){
122124
return pluginName;
123125
}
@@ -139,8 +141,8 @@ public List<SessionListener> getListeners(){
139141
return this.listeners;
140142
}
141143
@Override
142-
public void setManifest(Manifest manifest){
143-
this.manifest = manifest;
144+
public void setPluginManifest(Manifest pluginManifest){
145+
this.pluginManifest = pluginManifest;
144146
}
145147
@Override
146148
public void setEnabled(boolean state){

src/main/java/org/angellock/impl/plugin/Plugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface Plugin {
2828
String getVersion();
2929
String getDescription();
3030
boolean isEnabled();
31-
void setManifest(Manifest name);
31+
void setPluginManifest(Manifest name);
3232
void setEnabled(boolean state);
3333
List<SessionListener> getListeners();
3434
void onDisable();

src/main/java/org/angellock/impl/plugin/PluginManager.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ public void keepScheduleThreadsAlive(){
8585

8686
public void listRegisterInfo(AbstractRobot botInstance) {
8787
Set<String> pl = botInstance.getRegisteredCommands().getRegisteredCommands().keySet();
88-
log.info(botInstance.getBotLabel(), TranslatableUtil.getFormattedMessage(EnumSystemEvents.PLUGIN_LOAD_COMMANDS, pl, pl.size()));
88+
if (!pl.isEmpty()){
89+
log.info(botInstance.getBotLabel(), TranslatableUtil.getFormattedMessage(EnumSystemEvents.PLUGIN_LOAD_COMMANDS, pl, pl.size()));
90+
}
8991
Set<String> tCommand = TerminalCommandManager.registeredCommand.keySet();
9092
log.info(botInstance.getBotLabel(), TranslatableUtil.getFormattedMessage(EnumSystemEvents.PLUGIN_LOAD_TERMINAL_COMMANDS, tCommand, tCommand.size()));
9193
List<SessionListener> listeners = botInstance.getSession().getListeners();
9294
log.info(botInstance.getBotLabel(), TranslatableUtil.getFormattedMessage(EnumSystemEvents.PLUGIN_LISTENER_LOAD, listeners.size()));
9395
}
9496

95-
public void loadAllPlugins(AbstractRobot botInstance){
97+
public void loadAllPlugins(AbstractRobot botInstance) throws Exception{
9698
if(!this.registeredPlugins.isEmpty()){
9799
for (AbstractPlugin plugin : this.registeredPlugins.values()) {
98100
enable(plugin, botInstance);
@@ -147,7 +149,8 @@ public void disableAllPlugins(AbstractRobot botInstance){
147149
}
148150
@Override
149151
public void disable(AbstractRobot botInstance, String pluginName){
150-
Plugin target = this.registeredPlugins.get(pluginName);
152+
Plugin target = this.registeredPlugins.get(pluginName.toLowerCase());
153+
target.setEnabled(false);
151154
List<SessionListener> pluginListeners = target.getListeners();
152155

153156
for (SessionListener listener : pluginListeners) {
@@ -157,10 +160,9 @@ public void disable(AbstractRobot botInstance, String pluginName){
157160
}
158161
}
159162
target.onDisable();
160-
target.setEnabled(false);
161163

162-
if (target instanceof AbstractPlugin) {
163-
ClassLoader classLoader = ((AbstractPlugin) target).getClassLoader();
164+
if (target instanceof AbstractPlugin plugin) {
165+
ClassLoader classLoader = plugin.getClassLoader();
164166
if (classLoader instanceof URLClassLoader) {
165167
try {
166168
((URLClassLoader) classLoader).close();

0 commit comments

Comments
 (0)