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

Adds some fire resistant syntax #6639

Merged
merged 15 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
52 changes: 52 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondIsFireResistant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* 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 ch.njol.skript.aliases.ItemType;
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.RequiredPlugins;
import ch.njol.skript.doc.Since;

@Name("Is Fire Resistant")
@Description("Checks whether an item is fire resistant.")
@Examples({
"if player's tool is fire resistant:",
"if {_items::*} aren't resistant to fire:"
})
@RequiredPlugins("Spigot 1.20.5+")
@Since("INSERT VERSION")
public class CondIsFireResistant extends PropertyCondition<ItemType> {

static {
PropertyCondition.register(CondIsFireResistant.class, "(fire resistant|resistant to fire)", "itemtypes");
cheeezburga marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public boolean check(ItemType item) {
return item.getItemMeta().isFireResistant();
}

@Override
public String getPropertyName() {
return "(fire resistant|resistant to fire)";
cheeezburga marked this conversation as resolved.
Show resolved Hide resolved
}
}
cheeezburga marked this conversation as resolved.
Show resolved Hide resolved
77 changes: 77 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffFireResistant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* 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.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.RequiredPlugins;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Nullable;

@Name("Make Fire Resistant")
@Description("Makes items fire resistant.")
@Examples({
"make player's tool fire resistant:",
"make {_items::*} not resistant to fire"
})
@RequiredPlugins("Spigot 1.20.5+")
@Since("INSERT VERSION")
public class EffFireResistant extends Effect {

static {
Skript.registerEffect(EffFireResistant.class,
cheeezburga marked this conversation as resolved.
Show resolved Hide resolved
"make %itemtypes% [:not] (fire resistant|resistant to fire)"
);
}

@SuppressWarnings("NotNullFieldNotInitialized")
private Expression<ItemType> items;
private boolean not;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
items = (Expression<ItemType>) exprs[0];
not = parseResult.hasTag("not");
return true;
}

@Override
protected void execute(Event event) {
for (ItemType item : this.items.getArray(event)) {
ItemMeta meta = item.getItemMeta();
meta.setFireResistant(!not);
item.setItemMeta(meta);
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "make " + items.toString(event, debug) + (not ? " not" : "") + " fire resistant";
}
}
cheeezburga marked this conversation as resolved.
Show resolved Hide resolved