generated from xpdustry/template-plugin
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(command): Implement CommandSender
- Loading branch information
Showing
3 changed files
with
112 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...ributor-core/src/main/java/com/xpdustry/distributor/core/command/PlayerCommandSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Distributor, a feature-rich framework for Mindustry plugins. | ||
* | ||
* Copyright (C) 2024 Xpdustry | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.xpdustry.distributor.core.command; | ||
|
||
import mindustry.gen.Player; | ||
|
||
record PlayerCommandSender(Player player) implements CommandSender { | ||
|
||
@Override | ||
public void sendMessage(final String text) { | ||
this.player.sendMessage(text); | ||
} | ||
|
||
@Override | ||
public void sendWarning(final String text) { | ||
this.player.sendMessage("[red]" + text); | ||
} | ||
|
||
@Override | ||
public boolean isPlayer() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isServer() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Player getPlayer() { | ||
return this.player; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...ributor-core/src/main/java/com/xpdustry/distributor/core/command/ServerCommandSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Distributor, a feature-rich framework for Mindustry plugins. | ||
* | ||
* Copyright (C) 2024 Xpdustry | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.xpdustry.distributor.core.command; | ||
|
||
import arc.util.Log; | ||
import mindustry.gen.Player; | ||
|
||
final class ServerCommandSender implements CommandSender { | ||
|
||
static final ServerCommandSender INSTANCE = new ServerCommandSender(); | ||
|
||
private ServerCommandSender() {} | ||
|
||
@Override | ||
public void sendMessage(final String text) { | ||
for (final var line : text.split("\n", -1)) { | ||
Log.info(line); | ||
} | ||
} | ||
|
||
@Override | ||
public void sendWarning(final String text) { | ||
for (final var line : text.split("\n", -1)) { | ||
Log.warn(line); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isPlayer() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isServer() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Player getPlayer() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |