SteamWar/BauSystem
Archiviert
13
0

Add CommandRedstoneTesterTabCompleter

Optimize CommandSimulatorTabCompleter
Optimize CommandTNTTabComplete
Add TabCompleteUtils.manageList
Dieser Commit ist enthalten in:
yoyosource 2021-03-07 16:37:19 +01:00
Ursprung d30a8ff4aa
Commit 6c91c96524
6 geänderte Dateien mit 106 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,35 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem;
import java.util.List;
public class TabCompleteUtils {
public static List<String> manageList(List<String> strings, String[] args, int index) {
for (int i = strings.size() - 1; i >= 0; i--) {
if (!strings.get(i).startsWith(args[index])) {
strings.remove(i);
}
}
return strings;
}
}

Datei anzeigen

@ -100,6 +100,7 @@ public class BauSystem extends JavaPlugin implements Listener {
getCommand("simulator").setExecutor(new CommandSimulator()); getCommand("simulator").setExecutor(new CommandSimulator());
getCommand("simulator").setTabCompleter(new CommandSimulatorTabCompleter()); getCommand("simulator").setTabCompleter(new CommandSimulatorTabCompleter());
getCommand("redstonetester").setExecutor(new CommandRedstoneTester()); getCommand("redstonetester").setExecutor(new CommandRedstoneTester());
getCommand("redstonetester").setTabCompleter(new CommandRedstoneTesterTabCompleter());
getCommand("gui").setExecutor(new CommandGUI()); getCommand("gui").setExecutor(new CommandGUI());
Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(this, this);

Datei anzeigen

@ -29,16 +29,29 @@ import org.bukkit.entity.Player;
public class CommandRedstoneTester implements CommandExecutor { public class CommandRedstoneTester implements CommandExecutor {
private void help(Player player) {
player.sendMessage("§7Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten");
player.sendMessage("§8/§eredstonetester help §8- §7Zeigt diese Nachricht");
player.sendMessage("§8/§eredstonetester wand §8- §7Legt dir den Testerstab ins Inventar");
}
@Override @Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if (!(commandSender instanceof Player)) if (!(commandSender instanceof Player))
return false; return false;
Player player = (Player) commandSender; Player player = (Player) commandSender;
if (args.length != 0 && args[0].equalsIgnoreCase("help")) { if (args.length == 0) {
player.sendMessage(BauSystem.PREFIX + "Messe die Zeit zwischen der Aktivierung zweier Redstone Komponenten"); help(player);
return false; return false;
} }
switch (args[0].toLowerCase()) {
case "help":
help(player);
break;
case "wand":
PlayerUtils.giveItemToPlayer(player, RedstoneListener.WAND); PlayerUtils.giveItemToPlayer(player, RedstoneListener.WAND);
break;
}
return false; return false;
} }

Datei anzeigen

@ -0,0 +1,50 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.TabCompleteUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class CommandRedstoneTesterTabCompleter implements TabCompleter {
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) return new ArrayList<>();
return commandTabComplete((Player) sender, args);
}
private List<String> commandTabComplete(Player player, String[] args) {
List<String> tabComplete = new ArrayList<>();
tabComplete.add("help");
tabComplete.add("wand");
if (args.length >= 2) {
return new ArrayList<>();
}
return TabCompleteUtils.manageList(tabComplete, args, 0);
}
}

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.bausystem.commands; package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.TabCompleteUtils;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
@ -45,16 +46,7 @@ public class CommandSimulatorTabCompleter implements TabCompleter {
if (args.length >= 2) { if (args.length >= 2) {
return new ArrayList<>(); return new ArrayList<>();
} }
return manageList(tabComplete, args, 0); return TabCompleteUtils.manageList(tabComplete, args, 0);
}
private List<String> manageList(List<String> strings, String[] args, int index) {
for (int i = strings.size() - 1; i >= 0; i--) {
if (!strings.get(i).startsWith(args[index])) {
strings.remove(i);
}
}
return strings;
} }
} }

Datei anzeigen

@ -21,6 +21,7 @@
package de.steamwar.bausystem.commands; package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.TabCompleteUtils;
import de.steamwar.bausystem.world.Region; import de.steamwar.bausystem.world.Region;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -52,16 +53,7 @@ public class CommandTNTTabComplete implements TabCompleter {
if (args.length >= 2) { if (args.length >= 2) {
return new ArrayList<>(); return new ArrayList<>();
} }
return manageList(tabComplete, args, 0); return TabCompleteUtils.manageList(tabComplete, args, 0);
}
private List<String> manageList(List<String> strings, String[] args, int index) {
for (int i = strings.size() - 1; i >= 0; i--) {
if (!strings.get(i).startsWith(args[index])) {
strings.remove(i);
}
}
return strings;
} }
} }