diff --git a/docs/css/styles.css b/docs/css/styles.css index e35ce476b24..017020892e9 100644 --- a/docs/css/styles.css +++ b/docs/css/styles.css @@ -143,9 +143,11 @@ a:visited { .type-Event { border-left: 5px solid rgb(28, 181, 152); } + .type-Event .item-type { color: rgb(28, 181, 152); } + .type-Event .item-examples p { background-color: rgb(28, 181, 152); } @@ -153,9 +155,11 @@ a:visited { .type-Effect { border-left: 5px solid rgb(139, 255, 0); } + .type-Effect .item-type { color: rgb(139, 255, 0); } + .type-Effect .item-examples p { background-color: rgb(139, 255, 0); } @@ -163,9 +167,11 @@ a:visited { .type-Expression { border-left: 5px solid rgb(255, 152, 0); } + .type-Expression .item-type { color: rgb(255, 152, 0); } + .type-Expression .item-examples p { background-color: rgb(255, 152, 0); } @@ -173,9 +179,11 @@ a:visited { .type-Condition { border-left: 5px solid rgb(181, 28, 28); } + .type-Condition .item-type { color: rgb(181, 28, 28); } + .type-Condition .item-examples p { background-color: rgb(181, 28, 28); color: white; @@ -184,20 +192,37 @@ a:visited { .type-Section { border-left: 5px solid rgb(181, 28, 121); } + .type-Section .item-type { color: rgb(181, 28, 121); } + .type-Section .item-examples p { background-color: rgb(181, 28, 121); color: white; } +.type-EffectSection { + border-left: 5px solid rgb(199, 0, 255); +} + +.type-EffectSection .item-type { + color: rgb(199, 0, 255); +} + +.type-EffectSection .item-examples p { + background-color: rgb(199, 0, 255); + color: white; +} + .type-Type { border-left: 5px solid rgb(0, 100, 255); } + .type-Type .item-type { color: rgb(0, 100, 255); } + .type-Type .item-examples p { background-color: rgb(0, 100, 255); color: white; @@ -206,9 +231,11 @@ a:visited { .type-Function { border-left: 5px solid rgb(128, 0, 255); } + .type-Function .item-type { color: rgb(128, 0, 255); } + .type-Function .item-examples p { background-color: rgb(128, 0, 255); color: white; @@ -269,11 +296,24 @@ a:visited { div.active-syntax { border-left: 5px solid #ff4e4e; } + div.active-syntax .item-examples p { background-color: #ff4e4e; color: white; } +.item-examples p { + cursor: pointer; +} + +.example-details-closed:before { + content: '▶ '; +} + +.example-details-opened:before { + content: '▼ '; +} + /* Active tab for sub menus */ .menu-subtabs .active-tab { color: #ffc107 !important; @@ -364,7 +404,8 @@ div.active-syntax .item-examples p { margin-top: 110px; height: calc(100vh - 110px); /* Fixed the TOP CSS 110px due to body having overflow hidden and top = 110px so the last 110px is hidden, this will fix it */ - /* padding: calc(0.22em + 30px); */ /* When applied it will break the padding when an anchor is clicked */ + /* padding: calc(0.22em + 30px); */ + /* When applied it will break the padding when an anchor is clicked */ padding-right: 30px; overflow-x: hidden; overflow-y: scroll; @@ -572,6 +613,7 @@ td ul { padding: 30px; font-size: 0.9em; color: var(--code-font-color); + display: none; } .box-title { @@ -639,7 +681,8 @@ td ul { display: none; } - span .search-bar-version { /* More specific to override the other */ + span .search-bar-version { + /* More specific to override the other */ left: calc(20% + 150px) !important; } @@ -732,7 +775,8 @@ td ul { top: calc(4.1em + 24px) !important; } - span .search-bar-version { /* More specific to override the other */ + span .search-bar-version { + /* More specific to override the other */ left: 150px !important; } @@ -750,13 +794,16 @@ td ul { div.item-content { max-width: 100vw; } + div.grid-container { grid-template-columns: initial; } + .box.code { height: 300px; font-size: 14px; } + p.item-type { display: none; } @@ -772,7 +819,12 @@ td ul { color: var(--font-color); } -p, h1, h2, h3, h4, h5 { +p, +h1, +h2, +h3, +h4, +h5 { color: var(--font-color); } @@ -929,7 +981,7 @@ pre { color: var(--search-color); box-shadow: 0 3px 5px 0 rgba(0, 0, 0, .05); right: 0.8%; - top: 102px; + top: 101px; text-align: right; } @@ -1009,58 +1061,76 @@ pre { #global-navigation .menu-subtabs a:hover { box-shadow: unset; /* border-left: 3px solid #ff9800; */ - background: rgba(0,0,0,.1); + background: rgba(0, 0, 0, .1); } /* Syntax Highlighting */ -.sk-cond, .sk-loop { +.sk-cond, +.sk-loop { color: #a52e91; font-weight: bold; } -.sk-eff { + +.sk-eff { color: rgb(255, 174, 0) } + .sk-expr { color: rgb(199, 152, 66) } + .sk-event { color: #c23838; } + .sk-command { color: #c27715; } + .sk-arg-type { color: #dbab28; } + .sk-loop-value { color: #ff6600; } + .sk-false { color: #b10000; font-weight: bold; } + .sk-true { color: #20b628; font-weight: bold; } + .sk-operators { font-weight: bold; } + .sk-var { color: #e74040; } -.sk-string [class*="sk-"], .sk-string { /* More specific = higher priority to override other css in strings and comments */ + +.sk-string [class*="sk-"], +.sk-string { + /* More specific = higher priority to override other css in strings and comments */ color: #34a52a !important; font-weight: unset; } -.sk-comment, .sk-comment [class*="sk-"] { + +.sk-comment, +.sk-comment [class*="sk-"] { color: #696969 !important; font-weight: unset; } + .sk-function { color: #e873ff; font-weight: bold; } + .sk-timespan { color: #ff5967; font-style: italic; diff --git a/docs/js/main.js b/docs/js/main.js index 051fa3805b5..fd0681ed3b9 100644 --- a/docs/js/main.js +++ b/docs/js/main.js @@ -279,7 +279,7 @@ function checkVersionFilter() { function searchNow(value = "") { if (value != "") // Update searchBar value searchBar.value = value; - + let allElements = document.querySelectorAll(".item-wrapper"); let searchValue = searchBar.value; let count = 0; // Check if any matches found @@ -298,7 +298,7 @@ function searchNow(value = "") { } searchValue = searchValue.replaceAll(versionPattern, "") // Don't include filters in the search } - + // Type let filterType; if (searchValue.match(typePattern)) { @@ -323,12 +323,12 @@ function searchNow(value = "") { let regex = new RegExp(searchValue, "gi") let name = document.querySelectorAll(`#${e.id} .item-title h1`)[0].textContent // Syntax Name let filtersFound = false; - + // Version check let versionFound; if (version != "") { versionFound = document.querySelectorAll(`#${e.id} .item-details:nth-child(2) td:nth-child(2)`)[0].textContent.includes(version); - + if (versionAndUp || versionAndDown) { let versions = document.querySelectorAll(`#${e.id} .item-details:nth-child(2) td:nth-child(2)`)[0].textContent.split(","); for (const v in versions) { // split on ',' without space in case some version didn't have space and versionCompare will handle it @@ -415,11 +415,11 @@ if (searchBar) { setTimeout(() => { // Important to actually get the value after typing or deleting + better performance searchNow(); }, 100); - }); + }); } // Search Bar -// <> Dark Mode +// <> Dark Mode // Auto load DarkMode from cookies if (getCookie("darkMode") == "false") { @@ -550,7 +550,7 @@ function getCookie(cname) { // Example: (.+) = ✓ const patterns = [ // [REGEX, CLASS] [/((?") - + for (let j = 0; j < lines.length; j++) { Loop2: for (let i = 0; i < patterns.length; i++) { @@ -580,7 +580,7 @@ function highlightElement(element) { let regex = patterns[i][0]; let oldLine = lines[j]; // console.log(regex) - + while ((match = regex.exec(oldLine)) != null) { lines[j] = lines[j].replaceAll(regex, `$1`) if (regex.lastIndex == 0) // Break after it reaches the end of exec count to avoid inf loop @@ -591,7 +591,7 @@ function highlightElement(element) { element.innerHTML = lines.join("
") } -document.addEventListener("DOMContentLoaded", function(event) { +document.addEventListener("DOMContentLoaded", function(event) { setTimeout(() => { document.querySelectorAll('.item-examples .skript-code-block').forEach(el => { highlightElement(el); @@ -604,4 +604,26 @@ document.addEventListener("DOMContentLoaded", function(event) { }); }, 100); }); -// Syntax Highlighting \ No newline at end of file +// Syntax Highlighting + + +// <> Collapsible Examples +var examples = document.querySelectorAll(".item-examples p"); +if (examples) { + examples.forEach(e => { + let pElement = e; + let divElement = e.parentElement.children[1]; + pElement.addEventListener("click", ev => { + if (pElement.classList.contains("example-details-opened")) { + pElement.classList.remove("example-details-opened"); + pElement.classList.add("example-details-closed"); + divElement.style.display = "none"; + } else { + pElement.classList.remove("example-details-closed"); + pElement.classList.add("example-details-opened"); + divElement.style.display = "block"; + } + }) + }) +} +// Collapsible Examples \ No newline at end of file diff --git a/docs/templates/desc_full.html b/docs/templates/desc_full.html index 6e6e47fb9b7..cfd49e28142 100644 --- a/docs/templates/desc_full.html +++ b/docs/templates/desc_full.html @@ -30,6 +30,12 @@

${element.name}

Requirements: ${element.required-plugins} + + ${end} ${if by-addon} + + By Addon: + ${element.by-addon} + ${end} @@ -38,7 +44,7 @@

${element.name}

-

Examples:

+

Examples:

${element.examples} diff --git a/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java b/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java index c38ff20d433..8cf2087c3fb 100644 --- a/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java +++ b/src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java @@ -311,9 +311,7 @@ public World[] executeSimple(Object[][] params) { }).description("Gets a world from its name.") .examples("set {_nether} to world(\"%{_world}%_nether\")") .since("2.2"); - - // the location expression doesn't work, so why not make a function for the same purpose - // FIXME document on ExprLocation as well + Functions.registerFunction(new JavaFunction("location", new Parameter[] { new Parameter<>("x", DefaultClasses.NUMBER, true, null), new Parameter<>("y", DefaultClasses.NUMBER, true, null), diff --git a/src/main/java/ch/njol/skript/doc/Documentation.java b/src/main/java/ch/njol/skript/doc/Documentation.java index fc49c9c9bad..393364840c7 100644 --- a/src/main/java/ch/njol/skript/doc/Documentation.java +++ b/src/main/java/ch/njol/skript/doc/Documentation.java @@ -256,11 +256,11 @@ public String run(final Matcher m) { first = false; final NonNullPair p = Utils.getEnglishPlural(c); final ClassInfo ci = Classes.getClassInfoNoError(p.getFirst()); - if (ci != null && ci.getDocName() != null && ci.getDocName() != ClassInfo.NO_DOC) { + if (ci != null && ci.getDocName() != null && ci.getDocName() != ClassInfo.NO_DOC) { // equals method throws null error when doc name is null b.append("").append(ci.getName().toString(p.getSecond())).append(""); } else { b.append(c); - if (ci != null && ci.getDocName() != null && !ci.getDocName().equals(ClassInfo.NO_DOC)) + if (ci != null && ci.getDocName() != null && ci.getDocName() != ClassInfo.NO_DOC) Skript.warning("Used class " + p.getFirst() + " has no docName/name defined"); } } diff --git a/src/main/java/ch/njol/skript/doc/HTMLGenerator.java b/src/main/java/ch/njol/skript/doc/HTMLGenerator.java index 3777f4d3c6e..82a0922fa5d 100644 --- a/src/main/java/ch/njol/skript/doc/HTMLGenerator.java +++ b/src/main/java/ch/njol/skript/doc/HTMLGenerator.java @@ -26,12 +26,12 @@ import java.util.regex.Pattern; import ch.njol.skript.lang.*; +import com.google.common.io.Files; import org.apache.commons.lang.StringUtils; import org.eclipse.jdt.annotation.Nullable; import com.google.common.base.Joiner; import com.google.common.collect.Lists; -import com.google.common.io.Files; import ch.njol.skript.Skript; import ch.njol.skript.SkriptAPIException; import ch.njol.skript.classes.ClassInfo; @@ -53,6 +53,7 @@ public class HTMLGenerator { private String skeleton; private String skriptVersion = Skript.getVersion().toString().replaceAll("-(dev|alpha|beta)\\d*", ""); // Filter branches + private final Pattern NEW_TAG_PATTERN = Pattern.compile(skriptVersion + "(?!\\.)"); public HTMLGenerator(File templateDir, File outputDir) { this.template = templateDir; @@ -67,12 +68,14 @@ private static Iterator sortedIterator(Iterator it, Comparator) item).c + "' from docs due to missing Name Annotation"); continue; + } list.add(item); } - Collections.sort(list, comparator); + list.sort(comparator); return list.iterator(); } @@ -273,33 +276,38 @@ else if (!filesInside.getName().matches("(?i)(.*)\\.(html?|js|css|json)")) { generated.append(desc); } } if (genType.equals("effects") || isNewPage) { - Collection> filteredEffects = Skript.getEffects(); -// filteredEffects.removeIf(el -> el.c.getAnnotation(Name.class) == null); - List> effects = new ArrayList<>(filteredEffects); - Collections.sort(effects, annotatedComparator); - for (SyntaxElementInfo info : effects) { + Iterator> it = sortedIterator(Skript.getEffects().iterator(), annotatedComparator); + while (it.hasNext()) { + SyntaxElementInfo info = it.next(); assert info != null; if (info.c.getAnnotation(NoDoc.class) != null) continue; generated.append(generateAnnotated(descTemp, info, generated.toString(), "Effect")); } + + Iterator> effectSection = sortedIterator(Skript.getSections().iterator(), annotatedComparator); + while (effectSection.hasNext()) { + SyntaxElementInfo info = effectSection.next(); + assert info != null; + if (EffectSection.class.isAssignableFrom(info.c)) { + if (info.c.getAnnotation(NoDoc.class) != null) + continue; + generated.append(generateAnnotated(descTemp, info, generated.toString(), "EffectSection")); + } + } } if (genType.equals("conditions") || isNewPage) { - Collection> filteredConditions = Skript.getConditions(); -// filteredConditions.removeIf(el -> el.c.getAnnotation(Name.class) == null); - List> conditions = new ArrayList<>(filteredConditions); - Collections.sort(conditions, annotatedComparator); - for (SyntaxElementInfo info : conditions) { + Iterator> it = sortedIterator(Skript.getConditions().iterator(), annotatedComparator); + while (it.hasNext()) { + SyntaxElementInfo info = it.next(); assert info != null; if (info.c.getAnnotation(NoDoc.class) != null) continue; generated.append(generateAnnotated(descTemp, info, generated.toString(), "Condition")); } } if (genType.equals("sections") || isNewPage) { - Collection> filteredSections = Skript.getSections(); -// filteredSections.removeIf(el -> el.c.getAnnotation(Name.class) == null); - List> sections = new ArrayList<>(filteredSections); - Collections.sort(sections, annotatedComparator); - for (SyntaxElementInfo info : sections) { + Iterator> it = sortedIterator(Skript.getSections().iterator(), annotatedComparator); + while (it.hasNext()) { + SyntaxElementInfo info = it.next(); assert info != null; if (info.c.getAnnotation(NoDoc.class) != null) continue; @@ -307,7 +315,7 @@ else if (!filesInside.getName().matches("(?i)(.*)\\.(html?|js|css|json)")) { } } if (genType.equals("events") || isNewPage) { List> events = new ArrayList<>(Skript.getEvents()); - Collections.sort(events, eventComparator); + events.sort(eventComparator); for (SkriptEventInfo info : events) { assert info != null; if (info.c.getAnnotation(NoDoc.class) != null) @@ -316,7 +324,7 @@ else if (!filesInside.getName().matches("(?i)(.*)\\.(html?|js|css|json)")) { } } if (genType.equals("classes") || isNewPage) { List> classes = new ArrayList<>(Classes.getClassInfos()); - Collections.sort(classes, classInfoComparator); + classes.sort(classInfoComparator); for (ClassInfo info : classes) { if (ClassInfo.NO_DOC.equals(info.getDocName()) || info.getDocName() == null) continue; @@ -325,7 +333,7 @@ else if (!filesInside.getName().matches("(?i)(.*)\\.(html?|js|css|json)")) { } } if (genType.equals("functions") || isNewPage) { List> functions = new ArrayList<>(Functions.getJavaFunctions()); - Collections.sort(functions, functionComparator); + functions.sort(functionComparator); for (JavaFunction info : functions) { assert info != null; generated.append(generateFunction(descTemp, info)); @@ -402,26 +410,26 @@ private static String handleIf(String desc, String start, boolean value) { */ private String generateAnnotated(String descTemp, SyntaxElementInfo info, @Nullable String page, String type) { Class c = info.c; - String desc = ""; + String desc; Name name = c.getAnnotation(Name.class); - desc = descTemp.replace("${element.name}", getNullOrEmptyDefault(name.value(), "Unknown Name")); + desc = descTemp.replace("${element.name}", getNullOrEmptyDefault((name != null ? name.value() : null), "Unknown Name")); Since since = c.getAnnotation(Since.class); - desc = desc.replace("${element.since}", getNullOrEmptyDefault(since.value(), "Unknown")); + desc = desc.replace("${element.since}", getNullOrEmptyDefault((since != null ? since.value() : null), "Unknown")); Description description = c.getAnnotation(Description.class); - desc = desc.replace("${element.desc}", Joiner.on("\n").join(getNullOrEmptyDefault(description.value(), "Unknown description.")).replace("\n\n", "

")); - desc = desc.replace("${element.desc-safe}", Joiner.on("\n").join(getNullOrEmptyDefault(description.value(), "Unknown description.")) + desc = desc.replace("${element.desc}", Joiner.on("\n").join(getNullOrEmptyDefault((description != null ? description.value() : null), "Unknown description.")).replace("\n\n", "

")); + desc = desc.replace("${element.desc-safe}", Joiner.on("\n").join(getNullOrEmptyDefault((description != null ? description.value() : null), "Unknown description.")) .replace("\\", "\\\\").replace("\"", "\\\"").replace("\t", " ")); Examples examples = c.getAnnotation(Examples.class); - desc = desc.replace("${element.examples}", Joiner.on("
").join(getNullOrEmptyDefault(examples.value(), "Missing examples."))); - desc = desc.replace("${element.examples-safe}", Joiner.on("\\n").join(getNullOrEmptyDefault(examples.value(), "Missing examples.")) + desc = desc.replace("${element.examples}", Joiner.on("
").join(getNullOrEmptyDefault((examples != null ? examples.value() : null), "Missing examples."))); + desc = desc.replace("${element.examples-safe}", Joiner.on("\\n").join(getNullOrEmptyDefault((examples != null ? examples.value() : null), "Missing examples.")) .replace("\\", "\\\\").replace("\"", "\\\"").replace("\t", " ")); DocumentationId DocID = c.getAnnotation(DocumentationId.class); - String ID = DocID != null ? DocID.value() : info.c.getSimpleName(); + String ID = DocID != null ? (DocID != null ? DocID.value() : null) : info.c.getSimpleName(); // Fix duplicated IDs if (page != null) { if (page.contains("href=\"#" + ID + "\"")) { @@ -434,7 +442,7 @@ private String generateAnnotated(String descTemp, SyntaxElementInfo info, @Nu assert desc != null; desc = handleIf(desc, "${if events}", events != null); if (events != null) { - String[] eventNames = events.value(); + String[] eventNames = (events != null ? events.value() : null); String[] eventLinks = new String[eventNames.length]; for (int i = 0; i < eventNames.length; i++) { String eventName = eventNames[i]; @@ -442,15 +450,20 @@ private String generateAnnotated(String descTemp, SyntaxElementInfo info, @Nu } desc = desc.replace("${element.events}", Joiner.on(", ").join(eventLinks)); } - desc = desc.replace("${element.events-safe}", events == null ? "" : Joiner.on(", ").join(events.value())); + desc = desc.replace("${element.events-safe}", events == null ? "" : Joiner.on(", ").join((events != null ? events.value() : null))); RequiredPlugins plugins = c.getAnnotation(RequiredPlugins.class); assert desc != null; desc = handleIf(desc, "${if required-plugins}", plugins != null); - desc = desc.replace("${element.required-plugins}", plugins == null ? "" : Joiner.on(", ").join(plugins.value())); + desc = desc.replace("${element.required-plugins}", plugins == null ? "" : Joiner.on(", ").join((plugins != null ? plugins.value() : null))); + +// TODO LATER +// String addon = info.originClassPath; +// desc = handleIf(desc, "${if by-addon}", true && !addon.isEmpty()); +// desc = desc.replace("${element.by-addon}", addon); + desc = handleIf(desc, "${if by-addon}", false); - desc = handleIf(desc, "${if new-element}", Pattern.compile(skriptVersion + "(?!\\.)").matcher(since.value()).find()); // (?!\\.) to avoid matching 2.6 in 2.6.1 etc. -// System.out.println(since.value() + " | " + skriptVersion); + desc = handleIf(desc, "${if new-element}", NEW_TAG_PATTERN.matcher((since != null ? since.value() : "")).find()); // (?!\\.) to avoid matching 2.6 in 2.6.1 etc. desc = desc.replace("${element.type}", type); List toGen = Lists.newArrayList(); @@ -491,7 +504,7 @@ private String generateAnnotated(String descTemp, SyntaxElementInfo info, @Nu private String generateEvent(String descTemp, SkriptEventInfo info, @Nullable String page) { Class c = info.c; - String desc = ""; + String desc; String docName = getNullOrEmptyDefault(info.getName(), "Unknown Name"); desc = descTemp.replace("${element.name}", docName); @@ -504,7 +517,12 @@ private String generateEvent(String descTemp, SkriptEventInfo info, @Nullable desc = desc .replace("${element.desc-safe}", Joiner.on("\\n").join(description) .replace("\\", "\\\\").replace("\"", "\\\"").replace("\t", " ")); - + +// String addon = info.originClassPath; +// desc = handleIf(desc, "${if by-addon}", true && !addon.isEmpty()); +// desc = desc.replace("${element.by-addon}", addon); + desc = handleIf(desc, "${if by-addon}", false); + String[] examples = getNullOrEmptyDefault(info.getExamples(), "Missing examples."); desc = desc.replace("${element.examples}", Joiner.on("\n
").join(examples)); desc = desc @@ -524,7 +542,7 @@ private String generateEvent(String descTemp, SkriptEventInfo info, @Nullable assert desc != null; desc = handleIf(desc, "${if events}", events != null); if (events != null) { - String[] eventNames = events.value(); + String[] eventNames = (events != null ? events.value() : null); String[] eventLinks = new String[eventNames.length]; for (int i = 0; i < eventNames.length; i++) { String eventName = eventNames[i]; @@ -532,13 +550,13 @@ private String generateEvent(String descTemp, SkriptEventInfo info, @Nullable } desc = desc.replace("${element.events}", Joiner.on(", ").join(eventLinks)); } - desc = desc.replace("${element.events-safe}", events == null ? "" : Joiner.on(", ").join(events.value())); + desc = desc.replace("${element.events-safe}", events == null ? "" : Joiner.on(", ").join((events != null ? events.value() : null))); String[] requiredPlugins = info.getRequiredPlugins(); desc = handleIf(desc, "${if required-plugins}", requiredPlugins != null); desc = desc.replace("${element.required-plugins}", Joiner.on(", ").join(requiredPlugins == null ? new String[0] : requiredPlugins)); - desc = handleIf(desc, "${if new-element}", Pattern.compile(skriptVersion + "(?!\\.)").matcher(since).find()); + desc = handleIf(desc, "${if new-element}", NEW_TAG_PATTERN.matcher(since).find()); desc = desc.replace("${element.type}", "Event"); List toGen = Lists.newArrayList(); @@ -573,7 +591,7 @@ private String generateEvent(String descTemp, SkriptEventInfo info, @Nullable private String generateClass(String descTemp, ClassInfo info, @Nullable String page) { Class c = info.getC(); - String desc = ""; + String desc; String docName = getNullOrEmptyDefault(info.getDocName(), "Unknown Name"); desc = descTemp.replace("${element.name}", docName); @@ -586,7 +604,12 @@ private String generateClass(String descTemp, ClassInfo info, @Nullable Strin desc = desc .replace("${element.desc-safe}", Joiner.on("\\n").join(description) .replace("\\", "\\\\").replace("\"", "\\\"").replace("\t", " ")); - + +// String addon = c.getPackageName(); +// desc = handleIf(desc, "${if by-addon}", true && !addon.isEmpty()); +// desc = desc.replace("${element.by-addon}", addon); + desc = handleIf(desc, "${if by-addon}", false); + String[] examples = getNullOrEmptyDefault(info.getExamples(), "Missing examples."); desc = desc.replace("${element.examples}", Joiner.on("\n
").join(examples)); desc = desc.replace("${element.examples-safe}", Joiner.on("\\n").join(examples) @@ -605,7 +628,7 @@ private String generateClass(String descTemp, ClassInfo info, @Nullable Strin Events events = c.getAnnotation(Events.class); desc = handleIf(desc, "${if events}", events != null); if (events != null) { - String[] eventNames = events.value(); + String[] eventNames = (events != null ? events.value() : null); String[] eventLinks = new String[eventNames.length]; for (int i = 0; i < eventNames.length; i++) { String eventName = eventNames[i]; @@ -613,14 +636,14 @@ private String generateClass(String descTemp, ClassInfo info, @Nullable Strin } desc = desc.replace("${element.events}", Joiner.on(", ").join(eventLinks)); } - desc = desc.replace("${element.events-safe}", events == null ? "" : Joiner.on(", ").join(events.value())); + desc = desc.replace("${element.events-safe}", events == null ? "" : Joiner.on(", ").join((events != null ? events.value() : null))); String[] requiredPlugins = info.getRequiredPlugins(); desc = handleIf(desc, "${if required-plugins}", requiredPlugins != null); desc = desc.replace("${element.required-plugins}", Joiner.on(", ").join(requiredPlugins == null ? new String[0] : requiredPlugins)); - desc = handleIf(desc, "${if new-element}", Pattern.compile(skriptVersion + "(?!\\.)").matcher(since).find()); + desc = handleIf(desc, "${if new-element}", NEW_TAG_PATTERN.matcher(since).find()); desc = desc.replace("${element.type}", "Type"); List toGen = Lists.newArrayList(); @@ -670,7 +693,12 @@ private String generateFunction(String descTemp, JavaFunction info) { desc = desc .replace("${element.desc-safe}", Joiner.on("\\n").join(description) .replace("\\", "\\\\").replace("\"", "\\\"").replace("\t", " ")); - + +// String addon = info.getSignature().getOriginClassPath(); +// desc = handleIf(desc, "${if by-addon}", true && !addon.isEmpty()); +// desc = desc.replace("${element.by-addon}", addon); + desc = handleIf(desc, "${if by-addon}", false); + String[] examples = getNullOrEmptyDefault(info.getExamples(), "Missing examples."); desc = desc.replace("${element.examples}", Joiner.on("\n
").join(examples)); desc = desc @@ -683,7 +711,7 @@ private String generateFunction(String descTemp, JavaFunction info) { desc = handleIf(desc, "${if events}", false); // Functions do not require events nor plugins (at time writing this) desc = handleIf(desc, "${if required-plugins}", false); - desc = handleIf(desc, "${if new-element}", Pattern.compile(skriptVersion + "(?!\\.)").matcher(since).find()); + desc = handleIf(desc, "${if new-element}", NEW_TAG_PATTERN.matcher(since).find()); desc = desc.replace("${element.type}", "Function"); List toGen = Lists.newArrayList(); diff --git a/src/main/java/ch/njol/skript/expressions/ExprBed.java b/src/main/java/ch/njol/skript/expressions/ExprBed.java index 361c9c4b4a0..fb31d0849c6 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprBed.java +++ b/src/main/java/ch/njol/skript/expressions/ExprBed.java @@ -35,7 +35,7 @@ */ @Name("Bed") @Description("The bed location of a player, i.e. the spawn point of a player if he ever slept in a bed and the bed still exists and is unobstructed.") -@Examples({"bed of player exists:", +@Examples({"if bed of player exists:", " teleport player the the player's bed", "else:", " teleport the player to the world's spawn point"}) diff --git a/src/main/java/ch/njol/skript/expressions/ExprHotbarSlot.java b/src/main/java/ch/njol/skript/expressions/ExprHotbarSlot.java index 678c033d475..0c4e497ff46 100644 --- a/src/main/java/ch/njol/skript/expressions/ExprHotbarSlot.java +++ b/src/main/java/ch/njol/skript/expressions/ExprHotbarSlot.java @@ -33,9 +33,10 @@ import ch.njol.skript.util.slot.Slot; @Name("Hotbar Slot") -@Description({"The slot number of the currently selected hotbar slot."}) +@Description({"The currently selected hotbar slot. To retrieve its number use Slot Index expression."}) @Examples({"message \"%player's current hotbar slot%\"", - "set player's selected hotbar slot to slot 4 of player"}) + "set player's selected hotbar slot to slot 4 of player", + "send \"index of player's current hotbar slot = 1\" # second slot from the left"}) @Since("2.2-dev36") public class ExprHotbarSlot extends SimplePropertyExpression { diff --git a/src/main/java/ch/njol/skript/lang/function/Functions.java b/src/main/java/ch/njol/skript/lang/function/Functions.java index f325327acc9..a050e2feb09 100644 --- a/src/main/java/ch/njol/skript/lang/function/Functions.java +++ b/src/main/java/ch/njol/skript/lang/function/Functions.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -229,10 +228,10 @@ public static Signature loadSignature(String script, SectionNode node) { return signError("Cannot recognise the type '" + returnType + "'"); } } - + @SuppressWarnings({"unchecked", "null"}) Signature sign = new Signature<>(script, name, - params.toArray(new Parameter[0]), (ClassInfo) returnClass, singleReturn); + params.toArray(new Parameter[0]), (ClassInfo) returnClass, singleReturn, ""); // Register this signature Namespace.Key namespaceKey = new Namespace.Key(Namespace.Origin.SCRIPT, script); diff --git a/src/main/java/ch/njol/skript/lang/function/JavaFunction.java b/src/main/java/ch/njol/skript/lang/function/JavaFunction.java index 0a6ba616b0e..d196a56b9d9 100644 --- a/src/main/java/ch/njol/skript/lang/function/JavaFunction.java +++ b/src/main/java/ch/njol/skript/lang/function/JavaFunction.java @@ -30,9 +30,9 @@ public abstract class JavaFunction extends Function { public JavaFunction(Signature sign) { super(sign); } - + public JavaFunction(String name, Parameter[] parameters, ClassInfo returnType, boolean single) { - this(new Signature<>("none", name, parameters, returnType, single)); + this(new Signature<>("none", name, parameters, returnType, single, Thread.currentThread().getStackTrace()[3].getClassName())); } @Override diff --git a/src/main/java/ch/njol/skript/lang/function/Signature.java b/src/main/java/ch/njol/skript/lang/function/Signature.java index 6d4a5251a7a..d59de2104c4 100644 --- a/src/main/java/ch/njol/skript/lang/function/Signature.java +++ b/src/main/java/ch/njol/skript/lang/function/Signature.java @@ -63,16 +63,26 @@ public class Signature { * References (function calls) to function with this signature. */ final Collection> calls; - - public Signature(String script, String name, Parameter[] parameters, @Nullable final ClassInfo returnType, boolean single) { + + /** + * References (function calls) to function with this signature. + */ + final String originClassPath; + + public Signature(String script, String name, Parameter[] parameters, @Nullable final ClassInfo returnType, boolean single, String originClassPath) { this.script = script; this.name = name; this.parameters = parameters; this.returnType = returnType; this.single = single; - + this.originClassPath = originClassPath; + calls = new ArrayList<>(); } + + public Signature(String script, String name, Parameter[] parameters, @Nullable final ClassInfo returnType, boolean single) { + this(script, name ,parameters, returnType, single, ""); + } public String getName() { return name; @@ -95,7 +105,11 @@ public ClassInfo getReturnType() { public boolean isSingle() { return single; } - + + public String getOriginClassPath() { + return originClassPath; + } + /** * Gets maximum number of parameters that the function described by this * signature is able to take. diff --git a/src/main/java/ch/njol/skript/sections/EffSecSpawn.java b/src/main/java/ch/njol/skript/sections/EffSecSpawn.java index e6f31edf4e6..63bb6f3e454 100644 --- a/src/main/java/ch/njol/skript/sections/EffSecSpawn.java +++ b/src/main/java/ch/njol/skript/sections/EffSecSpawn.java @@ -45,8 +45,6 @@ import java.util.List; -// TODO this won't show up in the docs, sections don't have a tab. We should create a tab for them, -// and maybe add EffectSections to the effects page as well @Name("Spawn") @Description({"Spawn a creature. This can be used as an effect and as a section.", "If it is used as a section, the section is run before the entity is added to the world.",