Skip to content

Commit

Permalink
Merge branch 'dev/patch' into fix/docs-release-push
Browse files Browse the repository at this point in the history
  • Loading branch information
Moderocky authored Oct 4, 2023
2 parents 4fbc3a5 + b774caf commit 3f9c9d8
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 102 deletions.
4 changes: 2 additions & 2 deletions src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ public String toVariableNameString(FireworkEffect effect) {
.user("(panda )?genes?")
.name("Gene")
.description("Represents a Panda's main or hidden gene. " +
"See <a href='https://minecraft.gamepedia.com/Panda#Genetics'>genetics</a> for more info.")
"See <a href='https://minecraft.wiki/w/Panda#Genetics'>genetics</a> for more info.")
.since("2.4")
.requiredPlugins("Minecraft 1.14 or newer"));
}
Expand Down Expand Up @@ -1486,7 +1486,7 @@ public String toVariableNameString(EnchantmentOffer eo) {
.user("attribute ?types?")
.name("Attribute Type")
.description("Represents the type of an attribute. Note that this type does not contain any numerical values."
+ "See <a href='https://minecraft.gamepedia.com/Attribute#Attributes'>attribute types</a> for more info.")
+ "See <a href='https://minecraft.wiki/w/Attribute#Attributes'>attribute types</a> for more info.")
.since("2.5"));

