Add Remove
Dieser Commit ist enthalten in:
Ursprung
93ba4efa1f
Commit
ee6c208c26
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 Remove implements SpecialCommand {
|
||||
|
||||
@Override
|
||||
public String[] description() {
|
||||
return new String[]{
|
||||
"§eremove §8<§7Variable§8> §8<§7Von Variable§8>",
|
||||
"§eremove §8<§7Variable§8> §8<§7Variable§8> §8<§7Von Variable§8>",
|
||||
"",
|
||||
"Lösche eine Zeichenkette aus dem Ursprung. Dies ersetzt nicht nur die erste Stelle sondern alle.",
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String command() {
|
||||
return "remove";
|
||||
}
|
||||
|
||||
@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 v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]);
|
||||
Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
|
||||
|
||||
if (v1.getClass() != Value.StringValue.class) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Strings können verwendet werden");
|
||||
return true;
|
||||
}
|
||||
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.StringValue(v1.asString().replace(v2.asString(), "")));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -23,7 +23,10 @@ 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 Replace implements SpecialCommand {
|
||||
|
||||
@Override
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren