mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Stop touching this without tests. NO MORE PRS TO DECREE
This commit is contained in:
parent
6f6e74e015
commit
434e7f75fa
@ -22,7 +22,6 @@ import com.volmit.iris.engine.data.cache.AtomicCache;
|
|||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.decree.annotations.Param;
|
import com.volmit.iris.util.decree.annotations.Param;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
import com.volmit.iris.util.decree.specialhandlers.DummyHandler;
|
import com.volmit.iris.util.decree.specialhandlers.DummyHandler;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@ -91,7 +90,7 @@ public class DecreeParameter {
|
|||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getDefaultValue() throws DecreeParsingException, DecreeWhichException {
|
public Object getDefaultValue() throws DecreeParsingException {
|
||||||
return param.defaultValue().trim().isEmpty() ? null : getHandler().parse(param.defaultValue().trim(), true);
|
return param.defaultValue().trim().isEmpty() ? null : getHandler().parse(param.defaultValue().trim(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ package com.volmit.iris.util.decree;
|
|||||||
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
@ -60,9 +59,8 @@ public interface DecreeParameterHandler<T> {
|
|||||||
* @param in The string to parse
|
* @param in The string to parse
|
||||||
* @return The value extracted from the string, of the designated type
|
* @return The value extracted from the string, of the designated type
|
||||||
* @throws DecreeParsingException Thrown when the parsing fails (ex: "oop" translated to an integer throws this)
|
* @throws DecreeParsingException Thrown when the parsing fails (ex: "oop" translated to an integer throws this)
|
||||||
* @throws DecreeWhichException Thrown when multiple results are possible
|
|
||||||
*/
|
*/
|
||||||
default T parse(String in) throws DecreeParsingException, DecreeWhichException {
|
default T parse(String in) throws DecreeParsingException {
|
||||||
return parse(in, false);
|
return parse(in, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,9 +71,8 @@ public interface DecreeParameterHandler<T> {
|
|||||||
* @param force force an option instead of throwing decreewhich
|
* @param force force an option instead of throwing decreewhich
|
||||||
* @return The value extracted from the string, of the designated type
|
* @return The value extracted from the string, of the designated type
|
||||||
* @throws DecreeParsingException Thrown when the parsing fails (ex: "oop" translated to an integer throws this)
|
* @throws DecreeParsingException Thrown when the parsing fails (ex: "oop" translated to an integer throws this)
|
||||||
* @throws DecreeWhichException Thrown when multiple results are possible
|
|
||||||
*/
|
*/
|
||||||
T parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException;
|
T parse(String in, boolean force) throws DecreeParsingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether a certain type is supported by this handler<br>
|
* Returns whether a certain type is supported by this handler<br>
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* 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.volmit.iris.util.decree.exceptions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown when more than one option is available for a singular mapping<br>
|
|
||||||
* Like having a hashmap where one input maps to two outputs.
|
|
||||||
*/
|
|
||||||
public class DecreeWhichException extends Exception {
|
|
||||||
public DecreeWhichException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
}
|
|
@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KList;
|
|||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -56,7 +55,7 @@ public class BiomeHandler implements DecreeParameterHandler<IrisBiome> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IrisBiome parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException {
|
public IrisBiome parse(String in, boolean force) throws DecreeParsingException {
|
||||||
if (in.equals("null")) {
|
if (in.equals("null")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -64,19 +63,13 @@ public class BiomeHandler implements DecreeParameterHandler<IrisBiome> {
|
|||||||
|
|
||||||
if (options.isEmpty()) {
|
if (options.isEmpty()) {
|
||||||
throw new DecreeParsingException("Unable to find Biome \"" + in + "\"");
|
throw new DecreeParsingException("Unable to find Biome \"" + in + "\"");
|
||||||
} else if (options.size() > 1) {
|
|
||||||
if (force) {
|
|
||||||
try {
|
|
||||||
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new DecreeWhichException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return options.get(0);
|
try {
|
||||||
|
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,7 +23,6 @@ import com.volmit.iris.util.decree.DecreeContext;
|
|||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.DecreeSystem;
|
import com.volmit.iris.util.decree.DecreeSystem;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
import com.volmit.iris.util.format.Form;
|
import com.volmit.iris.util.format.Form;
|
||||||
import com.volmit.iris.util.math.M;
|
import com.volmit.iris.util.math.M;
|
||||||
import com.volmit.iris.util.plugin.VolmitSender;
|
import com.volmit.iris.util.plugin.VolmitSender;
|
||||||
@ -54,7 +53,7 @@ public class BlockVectorHandler implements DecreeParameterHandler<BlockVector> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockVector parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException {
|
public BlockVector parse(String in, boolean force) throws DecreeParsingException {
|
||||||
try {
|
try {
|
||||||
if (in.contains(",")) {
|
if (in.contains(",")) {
|
||||||
String[] comp = in.split("\\Q,\\E");
|
String[] comp = in.split("\\Q,\\E");
|
||||||
|
@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KList;
|
|||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -56,24 +55,16 @@ public class DimensionHandler implements DecreeParameterHandler<IrisDimension> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IrisDimension parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException {
|
public IrisDimension parse(String in, boolean force) throws DecreeParsingException {
|
||||||
KList<IrisDimension> options = getPossibilities(in);
|
KList<IrisDimension> options = getPossibilities(in);
|
||||||
|
|
||||||
if (options.isEmpty()) {
|
if (options.isEmpty()) {
|
||||||
throw new DecreeParsingException("Unable to find Dimension \"" + in + "\"");
|
throw new DecreeParsingException("Unable to find Dimension \"" + in + "\"");
|
||||||
} else if (options.size() > 1) {
|
} try {
|
||||||
if (force) {
|
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
||||||
try {
|
} catch (Throwable e) {
|
||||||
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
||||||
} catch (Throwable e) {
|
|
||||||
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new DecreeWhichException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return options.get(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KList;
|
|||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -73,27 +72,18 @@ public class EntityHandler implements DecreeParameterHandler<IrisEntity> {
|
|||||||
* @param in The string to parse
|
* @param in The string to parse
|
||||||
* @return The value extracted from the string, of the designated type
|
* @return The value extracted from the string, of the designated type
|
||||||
* @throws DecreeParsingException Thrown when the parsing fails (ex: "oop" translated to an integer throws this)
|
* @throws DecreeParsingException Thrown when the parsing fails (ex: "oop" translated to an integer throws this)
|
||||||
* @throws DecreeWhichException Thrown when multiple results are possible
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IrisEntity parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException {
|
public IrisEntity parse(String in, boolean force) throws DecreeParsingException {
|
||||||
KList<IrisEntity> options = getPossibilities(in);
|
KList<IrisEntity> options = getPossibilities(in);
|
||||||
|
|
||||||
if (options.isEmpty()) {
|
if (options.isEmpty()) {
|
||||||
throw new DecreeParsingException("Unable to find Entity \"" + in + "\"");
|
throw new DecreeParsingException("Unable to find Entity \"" + in + "\"");
|
||||||
} else if (options.size() > 1) {
|
} try {
|
||||||
if (force) {
|
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
||||||
try {
|
} catch (Throwable e) {
|
||||||
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
||||||
} catch (Throwable e) {
|
|
||||||
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new DecreeWhichException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return options.get(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KList;
|
|||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -56,24 +55,16 @@ public class GeneratorHandler implements DecreeParameterHandler<IrisGenerator> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IrisGenerator parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException {
|
public IrisGenerator parse(String in, boolean force) throws DecreeParsingException {
|
||||||
KList<IrisGenerator> options = getPossibilities(in);
|
KList<IrisGenerator> options = getPossibilities(in);
|
||||||
|
|
||||||
if (options.isEmpty()) {
|
if (options.isEmpty()) {
|
||||||
throw new DecreeParsingException("Unable to find Generator \"" + in + "\"");
|
throw new DecreeParsingException("Unable to find Generator \"" + in + "\"");
|
||||||
} else if (options.size() > 1) {
|
} try {
|
||||||
if (force) {
|
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
||||||
try {
|
} catch (Throwable e) {
|
||||||
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
||||||
} catch (Throwable e) {
|
|
||||||
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new DecreeWhichException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return options.get(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KList;
|
|||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -56,7 +55,7 @@ public class JigsawPieceHandler implements DecreeParameterHandler<IrisJigsawPiec
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IrisJigsawPiece parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException {
|
public IrisJigsawPiece parse(String in, boolean force) throws DecreeParsingException {
|
||||||
if (in.equals("null")) {
|
if (in.equals("null")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -64,19 +63,11 @@ public class JigsawPieceHandler implements DecreeParameterHandler<IrisJigsawPiec
|
|||||||
|
|
||||||
if (options.isEmpty()) {
|
if (options.isEmpty()) {
|
||||||
throw new DecreeParsingException("Unable to find Jigsaw Piece \"" + in + "\"");
|
throw new DecreeParsingException("Unable to find Jigsaw Piece \"" + in + "\"");
|
||||||
} else if (options.size() > 1) {
|
}try {
|
||||||
if (force) {
|
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
||||||
try {
|
} catch (Throwable e) {
|
||||||
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
throw new DecreeParsingException("Unable to filter which Jigsaw Piece \"" + in + "\"");
|
||||||
} catch (Throwable e) {
|
|
||||||
throw new DecreeParsingException("Unable to filter which Jigsaw Piece \"" + in + "\"");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new DecreeWhichException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return options.get(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KList;
|
|||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -56,7 +55,7 @@ public class JigsawStructureHandler implements DecreeParameterHandler<IrisJigsaw
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IrisJigsawStructure parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException {
|
public IrisJigsawStructure parse(String in, boolean force) throws DecreeParsingException {
|
||||||
if (in.equals("null")) {
|
if (in.equals("null")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -64,19 +63,11 @@ public class JigsawStructureHandler implements DecreeParameterHandler<IrisJigsaw
|
|||||||
|
|
||||||
if (options.isEmpty()) {
|
if (options.isEmpty()) {
|
||||||
throw new DecreeParsingException("Unable to find Jigsaw Structure \"" + in + "\"");
|
throw new DecreeParsingException("Unable to find Jigsaw Structure \"" + in + "\"");
|
||||||
} else if (options.size() > 1) {
|
} try {
|
||||||
if (force) {
|
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
||||||
try {
|
} catch (Throwable e) {
|
||||||
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
throw new DecreeParsingException("Unable to filter which Jigsaw Structure \"" + in + "\"");
|
||||||
} catch (Throwable e) {
|
|
||||||
throw new DecreeParsingException("Unable to filter which Jigsaw Structure \"" + in + "\"");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new DecreeWhichException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return options.get(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,7 +21,6 @@ package com.volmit.iris.util.decree.handlers;
|
|||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -40,24 +39,16 @@ public class PlayerHandler implements DecreeParameterHandler<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException {
|
public Player parse(String in, boolean force) throws DecreeParsingException {
|
||||||
KList<Player> options = getPossibilities(in);
|
KList<Player> options = getPossibilities(in);
|
||||||
|
|
||||||
if (options.isEmpty()) {
|
if (options.isEmpty()) {
|
||||||
throw new DecreeParsingException("Unable to find Player \"" + in + "\"");
|
throw new DecreeParsingException("Unable to find Player \"" + in + "\"");
|
||||||
} else if (options.size() > 1) {
|
} try {
|
||||||
if (force) {
|
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
||||||
try {
|
} catch (Throwable e) {
|
||||||
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
||||||
} catch (Throwable e) {
|
|
||||||
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new DecreeWhichException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return options.get(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KList;
|
|||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -56,7 +55,7 @@ public class RegionHandler implements DecreeParameterHandler<IrisRegion> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IrisRegion parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException {
|
public IrisRegion parse(String in, boolean force) throws DecreeParsingException {
|
||||||
if (in.equals("null")) {
|
if (in.equals("null")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -64,19 +63,11 @@ public class RegionHandler implements DecreeParameterHandler<IrisRegion> {
|
|||||||
|
|
||||||
if (options.isEmpty()) {
|
if (options.isEmpty()) {
|
||||||
throw new DecreeParsingException("Unable to find Region \"" + in + "\"");
|
throw new DecreeParsingException("Unable to find Region \"" + in + "\"");
|
||||||
} else if (options.size() > 1) {
|
} try {
|
||||||
if (force) {
|
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
||||||
try {
|
} catch (Throwable e) {
|
||||||
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
||||||
} catch (Throwable e) {
|
|
||||||
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new DecreeWhichException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return options.get(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KList;
|
|||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -56,24 +55,16 @@ public class ScriptHandler implements DecreeParameterHandler<IrisScript> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IrisScript parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException {
|
public IrisScript parse(String in, boolean force) throws DecreeParsingException {
|
||||||
KList<IrisScript> options = getPossibilities(in);
|
KList<IrisScript> options = getPossibilities(in);
|
||||||
|
|
||||||
if (options.isEmpty()) {
|
if (options.isEmpty()) {
|
||||||
throw new DecreeParsingException("Unable to find Script \"" + in + "\"");
|
throw new DecreeParsingException("Unable to find Script \"" + in + "\"");
|
||||||
} else if (options.size() > 1) {
|
} try {
|
||||||
if (force) {
|
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
||||||
try {
|
} catch (Throwable e) {
|
||||||
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
||||||
} catch (Throwable e) {
|
|
||||||
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new DecreeWhichException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return options.get(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,7 +23,6 @@ import com.volmit.iris.util.decree.DecreeContext;
|
|||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.DecreeSystem;
|
import com.volmit.iris.util.decree.DecreeSystem;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
import com.volmit.iris.util.format.Form;
|
import com.volmit.iris.util.format.Form;
|
||||||
import org.bukkit.FluidCollisionMode;
|
import org.bukkit.FluidCollisionMode;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -55,7 +54,7 @@ public class VectorHandler implements DecreeParameterHandler<Vector> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException {
|
public Vector parse(String in, boolean force) throws DecreeParsingException {
|
||||||
try {
|
try {
|
||||||
if (in.contains(",")) {
|
if (in.contains(",")) {
|
||||||
String[] comp = in.split("\\Q,\\E");
|
String[] comp = in.split("\\Q,\\E");
|
||||||
|
@ -21,7 +21,6 @@ package com.volmit.iris.util.decree.handlers;
|
|||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
@ -45,24 +44,16 @@ public class WorldHandler implements DecreeParameterHandler<World> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public World parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException {
|
public World parse(String in, boolean force) throws DecreeParsingException {
|
||||||
KList<World> options = getPossibilities(in);
|
KList<World> options = getPossibilities(in);
|
||||||
|
|
||||||
if (options.isEmpty()) {
|
if (options.isEmpty()) {
|
||||||
throw new DecreeParsingException("Unable to find World \"" + in + "\"");
|
throw new DecreeParsingException("Unable to find World \"" + in + "\"");
|
||||||
} else if (options.size() > 1) {
|
} try {
|
||||||
if (force) {
|
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
||||||
try {
|
} catch (Throwable e) {
|
||||||
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
||||||
} catch (Throwable e) {
|
|
||||||
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new DecreeWhichException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return options.get(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,7 +21,6 @@ package com.volmit.iris.util.decree.specialhandlers;
|
|||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
|
|
||||||
public class DummyHandler implements DecreeParameterHandler<Object> {
|
public class DummyHandler implements DecreeParameterHandler<Object> {
|
||||||
@Override
|
@Override
|
||||||
@ -39,7 +38,7 @@ public class DummyHandler implements DecreeParameterHandler<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException {
|
public Object parse(String in, boolean force) throws DecreeParsingException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@ import com.volmit.iris.core.loader.IrisData;
|
|||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -50,24 +49,16 @@ public class ObjectHandler implements DecreeParameterHandler<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException {
|
public String parse(String in, boolean force) throws DecreeParsingException {
|
||||||
KList<String> options = getPossibilities(in);
|
KList<String> options = getPossibilities(in);
|
||||||
|
|
||||||
if (options.isEmpty()) {
|
if (options.isEmpty()) {
|
||||||
throw new DecreeParsingException("Unable to find Object \"" + in + "\"");
|
throw new DecreeParsingException("Unable to find Object \"" + in + "\"");
|
||||||
} else if (options.size() > 1) {
|
} try {
|
||||||
if (force) {
|
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
||||||
try {
|
} catch (Throwable e) {
|
||||||
return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0);
|
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
||||||
} catch (Throwable e) {
|
|
||||||
throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\"");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new DecreeWhichException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return options.get(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -31,7 +31,6 @@ import com.volmit.iris.util.decree.DecreeParameter;
|
|||||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||||
import com.volmit.iris.util.decree.annotations.Decree;
|
import com.volmit.iris.util.decree.annotations.Decree;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|
||||||
import com.volmit.iris.util.format.C;
|
import com.volmit.iris.util.format.C;
|
||||||
import com.volmit.iris.util.format.Form;
|
import com.volmit.iris.util.format.Form;
|
||||||
import com.volmit.iris.util.plugin.CommandDummy;
|
import com.volmit.iris.util.plugin.CommandDummy;
|
||||||
@ -350,18 +349,6 @@ public class VirtualDecreeCommand {
|
|||||||
sender.sendMessage(C.RED + "Cannot convert \"" + value + "\" into a " + param.getType().getSimpleName());
|
sender.sendMessage(C.RED + "Cannot convert \"" + value + "\" into a " + param.getType().getSimpleName());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
} catch (DecreeWhichException e) {
|
|
||||||
KList<?> validOptions = param.getHandler().getPossibilities(value);
|
|
||||||
Iris.debug("Found multiple results for " + key + "=" + value + " in " + getPath() + " using the handler " + param.getHandler().getClass().getSimpleName() + " with potential matches [" + validOptions.toString(",") + "]. Asking client to define one");
|
|
||||||
String update = pickValidOption(sender, validOptions, param.getHandler(), param.getName(), param.getType().getSimpleName());
|
|
||||||
|
|
||||||
if (update == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iris.debug("Client chose " + update + " for " + key + "=" + value + " (old) in " + getPath());
|
|
||||||
nowhich.add(original);
|
|
||||||
in.set(original, update);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,17 +369,6 @@ public class VirtualDecreeCommand {
|
|||||||
sender.sendMessage(C.RED + "Cannot convert \"" + stringParam + "\" into a " + par.getType().getSimpleName());
|
sender.sendMessage(C.RED + "Cannot convert \"" + stringParam + "\" into a " + par.getType().getSimpleName());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
} catch (DecreeWhichException e) {
|
|
||||||
KList<?> validOptions = par.getHandler().getPossibilities(stringParam);
|
|
||||||
String update = pickValidOption(sender, validOptions, par.getHandler(), par.getName(), par.getType().getSimpleName());
|
|
||||||
|
|
||||||
if (update == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iris.debug("Client chose " + update + " for " + par.getName() + "=" + stringParam + " (old) in " + getPath());
|
|
||||||
nowhich.add(original);
|
|
||||||
in.set(original, update);
|
|
||||||
}
|
}
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
sender.sendMessage(C.YELLOW + "Unknown Parameter: " + stringParam + " (" + Form.getNumberSuffixThStRd(x + 1) + " argument)");
|
sender.sendMessage(C.YELLOW + "Unknown Parameter: " + stringParam + " (" + Form.getNumberSuffixThStRd(x + 1) + " argument)");
|
||||||
@ -467,16 +443,6 @@ public class VirtualDecreeCommand {
|
|||||||
Iris.debug("Can't parse parameter value for " + i.getName() + "=" + i.getParam().defaultValue() + " in " + getPath() + " using handler " + i.getHandler().getClass().getSimpleName());
|
Iris.debug("Can't parse parameter value for " + i.getName() + "=" + i.getParam().defaultValue() + " in " + getPath() + " using handler " + i.getHandler().getClass().getSimpleName());
|
||||||
sender.sendMessage(C.RED + "Cannot convert \"" + i.getParam().defaultValue() + "\" into a " + i.getType().getSimpleName());
|
sender.sendMessage(C.RED + "Cannot convert \"" + i.getParam().defaultValue() + "\" into a " + i.getType().getSimpleName());
|
||||||
return false;
|
return false;
|
||||||
} catch (DecreeWhichException e) {
|
|
||||||
KList<?> validOptions = i.getHandler().getPossibilities(i.getParam().defaultValue());
|
|
||||||
String update = pickValidOption(sender, validOptions, i.getHandler(), i.getName(), i.getType().getSimpleName());
|
|
||||||
|
|
||||||
if (update == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iris.debug("Client chose " + update + " for " + i.getName() + "=" + i + " (old) in " + getPath());
|
|
||||||
value = update;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender.isPlayer() && i.isContextual() && value == null) {
|
if (sender.isPlayer() && i.isContextual() && value == null) {
|
||||||
@ -536,53 +502,6 @@ public class VirtualDecreeCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String pickValidOption(VolmitSender sender, KList<?> validOptions, DecreeParameterHandler<?> handler, String name, String type) {
|
|
||||||
int tries = 3;
|
|
||||||
KList<String> options = validOptions.convert(handler::toStringForce);
|
|
||||||
String result = null;
|
|
||||||
|
|
||||||
sender.sendHeader("Pick a " + name + " (" + type + ")");
|
|
||||||
sender.sendMessageRaw("<gradient:#1ed497:#b39427>This query will expire in 15 seconds.</gradient>");
|
|
||||||
|
|
||||||
while (tries-- > 0 && (result == null || !options.contains(result))) {
|
|
||||||
sender.sendMessage("<gradient:#1ed497:#b39427>Please pick a valid option.");
|
|
||||||
String password = UUID.randomUUID().toString().replaceAll("\\Q-\\E", "");
|
|
||||||
int m = 0;
|
|
||||||
|
|
||||||
for (String i : validOptions.convert(handler::toStringForce)) {
|
|
||||||
sender.sendMessage("<hover:show_text:'" + gradients[m % gradients.length] + i + "</gradient>'><click:run_command:/irisdecree " + password + " " + i + ">" + "- " + gradients[m % gradients.length] + i + "</gradient></click></hover>");
|
|
||||||
m++;
|
|
||||||
}
|
|
||||||
|
|
||||||
CompletableFuture<String> future = new CompletableFuture<>();
|
|
||||||
if (sender.isPlayer()) {
|
|
||||||
Iris.service(CommandSVC.class).post(password, future);
|
|
||||||
|
|
||||||
if (IrisSettings.get().getGeneral().isCommandSounds()) {
|
|
||||||
(sender.player()).playSound((sender.player()).getLocation(), Sound.BLOCK_AMETHYST_CLUSTER_BREAK, 0.77f, 0.65f);
|
|
||||||
(sender.player()).playSound((sender.player()).getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.125f, 1.99f);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Iris.service(CommandSVC.class).postConsole(future);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
result = future.get(15, TimeUnit.SECONDS);
|
|
||||||
} catch (InterruptedException | ExecutionException | TimeoutException ignored) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != null && options.contains(result)) {
|
|
||||||
return result;
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(C.RED + "You did not enter a correct option within 3 tries.");
|
|
||||||
sender.sendMessage(C.RED + "Please double-check your arguments & option picking.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public KList<VirtualDecreeCommand> matchAllNodes(String in) {
|
public KList<VirtualDecreeCommand> matchAllNodes(String in) {
|
||||||
KList<VirtualDecreeCommand> g = new KList<>();
|
KList<VirtualDecreeCommand> g = new KList<>();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user