Classes.registerClass(new EnumClassInfo<>(Environment.class, "environment", "environments")
Expand Down
152 changes: 77 additions & 75 deletions src/main/java/ch/njol/skript/command/CommandHelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;

import org.bukkit.command.CommandSender;
Expand All @@ -33,118 +34,119 @@
import ch.njol.skript.localization.Message;
import ch.njol.skript.util.SkriptColor;

/**
* @author Peter Güttinger
*/
public class CommandHelp {

private final static String DEFAULTENTRY = "description";

private final static ArgsMessage m_invalid_argument = new ArgsMessage("commands.invalid argument");
private final static Message m_usage = new Message("skript command.usage");


private final String actualCommand, actualNode, argsColor;
private String command;
private String langNode;
@Nullable
private Message description = null;
private final String argsColor;

@Nullable
private String langNode = null;

private final LinkedHashMap<String, Object> arguments = new LinkedHashMap<>();

private Message description;

private final Map<String, Object> arguments = new LinkedHashMap<>();

@Nullable
private Message wildcardArg = null;

public CommandHelp(final String command, final SkriptColor argsColor, final String langNode) {
this.command = command;
this.argsColor = "" + argsColor.getFormattedChat();
this.langNode = langNode;
description = new Message(langNode + "." + DEFAULTENTRY);
private ArgumentHolder wildcardArg = null;

public CommandHelp(String command, SkriptColor argsColor, String langNode) {
this(command, argsColor.getFormattedChat(), langNode, new Message(langNode + "." + DEFAULTENTRY));
}

public CommandHelp(final String command, final SkriptColor argsColor) {
this.command = command;
this.argsColor = "" + argsColor.getFormattedChat();

public CommandHelp(String command, SkriptColor argsColor) {
this(command, argsColor.getFormattedChat(), command, null);
}

public CommandHelp add(final String argument) {
if (langNode == null) {
if (argument.startsWith("<") && argument.endsWith(">")) {
final String carg = GRAY + "<" + argsColor + argument.substring(1, argument.length() - 1) + GRAY + ">";
arguments.put(carg, argument);
} else {
arguments.put(argument, null);
}
} else {
if (argument.startsWith("<") && argument.endsWith(">")) {
final String carg = GRAY + "<" + argsColor + argument.substring(1, argument.length() - 1) + GRAY + ">";
wildcardArg = new Message(langNode + "." + argument);
arguments.put(carg, wildcardArg);
} else {
arguments.put(argument, new Message(langNode + "." + argument));
}

private CommandHelp(String command, String argsColor, String node, @Nullable Message description) {
this.actualCommand = this.command = command;
this.actualNode = this.langNode = node;
this.argsColor = argsColor;
this.description = description;
}

public CommandHelp add(String argument) {
ArgumentHolder holder = new ArgumentHolder(argument);
if (argument.startsWith("<") && argument.endsWith(">")) {
argument = GRAY + "<" + argsColor + argument.substring(1, argument.length() - 1) + GRAY + ">";
wildcardArg = holder;
}
arguments.put(argument, holder);
return this;
}
public CommandHelp add(final CommandHelp help) {

public CommandHelp add(CommandHelp help) {
arguments.put(help.command, help);
help.onAdd(this);
return this;
}
protected void onAdd(final CommandHelp parent) {
langNode = parent.langNode + "." + command;

protected void onAdd(CommandHelp parent) {
langNode = parent.langNode + "." + actualNode;
description = new Message(langNode + "." + DEFAULTENTRY);
command = parent.command + " " + parent.argsColor + command;
for (final Entry<String, Object> e : arguments.entrySet()) {
if (e.getValue() instanceof CommandHelp) {
((CommandHelp) e.getValue()).onAdd(this);
} else {
if (e.getValue() != null) { // wildcard arg
wildcardArg = new Message(langNode + "." + e.getValue());
e.setValue(wildcardArg);
} else {
e.setValue(new Message(langNode + "." + e.getKey()));
}
command = parent.command + " " + parent.argsColor + actualCommand;
for (Entry<String, Object> entry : arguments.entrySet()) {
if (entry.getValue() instanceof CommandHelp) {
((CommandHelp) entry.getValue()).onAdd(this);
continue;
}
((ArgumentHolder) entry.getValue()).update();
}
}
public boolean test(final CommandSender sender, final String[] args) {

public boolean test(CommandSender sender, String[] args) {
return test(sender, args, 0);
}
private boolean test(final CommandSender sender, final String[] args, final int index) {

private boolean test(CommandSender sender, String[] args, int index) {
if (index >= args.length) {
showHelp(sender);
return false;
}
final Object help = arguments.get(args[index].toLowerCase(Locale.ENGLISH));
Object help = arguments.get(args[index].toLowerCase(Locale.ENGLISH));
if (help == null && wildcardArg == null) {
showHelp(sender, m_invalid_argument.toString(argsColor + args[index]));
return false;
}
if (help instanceof CommandHelp)
return ((CommandHelp) help).test(sender, args, index + 1);
return true;
return !(help instanceof CommandHelp) || ((CommandHelp) help).test(sender, args, index + 1);
}
public void showHelp(final CommandSender sender) {

public void showHelp(CommandSender sender) {
showHelp(sender, m_usage.toString());
}
private void showHelp(final CommandSender sender, final String pre) {

private void showHelp(CommandSender sender, String pre) {
Skript.message(sender, pre + " " + command + " " + argsColor + "...");
for (final Entry<String, Object> e : arguments.entrySet()) {
Skript.message(sender, " " + argsColor + e.getKey() + " " + GRAY + "-" + RESET + " " + e.getValue());
}
for (Entry<String, Object> entry : arguments.entrySet())
Skript.message(sender, " " + argsColor + entry.getKey() + " " + GRAY + "-" + RESET + " " + entry.getValue());
}

@Override
public String toString() {
return "" + description;
}


private class ArgumentHolder {

private final String argument;
private Message description;

private ArgumentHolder(String argument) {
this.argument = argument;
this.description = new Message(langNode + "." + argument);
}

private void update() {
description = new Message(langNode + "." + argument);
}

@Override
public String toString() {
return description.toString();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@Name("Is Slime Chunk")
@Description({"Tests whether a chunk is a so-called slime chunk.",
"Slimes can generally spawn in the swamp biome and in slime chunks.",
"For more info, see <a href='https://minecraft.gamepedia.com/Slime#.22Slime_chunks.22'>the Minecraft wiki</a>."})
"For more info, see <a href='https://minecraft.wiki/w/Slime#.22Slime_chunks.22'>the Minecraft wiki</a>."})
@Examples({"command /slimey:",
"\ttrigger:",
"\t\tif chunk at player is a slime chunk:",
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/effects/EffExplosion.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* @author Peter Güttinger
*/
@Name("Explosion")
@Description({"Creates an explosion of a given force. The Minecraft Wiki has an <a href='https://www.minecraftwiki.net/wiki/Explosion'>article on explosions</a> " +
@Description({"Creates an explosion of a given force. The Minecraft Wiki has an <a href='https://www.minecraft.wiki/w/Explosion'>article on explosions</a> " +
"which lists the explosion forces of TNT, creepers, etc.",
"Hint: use a force of 0 to create a fake explosion that does no damage whatsoever, or use the explosion effect introduced in Skript 2.0.",
"Starting with Bukkit 1.4.5 and Skript 2.0 you can use safe explosions which will damage entities but won't destroy any blocks."})
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/expressions/ExprAge.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void change(Event event, @Nullable Object[] delta, ChangeMode mode) {
setAge(obj, newValue);
break;
case RESET:
// baby animals takes 20 minutes to grow up - ref: https://minecraft.fandom.com/wiki/Breeding
// baby animals takes 20 minutes to grow up - ref: https://minecraft.wiki/w/Breeding
if (obj instanceof org.bukkit.entity.Ageable)
// it might change later on so removing entity age reset would be better unless
// bukkit adds a method returning the default age
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@Name("Explosion Yield")
@Description({"The yield of the explosion in an explosion prime event. This is how big the explosion is.",
" When changing the yield, values less than 0 will be ignored.",
" Read <a href='https://minecraft.gamepedia.com/Explosion'>this wiki page</a> for more information"})
" Read <a href='https://minecraft.wiki/w/Explosion'>this wiki page</a> for more information"})
@Examples({"on explosion prime:",
"\tset the yield of the explosion to 10"})
@Events("explosion prime")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

@Name("Explosive Yield")
@Description({"The yield of an explosive (creeper, primed tnt, fireball, etc.). This is how big of an explosion is caused by the entity.",
"Read <a href='https://minecraft.gamepedia.com/Explosion'>this wiki page</a> for more information"})
"Read <a href='https://minecraft.wiki/w/Explosion'>this wiki page</a> for more information"})
@Examples({"on spawn of a creeper:",
"\tset the explosive yield of the event-entity to 10"})
@RequiredPlugins("Minecraft 1.12 or newer for creepers")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import ch.njol.skript.expressions.base.SimplePropertyExpression;

@Name("Gliding State")
@Description("Sets of gets gliding state of player. It allows you to set gliding state of entity even if they do not have an <a href=\"https://minecraft.gamepedia.com/Elytra\">Elytra</a> equipped.")
@Description("Sets of gets gliding state of player. It allows you to set gliding state of entity even if they do not have an <a href=\"https://minecraft.wiki/w/Elytra\">Elytra</a> equipped.")
@Examples({"set gliding of player to off"})
@Since("2.2-dev21")
public class ExprGlidingState extends SimplePropertyExpression<LivingEntity, Boolean> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,44 @@
*/
package ch.njol.skript.expressions;

import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.server.ServerListPingEvent;
import org.eclipse.jdt.annotation.Nullable;

import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
import ch.njol.skript.Skript;
import ch.njol.skript.bukkitutil.PlayerUtils;
import ch.njol.skript.classes.Changer.ChangeMode;
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.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.server.ServerListPingEvent;
import org.eclipse.jdt.annotation.Nullable;

@Name("Online Player Count")
@Description({"The amount of online players. This can be changed in a",
@Description({
"The amount of online players. This can be changed in a " +
"<a href='events.html#server_list_ping'>server list ping</a> event only to show fake online player amount.",
"'real online player count' always returns the real count of online players and can't be changed.",
"",
"Fake online player count requires PaperSpigot 1.12.2+."})
@Examples({"on server list ping:",
" # This will make the max players count 5 if there are 4 players online.",
" set the fake max players count to (online players count + 1)"})
"<code>real online player count</code> always return the real count of online players and can't be changed."
})
@Examples({
"on server list ping:",
"\t# This will make the max players count 5 if there are 4 players online.",
"\tset the fake max players count to (online player count + 1)"
})
@RequiredPlugins("Paper (fake count)")
@Since("2.3")
public class ExprOnlinePlayersCount extends SimpleExpression<Long> {

static {
Skript.registerExpression(ExprOnlinePlayersCount.class, Long.class, ExpressionType.PROPERTY,
"[the] [(1¦(real|default)|2¦(fake|shown|displayed))] [online] player (count|amount|number)",
"[the] [(1¦(real|default)|2¦(fake|shown|displayed))] (count|amount|number|size) of online players");
"[the] [(1:(real|default)|2:(fake|shown|displayed))] [online] player (count|amount|number)",
"[the] [(1:(real|default)|2:(fake|shown|displayed))] (count|amount|number|size) of online players");
}

private static final boolean PAPER_EVENT_EXISTS = Skript.classExists("com.destroystokyo.paper.event.server.PaperServerListPingEvent");
Expand All @@ -64,7 +66,7 @@ public class ExprOnlinePlayersCount extends SimpleExpression<Long> {
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
boolean isPaperEvent = PAPER_EVENT_EXISTS && getParser().isCurrentEvent(PaperServerListPingEvent.class);
if (parseResult.mark == 2) {
if (getParser().isCurrentEvent(ServerListPingEvent.class)) {
if (!PAPER_EVENT_EXISTS && getParser().isCurrentEvent(ServerListPingEvent.class)) {
Skript.error("The 'fake' online players count expression requires Paper 1.12.2 or newer");
return false;
} else if (!isPaperEvent) {
Expand Down Expand Up @@ -146,4 +148,4 @@ public String toString(@Nullable Event e, boolean debug) {
return "the count of " + (isReal ? "real max players" : "max players");
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@Name("Scoreboard Tags")
@Description({"Scoreboard tags are simple list of texts stored directly in the data of an <a href='classes.html#entity'>entity</a>.",
"So this is a Minecraft related thing, not Bukkit, so the tags will not get removed when the server stops. " +
"You can visit <a href='https://minecraft.gamepedia.com/Scoreboard#Tags'>visit Minecraft Wiki</a> for more info.",
"You can visit <a href='https://minecraft.wiki/w/Scoreboard#Tags'>visit Minecraft Wiki</a> for more info.",
"This is changeable and valid for any type of entity. " +
"Also you can use use the <a href='conditions.html#CondHasScoreboardTag'>Has Scoreboard Tag</a> condition to check whether an entity has the given tags.",
"",
Expand Down

0 comments on commit 3f9c9d8

Please sign in to comment.