forked from EngineHub/WorldEdit
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'EngineHub:master' into master
- Loading branch information
Showing
10 changed files
with
127 additions
and
33 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
54 changes: 54 additions & 0 deletions
54
.../src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/ClipboardMaskParser.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,54 @@ | ||
/* | ||
* 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 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.sk89q.worldedit.extension.factory.parser.mask; | ||
|
||
import com.sk89q.worldedit.EmptyClipboardException; | ||
import com.sk89q.worldedit.WorldEdit; | ||
import com.sk89q.worldedit.extension.input.InputParseException; | ||
import com.sk89q.worldedit.extension.input.ParserContext; | ||
import com.sk89q.worldedit.function.mask.Mask; | ||
import com.sk89q.worldedit.function.mask.MatchMask; | ||
import com.sk89q.worldedit.internal.registry.SimpleInputParser; | ||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; | ||
|
||
import java.util.List; | ||
|
||
public class ClipboardMaskParser extends SimpleInputParser<Mask> { | ||
|
||
private static final List<String> aliases = List.of("#clipboard", "#copy"); | ||
|
||
public ClipboardMaskParser(WorldEdit worldEdit) { | ||
super(worldEdit); | ||
} | ||
|
||
@Override | ||
public List<String> getMatchedAliases() { | ||
return aliases; | ||
} | ||
|
||
@Override | ||
public Mask parseFromSimpleInput(String input, ParserContext context) throws InputParseException { | ||
try { | ||
return new MatchMask(context.requireExtent(), context.requireSession().getClipboard().getClipboard()); | ||
} catch (EmptyClipboardException e) { | ||
throw new InputParseException(TranslatableComponent.of("worldedit.error.empty-clipboard")); | ||
} | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MatchMask.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,65 @@ | ||
/* | ||
* 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 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.sk89q.worldedit.function.mask; | ||
|
||
import com.sk89q.worldedit.extent.Extent; | ||
import com.sk89q.worldedit.math.BlockVector3; | ||
|
||
/** | ||
* A mask that returns true if the two given extents have the same block at the given position, with offset support. | ||
*/ | ||
public final class MatchMask extends AbstractMask { | ||
|
||
private final Extent extent; | ||
private final Extent matchExtent; | ||
private final BlockVector3 offset; | ||
|
||
/** | ||
* Create a new match mask. | ||
* | ||
* <p> | ||
* This will assume an offset of zero. To specify an offset, use {@link #MatchMask(Extent, Extent, BlockVector3)}. | ||
* </p> | ||
* | ||
* @param extent The base extent | ||
* @param matchExtent The match extent | ||
*/ | ||
public MatchMask(Extent extent, Extent matchExtent) { | ||
this(extent, matchExtent, BlockVector3.ZERO); | ||
} | ||
|
||
/** | ||
* Create a new match mask. | ||
* | ||
* @param extent The base extent | ||
* @param matchExtent The match extent | ||
* @param offset The offset of comparisons applied to the match extent | ||
*/ | ||
public MatchMask(Extent extent, Extent matchExtent, BlockVector3 offset) { | ||
this.extent = extent; | ||
this.matchExtent = matchExtent; | ||
this.offset = offset; | ||
} | ||
|
||
@Override | ||
public boolean test(BlockVector3 vector) { | ||
return extent.getBlock(vector).equals(matchExtent.getBlock(vector.add(offset))); | ||
} | ||
} |
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