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

Sign update #5797

Open
wants to merge 24 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
24 commits
Select commit Hold shift + click to select a range
2f87ec8
Add side, multiple lines, chat formats and more to signs
TheLimeGlass Jul 7, 2023
22e30f8
Add sign side classinfo
TheLimeGlass Jul 7, 2023
9e22b00
Attempt to fix error
TheLimeGlass Jul 7, 2023
6301ef2
Remove debug message
TheLimeGlass Jul 7, 2023
0345a3f
Attempt to fix error
TheLimeGlass Jul 7, 2023
60d4fd6
Fix error
TheLimeGlass Jul 7, 2023
6ca69d7
Merge branch 'master' into feature/line-signs
TheLimeGlass Aug 30, 2023
7cd5193
Merge branch 'master' into feature/line-signs
Moderocky Sep 8, 2023
2252c7b
Update BukkitClasses.java
TheLimeGlass Feb 14, 2024
67dea3b
Merge branch 'dev/feature' into feature/line-signs
TheLimeGlass Feb 14, 2024
8385d03
Update src/main/java/ch/njol/skript/expressions/ExprSignText.java
TheLimeGlass Feb 14, 2024
9141b49
Make a functional interface
TheLimeGlass Feb 14, 2024
2776bd1
Re-add broken compile
TheLimeGlass Feb 14, 2024
922fb2a
Remove debug
TheLimeGlass Feb 14, 2024
3098055
Merge branch 'dev/feature' into feature/line-signs
sovdeeth Feb 14, 2024
da44ef6
Remove deprecated method
TheLimeGlass Feb 15, 2024
19e570c
Merge branch 'feature/line-signs' of https://github.com/SkriptLang/Sk…
TheLimeGlass Feb 15, 2024
ead4234
Merge branch 'dev/feature' into feature/line-signs
Moderocky Apr 7, 2024
e27a78f
Merge branch 'dev/feature' into feature/line-signs
Moderocky May 3, 2024
fccdbec
Merge branch 'dev/feature' into feature/line-signs
TheLimeGlass May 10, 2024
3c1a20c
Merge branch 'dev/feature' into feature/line-signs
sovdeeth Jun 28, 2024
69c9e6e
Apply changes
TheLimeGlass Aug 31, 2024
62fbeb7
Merge branch 'feature/line-signs' of https://github.com/SkriptLang/Sk…
TheLimeGlass Aug 31, 2024
c54ff14
Resolve conflicts
TheLimeGlass Aug 31, 2024
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
36 changes: 36 additions & 0 deletions src/main/java/ch/njol/skript/bukkitutil/AdventureSetSignLine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* 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.bukkitutil;

import net.kyori.adventure.text.Component;

/**
* A utility interface to access the Sign::line while also providing the same arguments to SignChangeEvent::line
* Used in ExprSignText. Separated due to static versioning.
*/
@FunctionalInterface
public interface AdventureSetSignLine<T, S> {

void line(int line, Component value);

static void line(AdventureSetSignLine<Integer, String> setLineMethod, int line, Component value) {
setLineMethod.line(line, value);
}

}
27 changes: 27 additions & 0 deletions src/main/java/ch/njol/skript/classes/Changer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
*/
package ch.njol.skript.classes;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.SkriptConfig;
import ch.njol.skript.classes.data.DefaultChangers;
import ch.njol.skript.lang.Expression;

Expand Down Expand Up @@ -87,6 +91,29 @@ public static boolean acceptsChange(final Expression<?> expression, final Change
}
return false;
}

/**
* Handles removing string. The 'all' boolean is for if the ChangeMode is REMOVE_ALL
*
* @param input The String to modify.
* @param toRemove The value to remove from the input string.
* @param all If the ChangeMode is REMOVE_ALL or not
* @return Input formatted with the replacement.
*/
public static String handleStringRemove(String input, String toRemove, boolean all) {
TheLimeGlass marked this conversation as resolved.
Show resolved Hide resolved
if (SkriptConfig.caseSensitive.value()) {
if (all) {
return input.replace(toRemove, "");
} else {
// .replaceFirst requires the regex to be quoted, .replace does it internally
return input.replaceFirst(Pattern.quote(toRemove), "");
}
} else {
final Matcher m = Pattern.compile(Pattern.quote(toRemove),
Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE).matcher(input);
return all ? m.replaceAll("") : m.replaceFirst("");
}
}

}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.bukkit.block.BlockState;
import org.bukkit.block.DoubleChest;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.sign.Side;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.enchantments.EnchantmentOffer;
Expand Down Expand Up @@ -1526,6 +1527,14 @@ public String toVariableNameString(EnchantmentOffer eo) {
.name("Transform Reason")
.description("Represents a transform reason of an <a href='events.html#entity transform'>entity transform event</a>.")
.since("2.8.0"));

