Skip to content

Commit 2b5bbd0

Browse files
committed
pom.xml update
1 parent 5e87816 commit 2b5bbd0

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>ch.njol</groupId>
44
<artifactId>skript</artifactId>
5-
<version>2.2-dev13</version>
5+
<version>2.2-dev13b</version>
66
<name>Skript</name>
77
<description>A plugin for the Minecraft server API Bukkit that allows to create scripts in natural language.</description>
88
<url>http://njol.ch/projects/skript/</url>

src/main/java/ch/njol/skript/bukkitutil/PlayerUtils.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import java.util.Set;
3131

3232
import org.bukkit.Bukkit;
33+
import org.bukkit.GameMode;
34+
import org.bukkit.Material;
3335
import org.bukkit.entity.Player;
3436
import org.eclipse.jdt.annotation.Nullable;
3537

@@ -104,4 +106,28 @@ public final static Collection<? extends Player> getOnlinePlayers() {
104106
}
105107
}
106108

109+
110+
public final static boolean canEat(Player p, Material food) {
111+
GameMode gm = p.getGameMode();
112+
if (gm == GameMode.CREATIVE || gm == GameMode.SPECTATOR)
113+
return false; // Can't eat anything in those gamemodes
114+
115+
boolean edible = food.isEdible();
116+
if (!edible)
117+
return false;
118+
boolean special;
119+
switch (food) {
120+
case GOLDEN_APPLE:
121+
case CHORUS_FRUIT:
122+
special = true;
123+
break;
124+
//$CASES-OMITTED$
125+
default:
126+
special = false;
127+
}
128+
if (p.getFoodLevel() < 20 || special)
129+
return true;
130+
131+
return false;
132+
}
107133
}

src/main/java/ch/njol/skript/events/EvtClick.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import ch.njol.skript.Skript;
3939
import ch.njol.skript.aliases.ItemType;
40+
import ch.njol.skript.bukkitutil.PlayerUtils;
4041
import ch.njol.skript.classes.Comparator.Relation;
4142
import ch.njol.skript.classes.data.DefaultComparators;
4243
import ch.njol.skript.entity.EntityData;
@@ -103,7 +104,7 @@ public boolean check(final Event e) {
103104

104105
if (e instanceof PlayerInteractEntityEvent) {
105106
PlayerInteractEntityEvent clickEvent = ((PlayerInteractEntityEvent) e);
106-
if (Skript.isRunningMinecraft(1, 9)) { // If player has empty hand, BOTH hands trigger the event (might be a bug?)
107+
if (Skript.isRunningMinecraft(1, 9)) {
107108
ItemStack mainHand = clickEvent.getPlayer().getInventory().getItemInMainHand();
108109
ItemStack offHand = clickEvent.getPlayer().getInventory().getItemInOffHand();
109110

@@ -123,7 +124,7 @@ public boolean check(final Event e) {
123124
block = null;
124125
} else if (e instanceof PlayerInteractEvent) {
125126
PlayerInteractEvent clickEvent = ((PlayerInteractEvent) e);
126-
if (Skript.isRunningMinecraft(1, 9)) { // If player has empty hand, BOTH hands trigger the event (might be a bug?)
127+
if (Skript.isRunningMinecraft(1, 9)) {
127128
ItemStack mainHand = clickEvent.getPlayer().getInventory().getItemInMainHand();
128129
ItemStack offHand = clickEvent.getPlayer().getInventory().getItemInOffHand();
129130

@@ -198,6 +199,11 @@ public static boolean checkUseOffHand(Player player, int clickType, @Nullable Bl
198199
ItemStack mainHand = player.getInventory().getItemInMainHand();
199200
ItemStack offHand = player.getInventory().getItemInOffHand();
200201

202+
Material mainMat = mainHand.getType();
203+
Material offMat = offHand.getType();
204+
assert mainMat != null;
205+
assert offMat != null;
206+
201207
//Skript.info("block is " + block);
202208
//Skript.info("entity is " + entity);
203209

@@ -231,7 +237,7 @@ public static boolean checkUseOffHand(Player player, int clickType, @Nullable Bl
231237
}
232238

233239
// Seriously? Empty hand -> block in hand, since id of AIR < 256 :O
234-
if ((offHand.getType().isBlock() && offHand.getType() != Material.AIR) || offHand.getType().isEdible()) {
240+
if ((offMat.isBlock() && offMat != Material.AIR) || PlayerUtils.canEat(player, offMat)) {
235241
offUsable = true;
236242
}
237243

@@ -264,7 +270,7 @@ public static boolean checkUseOffHand(Player player, int clickType, @Nullable Bl
264270
}
265271

266272
// Seriously? Empty hand -> block in hand, since id of AIR < 256 :O
267-
if ((mainHand.getType().isBlock() && mainHand.getType() != Material.AIR) || mainHand.getType().isEdible()) {
273+
if ((mainMat.isBlock() && mainMat != Material.AIR) || PlayerUtils.canEat(player, mainMat)) {
268274
mainUsable = true;
269275
}
270276

0 commit comments

Comments
 (0)