Fixed /tc /mod and similar commands, the subcommands list and the restart bar #27
4 changed files with 40 additions and 19 deletions
|
@ -56,20 +56,18 @@ public class CommandCaller implements CommandExecutor {
|
|||
path += " " + arg;
|
||||
TBMCCommandBase cmd = TBMCChatAPI.GetCommands().get(path);
|
||||
int argc = 0;
|
||||
while (cmd == null && path.contains(" ")) {
|
||||
String[] subcmds = null;
|
||||
while (cmd == null && (subcmds = TBMCChatAPI.GetSubCommands(path, sender)).length == 0 && path.contains(" ")) {
|
||||
path = path.substring(0, path.lastIndexOf(' '));
|
||||
argc++;
|
||||
cmd = TBMCChatAPI.GetCommands().get(path);
|
||||
}
|
||||
if (cmd == null) {
|
||||
String[] subcmds = TBMCChatAPI.GetSubCommands(path, sender);
|
||||
if (subcmds.length > 0)
|
||||
if (subcmds == null || subcmds.length > 0)
|
||||
sender.sendMessage(subcmds);
|
||||
else {
|
||||
final String errormsg = "§cYou don't have access to any of this command's subcommands.";
|
||||
final String errormsg = "§cYou don't have access to any of this command's subcommands or it doesn't have any.";
|
||||
sender.sendMessage(errormsg);
|
||||
if (!(sender instanceof ConsoleCommandSender))
|
||||
Bukkit.getConsoleSender().sendMessage(errormsg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package buttondevteam.core;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarFlag;
|
||||
|
@ -32,11 +34,15 @@ public class ScheduledRestartCommand extends TBMCCommandBase {
|
|||
restartbar = Bukkit.createBossBar("Server restart in " + ticks / 20f, BarColor.RED, BarStyle.SOLID,
|
||||
BarFlag.DARKEN_SKY);
|
||||
restartbar.setProgress(1);
|
||||
// System.out.println("Progress: " + restartbar.getProgress());
|
||||
Bukkit.getOnlinePlayers().stream().forEach(p -> restartbar.addPlayer(p));
|
||||
/*
|
||||
* System.out.println( "Players: " + restartbar.getPlayers().stream().map(p -> p.getName()).collect(Collectors.joining(", ")));
|
||||
*/
|
||||
sender.sendMessage("Scheduled restart in " + ticks / 20f);
|
||||
ScheduledServerRestartEvent e = new ScheduledServerRestartEvent(ticks);
|
||||
Bukkit.getPluginManager().callEvent(e);
|
||||
restarttask = Bukkit.getScheduler().runTaskTimerAsynchronously(MainPlugin.Instance, () -> {
|
||||
restarttask = Bukkit.getScheduler().runTaskTimer(MainPlugin.Instance, () -> {
|
||||
if (restartcounter < 0) {
|
||||
restarttask.cancel();
|
||||
restartbar.getPlayers().stream().forEach(p -> restartbar.removePlayer(p));
|
||||
|
@ -44,7 +50,11 @@ public class ScheduledRestartCommand extends TBMCCommandBase {
|
|||
}
|
||||
if (restartcounter % 200 == 0)
|
||||
Bukkit.broadcastMessage("§c-- The server is restarting in " + restartcounter / 20 + " seconds!");
|
||||
restartbar.setProgress(restartcounter / restarttime);
|
||||
restartbar.setProgress(restartcounter / (double) restarttime);
|
||||
restartbar.setTitle("Server restart in " + restartcounter / 20f);
|
||||
/*
|
||||
* if (restartcounter % 20 == 0) System.out.println("Progress: " + restartbar.getProgress());
|
||||
*/
|
||||
restartcounter--;
|
||||
}, 1, 1);
|
||||
return true;
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.HashMap;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
@ -30,7 +31,7 @@ import com.palmergames.bukkit.towny.object.TownyUniverse;
|
|||
public class TBMCPlayer implements AutoCloseable {
|
||||
private static final String TBMC_PLAYERS_DIR = "TBMC/players";
|
||||
|
||||
private HashMap<String, Object> data = new HashMap<>();
|
||||
private ConcurrentHashMap<String, Object> data = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -254,6 +255,8 @@ public class TBMCPlayer implements AutoCloseable {
|
|||
return uuid;
|
||||
}
|
||||
|
||||
private ConcurrentHashMap<Class<? extends TBMCPlayer>, TBMCPlayer> playermap = new ConcurrentHashMap<>(); // TODO
|
||||
|
||||
/**
|
||||
* Gets the TBMCPlayer object as a specific plugin player, keeping it's data *
|
||||
*
|
||||
|
@ -262,12 +265,16 @@ public class TBMCPlayer implements AutoCloseable {
|
|||
* @param cl
|
||||
* The TBMCPlayer subclass
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends TBMCPlayer> T asPluginPlayer(Class<T> cl) {
|
||||
T obj = null;
|
||||
if (playermap.containsKey(cl))
|
||||
return (T) playermap.get(cl);
|
||||
try {
|
||||
obj = cl.newInstance();
|
||||
((TBMCPlayer) obj).uuid = uuid;
|
||||
((TBMCPlayer) obj).data.putAll(data);
|
||||
// ((TBMCPlayer) obj).data.putAll(data);
|
||||
playermap.put(cl, obj);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -42,7 +43,8 @@ public class TBMCChatAPI {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns messages formatted for Minecraft chat listing the subcommands of the command.
|
||||
* Returns messages formatted for Minecraft chat listing the subcommands of the command.<br>
|
||||
* Returns a header if subcommands were found, otherwise returns an empty array.
|
||||
*
|
||||
* @param command
|
||||
* The command which we want the subcommands of
|
||||
|
@ -52,20 +54,24 @@ public class TBMCChatAPI {
|
|||
*/
|
||||
public static String[] GetSubCommands(String command, CommandSender sender) {
|
||||
ArrayList<String> cmds = new ArrayList<String>();
|
||||
cmds.add("§6---- Subcommands ----");
|
||||
Consumer<String> addToCmds = cmd -> {
|
||||
if (cmds.size() == 0)
|
||||
cmds.add("§6---- Subcommands ----");
|
||||
cmds.add(cmd);
|
||||
};
|
||||
for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values()) {
|
||||
if (cmd.GetCommandPath().startsWith(command + " ")) {
|
||||
int ind = cmd.GetCommandPath().indexOf(' ', command.length() + 2);
|
||||
if (ind >= 0) {
|
||||
String newcmd = cmd.GetCommandPath().substring(0, ind);
|
||||
if (!cmds.contains("/" + newcmd))
|
||||
cmds.add("/" + newcmd);
|
||||
}
|
||||
if (cmd.GetPlayerOnly() && !(sender instanceof Player))
|
||||
continue;
|
||||
if (cmd.GetModOnly() && !MainPlugin.permission.has(sender, "tbmc.admin"))
|
||||
continue;
|
||||
cmds.add("/" + cmd.GetCommandPath());
|
||||
int ind = cmd.GetCommandPath().indexOf(' ', command.length() + 2);
|
||||
if (ind >= 0) {
|
||||
String newcmd = cmd.GetCommandPath().substring(0, ind);
|
||||
if (!cmds.contains("/" + newcmd))
|
||||
addToCmds.accept("/" + newcmd);
|
||||
} else
|
||||
addToCmds.accept("/" + cmd.GetCommandPath());
|
||||
}
|
||||
}
|
||||
return cmds.toArray(new String[cmds.size()]);
|
||||
|
|
Loading…
Reference in a new issue