-
-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for data values in the blacklist.
- Loading branch information
Showing
12 changed files
with
465 additions
and
34 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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/sk89q/worldguard/blacklist/target/DataMask.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,28 @@ | ||
/* | ||
* WorldGuard, a suite of tools for Minecraft | ||
* Copyright (C) sk89q <http://www.sk89q.com> | ||
* Copyright (C) WorldGuard 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.worldguard.blacklist.target; | ||
|
||
import com.google.common.base.Predicate; | ||
|
||
/** | ||
* Tests a data value. | ||
*/ | ||
public interface DataMask extends Predicate<Short> { | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/sk89q/worldguard/blacklist/target/DataValueRangeMatcher.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,51 @@ | ||
/* | ||
* WorldGuard, a suite of tools for Minecraft | ||
* Copyright (C) sk89q <http://www.sk89q.com> | ||
* Copyright (C) WorldGuard 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.worldguard.blacklist.target; | ||
|
||
import com.google.common.base.Predicate; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
public class DataValueRangeMatcher implements TargetMatcher { | ||
|
||
private final int typeId; | ||
private final Predicate<Short> dataMatcher; | ||
|
||
public DataValueRangeMatcher(int typeId, Predicate<Short> dataMatcher) { | ||
checkNotNull(dataMatcher); | ||
this.typeId = typeId; | ||
this.dataMatcher = dataMatcher; | ||
} | ||
|
||
@Override | ||
public int getMatchedTypeId() { | ||
return typeId; | ||
} | ||
|
||
@Override | ||
public boolean test(Target target) { | ||
return typeId == target.getTypeId() && isDataInRange(target.getData()); | ||
} | ||
|
||
private boolean isDataInRange(short data) { | ||
return dataMatcher.apply(data); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/sk89q/worldguard/blacklist/target/MaterialTarget.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 @@ | ||
/* | ||
* WorldGuard, a suite of tools for Minecraft | ||
* Copyright (C) sk89q <http://www.sk89q.com> | ||
* Copyright (C) WorldGuard 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.worldguard.blacklist.target; | ||
|
||
import com.sk89q.worldedit.blocks.ItemType; | ||
|
||
public class MaterialTarget implements Target { | ||
|
||
private int id; | ||
private short data; | ||
|
||
public MaterialTarget(int id, short data) { | ||
this.id = id; | ||
this.data = data; | ||
} | ||
|
||
@Override | ||
public int getTypeId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public short getData() { | ||
return data; | ||
} | ||
|
||
@Override | ||
public String getFriendlyName() { | ||
ItemType type = ItemType.fromID(id); | ||
if (type != null) { | ||
return type.getName() + " (#" + id + ":" + data + ")"; | ||
} else { | ||
return "#" + id + ":" + data; | ||
} | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/sk89q/worldguard/blacklist/target/RangeMask.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,40 @@ | ||
/* | ||
* WorldGuard, a suite of tools for Minecraft | ||
* Copyright (C) sk89q <http://www.sk89q.com> | ||
* Copyright (C) WorldGuard 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.worldguard.blacklist.target; | ||
|
||
import com.google.common.collect.Range; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
public class RangeMask implements DataMask { | ||
|
||
private final Range<Short> range; | ||
|
||
public RangeMask(Range<Short> range) { | ||
checkNotNull(range); | ||
this.range = range; | ||
} | ||
|
||
@Override | ||
public boolean apply(Short data) { | ||
return range.contains(data); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/sk89q/worldguard/blacklist/target/Target.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,48 @@ | ||
/* | ||
* WorldGuard, a suite of tools for Minecraft | ||
* Copyright (C) sk89q <http://www.sk89q.com> | ||
* Copyright (C) WorldGuard 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.worldguard.blacklist.target; | ||
|
||
/** | ||
* A target is something that can have events attached to it. | ||
*/ | ||
public interface Target { | ||
|
||
/** | ||
* Get the type ID. | ||
* | ||
* @return the type ID | ||
*/ | ||
int getTypeId(); | ||
|
||
/** | ||
* Get the data value. | ||
* | ||
* @return the data value | ||
*/ | ||
short getData(); | ||
|
||
/** | ||
* Get a friendly name to be printed. | ||
* | ||
* @return a friendly name | ||
*/ | ||
String getFriendlyName(); | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/sk89q/worldguard/blacklist/target/TargetMatcher.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,42 @@ | ||
/* | ||
* WorldGuard, a suite of tools for Minecraft | ||
* Copyright (C) sk89q <http://www.sk89q.com> | ||
* Copyright (C) WorldGuard 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.worldguard.blacklist.target; | ||
|
||
/** | ||
* Matches a {@link Target}. | ||
*/ | ||
public interface TargetMatcher { | ||
|
||
/** | ||
* Get the matched type ID, which is merely used for indexing. | ||
* | ||
* @return the type ID | ||
*/ | ||
int getMatchedTypeId(); | ||
|
||
/** | ||
* Return whether the given target is matched by this matcher. | ||
* | ||
* @param target the target | ||
* @return true if matched | ||
*/ | ||
boolean test(Target target); | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/sk89q/worldguard/blacklist/target/TargetMatcherParseException.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,30 @@ | ||
/* | ||
* WorldGuard, a suite of tools for Minecraft | ||
* Copyright (C) sk89q <http://www.sk89q.com> | ||
* Copyright (C) WorldGuard 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.worldguard.blacklist.target; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
public class TargetMatcherParseException extends Exception { | ||
|
||
public TargetMatcherParseException(String message) { | ||
super(checkNotNull(message)); | ||
} | ||
|
||
} |
Oops, something went wrong.
956d1b4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh my god, finally. Thank you so much!