Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Commands: rename technical-works to maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFaser committed Aug 2, 2023
1 parent 88cbfa5 commit 4ca5a45
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 34 deletions.
6 changes: 5 additions & 1 deletion src/main/java/net/flectone/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.util.List;

public final class Main extends JavaPlugin {

Expand Down Expand Up @@ -94,7 +95,10 @@ private void registerClasses() {
private void loadIcons() {
String path = Main.getInstance().getDataFolder() + File.separator + "icons" + File.separator;

for (String iconName : Main.config.getStringList("server.icon.names")) {
List<String> iconNames = Main.config.getStringList("server.icon.names");
iconNames.add("maintenance");

for (String iconName : iconNames) {
if (new File(path + iconName + ".png").exists()) continue;

Main.getInstance().saveResource("icons" + File.separator + iconName + ".png", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import java.util.List;
import java.util.Set;

public class CommandTechnicalWorks extends FTabCompleter {
public class CommandMaintenance extends FTabCompleter {

public CommandTechnicalWorks() {
super.commandName = "technical-works";
public CommandMaintenance() {
super.commandName = "maintenance";
}

@Override
Expand All @@ -32,35 +32,35 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command
return true;
}

boolean isTechnicalWorks = Main.config.getBoolean("command.technical-works.enable");
boolean haveMaintenance = Main.config.getBoolean("command.maintenance.enable");

if (isTechnicalWorks && strings[0].equalsIgnoreCase("on")) {
fCommand.sendMeMessage("command.technical-works.turned-on.already");
if (haveMaintenance && strings[0].equalsIgnoreCase("on")) {
fCommand.sendMeMessage("command.maintenance.turned-on.already");
return true;
}

if (!isTechnicalWorks && strings[0].equalsIgnoreCase("off")) {
fCommand.sendMeMessage("command.technical-works.turned-off.not");
if (!haveMaintenance && strings[0].equalsIgnoreCase("off")) {
fCommand.sendMeMessage("command.maintenance.turned-off.not");
return true;
}

if (fCommand.isHaveCD()) return true;

if (fCommand.isMuted()) return true;

isTechnicalWorks = strings[0].equalsIgnoreCase("on");
haveMaintenance = strings[0].equalsIgnoreCase("on");

if (isTechnicalWorks) {
if (haveMaintenance) {

Set<Player> playerSet = new HashSet<>(Bukkit.getOnlinePlayers());

playerSet.stream().parallel()
.filter(player -> !player.isOp() && !player.hasPermission(Main.config.getString("command.technical-works.permission")) && player.isOnline())
.forEach(player -> player.kickPlayer(Main.locale.getFormatString("command.technical-works.kicked-message", null)));
.filter(player -> !player.isOp() && !player.hasPermission(Main.config.getString("command.maintenance.permission")) && player.isOnline())
.forEach(player -> player.kickPlayer(Main.locale.getFormatString("command.maintenance.kicked-message", null)));
}

fCommand.sendMeMessage("command.technical-works.turned-" + strings[0].toLowerCase() + ".message");
Main.config.setObject("command.technical-works.enable", isTechnicalWorks);
fCommand.sendMeMessage("command.maintenance.turned-" + strings[0].toLowerCase() + ".message");
Main.config.setObject("command.maintenance.enable", haveMaintenance);
Main.config.saveFile();

return true;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/flectone/listeners/PlayerJoinListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public void onLoginPlayer(PlayerLoginEvent event) {
return;
}

if (Main.config.getBoolean("command.technical-works.enable")
if (Main.config.getBoolean("command.maintenance.enable")
&& !event.getPlayer().isOp()
&& !event.getPlayer().hasPermission("flectonechat.technical-works")) {
&& !event.getPlayer().hasPermission("flectonechat.maintenance")) {

event.disallow(PlayerLoginEvent.Result.KICK_BANNED, Main.locale.getFormatString("command.technical-works.kicked-message", null));
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, Main.locale.getFormatString("command.maintenance.kicked-message", null));
}
}
}
10 changes: 5 additions & 5 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ command:
time: 50
permission: "flectonechat.pollcreate"

technical-works:
permission: "flectonechat.technical-works"
maintenance:
permission: "flectonechat.maintenance"
enable: false

stream:
Expand Down Expand Up @@ -277,10 +277,10 @@ cool-down:
enable: false
time: 5
permission: "flectonechat.mute.cooldown.immune"
technical-works:
maintenance:
enable: false
time: 5
permission: "flectonechat.technical-works.cooldown.immune"
permission: "flectonechat.maintenance.cooldown.immune"
ball:
enable: false
time: 5
Expand Down Expand Up @@ -386,7 +386,7 @@ sound:
unmute:
enable: false
type: "BLOCK_NOTE_BLOCK_BELL"
technical-works:
maintenance:
enable: true
type: "BLOCK_NOTE_BLOCK_BELL"
ball:
Expand Down
13 changes: 7 additions & 6 deletions src/main/resources/language/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

server:
motd:
maintenance: "&cThe server is under maintenance"
messages:
- "&&1This server uses FlectoneChat ❤"
- "&&1Welcome to our server!"
Expand Down Expand Up @@ -331,15 +332,15 @@ command:
- "&&2• • • • • • • • •"
- "&&1Url(s): \n<links>"

technical-works:
maintenance:
usage: "&&1⚑ Usage: &&2/<command> on/off"
turned-on:
already: "#ff4e4e⁉ You have already enabled technical work"
message: "&&1★ You have enabled technical works on server"
already: "#ff4e4e⁉ You have already switched on maintenance"
message: "&&1★ You have enabled maintenance on the server"
turned-off:
not: "#ff4e4e⁉ You did not enabled technical works"
message: "&&1★ You turned off technical works on server"
kicked-message: "&&1★ The server is undergoing technical works"
not: "#ff4e4e⁉ You have not switched on maintenance"
message: "&&1★ You have disabled maintenance on the server"
kicked-message: "&&1★ The server is under maintenance"

flectonechat:
usage: "&&1⚑ Usage: &&2/<command> reload/config/locale"
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/language/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

server:
motd:
maintenance: "&cВ настоящее время проводятся технические работы"
messages:
- "&&1Этот сервер использует FlectoneChat ❤"
- "&&1Добро пожаловать на наш сервер!"
Expand Down Expand Up @@ -331,7 +332,7 @@ command:
- "&&2• • • • • • • • •"
- "&&1Ссылка(и): \n<links>"

technical-works:
maintenance:
usage: "&&1⚑ Использование: &&2/<command> on/off"
turned-on:
already: "#ff4e4e⁉ Вы уже включили технические работы"
Expand Down
9 changes: 5 additions & 4 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ commands:
usage: /helper <message>
permission: flectonechat.helper

technical-works:
usage: /technical-works on/off
permission: flectonechat.technical-works
maintenance:
usage: /maintenance on/off
aliases: [ technical-works ]
permission: flectonechat.maintenance

chat:
usage: /chat switch/hide local/global
Expand Down Expand Up @@ -181,7 +182,7 @@ permissions:
default: op
flectonechat.helper:
default: true
flectonechat.technical-works:
flectonechat.maintenance:
default: op
flectonechat.chat:
default: true
Expand Down

0 comments on commit 4ca5a45

Please sign in to comment.