parent
b7d7f1188f
commit
a7912f9cbf
@ -1,125 +0,0 @@
|
||||
package tc.oc.commons.bukkit.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.CraftBukkitRuntime;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.potion.CraftPotionBrewer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import static org.bukkit.potion.PotionEffectType.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static tc.oc.commons.bukkit.util.PotionClassification.*;
|
||||
|
||||
/** Tests for {@link PotionUtils} and {@link PotionClassification} */
|
||||
@RunWith(JUnit4.class)
|
||||
public class PotionClassificationTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
CraftBukkitRuntime.load();
|
||||
if(Potion.getBrewer() == null) {
|
||||
Potion.setPotionBrewer(new CraftPotionBrewer());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void effectTypes() throws Exception {
|
||||
assertEquals(BENEFICIAL, classify(HEAL));
|
||||
assertEquals(HARMFUL, classify(HARM));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void classifyByMostEffects() throws Exception {
|
||||
assertEquals(BENEFICIAL, classify(ImmutableList.of(
|
||||
new PotionEffect(SPEED, 1, 0),
|
||||
new PotionEffect(HARM, 1, 0),
|
||||
new PotionEffect(LUCK, 1, 0)
|
||||
)));
|
||||
|
||||
assertEquals(HARMFUL, classify(ImmutableList.of(
|
||||
new PotionEffect(SLOW, 1, 0),
|
||||
new PotionEffect(HEAL, 1, 0),
|
||||
new PotionEffect(UNLUCK, 1, 0)
|
||||
)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void classifyByDuration() throws Exception {
|
||||
assertEquals(BENEFICIAL, classify(ImmutableList.of(
|
||||
new PotionEffect(HEAL, 2, 0),
|
||||
new PotionEffect(HARM, 1, 0)
|
||||
)));
|
||||
|
||||
assertEquals(HARMFUL, classify(ImmutableList.of(
|
||||
new PotionEffect(HEAL, 1, 0),
|
||||
new PotionEffect(HARM, 2, 0)
|
||||
)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void classifyByAmplifier() throws Exception {
|
||||
assertEquals(BENEFICIAL, classify(ImmutableList.of(
|
||||
new PotionEffect(HEAL, 1, 1),
|
||||
new PotionEffect(HARM, 1, 0)
|
||||
)));
|
||||
|
||||
assertEquals(HARMFUL, classify(ImmutableList.of(
|
||||
new PotionEffect(HEAL, 1, 0),
|
||||
new PotionEffect(HARM, 1, 1)
|
||||
)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void negativeAmplifier() throws Exception {
|
||||
assertEquals(BENEFICIAL, classify(ImmutableList.of(
|
||||
new PotionEffect(HARM, 1, -1)
|
||||
)));
|
||||
assertEquals(HARMFUL, classify(ImmutableList.of(
|
||||
new PotionEffect(HEAL, 1, -1)
|
||||
)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vanillaBrews() throws Exception {
|
||||
assertEquals(BENEFICIAL, classify(Bukkit.potionRegistry().get(Bukkit.key("healing"))));
|
||||
assertEquals(BENEFICIAL, classify(new PotionData(PotionType.INSTANT_HEAL, false, false)));
|
||||
assertEquals(HARMFUL, classify(Bukkit.potionRegistry().get(Bukkit.key("harming"))));
|
||||
assertEquals(HARMFUL, classify(new PotionData(PotionType.INSTANT_DAMAGE, false, false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void potionItem() throws Exception {
|
||||
final ItemStack item = new ItemStack(Material.POTION);
|
||||
final PotionMeta meta = (PotionMeta) item.getItemMeta();
|
||||
meta.setPotionBrew(Bukkit.potionRegistry().get(Bukkit.key("healing")));
|
||||
item.setItemMeta(meta);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void riftCaseTest() {
|
||||
List<PotionEffect> effects = ImmutableList.of(
|
||||
new PotionEffect(FAST_DIGGING, 3600, 3),
|
||||
new PotionEffect(REGENERATION, 3600, 2),
|
||||
new PotionEffect(DAMAGE_RESISTANCE, 3600, 1),
|
||||
new PotionEffect(FIRE_RESISTANCE, 3600, 1),
|
||||
new PotionEffect(SPEED, 3600, 1),
|
||||
new PotionEffect(INCREASE_DAMAGE, 3600, 1)
|
||||
);
|
||||
|
||||
assertEquals("Rift Baron potion was not classified as <BENEFICIAL>",
|
||||
PotionClassification.BENEFICIAL, classify(effects));
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package tc.oc.pgm.channels;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import tc.oc.chatmoderator.channels.SimpleFilteredChannel;
|
||||
import tc.oc.pgm.match.Party;
|
||||
|
||||
public class FilteredPartyChannel extends SimpleFilteredChannel implements PartyChannel {
|
||||
|
||||
private final Party party;
|
||||
|
||||
public FilteredPartyChannel(String format, final Permission permission, final Party party, int minimumScoreNoSend, float partial) {
|
||||
super(format, permission, minimumScoreNoSend, partial);
|
||||
this.party = Preconditions.checkNotNull(party, "party");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Party getParty() {
|
||||
return this.party;
|
||||
}
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
package tc.oc.pgm.filter;
|
||||
|
||||
import org.bukkit.CraftBukkitRuntime;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ImItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.material.Wool;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.bukkit.potion.PotionType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import tc.oc.pgm.filters.ItemMatcher;
|
||||
import tc.oc.pgm.kits.tag.ItemTags;
|
||||
import tc.oc.pgm.projectile.Projectiles;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ItemMatcherTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
CraftBukkitRuntime.load();
|
||||
}
|
||||
|
||||
private void assertMatches(ItemStack item, ItemStack query) {
|
||||
final ItemMatcher matcher = new ItemMatcher(item);
|
||||
|
||||
if(!matcher.test(query)) {
|
||||
fail("Item should match: reference=" + item + " query=" + query);
|
||||
}
|
||||
|
||||
final CraftItemStack nms = CraftItemStack.asCraftMirror(CraftItemStack.asNMSCopy(query));
|
||||
if(!matcher.test(nms)) {
|
||||
fail("Converted item should match: reference=" + item + " query=" + query);
|
||||
}
|
||||
}
|
||||
|
||||
private void refuteMatches(ItemStack item, ItemStack query) {
|
||||
final ItemMatcher matcher = new ItemMatcher(item);
|
||||
|
||||
if(matcher.test(query)) {
|
||||
fail("Item should not match: reference=" + item + " query=" + query);
|
||||
}
|
||||
|
||||
final CraftItemStack nms = CraftItemStack.asCraftMirror(CraftItemStack.asNMSCopy(query));
|
||||
if(matcher.test(nms)) {
|
||||
fail("Converted item should not match: reference=" + item + " query=" + query);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleItemMatches() throws Throwable {
|
||||
ImItemStack item = ItemStack.builder(Material.BEDROCK)
|
||||
.immutable();
|
||||
assertMatches(item, item);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemWithDataMatches() throws Throwable {
|
||||
ImItemStack item = ItemStack.builder(new Wool(DyeColor.PINK))
|
||||
.immutable();
|
||||
assertMatches(item, item);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemWithMetaMatches() throws Throwable {
|
||||
ImItemStack item = ItemStack.builder(Material.BEDROCK)
|
||||
.meta(meta -> meta.setDisplayName("Hi!"))
|
||||
.immutable();
|
||||
assertMatches(item, item);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemWithTypedMetaMatches() throws Throwable {
|
||||
ImItemStack item = ItemStack.builder(Material.POTION)
|
||||
.meta(PotionMeta.class, meta -> meta.setBasePotionData(new PotionData(PotionType.LUCK, false, false)))
|
||||
.immutable();
|
||||
assertMatches(item, item);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemWithCustomProjectileMatches() throws Throwable {
|
||||
ImItemStack item = ItemStack.builder(Material.STICK)
|
||||
.meta(meta -> Projectiles.setProjectileId(meta, "woot"))
|
||||
.immutable();
|
||||
assertMatches(item, item);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void differentMaterialsDontMatch() throws Throwable {
|
||||
refuteMatches(new ItemStack(Material.BEDROCK),
|
||||
new ItemStack(Material.APPLE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void differentDataDoesntMatch() throws Throwable {
|
||||
refuteMatches(new ItemStack(new Wool(DyeColor.PINK)),
|
||||
new ItemStack(new Wool(DyeColor.BLUE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void differentMetaDoesntMatch() throws Throwable {
|
||||
refuteMatches(ItemStack.builder(Material.BEDROCK).meta(meta -> meta.setDisplayName("Hi!")).immutable(),
|
||||
ItemStack.builder(Material.BEDROCK).meta(meta -> meta.setDisplayName("Bye!")).immutable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void differentProjectileDoesntMatch() throws Throwable {
|
||||
refuteMatches(ItemStack.builder(Material.STICK).meta(meta -> Projectiles.setProjectileId(meta, "woot")).immutable(),
|
||||
ItemStack.builder(Material.STICK).meta(meta -> Projectiles.setProjectileId(meta, "doink")).immutable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullDoesntMatch() throws Throwable {
|
||||
assertFalse(new ItemMatcher(new ItemStack(Material.BEDROCK)).test(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biggerStackMatches() throws Throwable {
|
||||
assertMatches(new ItemStack(Material.BEDROCK, 3),
|
||||
new ItemStack(Material.BEDROCK, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smallerStackDoesNotMatch() throws Throwable {
|
||||
refuteMatches(new ItemStack(Material.BEDROCK, 3),
|
||||
new ItemStack(Material.BEDROCK, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void durabilityIgnoredOnDamageableItem() throws Throwable {
|
||||
assertMatches(new ItemStack(Material.STONE_SWORD, 1, (short) 123),
|
||||
new ItemStack(Material.STONE_SWORD, 1, (short) 456));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void durabilityMattersOnDataItem() throws Throwable {
|
||||
refuteMatches(new ItemStack(Material.WOOL, 1, (short) 1),
|
||||
new ItemStack(Material.WOOL, 1, (short) 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lockFlagIgnored() throws Throwable {
|
||||
ItemStack ref = new ItemStack(Material.BEDROCK);
|
||||
ItemStack query = ref.clone();
|
||||
ItemTags.LOCKED.set(query, true);
|
||||
assertMatches(ref, query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preventSharingFlagIgnored() throws Throwable {
|
||||
ItemStack ref = new ItemStack(Material.BEDROCK);
|
||||
ItemStack query = ref.clone();
|
||||
ItemTags.PREVENT_SHARING.set(query, true);
|
||||
assertMatches(ref, query);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue