Add Length
Dieser Commit ist enthalten in:
Ursprung
dd5d9b2b45
Commit
6283c53b17
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 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.features.script.command.string;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.features.script.ScriptExecutor;
|
||||||
|
import de.steamwar.bausystem.features.script.SpecialCommand;
|
||||||
|
import de.steamwar.bausystem.features.script.variables.Value;
|
||||||
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
|
|
||||||
|
@Linked(LinkageType.SCRIPT_COMMAND)
|
||||||
|
public class Length implements SpecialCommand {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] description() {
|
||||||
|
return new String[]{
|
||||||
|
"§elength §8<§7Variable§8>",
|
||||||
|
"§elength §8<§7Variable§8> §8<§7Variable§8>",
|
||||||
|
"",
|
||||||
|
"Ermittle die Länge eines Textes."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String command() {
|
||||||
|
return "length";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
|
||||||
|
if (command.length <= 1) {
|
||||||
|
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (command.length <= 2) {
|
||||||
|
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte eine Variable sein");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String resultName = command[1];
|
||||||
|
Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
|
||||||
|
|
||||||
|
if (v2.getClass() != Value.StringValue.class) {
|
||||||
|
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Strings können verwendet werden");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
scriptExecutor.getLocalVariables().putValue(resultName, new Value.LongValue(v2.asString().length()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren