Add Replace
Dieser Commit ist enthalten in:
Ursprung
6283c53b17
Commit
93ba4efa1f
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class Replace implements SpecialCommand {
|
||||
|
||||
@Override
|
||||
public String[] description() {
|
||||
return new String[]{
|
||||
"§ereplace §8<§7Variable§8> §8<§7Von Variable§8> §8<§7Zu Variable§8>",
|
||||
"§ereplace §8<§7Variable§8> §8<§7Variable§8> §8<§7Von Variable§8> §8<§7Zu Variable§8>",
|
||||
"",
|
||||
"Ersetzte eine Zeichenkette aus dem Ursprung mit einer neuen Zeichenkette. Dies ersetzt nicht nur die erste Stelle sondern alle.",
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String command() {
|
||||
return "replace";
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
if (command.length <= 3) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas dritte Argument fehlt und sollte eine Variable sein");
|
||||
return true;
|
||||
}
|
||||
|
||||
String resultName = command[1];
|
||||
Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 3]);
|
||||
Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 2]);
|
||||
Value v3 = 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;
|
||||
}
|
||||
if (v3.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(), v3.asString())));
|
||||
return true;
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren