Skip to content

Commit

Permalink
Merge some fixes here
Browse files Browse the repository at this point in the history
  • Loading branch information
bensku committed Mar 9, 2016
1 parent bf48f90 commit b5a4616
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 37 deletions.
15 changes: 8 additions & 7 deletions src/main/java/ch/njol/skript/bukkitutil/Workarounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ public final static void init() {}

static {
// allows to properly remove a player's tool in right click events
Bukkit.getPluginManager().registerEvents(new Listener() {
@EventHandler(priority = EventPriority.HIGHEST)
public void onInteract(final PlayerInteractEvent e) {
if (e.hasItem() && (e.getPlayer().getItemInHand() == null || e.getPlayer().getItemInHand().getType() == Material.AIR || e.getPlayer().getItemInHand().getAmount() == 0))
e.setUseItemInHand(Result.DENY);
}
}, Skript.getInstance());
Bukkit.getPluginManager().registerEvents(new Listener() {
@EventHandler(priority = EventPriority.HIGHEST)
public void onInteract(final PlayerInteractEvent e) {
//TODO Check if it's needed to do one for off hand?
if (e.hasItem() && (e.getPlayer().getInventory().getItemInMainHand() == null || e.getPlayer().getInventory().getItemInMainHand().getType() == Material.AIR || e.getPlayer().getInventory().getItemInMainHand().getAmount() == 0))
e.setUseItemInHand(Result.DENY);
}
}, Skript.getInstance());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ public boolean mustSyncDeserialization() {

@Override
public boolean canBeInstantiated() {
return false;
}

@Override
protected T deserialize(final Fields fields) throws StreamCorruptedException {
final String val = fields.getObject("value", String.class);
return false;
}

@SuppressWarnings("null")
@Override
protected T deserialize(final Fields fields) throws StreamCorruptedException {
final String val = fields.getObject("value", String.class);
if (val == null)
throw new StreamCorruptedException();
final ClassInfo<? extends T> info = this.info;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/classes/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public boolean canBeInstantiated(final Class<? extends T> c) {
*/
protected abstract boolean canBeInstantiated();

@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "null"})
@Override
public <E extends T> E deserialize(final Class<E> c, final Fields fields) throws StreamCorruptedException, NotSerializableException {
final ClassInfo<? extends T> info = this.info;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java (rejected hunks)
@@ -61,8 +61,8 @@ import org.bukkit.event.hanging.HangingEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
-import org.bukkit.event.painting.PaintingEvent;
-import org.bukkit.event.painting.PaintingPlaceEvent;
+//import org.bukkit.event.painting.PaintingEvent;
+//import org.bukkit.event.painting.PaintingPlaceEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
@@ -584,7 +584,7 @@ public final class BukkitEventValues {
return e.getPlayer();
}
}, 0);
- } else {
+ /*} else {
EventValues.registerEventValue(PaintingEvent.class, Painting.class, new Getter<Painting, PaintingEvent>() {
@Override
@Nullable
33 changes: 25 additions & 8 deletions src/main/java/ch/njol/skript/conditions/CondItemInHand.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,37 @@
public class CondItemInHand extends Condition {

static {
Skript.registerCondition(CondItemInHand.class,
"[%livingentities%] ha(s|ve) %itemtypes% in hand",
"[%livingentities%] (is|are) holding %itemtypes%",
"[%livingentities%] (ha(s|ve) not|do[es]n't have) %itemtypes% in hand",
"[%livingentities%] (is not|isn't) holding %itemtypes%");
if (Skript.isRunningMinecraft(1, 9)) {
Skript.registerCondition(CondItemInHand.class,
"[%livingentities%] ha(s|ve) %itemtypes% in [main] hand", "[%livingentities%] (is|are) holding %itemtypes% [in main hand]",
"[%livingentities%] ha(s|ve) %itemtypes% in off[(-| )]hand", "[%livingentities%] (is|are) holding %itemtypes% in off[(-| )]hand",
"[%livingentities%] (ha(s|ve) not|do[es]n't have) %itemtypes% in [main] hand", "[%livingentities%] (is not|isn't) holding %itemtypes% [in main hand]",
"[%livingentities%] (ha(s|ve) not|do[es]n't have) %itemtypes% in off[(-| )]hand", "[%livingentities%] (is not|isn't) holding %itemtypes% in off[(-| )]hand");
} else {
Skript.registerCondition(CondItemInHand.class,
"[%livingentities%] ha(s|ve) %itemtypes% in hand", "[%livingentities%] (is|are) holding %itemtypes% in hand",
"[%livingentities%] (ha(s|ve) not|do[es]n't have) %itemtypes%", "[%livingentities%] (is not|isn't) holding %itemtypes%");
}
}

@SuppressWarnings("null")
private Expression<LivingEntity> entities;
@SuppressWarnings("null")
Expression<ItemType> types;
boolean offTool;

@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) {
entities = (Expression<LivingEntity>) vars[0];
types = (Expression<ItemType>) vars[1];
setNegated(matchedPattern >= 2);
if (Skript.isRunningMinecraft(1, 9)) {
offTool = (matchedPattern == 2 || matchedPattern == 3 || matchedPattern == 6 || matchedPattern == 7);
setNegated(matchedPattern >= 4);
} else {
offTool = false;
setNegated(matchedPattern >= 2);
}
return true;
}

Expand All @@ -75,9 +88,13 @@ public boolean check(final Event e) {
@Override
public boolean check(final LivingEntity en) {
return types.check(e, new Checker<ItemType>() {
@SuppressWarnings("deprecation")
@Override
public boolean check(final ItemType type) {
return type.isOfType(en.getEquipment().getItemInHand());
if (Skript.isRunningMinecraft(1, 9))
return (offTool ? type.isOfType(en.getEquipment().getItemInOffHand()) : type.isOfType(en.getEquipment().getItemInMainHand()));
else
return type.isOfType(en.getEquipment().getItemInHand());
}
}, isNegated());
}
Expand All @@ -86,7 +103,7 @@ public boolean check(final ItemType type) {

@Override
public String toString(final @Nullable Event e, final boolean debug) {
return entities.toString(e, debug) + " " + (entities.isSingle() ? "is" : "are") + " holding " + types.toString(e, debug);
return entities.toString(e, debug) + " " + (entities.isSingle() ? "is" : "are") + " holding " + types.toString(e, debug) + (offTool ? " in off-hand" : "");
}

}
4 changes: 4 additions & 0 deletions src/main/java/ch/njol/skript/entity/SimpleEntityData.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.MagmaCube;
import org.bukkit.entity.Monster;
import org.bukkit.entity.MushroomCow;
import org.bukkit.entity.Painting;
import org.bukkit.entity.PigZombie;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Shulker;
import org.bukkit.entity.ShulkerBullet;
import org.bukkit.entity.Silverfish;
import org.bukkit.entity.Slime;
import org.bukkit.entity.SmallFireball;
Expand Down Expand Up @@ -150,6 +152,7 @@ public boolean equals(final @Nullable Object obj) {
types.add(new SimpleEntityDataInfo("tnt", TNTPrimed.class));
types.add(new SimpleEntityDataInfo("zombie", Zombie.class));
types.add(new SimpleEntityDataInfo("shulker", Shulker.class));
types.add(new SimpleEntityDataInfo("shulker bullet", ShulkerBullet.class));
types.add(new SimpleEntityDataInfo("golem", Golem.class));
types.add(new SimpleEntityDataInfo("guardian", Guardian.class));

Expand All @@ -170,6 +173,7 @@ public boolean equals(final @Nullable Object obj) {

// supertypes
types.add(new SimpleEntityDataInfo("human", HumanEntity.class, true));
types.add(new SimpleEntityDataInfo("monster", Monster.class, true)); //I don't know why Njol never included that. I did now ^^
types.add(new SimpleEntityDataInfo("creature", Creature.class, true));
types.add(new SimpleEntityDataInfo("projectile", Projectile.class, true));
types.add(new SimpleEntityDataInfo("living entity", LivingEntity.class, true));
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/ch/njol/skript/events/EvtClick.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
public class EvtClick extends SkriptEvent {

// Important: a click on an entity fires both an PlayerInteractEntityEvent and a PlayerInteractEvent

// TheBukor: It only fires a PlayerInteractEntityEvent in 1.9, I guess.

private final static int RIGHT = 1, LEFT = 2, ANY = RIGHT | LEFT;

Expand Down Expand Up @@ -139,7 +141,7 @@ public boolean check(final Event e) {
return false;
}

if (tools != null && !tools.check(e, new Checker<ItemType>() {
if (e instanceof PlayerInteractEvent && tools != null && !tools.check(e, new Checker<ItemType>() {
@Override
public boolean check(final ItemType t) {
return t.isOfType(((PlayerInteractEvent) e).getItem());
Expand Down
29 changes: 19 additions & 10 deletions src/main/java/ch/njol/skript/expressions/ExprTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,23 @@
@Since("1.0")
public class ExprTool extends PropertyExpression<LivingEntity, Slot> {
static {
Skript.registerExpression(ExprTool.class, Slot.class, ExpressionType.PROPERTY, "[the] (tool|held item|weapon) [of %livingentities%]", "%livingentities%'[s] (tool|held item|weapon)");
Skript.registerExpression(ExprTool.class, Slot.class, ExpressionType.PROPERTY, "[the] ((offhand|off) (tool|held item|weapon)|shield) [of %livingentities%]", "%livingentities%'[s] ((offhand|off) (tool|held item|weapon)|shield)");
Skript.registerExpression(ExprTool.class, Slot.class, ExpressionType.PROPERTY, "[the] (tool|held item|weapon) [of %livingentities%]", "%livingentities%'[s] (tool|held item|weapon)",
"[the] (off[-]tool|off[-][held ]item|off[-]weapon) [of %livingentities%]", "%livingentities%'[s] (off[-]tool|off[-][held ]item|off[-]weapon)");
if (Skript.isRunningMinecraft(1, 9)) {
Skript.registerExpression(ExprTool.class, Slot.class, ExpressionType.PROPERTY, "[the] (tool|held item|weapon) [of %livingentities%]", "%livingentities%'[s] (tool|held item|weapon)",
"[the] (off[(-| )]tool|off[(-| )][held ]item|off[(-| )]weapon) [of %livingentities%]", "%livingentities%'[s] (off[(-| )]tool|off[(-| )][held ]item|off[(-| )]weapon)");
} else {
Skript.registerExpression(ExprTool.class, Slot.class, ExpressionType.PROPERTY, "[the] (tool|held item|weapon) [of %livingentities%]", "%livingentities%'[s] (tool|held item|weapon)");
}
}

boolean offTool; //Is this item offhand tools

@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) {
setExpr((Expression<Player>) exprs[0]);
offTool = matchedPattern >= 2;
return true;
}

Expand Down Expand Up @@ -106,13 +115,13 @@ public void setItem(final @Nullable ItemStack item) {
};
}
}
final EntityEquipment e = p.getEquipment();
if (e == null)
return null;
return new EquipmentSlot(e, EquipmentSlot.EquipSlot.TOOL) {
@Override
public String toString_i() {
return "the " + (getTime() == 1 ? "future " : getTime() == -1 ? "former " : "") + super.toString_i();
final EntityEquipment e = p.getEquipment();
if (e == null)
return null;
return new EquipmentSlot(e, offTool ? EquipmentSlot.EquipSlot.OFF_TOOL : EquipmentSlot.EquipSlot.TOOL) {
@Override
public String toString_i() {
return "the " + (getTime() == 1 ? "future " : getTime() == -1 ? "former " : "") + super.toString_i();
}
};
}
Expand Down Expand Up @@ -179,7 +188,7 @@ public void setItem(final @Nullable ItemStack item) {
final EntityEquipment e = p.getEquipment();
if (e == null)
return null;
return new EquipmentSlot(e, EquipmentSlot.EquipSlot.OFFHAND) {
return new EquipmentSlot(e, EquipmentSlot.EquipSlot.OFF_HAND) {
@Override
public String toString_i() {
return "the " + (getTime() == 1 ? "future " : getTime() == -1 ? "former " : "") + super.toString_i();
Expand Down
24 changes: 21 additions & 3 deletions src/main/java/ch/njol/skript/util/EquipmentSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,24 @@ public void set(final EntityEquipment e, final @Nullable ItemStack item) {
}
}
},
OFFHAND { // Since Minecraft 1.9 (defaults to main hand if earlier version)
OFF_HAND { // Since Minecraft 1.9 (defaults to main hand if earlier version)

@Override
@Nullable
public ItemStack get(EntityEquipment e) {
if (Skript.isRunningMinecraft(1, 9)) {
return e.getItemInOffHand();
}
return e.getItemInHand();
Skript.warning("No off hand support, but skript would need that!");
return new ItemStack(Material.AIR);
}

@Override
public void set(EntityEquipment e, @Nullable ItemStack item) {
if (Skript.isRunningMinecraft(1, 9)) {
e.setItemInOffHand(item);
} else {
e.setItemInHand(item);
Skript.warning("No off hand support, but skript would need that!");
}
}

Expand Down Expand Up @@ -132,6 +133,23 @@ public ItemStack get(final EntityEquipment e) {
public void set(final EntityEquipment e, final @Nullable ItemStack item) {
e.setBoots(item);
}
},
OFF_TOOL {
@SuppressWarnings("deprecation")
@Override
@Nullable
public ItemStack get(final EntityEquipment e) {
return (Skript.isRunningMinecraft(1, 9) ? e.getItemInOffHand() : e.getItemInHand()); //Compatibility reasons
}

@SuppressWarnings("deprecation")
@Override
public void set(final EntityEquipment e, final @Nullable ItemStack item) {
if (Skript.isRunningMinecraft(1, 9))
e.setItemInOffHand(item);
else
e.setItemInHand(item); //Compatibility reasons
}
};

@Nullable
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/yggdrasil/JRESerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void deserialize(final Object o, final Fields fields) throws StreamCorrup
throw new StreamCorruptedException();
}

@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "null"})
@Override
public <E> E deserialize(Class<E> c, Fields fields) throws StreamCorruptedException, NotSerializableException {
if (c == UUID.class) {
Expand Down

0 comments on commit b5a4616

Please sign in to comment.