if (Skript.isRunningMinecraft(1, 20))
Classes.registerClass(new EnumClassInfo<>(Side.class, "signside", "sign sides")
.user("sign ?sides?")
.name("Sign Sides")
.description("Represents a side of a sign.")
.requiredPlugins("Spigot 1.20+"));

}

}
11 changes: 10 additions & 1 deletion src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.sign.Side;
import org.bukkit.block.data.BlockData;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.AbstractVillager;
Expand Down Expand Up @@ -460,21 +461,29 @@ public Player get(final BlockCanBuildEvent e) {
}
}, 0);
}

// SignChangeEvent
EventValues.registerEventValue(SignChangeEvent.class, Player.class, new Getter<Player, SignChangeEvent>() {
@Override
@Nullable
public Player get(final SignChangeEvent e) {
return e.getPlayer();
}
}, 0);
}, EventValues.TIME_NOW);
EventValues.registerEventValue(SignChangeEvent.class, String[].class, new Getter<String[], SignChangeEvent>() {
@Override
@Nullable
public String[] get(SignChangeEvent event) {
return event.getLines();
}
}, EventValues.TIME_NOW);
if (Skript.isRunningMinecraft(1, 20))
EventValues.registerEventValue(SignChangeEvent.class, Side.class, new Getter<Side, SignChangeEvent>() {
@Override
public Side get(SignChangeEvent event) {
return event.getSide();
}
}, EventValues.TIME_NOW);

// === EntityEvents ===
EventValues.registerEventValue(EntityEvent.class, Entity.class, new Getter<Entity, EntityEvent>() {
Expand Down
21 changes: 4 additions & 17 deletions src/main/java/ch/njol/skript/expressions/ExprLore.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.eclipse.jdt.annotation.Nullable;
import org.jetbrains.annotations.ApiStatus.ScheduledForRemoval;

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptConfig;
Expand All @@ -45,6 +46,7 @@
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Callback;
import ch.njol.util.Kleenean;
import ch.njol.util.Math2;
import ch.njol.util.StringUtils;
Expand Down Expand Up @@ -182,7 +184,7 @@ public void change(final Event e, final @Nullable Object[] delta, final ChangeMo
case REMOVE:
case REMOVE_ALL:
assert stringDelta != null;
lore = Arrays.asList(handleRemove(
lore = Arrays.asList(ChangerUtils.handleStringRemove(
StringUtils.join(lore, "\n"), stringDelta[0], mode == ChangeMode.REMOVE_ALL).split("\n"));
break;
case RESET:
Expand Down Expand Up @@ -211,7 +213,7 @@ public void change(final Event e, final @Nullable Object[] delta, final ChangeMo
case REMOVE:
case REMOVE_ALL:
assert stringDelta != null;
lore.set(lineNum, handleRemove(lore.get(lineNum), stringDelta[0], mode == ChangeMode.REMOVE_ALL));
lore.set(lineNum, ChangerUtils.handleStringRemove(lore.get(lineNum), stringDelta[0], mode == ChangeMode.REMOVE_ALL));
break;
case RESET:
assert false;
Expand All @@ -236,21 +238,6 @@ public void change(final Event e, final @Nullable Object[] delta, final ChangeMo
}
}

private String handleRemove(String input, String toRemove, boolean all) {
if (SkriptConfig.caseSensitive.value()) {
if (all) {
return input.replace(toRemove, "");
} else {
// .replaceFirst requires the regex to be quoted, .replace does it internally
return input.replaceFirst(Pattern.quote(toRemove), "");
}
} else {
final Matcher m = Pattern.compile(Pattern.quote(toRemove),
Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE).matcher(input);
return all ? m.replaceAll("") : m.replaceFirst("");
}
}

@Override
public boolean isSingle() {
return lineNumber != null;
Expand Down
Loading
Loading