Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update passengers and vehicles #5312

Open
wants to merge 21 commits into
base: dev/feature
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 0 additions & 105 deletions src/main/java/ch/njol/skript/bukkitutil/PassengerUtils.java

This file was deleted.

69 changes: 69 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondHasPassengers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* This file is part of Skript.
*
* Skript 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.
*
* Skript 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 Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.conditions;

import org.bukkit.entity.Entity;

import ch.njol.skript.Skript;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;

@Name("Has Passengers")
@Description("Checks whether the given entities have passengers.")
@Examples("if the vehicle has passengers:")
TheLimeGlass marked this conversation as resolved.
Show resolved Hide resolved
@Since("INSERT VERSION")
public class CondHasPassengers extends PropertyCondition<Entity> {

static {
Skript.registerCondition(CondHasPassengers.class,
"%entities% (has|have) [a[ny]|:no] passenger[s]",
"%entities% (doesn't|does not|do not|don't) have [a[ny]] passenger[s]"
TheLimeGlass marked this conversation as resolved.
Show resolved Hide resolved
);
}

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
setExpr((Expression<? extends Entity>) exprs[0]);
setNegated(matchedPattern == 1 || parseResult.hasTag("no"));
return true;
}

@Override
public boolean check(Entity entity) {
return !entity.isEmpty();
AyhamAl-Ali marked this conversation as resolved.
Show resolved Hide resolved
}

TheLimeGlass marked this conversation as resolved.
Show resolved Hide resolved
@Override
protected PropertyType getPropertyType() {
return PropertyType.HAVE;
}

@Override
protected String getPropertyName() {
return "passengers";
}

}
46 changes: 25 additions & 21 deletions src/main/java/ch/njol/skript/conditions/CondIsEmpty.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,53 +18,57 @@
*/
package ch.njol.skript.conditions;

import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import ch.njol.skript.bukkitutil.ItemUtils;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.util.slot.Slot;

/**
* @author Peter Güttinger
*/
@Name("Is Empty")
@Description("Checks whether an inventory, an inventory slot, or a text is empty.")
@Description({
"Checks whether an inventory, an inventory slot, or a text is empty.",
"An entity can be a type, which will check if there are no passengers."
})
@Examples("player's inventory is empty")
@Since("<i>unknown</i> (before 2.1)")
@Since("<i>unknown</i> (before 2.1), INSERT VERSION (Entity)")
public class CondIsEmpty extends PropertyCondition<Object> {

static {
register(CondIsEmpty.class, "empty", "inventories/slots/strings");
register(CondIsEmpty.class, "empty", "entities/inventories/slots/strings");
}

@Override
public boolean check(final Object o) {
if (o instanceof String)
return ((String) o).isEmpty();
if (o instanceof Inventory) {
for (ItemStack s : ((Inventory) o).getContents()) {
if (s != null && s.getType() != Material.AIR)
public boolean check(Object object) {
if (object instanceof String)
return ((String) object).isEmpty();
if (object instanceof Inventory) {
for (ItemStack item : ((Inventory) object).getContents()) {
if (item != null && !ItemUtils.isAir(item.getType()))
return false; // There is an item here!
}
return true;
}
if (o instanceof Slot) {
final Slot s = (Slot) o;
final ItemStack i = s.getItem();
return i == null || i.getType() == Material.AIR;
if (object instanceof Slot) {
Slot slot = (Slot) object;
ItemStack item = slot.getItem();
return item == null || !ItemUtils.isAir(item.getType());
}
if (object instanceof Entity) {
return ((Entity) object).isEmpty();
}
assert false;
return false;
}

@Override
protected String getPropertyName() {
return "empty";
}

}
Loading
Loading