Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the concept of configurable side effects, all are configurable…
…. And each platform specifies what it supports.
- Loading branch information
Showing
14 changed files
with
173 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/SideEffectConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* WorldEdit, a Minecraft world manipulation toolkit | ||
* Copyright (C) sk89q <http://www.sk89q.com> | ||
* Copyright (C) WorldEdit team and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser 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 Lesser General Public License | ||
* for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.sk89q.worldedit.command.argument; | ||
|
||
import static org.enginehub.piston.converter.SuggestionHelper.limitByPrefix; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.sk89q.worldedit.WorldEdit; | ||
import com.sk89q.worldedit.command.util.EntityRemover; | ||
import com.sk89q.worldedit.util.SideEffect; | ||
import com.sk89q.worldedit.util.formatting.text.Component; | ||
import com.sk89q.worldedit.util.formatting.text.TextComponent; | ||
import org.enginehub.piston.CommandManager; | ||
import org.enginehub.piston.converter.ArgumentConverter; | ||
import org.enginehub.piston.converter.ConversionResult; | ||
import org.enginehub.piston.converter.FailedConversion; | ||
import org.enginehub.piston.converter.SuccessfulConversion; | ||
import org.enginehub.piston.inject.InjectedValueAccess; | ||
import org.enginehub.piston.inject.Key; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
public class SideEffectConverter implements ArgumentConverter<SideEffect> { | ||
|
||
public static void register(CommandManager commandManager) { | ||
commandManager.registerConverter(Key.of(SideEffect.class), new SideEffectConverter()); | ||
} | ||
|
||
private final TextComponent choices = TextComponent.of("any side effect"); | ||
|
||
private SideEffectConverter() { | ||
} | ||
|
||
private Collection<SideEffect> getSideEffects() { | ||
return WorldEdit.getInstance().getPlatformManager().getSupportedSideEffects(); | ||
} | ||
|
||
@Override | ||
public Component describeAcceptableArguments() { | ||
return choices; | ||
} | ||
|
||
@Override | ||
public List<String> getSuggestions(String input) { | ||
return limitByPrefix(getSideEffects().stream().map(sideEffect -> sideEffect.name().toLowerCase(Locale.US)), input); | ||
} | ||
|
||
@Override | ||
public ConversionResult<SideEffect> convert(String argument, InjectedValueAccess context) { | ||
try { | ||
return SuccessfulConversion.fromSingle(SideEffect.valueOf(argument.toUpperCase(Locale.US))); | ||
} catch (Exception e) { | ||
return FailedConversion.from(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.