From 0fe7372973e5e88c19b864ed4b7ac75519a5a60a Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 23 Sep 2022 22:10:25 -0400 Subject: [PATCH 01/25] Update to world events Removes world load/unload/init/save from simpleevents Adds a save world effect --- .../ch/njol/skript/effects/EffSaveWorld.java | 72 +++++++++++++++++++ .../ch/njol/skript/events/EvtWorldInit.java | 63 ++++++++++++++++ .../ch/njol/skript/events/EvtWorldLoad.java | 62 ++++++++++++++++ .../ch/njol/skript/events/EvtWorldSave.java | 63 ++++++++++++++++ .../ch/njol/skript/events/EvtWorldUnload.java | 62 ++++++++++++++++ .../ch/njol/skript/events/SimpleEvents.java | 24 ------- 6 files changed, 322 insertions(+), 24 deletions(-) create mode 100644 src/main/java/ch/njol/skript/effects/EffSaveWorld.java create mode 100644 src/main/java/ch/njol/skript/events/EvtWorldInit.java create mode 100644 src/main/java/ch/njol/skript/events/EvtWorldLoad.java create mode 100644 src/main/java/ch/njol/skript/events/EvtWorldSave.java create mode 100644 src/main/java/ch/njol/skript/events/EvtWorldUnload.java diff --git a/src/main/java/ch/njol/skript/effects/EffSaveWorld.java b/src/main/java/ch/njol/skript/effects/EffSaveWorld.java new file mode 100644 index 00000000000..a79c8e766a5 --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffSaveWorld.java @@ -0,0 +1,72 @@ +/** + * 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 . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +package ch.njol.skript.effects; + +import ch.njol.skript.Skript; +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.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.Literal; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + +import java.util.Arrays; + +@Name("Save World") +@Description("Saves a world manually") +@Examples({ + "save all worlds", + "save the world \"world_nether\"" +}) +@Since("INSERT VERSION") +public class EffSaveWorld extends Effect { + + static { + Skript.registerEffect(EffSaveWorld.class, "save all worlds", "save [the] world[s] %worlds%"); + } + + @Nullable + private Expression worlds; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + if (matchedPattern == 1) worlds = (Expression) exprs[0]; + return true; + } + + @Override + public String toString(@Nullable Event e, boolean debug) { + return "saving the world" + (worlds == null ? "" : " " + worlds.toString()); + } + + @Override + protected void execute(Event event) { + for (World world : (worlds != null ? Arrays.stream(worlds.getArray(event)).toList() : Bukkit.getWorlds())) { + world.save(); + } + return; + } +} diff --git a/src/main/java/ch/njol/skript/events/EvtWorldInit.java b/src/main/java/ch/njol/skript/events/EvtWorldInit.java new file mode 100644 index 00000000000..a1bfc4d5bd6 --- /dev/null +++ b/src/main/java/ch/njol/skript/events/EvtWorldInit.java @@ -0,0 +1,63 @@ +/** + * 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 . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +package ch.njol.skript.events; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Literal; +import ch.njol.skript.lang.SkriptEvent; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import org.bukkit.World; +import org.bukkit.event.Event; +import org.bukkit.event.world.WorldInitEvent; +import org.eclipse.jdt.annotation.Nullable; + +import java.util.Arrays; + +public class EvtWorldInit extends SkriptEvent { + + static { + Skript.registerEvent("World Init", EvtWorldInit.class, WorldInitEvent.class, "world init[ialization] [of %worlds%]") + .description("Called when a world is initialised. As all default worlds are initialised before any scripts are loaded, this event is only called for newly created worlds.", + "World management plugins might change the behaviour of this event though.") + .examples("on world init of \"world_the_end\":") + .since("1.0, INSERT VERSION (defining worlds)"); + } + + @Nullable + private World[] worlds; + + @Override + public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { + if (worlds != null) worlds = ((Literal) args[0]).getArray(); + return true; + } + + @Override + public boolean check(Event event) { + if (worlds == null) return true; + return (Arrays.asList(worlds).contains((((WorldInitEvent) event).getWorld()))); + } + + + @Override + public String toString(final @Nullable Event event, final boolean debug) { + return "initialization of world" + (worlds == null ? "" : " " + worlds); + } + +} diff --git a/src/main/java/ch/njol/skript/events/EvtWorldLoad.java b/src/main/java/ch/njol/skript/events/EvtWorldLoad.java new file mode 100644 index 00000000000..ec7b40af0a8 --- /dev/null +++ b/src/main/java/ch/njol/skript/events/EvtWorldLoad.java @@ -0,0 +1,62 @@ +/** + * 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 . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +package ch.njol.skript.events; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Literal; +import ch.njol.skript.lang.SkriptEvent; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import org.bukkit.World; +import org.bukkit.event.Event; +import org.bukkit.event.world.WorldLoadEvent; +import org.eclipse.jdt.annotation.Nullable; + +import java.util.Arrays; + +public class EvtWorldLoad extends SkriptEvent { + + static { + Skript.registerEvent("World Load", EvtWorldLoad.class, WorldLoadEvent.class, "world load[ing] [of %worlds%]") + .description("Called when a world is loaded. As with the world init event, this event will not be called for the server's default world(s).") + .examples("on world load of \"world_nether\":") + .since("1.0, INSERT VERSION (defining worlds)"); + } + + @Nullable + private World[] worlds; + + @Override + public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { + if (worlds != null) worlds = ((Literal) args[0]).getArray(); + return true; + } + + @Override + public boolean check(Event event) { + if (worlds == null) return true; + return (Arrays.asList(worlds).contains((((WorldLoadEvent) event).getWorld()))); + } + + + @Override + public String toString(final @Nullable Event event, final boolean debug) { + return "loading of world" + (worlds == null ? "" : " " + worlds); + } + +} diff --git a/src/main/java/ch/njol/skript/events/EvtWorldSave.java b/src/main/java/ch/njol/skript/events/EvtWorldSave.java new file mode 100644 index 00000000000..0efb5f13a5c --- /dev/null +++ b/src/main/java/ch/njol/skript/events/EvtWorldSave.java @@ -0,0 +1,63 @@ +/** + * 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 . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +package ch.njol.skript.events; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Literal; +import ch.njol.skript.lang.LiteralList; +import ch.njol.skript.lang.SkriptEvent; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import org.bukkit.World; +import org.bukkit.event.Event; +import org.bukkit.event.world.WorldSaveEvent; +import org.eclipse.jdt.annotation.Nullable; + +import java.util.Arrays; + +public class EvtWorldSave extends SkriptEvent { + + static { + Skript.registerEvent("World Save", EvtWorldSave.class, WorldSaveEvent.class, "world sav(e|ing) [of %worlds%]") + .description("Called when a world is saved to disk. Usually all worlds are saved simultaneously, but world management plugins could change this.") + .examples("on world save of \"world\":", "\tbroadcast \"The world %event-world% has been saved\"") + .since("1.0, INSERT VERSION (defining worlds)"); + } + + @Nullable + private World[] worlds; + + @Override + public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { + if (worlds != null) worlds = ((Literal) args[0]).getArray(); + return true; + } + + @Override + public boolean check(Event event) { + if (worlds == null) return true; + return (Arrays.asList(worlds).contains((((WorldSaveEvent) event).getWorld()))); + } + + + @Override + public String toString(final @Nullable Event event, final boolean debug) { + return "saving of world" + (worlds == null ? "" : " " + worlds); + } + +} diff --git a/src/main/java/ch/njol/skript/events/EvtWorldUnload.java b/src/main/java/ch/njol/skript/events/EvtWorldUnload.java new file mode 100644 index 00000000000..5063c0ca03f --- /dev/null +++ b/src/main/java/ch/njol/skript/events/EvtWorldUnload.java @@ -0,0 +1,62 @@ +/** + * 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 . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +package ch.njol.skript.events; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Literal; +import ch.njol.skript.lang.SkriptEvent; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import org.bukkit.World; +import org.bukkit.event.Event; +import org.bukkit.event.world.WorldUnloadEvent; +import org.eclipse.jdt.annotation.Nullable; + +import java.util.Arrays; + +public class EvtWorldUnload extends SkriptEvent { + + static { + Skript.registerEvent("World Unload", EvtWorldUnload.class, WorldUnloadEvent.class, "world unload[ing] [of %worlds%]") + .description("Called when a world is unloaded. This event might never be called if you don't have a world management plugin.") + .examples("on world unload:") + .since("1.0, INSERT VERSION (defining worlds)"); + } + + @Nullable + private World[] worlds; + + @Override + public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { + if (worlds != null) worlds = ((Literal) args[0]).getArray(); + return true; + } + + @Override + public boolean check(Event event) { + if (worlds == null) return true; + return (Arrays.asList(worlds).contains((((WorldUnloadEvent) event).getWorld()))); + } + + + @Override + public String toString(final @Nullable Event event, final boolean debug) { + return "unloading of world" + (worlds == null ? "" : " " + worlds); + } + +} diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index d1b193ac5b0..a0b18d5cd1a 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -97,10 +97,6 @@ import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.event.world.PortalCreateEvent; import org.bukkit.event.world.SpawnChangeEvent; -import org.bukkit.event.world.WorldInitEvent; -import org.bukkit.event.world.WorldLoadEvent; -import org.bukkit.event.world.WorldSaveEvent; -import org.bukkit.event.world.WorldUnloadEvent; import org.spigotmc.event.entity.EntityDismountEvent; import org.spigotmc.event.entity.EntityMountEvent; @@ -413,26 +409,6 @@ public class SimpleEvents { "\tkill event-entity") .since("2.2-dev13b"); } - Skript.registerEvent("World Init", SimpleEvent.class, WorldInitEvent.class, "world init[ialization]") - .description("Called when a world is initialised. As all default worlds are initialised before any scripts are loaded, this event is only called for newly created worlds.", - "World management plugins might change the behaviour of this event though.") - .examples("on world init:") - .since("1.0"); - Skript.registerEvent("World Load", SimpleEvent.class, WorldLoadEvent.class, "world load[ing]") - .description("Called when a world is loaded. As with the world init event, this event will not be called for the server's default world(s).") - .examples("on world load:", - "\tsend \"World is loading...\" to console") - .since("1.0"); - Skript.registerEvent("World Save", SimpleEvent.class, WorldSaveEvent.class, "world sav(e|ing)") - .description("Called when a world is saved to disk. Usually all worlds are saved simultaneously, but world management plugins could change this.") - .examples("on world saving:", - "\tbroadcast \"World has been saved!\"") - .since("1.0"); - Skript.registerEvent("World Unload", SimpleEvent.class, WorldUnloadEvent.class, "world unload[ing]") - .description("Called when a world is unloaded. This event might never be called if you don't have a world management plugin.") - .examples("on world unload:", - "\tcancel event") - .since("1.0"); if (Skript.classExists("org.bukkit.event.entity.EntityToggleGlideEvent")) { Skript.registerEvent("Gliding State Change", SimpleEvent.class, EntityToggleGlideEvent.class, "(gliding state change|toggl(e|ing) gliding)") .description("Called when an entity toggles glider on or off, or when server toggles gliding state of an entity forcibly.") From 29404c3ca44e685d9fc8de4c8ecf428ec05a64a5 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Sat, 24 Sep 2022 01:22:56 -0400 Subject: [PATCH 02/25] Added unload world effect --- .../njol/skript/effects/EffWorldUnload.java | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/main/java/ch/njol/skript/effects/EffWorldUnload.java diff --git a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java new file mode 100644 index 00000000000..3f97e13d2ab --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java @@ -0,0 +1,85 @@ +/** + * 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 . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +package ch.njol.skript.effects; + +import ch.njol.skript.Skript; +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.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + +@Name("Unload World") +@Description({"Unload a world"}) +@Examples({ + "unload the world \"world_nether\" and save", + "unload the world \"world_the_end\" and don't save" +}) +@Since("INSERT VERSION") +public class EffWorldUnload extends Effect { + + static { + Skript.registerEffect(EffWorldUnload.class, "unload [the] world[s] %worlds% [and (save|!save:(do not|don't) save)]" + ); + } + + private boolean save; + @Nullable + private Expression world; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + world = (Expression) exprs[0]; + save = !parseResult.hasTag("!save"); + return true; + } + + @Override + protected void execute(Event event) { + World mainWorld = Bukkit.getWorlds().get(0); + if (world == mainWorld) { + if (Bukkit.getWorlds().size() > 1) { + mainWorld = Bukkit.getWorlds().get(1); + } else { + mainWorld = null; + } + } + for (World world : this.world.getArray(event)) { + if (mainWorld != null) { + World finalMainWorld = mainWorld; + world.getPlayers().forEach(player -> player.teleport(finalMainWorld.getSpawnLocation())); + } + + Bukkit.unloadWorld(world, save); + } + return; + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "unload the world " + world.toString(event, debug) + " " + (save ? "and saving" : "without saving"); + } +} From 692c90988201cad3ed83e7588796b09d477b9ab9 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Sat, 24 Sep 2022 07:49:37 -0400 Subject: [PATCH 03/25] Removed world from effects --- src/main/java/ch/njol/skript/effects/EffSaveWorld.java | 2 +- src/main/java/ch/njol/skript/effects/EffWorldUnload.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffSaveWorld.java b/src/main/java/ch/njol/skript/effects/EffSaveWorld.java index a79c8e766a5..a1e0b722584 100644 --- a/src/main/java/ch/njol/skript/effects/EffSaveWorld.java +++ b/src/main/java/ch/njol/skript/effects/EffSaveWorld.java @@ -45,7 +45,7 @@ public class EffSaveWorld extends Effect { static { - Skript.registerEffect(EffSaveWorld.class, "save all worlds", "save [the] world[s] %worlds%"); + Skript.registerEffect(EffSaveWorld.class, "save all worlds", "save [the] %worlds%"); } @Nullable diff --git a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java index 3f97e13d2ab..47b2e9408ea 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java @@ -42,7 +42,7 @@ public class EffWorldUnload extends Effect { static { - Skript.registerEffect(EffWorldUnload.class, "unload [the] world[s] %worlds% [and (save|!save:(do not|don't) save)]" + Skript.registerEffect(EffWorldUnload.class, "unload [the] %worlds% [and (save|1¦(do not|don't) save)]" ); } @@ -53,7 +53,7 @@ public class EffWorldUnload extends Effect { @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { world = (Expression) exprs[0]; - save = !parseResult.hasTag("!save"); + save = parseResult.mark != 1; return true; } From 481be81b18c1d641aa6fcefbec4c22e6e6b33696 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Thu, 29 Sep 2022 06:07:31 -0400 Subject: [PATCH 04/25] Apply suggestions from code review This will be the first batch, anything not updated I'll edit manually on my end Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> --- .../java/ch/njol/skript/effects/EffSaveWorld.java | 11 +++++------ .../java/ch/njol/skript/effects/EffWorldUnload.java | 5 ++--- .../java/ch/njol/skript/events/EvtWorldInit.java | 10 ++++++---- .../java/ch/njol/skript/events/EvtWorldLoad.java | 12 +++++++----- .../java/ch/njol/skript/events/EvtWorldSave.java | 10 ++++++---- .../java/ch/njol/skript/events/EvtWorldUnload.java | 9 +++++---- 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffSaveWorld.java b/src/main/java/ch/njol/skript/effects/EffSaveWorld.java index a1e0b722584..ee3b68e7c12 100644 --- a/src/main/java/ch/njol/skript/effects/EffSaveWorld.java +++ b/src/main/java/ch/njol/skript/effects/EffSaveWorld.java @@ -45,26 +45,25 @@ public class EffSaveWorld extends Effect { static { - Skript.registerEffect(EffSaveWorld.class, "save all worlds", "save [the] %worlds%"); + Skript.registerEffect(EffSaveWorld.class, "save %worlds%"); } - @Nullable private Expression worlds; @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - if (matchedPattern == 1) worlds = (Expression) exprs[0]; + worlds = (Expression) exprs[0]; return true; } @Override - public String toString(@Nullable Event e, boolean debug) { - return "saving the world" + (worlds == null ? "" : " " + worlds.toString()); + public String toString(@Nullable Event event, boolean debug) { + return "saving worlds " + worlds.toString(event, debug); } @Override protected void execute(Event event) { - for (World world : (worlds != null ? Arrays.stream(worlds.getArray(event)).toList() : Bukkit.getWorlds())) { + for (World world : worlds.getArray(event)) { world.save(); } return; diff --git a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java index 47b2e9408ea..31cbc1474fc 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java @@ -47,8 +47,7 @@ public class EffWorldUnload extends Effect { } private boolean save; - @Nullable - private Expression world; + private Expression worlds; @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { @@ -80,6 +79,6 @@ protected void execute(Event event) { @Override public String toString(@Nullable Event event, boolean debug) { - return "unload the world " + world.toString(event, debug) + " " + (save ? "and saving" : "without saving"); + return "unload world(s) " + world.toString(event, debug) + " " + (save ? "and saving" : "without saving"); } } diff --git a/src/main/java/ch/njol/skript/events/EvtWorldInit.java b/src/main/java/ch/njol/skript/events/EvtWorldInit.java index a1bfc4d5bd6..8d4e5fb0f7a 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorldInit.java +++ b/src/main/java/ch/njol/skript/events/EvtWorldInit.java @@ -32,7 +32,7 @@ public class EvtWorldInit extends SkriptEvent { static { - Skript.registerEvent("World Init", EvtWorldInit.class, WorldInitEvent.class, "world init[ialization] [of %worlds%]") + Skript.registerEvent("World Init", EvtWorldInit.class, WorldInitEvent.class, "world init[ialization] [of %-worlds%]") .description("Called when a world is initialised. As all default worlds are initialised before any scripts are loaded, this event is only called for newly created worlds.", "World management plugins might change the behaviour of this event though.") .examples("on world init of \"world_the_end\":") @@ -44,19 +44,21 @@ public class EvtWorldInit extends SkriptEvent { @Override public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { - if (worlds != null) worlds = ((Literal) args[0]).getArray(); + if (worlds != null) + worlds = ((Literal) args[0]).getArray(); return true; } @Override public boolean check(Event event) { - if (worlds == null) return true; + if (worlds == null) + return true; return (Arrays.asList(worlds).contains((((WorldInitEvent) event).getWorld()))); } @Override - public String toString(final @Nullable Event event, final boolean debug) { + public String toString(@Nullable Event event, boolean debug) { return "initialization of world" + (worlds == null ? "" : " " + worlds); } diff --git a/src/main/java/ch/njol/skript/events/EvtWorldLoad.java b/src/main/java/ch/njol/skript/events/EvtWorldLoad.java index ec7b40af0a8..9b800071d95 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorldLoad.java +++ b/src/main/java/ch/njol/skript/events/EvtWorldLoad.java @@ -32,7 +32,7 @@ public class EvtWorldLoad extends SkriptEvent { static { - Skript.registerEvent("World Load", EvtWorldLoad.class, WorldLoadEvent.class, "world load[ing] [of %worlds%]") + Skript.registerEvent("World Load", EvtWorldLoad.class, WorldLoadEvent.class, "world load[ing] [of %-worlds%]") .description("Called when a world is loaded. As with the world init event, this event will not be called for the server's default world(s).") .examples("on world load of \"world_nether\":") .since("1.0, INSERT VERSION (defining worlds)"); @@ -43,19 +43,21 @@ public class EvtWorldLoad extends SkriptEvent { @Override public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { - if (worlds != null) worlds = ((Literal) args[0]).getArray(); + if (worlds != null) + worlds = ((Literal) args[0]).getArray(); return true; } @Override public boolean check(Event event) { - if (worlds == null) return true; - return (Arrays.asList(worlds).contains((((WorldLoadEvent) event).getWorld()))); + if (worlds == null) + return true; + return Arrays.asList(worlds).contains(((WorldLoadEvent) event).getWorld()); } @Override - public String toString(final @Nullable Event event, final boolean debug) { + public String toString(@Nullable Event event, boolean debug) { return "loading of world" + (worlds == null ? "" : " " + worlds); } diff --git a/src/main/java/ch/njol/skript/events/EvtWorldSave.java b/src/main/java/ch/njol/skript/events/EvtWorldSave.java index 0efb5f13a5c..834fa917634 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorldSave.java +++ b/src/main/java/ch/njol/skript/events/EvtWorldSave.java @@ -33,7 +33,7 @@ public class EvtWorldSave extends SkriptEvent { static { - Skript.registerEvent("World Save", EvtWorldSave.class, WorldSaveEvent.class, "world sav(e|ing) [of %worlds%]") + Skript.registerEvent("World Save", EvtWorldSave.class, WorldSaveEvent.class, "world sav(e|ing) [of %-worlds%]") .description("Called when a world is saved to disk. Usually all worlds are saved simultaneously, but world management plugins could change this.") .examples("on world save of \"world\":", "\tbroadcast \"The world %event-world% has been saved\"") .since("1.0, INSERT VERSION (defining worlds)"); @@ -44,14 +44,16 @@ public class EvtWorldSave extends SkriptEvent { @Override public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { - if (worlds != null) worlds = ((Literal) args[0]).getArray(); + if (worlds != null) + worlds = ((Literal) args[0]).getArray(); return true; } @Override public boolean check(Event event) { - if (worlds == null) return true; - return (Arrays.asList(worlds).contains((((WorldSaveEvent) event).getWorld()))); + if (worlds == null) + return true; + return Arrays.asList(worlds).contains(((WorldSaveEvent) event).getWorld()); } diff --git a/src/main/java/ch/njol/skript/events/EvtWorldUnload.java b/src/main/java/ch/njol/skript/events/EvtWorldUnload.java index 5063c0ca03f..bb2a7410455 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorldUnload.java +++ b/src/main/java/ch/njol/skript/events/EvtWorldUnload.java @@ -32,8 +32,8 @@ public class EvtWorldUnload extends SkriptEvent { static { - Skript.registerEvent("World Unload", EvtWorldUnload.class, WorldUnloadEvent.class, "world unload[ing] [of %worlds%]") - .description("Called when a world is unloaded. This event might never be called if you don't have a world management plugin.") + Skript.registerEvent("World Unload", EvtWorldUnload.class, WorldUnloadEvent.class, "world unload[ing] [of %-worlds%]") + .description("Called when a world is unloaded. This event will never be called if you don't have a world management plugin.") .examples("on world unload:") .since("1.0, INSERT VERSION (defining worlds)"); } @@ -49,13 +49,14 @@ public boolean init(Literal[] args, int matchedPattern, ParseResult parseResu @Override public boolean check(Event event) { - if (worlds == null) return true; + if (worlds == null) + return true; return (Arrays.asList(worlds).contains((((WorldUnloadEvent) event).getWorld()))); } @Override - public String toString(final @Nullable Event event, final boolean debug) { + public String toString(@Nullable Event event, boolean debug) { return "unloading of world" + (worlds == null ? "" : " " + worlds); } From b75f1bb5c2b966c5d1d1c4ffe1390541b0ddf804 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Thu, 29 Sep 2022 07:12:35 -0400 Subject: [PATCH 05/25] Requested changes Finished off the requested changes that weren't merged with first batch along with switch some other things around --- .../{EffSaveWorld.java => EffWorldSave.java} | 14 ++++----- .../njol/skript/effects/EffWorldUnload.java | 29 ++++++++----------- .../ch/njol/skript/events/EvtWorldInit.java | 5 ++-- .../ch/njol/skript/events/EvtWorldLoad.java | 6 ++-- .../ch/njol/skript/events/EvtWorldSave.java | 7 +++-- .../ch/njol/skript/events/EvtWorldUnload.java | 9 ++++-- 6 files changed, 34 insertions(+), 36 deletions(-) rename src/main/java/ch/njol/skript/effects/{EffSaveWorld.java => EffWorldSave.java} (85%) diff --git a/src/main/java/ch/njol/skript/effects/EffSaveWorld.java b/src/main/java/ch/njol/skript/effects/EffWorldSave.java similarity index 85% rename from src/main/java/ch/njol/skript/effects/EffSaveWorld.java rename to src/main/java/ch/njol/skript/effects/EffWorldSave.java index ee3b68e7c12..8b39fe0487a 100644 --- a/src/main/java/ch/njol/skript/effects/EffSaveWorld.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldSave.java @@ -25,27 +25,23 @@ import ch.njol.skript.doc.Since; import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.util.Kleenean; -import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; -import java.util.Arrays; - @Name("Save World") @Description("Saves a world manually") @Examples({ - "save all worlds", - "save the world \"world_nether\"" + "save \"world_nether\"", + "save all worlds" }) @Since("INSERT VERSION") -public class EffSaveWorld extends Effect { +public class EffWorldSave extends Effect { static { - Skript.registerEffect(EffSaveWorld.class, "save %worlds%"); + Skript.registerEffect(EffWorldSave.class, "save %worlds%"); } private Expression worlds; @@ -58,7 +54,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override public String toString(@Nullable Event event, boolean debug) { - return "saving worlds " + worlds.toString(event, debug); + return "save world(s) " + worlds.toString(event, debug); } @Override diff --git a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java index 31cbc1474fc..3eaf1c520c8 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java @@ -32,17 +32,20 @@ import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; +import java.util.Arrays; + @Name("Unload World") @Description({"Unload a world"}) @Examples({ - "unload the world \"world_nether\" and save", - "unload the world \"world_the_end\" and don't save" + "unload \"world_nether\" and save", + "unload \"world_the_end\" and don't save", + "unload all worlds" }) @Since("INSERT VERSION") public class EffWorldUnload extends Effect { static { - Skript.registerEffect(EffWorldUnload.class, "unload [the] %worlds% [and (save|1¦(do not|don't) save)]" + Skript.registerEffect(EffWorldUnload.class, "unload %worlds% [and (save|1¦(do not|don't) save)]" ); } @@ -51,7 +54,7 @@ public class EffWorldUnload extends Effect { @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - world = (Expression) exprs[0]; + worlds = (Expression) exprs[0]; save = parseResult.mark != 1; return true; } @@ -59,19 +62,11 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override protected void execute(Event event) { World mainWorld = Bukkit.getWorlds().get(0); - if (world == mainWorld) { - if (Bukkit.getWorlds().size() > 1) { - mainWorld = Bukkit.getWorlds().get(1); - } else { - mainWorld = null; - } - } - for (World world : this.world.getArray(event)) { - if (mainWorld != null) { - World finalMainWorld = mainWorld; - world.getPlayers().forEach(player -> player.teleport(finalMainWorld.getSpawnLocation())); + Bukkit.broadcastMessage(mainWorld.toString()); + for (World world : this.worlds.getArray(event)) { + if (mainWorld != null && world != mainWorld) { + world.getPlayers().forEach(player -> player.teleport(mainWorld.getSpawnLocation())); } - Bukkit.unloadWorld(world, save); } return; @@ -79,6 +74,6 @@ protected void execute(Event event) { @Override public String toString(@Nullable Event event, boolean debug) { - return "unload world(s) " + world.toString(event, debug) + " " + (save ? "and saving" : "without saving"); + return "unload world(s) " + worlds.toString(event, debug) + " " + (save ? "with saving" : "without saving"); } } diff --git a/src/main/java/ch/njol/skript/events/EvtWorldInit.java b/src/main/java/ch/njol/skript/events/EvtWorldInit.java index 8d4e5fb0f7a..498f453c040 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorldInit.java +++ b/src/main/java/ch/njol/skript/events/EvtWorldInit.java @@ -33,7 +33,8 @@ public class EvtWorldInit extends SkriptEvent { static { Skript.registerEvent("World Init", EvtWorldInit.class, WorldInitEvent.class, "world init[ialization] [of %-worlds%]") - .description("Called when a world is initialised. As all default worlds are initialised before any scripts are loaded, this event is only called for newly created worlds.", + .description("Called when a world is initialised. As all default worlds are initialised before", + "any scripts are loaded, this event is only called for newly created worlds.", "World management plugins might change the behaviour of this event though.") .examples("on world init of \"world_the_end\":") .since("1.0, INSERT VERSION (defining worlds)"); @@ -53,7 +54,7 @@ public boolean init(Literal[] args, int matchedPattern, ParseResult parseResu public boolean check(Event event) { if (worlds == null) return true; - return (Arrays.asList(worlds).contains((((WorldInitEvent) event).getWorld()))); + return Arrays.stream(worlds).anyMatch(world -> ((WorldInitEvent) event).getWorld().equals(world)); } diff --git a/src/main/java/ch/njol/skript/events/EvtWorldLoad.java b/src/main/java/ch/njol/skript/events/EvtWorldLoad.java index 9b800071d95..5e65abf824f 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorldLoad.java +++ b/src/main/java/ch/njol/skript/events/EvtWorldLoad.java @@ -34,7 +34,9 @@ public class EvtWorldLoad extends SkriptEvent { static { Skript.registerEvent("World Load", EvtWorldLoad.class, WorldLoadEvent.class, "world load[ing] [of %-worlds%]") .description("Called when a world is loaded. As with the world init event, this event will not be called for the server's default world(s).") - .examples("on world load of \"world_nether\":") + .examples( + "on world load of \"world_nether\":", + "\tbroadcast \"The world %event-world% has been loaded!\"") .since("1.0, INSERT VERSION (defining worlds)"); } @@ -52,7 +54,7 @@ public boolean init(Literal[] args, int matchedPattern, ParseResult parseResu public boolean check(Event event) { if (worlds == null) return true; - return Arrays.asList(worlds).contains(((WorldLoadEvent) event).getWorld()); + return Arrays.stream(worlds).anyMatch(world -> ((WorldLoadEvent) event).getWorld().equals(world)); } diff --git a/src/main/java/ch/njol/skript/events/EvtWorldSave.java b/src/main/java/ch/njol/skript/events/EvtWorldSave.java index 834fa917634..86b686f2741 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorldSave.java +++ b/src/main/java/ch/njol/skript/events/EvtWorldSave.java @@ -20,7 +20,6 @@ import ch.njol.skript.Skript; import ch.njol.skript.lang.Literal; -import ch.njol.skript.lang.LiteralList; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser.ParseResult; import org.bukkit.World; @@ -35,7 +34,9 @@ public class EvtWorldSave extends SkriptEvent { static { Skript.registerEvent("World Save", EvtWorldSave.class, WorldSaveEvent.class, "world sav(e|ing) [of %-worlds%]") .description("Called when a world is saved to disk. Usually all worlds are saved simultaneously, but world management plugins could change this.") - .examples("on world save of \"world\":", "\tbroadcast \"The world %event-world% has been saved\"") + .examples( + "on world save of \"world\":", + "\tbroadcast \"The world %event-world% has been saved\"") .since("1.0, INSERT VERSION (defining worlds)"); } @@ -53,7 +54,7 @@ public boolean init(Literal[] args, int matchedPattern, ParseResult parseResu public boolean check(Event event) { if (worlds == null) return true; - return Arrays.asList(worlds).contains(((WorldSaveEvent) event).getWorld()); + return Arrays.stream(worlds).anyMatch(world -> ((WorldSaveEvent) event).getWorld().equals(world)); } diff --git a/src/main/java/ch/njol/skript/events/EvtWorldUnload.java b/src/main/java/ch/njol/skript/events/EvtWorldUnload.java index bb2a7410455..3c3e9e4ecd5 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorldUnload.java +++ b/src/main/java/ch/njol/skript/events/EvtWorldUnload.java @@ -34,7 +34,9 @@ public class EvtWorldUnload extends SkriptEvent { static { Skript.registerEvent("World Unload", EvtWorldUnload.class, WorldUnloadEvent.class, "world unload[ing] [of %-worlds%]") .description("Called when a world is unloaded. This event will never be called if you don't have a world management plugin.") - .examples("on world unload:") + .examples( + "on world unload:", + "\tbroadcast \"the %event-world% has been unloaded!\"") .since("1.0, INSERT VERSION (defining worlds)"); } @@ -43,7 +45,8 @@ public class EvtWorldUnload extends SkriptEvent { @Override public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { - if (worlds != null) worlds = ((Literal) args[0]).getArray(); + if (worlds != null) + worlds = ((Literal) args[0]).getArray(); return true; } @@ -51,7 +54,7 @@ public boolean init(Literal[] args, int matchedPattern, ParseResult parseResu public boolean check(Event event) { if (worlds == null) return true; - return (Arrays.asList(worlds).contains((((WorldUnloadEvent) event).getWorld()))); + return Arrays.stream(worlds).anyMatch(world -> ((WorldUnloadEvent) event).getWorld().equals(world)); } From 6c90aafe0793edfae6221aefd66ef7e7e2e5b96b Mon Sep 17 00:00:00 2001 From: Fusezion Date: Thu, 29 Sep 2022 07:18:39 -0400 Subject: [PATCH 06/25] Update EffWorldUnload.java Missed a requested change --- src/main/java/ch/njol/skript/effects/EffWorldUnload.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java index 3eaf1c520c8..151133a16f0 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java @@ -45,8 +45,7 @@ public class EffWorldUnload extends Effect { static { - Skript.registerEffect(EffWorldUnload.class, "unload %worlds% [and (save|1¦(do not|don't) save)]" - ); + Skript.registerEffect(EffWorldUnload.class, "unload %worlds% [and (save|1¦(do not|don't) save)]"); } private boolean save; From c27076867a91fb213472bd54d81b6872c8fb0929 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 30 Sep 2022 21:30:22 -0400 Subject: [PATCH 07/25] Requested changes --- src/main/java/ch/njol/skript/effects/EffWorldUnload.java | 1 - src/main/java/ch/njol/skript/events/EvtWorldInit.java | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java index 151133a16f0..cf208514c4d 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java @@ -61,7 +61,6 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override protected void execute(Event event) { World mainWorld = Bukkit.getWorlds().get(0); - Bukkit.broadcastMessage(mainWorld.toString()); for (World world : this.worlds.getArray(event)) { if (mainWorld != null && world != mainWorld) { world.getPlayers().forEach(player -> player.teleport(mainWorld.getSpawnLocation())); diff --git a/src/main/java/ch/njol/skript/events/EvtWorldInit.java b/src/main/java/ch/njol/skript/events/EvtWorldInit.java index 498f453c040..24c38feec20 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorldInit.java +++ b/src/main/java/ch/njol/skript/events/EvtWorldInit.java @@ -45,8 +45,7 @@ public class EvtWorldInit extends SkriptEvent { @Override public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { - if (worlds != null) - worlds = ((Literal) args[0]).getArray(); + worlds = ((Literal) args[0]).getArray(); return true; } From 0ae69912cc11a2ecf96f54fb275ba093578dcf42 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Wed, 16 Nov 2022 15:36:59 -0500 Subject: [PATCH 08/25] Hopefully final touches to this Some requested changes Syntax change for EffUnloadWorld Changed from World[] to Literal --- .../ch/njol/skript/effects/EffWorldUnload.java | 6 ++---- .../java/ch/njol/skript/events/EvtWorldInit.java | 13 ++++++------- .../java/ch/njol/skript/events/EvtWorldLoad.java | 15 +++++++-------- .../java/ch/njol/skript/events/EvtWorldSave.java | 15 +++++++-------- .../ch/njol/skript/events/EvtWorldUnload.java | 15 +++++++-------- 5 files changed, 29 insertions(+), 35 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java index cf208514c4d..ef41b011270 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java @@ -32,8 +32,6 @@ import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; -import java.util.Arrays; - @Name("Unload World") @Description({"Unload a world"}) @Examples({ @@ -45,7 +43,7 @@ public class EffWorldUnload extends Effect { static { - Skript.registerEffect(EffWorldUnload.class, "unload %worlds% [and (save|1¦(do not|don't) save)]"); + Skript.registerEffect(EffWorldUnload.class, "unload %worlds% [and (:save)]"); } private boolean save; @@ -54,7 +52,7 @@ public class EffWorldUnload extends Effect { @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { worlds = (Expression) exprs[0]; - save = parseResult.mark != 1; + save = parseResult.hasTag("save"); return true; } diff --git a/src/main/java/ch/njol/skript/events/EvtWorldInit.java b/src/main/java/ch/njol/skript/events/EvtWorldInit.java index 24c38feec20..4c901c602b8 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorldInit.java +++ b/src/main/java/ch/njol/skript/events/EvtWorldInit.java @@ -27,8 +27,6 @@ import org.bukkit.event.world.WorldInitEvent; import org.eclipse.jdt.annotation.Nullable; -import java.util.Arrays; - public class EvtWorldInit extends SkriptEvent { static { @@ -41,11 +39,11 @@ public class EvtWorldInit extends SkriptEvent { } @Nullable - private World[] worlds; + private Literal worlds; @Override public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { - worlds = ((Literal) args[0]).getArray(); + worlds = (Literal) args[0]; return true; } @@ -53,13 +51,14 @@ public boolean init(Literal[] args, int matchedPattern, ParseResult parseResu public boolean check(Event event) { if (worlds == null) return true; - return Arrays.stream(worlds).anyMatch(world -> ((WorldInitEvent) event).getWorld().equals(world)); + return worlds.check(event, world -> world.equals(((WorldInitEvent) event).getWorld())); } @Override - public String toString(@Nullable Event event, boolean debug) { - return "initialization of world" + (worlds == null ? "" : " " + worlds); + @Nullable + public String toString(Event event, boolean debug) { + return "initialization of world" + (worlds == null ? "" : " of " + worlds.toString(event,debug)); } } diff --git a/src/main/java/ch/njol/skript/events/EvtWorldLoad.java b/src/main/java/ch/njol/skript/events/EvtWorldLoad.java index 5e65abf824f..383cb27aa3f 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorldLoad.java +++ b/src/main/java/ch/njol/skript/events/EvtWorldLoad.java @@ -27,8 +27,6 @@ import org.bukkit.event.world.WorldLoadEvent; import org.eclipse.jdt.annotation.Nullable; -import java.util.Arrays; - public class EvtWorldLoad extends SkriptEvent { static { @@ -41,12 +39,11 @@ public class EvtWorldLoad extends SkriptEvent { } @Nullable - private World[] worlds; + private Literal worlds; @Override public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { - if (worlds != null) - worlds = ((Literal) args[0]).getArray(); + worlds = (Literal) args[0]; return true; } @@ -54,13 +51,15 @@ public boolean init(Literal[] args, int matchedPattern, ParseResult parseResu public boolean check(Event event) { if (worlds == null) return true; - return Arrays.stream(worlds).anyMatch(world -> ((WorldLoadEvent) event).getWorld().equals(world)); + + return worlds.check(event, world -> world.equals(((WorldLoadEvent) event).getWorld())); } @Override - public String toString(@Nullable Event event, boolean debug) { - return "loading of world" + (worlds == null ? "" : " " + worlds); + @Nullable + public String toString( Event event, boolean debug) { + return "loading of world" + (worlds == null ? "" : " of " + worlds.toString(event,debug)); } } diff --git a/src/main/java/ch/njol/skript/events/EvtWorldSave.java b/src/main/java/ch/njol/skript/events/EvtWorldSave.java index 86b686f2741..b433a845047 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorldSave.java +++ b/src/main/java/ch/njol/skript/events/EvtWorldSave.java @@ -27,8 +27,6 @@ import org.bukkit.event.world.WorldSaveEvent; import org.eclipse.jdt.annotation.Nullable; -import java.util.Arrays; - public class EvtWorldSave extends SkriptEvent { static { @@ -41,12 +39,11 @@ public class EvtWorldSave extends SkriptEvent { } @Nullable - private World[] worlds; + private Literal worlds; @Override public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { - if (worlds != null) - worlds = ((Literal) args[0]).getArray(); + worlds = (Literal) args[0]; return true; } @@ -54,13 +51,15 @@ public boolean init(Literal[] args, int matchedPattern, ParseResult parseResu public boolean check(Event event) { if (worlds == null) return true; - return Arrays.stream(worlds).anyMatch(world -> ((WorldSaveEvent) event).getWorld().equals(world)); + + return worlds.check(event, world -> world.equals(((WorldSaveEvent) event).getWorld())); } @Override - public String toString(final @Nullable Event event, final boolean debug) { - return "saving of world" + (worlds == null ? "" : " " + worlds); + @Nullable + public String toString(Event event, boolean debug) { + return "saving of world" + (worlds == null ? "" : " of " + worlds.toString(event,debug)); } } diff --git a/src/main/java/ch/njol/skript/events/EvtWorldUnload.java b/src/main/java/ch/njol/skript/events/EvtWorldUnload.java index 3c3e9e4ecd5..760542b5eb9 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorldUnload.java +++ b/src/main/java/ch/njol/skript/events/EvtWorldUnload.java @@ -27,8 +27,6 @@ import org.bukkit.event.world.WorldUnloadEvent; import org.eclipse.jdt.annotation.Nullable; -import java.util.Arrays; - public class EvtWorldUnload extends SkriptEvent { static { @@ -41,12 +39,11 @@ public class EvtWorldUnload extends SkriptEvent { } @Nullable - private World[] worlds; + private Literal worlds; @Override public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { - if (worlds != null) - worlds = ((Literal) args[0]).getArray(); + worlds = (Literal) args[0]; return true; } @@ -54,13 +51,15 @@ public boolean init(Literal[] args, int matchedPattern, ParseResult parseResu public boolean check(Event event) { if (worlds == null) return true; - return Arrays.stream(worlds).anyMatch(world -> ((WorldUnloadEvent) event).getWorld().equals(world)); + + return worlds.check(event, world -> world.equals(((WorldUnloadEvent) event).getWorld())); } @Override - public String toString(@Nullable Event event, boolean debug) { - return "unloading of world" + (worlds == null ? "" : " " + worlds); + @Nullable + public String toString(Event event, boolean debug) { + return "unloading of world" + (worlds == null ? "" : " of " + worlds.toString(event,debug)); } } From 0b045a1b0d3b379fb74486c1493f988e54de4858 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Wed, 16 Nov 2022 16:40:01 -0500 Subject: [PATCH 09/25] Requested change Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> --- src/main/java/ch/njol/skript/effects/EffWorldUnload.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java index ef41b011270..9061df8278c 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java @@ -60,9 +60,8 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye protected void execute(Event event) { World mainWorld = Bukkit.getWorlds().get(0); for (World world : this.worlds.getArray(event)) { - if (mainWorld != null && world != mainWorld) { + if (mainWorld != null && world != mainWorld) world.getPlayers().forEach(player -> player.teleport(mainWorld.getSpawnLocation())); - } Bukkit.unloadWorld(world, save); } return; From 431823fadf7f690145c4722c4bbdbb7a8d4529d9 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 27 Jan 2023 03:42:12 -0500 Subject: [PATCH 10/25] EvtWorld - Request and Changes Combined all world events into a single file, "EvtWorld" Did the requested changes for both effects Added a warning about possibly freezing a server with the save effect Co-Authored-By: Patrick Miller --- .../ch/njol/skript/effects/EffWorldSave.java | 16 ++-- .../njol/skript/effects/EffWorldUnload.java | 12 ++- .../java/ch/njol/skript/events/EvtWorld.java | 96 +++++++++++++++++++ .../ch/njol/skript/events/EvtWorldInit.java | 64 ------------- .../ch/njol/skript/events/EvtWorldLoad.java | 65 ------------- .../ch/njol/skript/events/EvtWorldSave.java | 65 ------------- .../ch/njol/skript/events/EvtWorldUnload.java | 65 ------------- 7 files changed, 111 insertions(+), 272 deletions(-) create mode 100644 src/main/java/ch/njol/skript/events/EvtWorld.java delete mode 100644 src/main/java/ch/njol/skript/events/EvtWorldInit.java delete mode 100644 src/main/java/ch/njol/skript/events/EvtWorldLoad.java delete mode 100644 src/main/java/ch/njol/skript/events/EvtWorldSave.java delete mode 100644 src/main/java/ch/njol/skript/events/EvtWorldUnload.java diff --git a/src/main/java/ch/njol/skript/effects/EffWorldSave.java b/src/main/java/ch/njol/skript/effects/EffWorldSave.java index 8b39fe0487a..bbe81a2d813 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldSave.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldSave.java @@ -32,7 +32,7 @@ import org.eclipse.jdt.annotation.Nullable; @Name("Save World") -@Description("Saves a world manually") +@Description({"Save all worlds or a given world manually.","note: saving many worlds at once may possible cause a server to freeze."}) @Examples({ "save \"world_nether\"", "save all worlds" @@ -52,16 +52,16 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye return true; } - @Override - public String toString(@Nullable Event event, boolean debug) { - return "save world(s) " + worlds.toString(event, debug); - } - @Override protected void execute(Event event) { - for (World world : worlds.getArray(event)) { + for (World world : worlds.getArray(event)) world.save(); - } return; } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "save world(s) " + worlds.toString(event, debug); + } + } diff --git a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java index 9061df8278c..100cdedb9a5 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java @@ -33,7 +33,7 @@ import org.eclipse.jdt.annotation.Nullable; @Name("Unload World") -@Description({"Unload a world"}) +@Description({"Unload a given world with optional saving"}) @Examples({ "unload \"world_nether\" and save", "unload \"world_the_end\" and don't save", @@ -43,7 +43,7 @@ public class EffWorldUnload extends Effect { static { - Skript.registerEffect(EffWorldUnload.class, "unload %worlds% [and (:save)]"); + Skript.registerEffect(EffWorldUnload.class, "unload %worlds% [:without saving]"); } private boolean save; @@ -52,7 +52,7 @@ public class EffWorldUnload extends Effect { @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { worlds = (Expression) exprs[0]; - save = parseResult.hasTag("save"); + save = !parseResult.hasTag("without saving"); return true; } @@ -60,9 +60,10 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye protected void execute(Event event) { World mainWorld = Bukkit.getWorlds().get(0); for (World world : this.worlds.getArray(event)) { - if (mainWorld != null && world != mainWorld) - world.getPlayers().forEach(player -> player.teleport(mainWorld.getSpawnLocation())); Bukkit.unloadWorld(world, save); +// if (mainWorld != null && world != mainWorld) { +// world.getPlayers().forEach(player -> player.teleport(mainWorld.getSpawnLocation())); +// } } return; } @@ -71,4 +72,5 @@ protected void execute(Event event) { public String toString(@Nullable Event event, boolean debug) { return "unload world(s) " + worlds.toString(event, debug) + " " + (save ? "with saving" : "without saving"); } + } diff --git a/src/main/java/ch/njol/skript/events/EvtWorld.java b/src/main/java/ch/njol/skript/events/EvtWorld.java new file mode 100644 index 00000000000..1fa1cf71832 --- /dev/null +++ b/src/main/java/ch/njol/skript/events/EvtWorld.java @@ -0,0 +1,96 @@ +/** + * 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 . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +package ch.njol.skript.events; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Literal; +import ch.njol.skript.lang.SkriptEvent; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.log.ErrorQuality; +import org.bukkit.World; +import org.bukkit.event.Event; +import org.bukkit.event.world.*; +import org.eclipse.jdt.annotation.Nullable; + +public class EvtWorld extends SkriptEvent { + + static { + // World Save Event + Skript.registerEvent("World Save", EvtWorld.class, WorldSaveEvent.class, "world sav(e|ing) [of %-worlds%]") + .description("Called when a world is saved to disk. Usually all worlds are saved simultaneously, but world management plugins could change this.") + .examples( + "on world save of \"world\":", + "\tbroadcast \"The world %event-world% has been saved\"") + .since("1.0, INSERT VERSION (defining worlds)"); + + // World Init Event + Skript.registerEvent("World Init", EvtWorld.class, WorldInitEvent.class, "world init[ialization] [of %-worlds%]") + .description("Called when a world is initialised. As all default worlds are initialised before", + "any scripts are loaded, this event is only called for newly created worlds.", + "World management plugins might change the behaviour of this event though.") + .examples("on world init of \"world_the_end\":") + .since("1.0, INSERT VERSION (defining worlds)"); + + // World Unload Event + Skript.registerEvent("World Unload", EvtWorld.class, WorldUnloadEvent.class, "world unload[ing] [of %-worlds%]") + .description("Called when a world is unloaded. This event will never be called if you don't have a world management plugin.") + .examples( + "on world unload:", + "\tbroadcast \"the %event-world% has been unloaded!\"") + .since("1.0, INSERT VERSION (defining worlds)"); + + // World Load Event + Skript.registerEvent("World Load", EvtWorld.class, WorldLoadEvent.class, "world load[ing] [of %-worlds%]") + .description("Called when a world is loaded. As with the world init event, this event will not be called for the server's default world(s).") + .examples( + "on world load of \"world_nether\":", + "\tbroadcast \"The world %event-world% has been loaded!\"") + .since("1.0, INSERT VERSION (defining worlds)"); + } + + @Nullable + private Literal worlds; + + @Override + public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { + worlds = (Literal) args[0]; + if (worlds != null) { + boolean isAnd = worlds.getAnd(); + if (isAnd) { + Skript.error("An \"and\" list cannot be used in this event as multiple worlds cannot load at the same time", ErrorQuality.SEMANTIC_ERROR); + return false; + } + } + return true; + } + + @Override + public boolean check(Event event) { + if (worlds == null) + return true; + World evtWorld = ((WorldEvent) event).getWorld(); + return worlds.check(event, world -> world.equals(evtWorld)); + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + return "world save/init/unload/load" + (worlds == null ? "" : " of " + worlds.toString(event,debug)); + } + +} diff --git a/src/main/java/ch/njol/skript/events/EvtWorldInit.java b/src/main/java/ch/njol/skript/events/EvtWorldInit.java deleted file mode 100644 index 4c901c602b8..00000000000 --- a/src/main/java/ch/njol/skript/events/EvtWorldInit.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * 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 . - * - * Copyright Peter Güttinger, SkriptLang team and contributors - */ -package ch.njol.skript.events; - -import ch.njol.skript.Skript; -import ch.njol.skript.lang.Literal; -import ch.njol.skript.lang.SkriptEvent; -import ch.njol.skript.lang.SkriptParser.ParseResult; -import org.bukkit.World; -import org.bukkit.event.Event; -import org.bukkit.event.world.WorldInitEvent; -import org.eclipse.jdt.annotation.Nullable; - -public class EvtWorldInit extends SkriptEvent { - - static { - Skript.registerEvent("World Init", EvtWorldInit.class, WorldInitEvent.class, "world init[ialization] [of %-worlds%]") - .description("Called when a world is initialised. As all default worlds are initialised before", - "any scripts are loaded, this event is only called for newly created worlds.", - "World management plugins might change the behaviour of this event though.") - .examples("on world init of \"world_the_end\":") - .since("1.0, INSERT VERSION (defining worlds)"); - } - - @Nullable - private Literal worlds; - - @Override - public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { - worlds = (Literal) args[0]; - return true; - } - - @Override - public boolean check(Event event) { - if (worlds == null) - return true; - return worlds.check(event, world -> world.equals(((WorldInitEvent) event).getWorld())); - } - - - @Override - @Nullable - public String toString(Event event, boolean debug) { - return "initialization of world" + (worlds == null ? "" : " of " + worlds.toString(event,debug)); - } - -} diff --git a/src/main/java/ch/njol/skript/events/EvtWorldLoad.java b/src/main/java/ch/njol/skript/events/EvtWorldLoad.java deleted file mode 100644 index 383cb27aa3f..00000000000 --- a/src/main/java/ch/njol/skript/events/EvtWorldLoad.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * 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 . - * - * Copyright Peter Güttinger, SkriptLang team and contributors - */ -package ch.njol.skript.events; - -import ch.njol.skript.Skript; -import ch.njol.skript.lang.Literal; -import ch.njol.skript.lang.SkriptEvent; -import ch.njol.skript.lang.SkriptParser.ParseResult; -import org.bukkit.World; -import org.bukkit.event.Event; -import org.bukkit.event.world.WorldLoadEvent; -import org.eclipse.jdt.annotation.Nullable; - -public class EvtWorldLoad extends SkriptEvent { - - static { - Skript.registerEvent("World Load", EvtWorldLoad.class, WorldLoadEvent.class, "world load[ing] [of %-worlds%]") - .description("Called when a world is loaded. As with the world init event, this event will not be called for the server's default world(s).") - .examples( - "on world load of \"world_nether\":", - "\tbroadcast \"The world %event-world% has been loaded!\"") - .since("1.0, INSERT VERSION (defining worlds)"); - } - - @Nullable - private Literal worlds; - - @Override - public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { - worlds = (Literal) args[0]; - return true; - } - - @Override - public boolean check(Event event) { - if (worlds == null) - return true; - - return worlds.check(event, world -> world.equals(((WorldLoadEvent) event).getWorld())); - } - - - @Override - @Nullable - public String toString( Event event, boolean debug) { - return "loading of world" + (worlds == null ? "" : " of " + worlds.toString(event,debug)); - } - -} diff --git a/src/main/java/ch/njol/skript/events/EvtWorldSave.java b/src/main/java/ch/njol/skript/events/EvtWorldSave.java deleted file mode 100644 index b433a845047..00000000000 --- a/src/main/java/ch/njol/skript/events/EvtWorldSave.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * 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 . - * - * Copyright Peter Güttinger, SkriptLang team and contributors - */ -package ch.njol.skript.events; - -import ch.njol.skript.Skript; -import ch.njol.skript.lang.Literal; -import ch.njol.skript.lang.SkriptEvent; -import ch.njol.skript.lang.SkriptParser.ParseResult; -import org.bukkit.World; -import org.bukkit.event.Event; -import org.bukkit.event.world.WorldSaveEvent; -import org.eclipse.jdt.annotation.Nullable; - -public class EvtWorldSave extends SkriptEvent { - - static { - Skript.registerEvent("World Save", EvtWorldSave.class, WorldSaveEvent.class, "world sav(e|ing) [of %-worlds%]") - .description("Called when a world is saved to disk. Usually all worlds are saved simultaneously, but world management plugins could change this.") - .examples( - "on world save of \"world\":", - "\tbroadcast \"The world %event-world% has been saved\"") - .since("1.0, INSERT VERSION (defining worlds)"); - } - - @Nullable - private Literal worlds; - - @Override - public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { - worlds = (Literal) args[0]; - return true; - } - - @Override - public boolean check(Event event) { - if (worlds == null) - return true; - - return worlds.check(event, world -> world.equals(((WorldSaveEvent) event).getWorld())); - } - - - @Override - @Nullable - public String toString(Event event, boolean debug) { - return "saving of world" + (worlds == null ? "" : " of " + worlds.toString(event,debug)); - } - -} diff --git a/src/main/java/ch/njol/skript/events/EvtWorldUnload.java b/src/main/java/ch/njol/skript/events/EvtWorldUnload.java deleted file mode 100644 index 760542b5eb9..00000000000 --- a/src/main/java/ch/njol/skript/events/EvtWorldUnload.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * 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 . - * - * Copyright Peter Güttinger, SkriptLang team and contributors - */ -package ch.njol.skript.events; - -import ch.njol.skript.Skript; -import ch.njol.skript.lang.Literal; -import ch.njol.skript.lang.SkriptEvent; -import ch.njol.skript.lang.SkriptParser.ParseResult; -import org.bukkit.World; -import org.bukkit.event.Event; -import org.bukkit.event.world.WorldUnloadEvent; -import org.eclipse.jdt.annotation.Nullable; - -public class EvtWorldUnload extends SkriptEvent { - - static { - Skript.registerEvent("World Unload", EvtWorldUnload.class, WorldUnloadEvent.class, "world unload[ing] [of %-worlds%]") - .description("Called when a world is unloaded. This event will never be called if you don't have a world management plugin.") - .examples( - "on world unload:", - "\tbroadcast \"the %event-world% has been unloaded!\"") - .since("1.0, INSERT VERSION (defining worlds)"); - } - - @Nullable - private Literal worlds; - - @Override - public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { - worlds = (Literal) args[0]; - return true; - } - - @Override - public boolean check(Event event) { - if (worlds == null) - return true; - - return worlds.check(event, world -> world.equals(((WorldUnloadEvent) event).getWorld())); - } - - - @Override - @Nullable - public String toString(Event event, boolean debug) { - return "unloading of world" + (worlds == null ? "" : " of " + worlds.toString(event,debug)); - } - -} From 6266bd25c579eb38582e809cc90bab1562914192 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 27 Jan 2023 03:51:16 -0500 Subject: [PATCH 11/25] Changes Removed some commented out code Fixed a spelling mistake or two Removed accidental * import --- src/main/java/ch/njol/skript/effects/EffWorldSave.java | 1 - src/main/java/ch/njol/skript/effects/EffWorldUnload.java | 4 ---- src/main/java/ch/njol/skript/events/EvtWorld.java | 8 ++++++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffWorldSave.java b/src/main/java/ch/njol/skript/effects/EffWorldSave.java index bbe81a2d813..3e8d79c6e83 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldSave.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldSave.java @@ -56,7 +56,6 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye protected void execute(Event event) { for (World world : worlds.getArray(event)) world.save(); - return; } @Override diff --git a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java index 100cdedb9a5..871492d2472 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java @@ -61,11 +61,7 @@ protected void execute(Event event) { World mainWorld = Bukkit.getWorlds().get(0); for (World world : this.worlds.getArray(event)) { Bukkit.unloadWorld(world, save); -// if (mainWorld != null && world != mainWorld) { -// world.getPlayers().forEach(player -> player.teleport(mainWorld.getSpawnLocation())); -// } } - return; } @Override diff --git a/src/main/java/ch/njol/skript/events/EvtWorld.java b/src/main/java/ch/njol/skript/events/EvtWorld.java index 1fa1cf71832..8aa26213343 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorld.java +++ b/src/main/java/ch/njol/skript/events/EvtWorld.java @@ -25,7 +25,11 @@ import ch.njol.skript.log.ErrorQuality; import org.bukkit.World; import org.bukkit.event.Event; -import org.bukkit.event.world.*; +import org.bukkit.event.world.WorldInitEvent; +import org.bukkit.event.world.WorldLoadEvent; +import org.bukkit.event.world.WorldSaveEvent; +import org.bukkit.event.world.WorldUnloadEvent; +import org.bukkit.event.world.WorldEvent; import org.eclipse.jdt.annotation.Nullable; public class EvtWorld extends SkriptEvent { @@ -41,7 +45,7 @@ public class EvtWorld extends SkriptEvent { // World Init Event Skript.registerEvent("World Init", EvtWorld.class, WorldInitEvent.class, "world init[ialization] [of %-worlds%]") - .description("Called when a world is initialised. As all default worlds are initialised before", + .description("Called when a world is initialized. As all default worlds are initialized before", "any scripts are loaded, this event is only called for newly created worlds.", "World management plugins might change the behaviour of this event though.") .examples("on world init of \"world_the_end\":") From 369303aa02bb4ee106410eeb46c744f3a3926f15 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 27 Jan 2023 15:28:55 -0500 Subject: [PATCH 12/25] Apply suggestions from code review Co-authored-by: Ayham Al Ali --- src/main/java/ch/njol/skript/effects/EffWorldSave.java | 5 ++++- src/main/java/ch/njol/skript/effects/EffWorldUnload.java | 2 +- src/main/java/ch/njol/skript/events/EvtWorld.java | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffWorldSave.java b/src/main/java/ch/njol/skript/effects/EffWorldSave.java index 3e8d79c6e83..3e4c7df0e96 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldSave.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldSave.java @@ -32,7 +32,10 @@ import org.eclipse.jdt.annotation.Nullable; @Name("Save World") -@Description({"Save all worlds or a given world manually.","note: saving many worlds at once may possible cause a server to freeze."}) +@Description({ + "Save all worlds or a given world manually.", + "Note: saving many worlds at once may possibly cause the server to freeze." +}) @Examples({ "save \"world_nether\"", "save all worlds" diff --git a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java index 871492d2472..cb62909bca9 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java @@ -33,7 +33,7 @@ import org.eclipse.jdt.annotation.Nullable; @Name("Unload World") -@Description({"Unload a given world with optional saving"}) +@Description("Unload a given world with optional saving") @Examples({ "unload \"world_nether\" and save", "unload \"world_the_end\" and don't save", diff --git a/src/main/java/ch/njol/skript/events/EvtWorld.java b/src/main/java/ch/njol/skript/events/EvtWorld.java index 8aa26213343..2e319af89fb 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorld.java +++ b/src/main/java/ch/njol/skript/events/EvtWorld.java @@ -77,7 +77,7 @@ public boolean init(Literal[] args, int matchedPattern, ParseResult parseResu if (worlds != null) { boolean isAnd = worlds.getAnd(); if (isAnd) { - Skript.error("An \"and\" list cannot be used in this event as multiple worlds cannot load at the same time", ErrorQuality.SEMANTIC_ERROR); + Skript.error("An \"and\" list cannot be used in this event as multiple worlds cannot load at the same time"); return false; } } From 121819eba0305c8f58eb6fcc187371f2b89b84e0 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 27 Jan 2023 15:30:28 -0500 Subject: [PATCH 13/25] Fixed mistakes in EffWorldUnload examples Co-Authored-By: Ayham Al Ali --- src/main/java/ch/njol/skript/effects/EffWorldUnload.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java index 871492d2472..d07ab5b37e8 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java @@ -35,8 +35,8 @@ @Name("Unload World") @Description({"Unload a given world with optional saving"}) @Examples({ - "unload \"world_nether\" and save", - "unload \"world_the_end\" and don't save", + "unload \"world_nether\"", + "unload \"world_the_end\" without saving", "unload all worlds" }) @Since("INSERT VERSION") From 30d2040a8ccd7d07dd036f294a381f595890cba7 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 27 Jan 2023 15:51:05 -0500 Subject: [PATCH 14/25] Forgotten import from a change --- src/main/java/ch/njol/skript/events/EvtWorld.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/events/EvtWorld.java b/src/main/java/ch/njol/skript/events/EvtWorld.java index 2e319af89fb..6e4d0220ea8 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorld.java +++ b/src/main/java/ch/njol/skript/events/EvtWorld.java @@ -22,7 +22,6 @@ import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser.ParseResult; -import ch.njol.skript.log.ErrorQuality; import org.bukkit.World; import org.bukkit.event.Event; import org.bukkit.event.world.WorldInitEvent; From 013039a3a0aacf3eccd284fdf7031cb9484c968e Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 27 Jan 2023 17:36:20 -0500 Subject: [PATCH 15/25] Apply requested changes Co-Authored-By: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> --- src/main/java/ch/njol/skript/events/EvtWorld.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/EvtWorld.java b/src/main/java/ch/njol/skript/events/EvtWorld.java index 6e4d0220ea8..f531bd6ad20 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorld.java +++ b/src/main/java/ch/njol/skript/events/EvtWorld.java @@ -74,9 +74,8 @@ public class EvtWorld extends SkriptEvent { public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { worlds = (Literal) args[0]; if (worlds != null) { - boolean isAnd = worlds.getAnd(); - if (isAnd) { - Skript.error("An \"and\" list cannot be used in this event as multiple worlds cannot load at the same time"); + if (worlds.getAnd()) { + Skript.error("An \"and\" list cannot be used in this event as multiple worlds cannot be called at the same time"); return false; } } From e8e064a843a2eaf25833abf50bfa5e9e615e9b1e Mon Sep 17 00:00:00 2001 From: Fusezion Date: Sat, 28 Jan 2023 01:41:06 -0500 Subject: [PATCH 16/25] Addressed requested change Co-Authored-By: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> --- src/main/java/ch/njol/skript/events/EvtWorld.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/EvtWorld.java b/src/main/java/ch/njol/skript/events/EvtWorld.java index f531bd6ad20..bcf5929d238 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorld.java +++ b/src/main/java/ch/njol/skript/events/EvtWorld.java @@ -73,11 +73,9 @@ public class EvtWorld extends SkriptEvent { @Override public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { worlds = (Literal) args[0]; - if (worlds != null) { - if (worlds.getAnd()) { - Skript.error("An \"and\" list cannot be used in this event as multiple worlds cannot be called at the same time"); - return false; - } + if (worlds != null && worlds.getAnd()) { + Skript.error("An \"and\" list cannot be used in this event as multiple worlds cannot be called at the same time"); + return false; } return true; } From a437ca9ac96e0610c99a724c187920f12ebecf3c Mon Sep 17 00:00:00 2001 From: Fusezion Date: Wed, 29 Mar 2023 20:33:00 -0400 Subject: [PATCH 17/25] Update aliases I guess? --- skript-aliases | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skript-aliases b/skript-aliases index fb9c3044e55..e99be898254 160000 --- a/skript-aliases +++ b/skript-aliases @@ -1 +1 @@ -Subproject commit fb9c3044e555667b4dc5558467608bd55fa32df0 +Subproject commit e99be898254965b0207992f66a3289ab6744106e From 296a944b5214b8fe5a555d9dc66f7df96f43d7ce Mon Sep 17 00:00:00 2001 From: Fusezion Date: Wed, 29 Mar 2023 20:55:42 -0400 Subject: [PATCH 18/25] Revert "Update aliases I guess?" This reverts commit a437ca9ac96e0610c99a724c187920f12ebecf3c. --- skript-aliases | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skript-aliases b/skript-aliases index e99be898254..fb9c3044e55 160000 --- a/skript-aliases +++ b/skript-aliases @@ -1 +1 @@ -Subproject commit e99be898254965b0207992f66a3289ab6744106e +Subproject commit fb9c3044e555667b4dc5558467608bd55fa32df0 From 6030c3455dc322c7411b1ad7abeed17c4578b4c1 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Thu, 30 Mar 2023 03:12:09 -0400 Subject: [PATCH 19/25] After 2 months of abandonment :pray: Please don't have the last push break something unintended :sparkles: Added load world effect :sparkles: Changed bits and bits around --- .../ch/njol/skript/effects/EffWorldLoad.java | 97 +++++++++++++++++++ .../njol/skript/effects/EffWorldUnload.java | 72 -------------- 2 files changed, 97 insertions(+), 72 deletions(-) create mode 100644 src/main/java/ch/njol/skript/effects/EffWorldLoad.java delete mode 100644 src/main/java/ch/njol/skript/effects/EffWorldUnload.java diff --git a/src/main/java/ch/njol/skript/effects/EffWorldLoad.java b/src/main/java/ch/njol/skript/effects/EffWorldLoad.java new file mode 100644 index 00000000000..7b9c0573b65 --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffWorldLoad.java @@ -0,0 +1,97 @@ +/** + * 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 . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +package ch.njol.skript.effects; + +import ch.njol.skript.Skript; +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.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.util.Kleenean; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.World.Environment; +import org.bukkit.WorldCreator; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + +@Name("Load World") +@Description({ + "Load your worlds or unload your worlds", + "The load effect will create a new world if world doesn't already exist.", + "When attempting to load a normal vanilla world you must define it's environment i.e \"world_nether\" must be loaded with nether environment" +}) +@Examples({ + "load world \"world_nether\" with environment nether", + "load the world \"myCustomWorld\"", + "unload \"world_nether\"", + "unload \"world_the_end\" without saving", + "unload all worlds" +}) +@Since("INSERT VERSION") +public class EffWorldLoad extends Effect { + + static { + Skript.registerEffect(EffWorldLoad.class, "load [[the] world] %strings% [with environment %-environment%]", "unload [[the] world] %worlds% [:without saving]"); + } + + private boolean save, load; + private Expression worlds; + @Nullable + private Expression environment; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + worlds = (Expression) exprs[0]; + load = matchedPattern == 0; + if (load) { + environment = (Expression) exprs[1]; + } else { + save = !parseResult.hasTag("without saving"); + } + return true; + } + + @Override + protected void execute(Event event) { + Environment environment = this.environment != null ? this.environment.getSingle(event) : null; + for (Object world : worlds.getArray(event)) { + if (load && world instanceof String) { + WorldCreator worldCreator = new WorldCreator((String) world); + if (environment != null) + worldCreator.environment(environment); + worldCreator.createWorld(); + } + else if (!load && world instanceof World) { + Bukkit.unloadWorld((World) world, save); + } + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + if (load) + return "load world(s) " + worlds.toString(event, debug) + (environment == null ? "" : " with environment " + environment.toString(event, debug)); + return "unload world(s) " + worlds.toString(event, debug) + " " + (save ? "with saving" : "without saving"); + } + +} diff --git a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java b/src/main/java/ch/njol/skript/effects/EffWorldUnload.java deleted file mode 100644 index 2d235faeeda..00000000000 --- a/src/main/java/ch/njol/skript/effects/EffWorldUnload.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * 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 . - * - * Copyright Peter Güttinger, SkriptLang team and contributors - */ -package ch.njol.skript.effects; - -import ch.njol.skript.Skript; -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.Effect; -import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.SkriptParser.ParseResult; -import ch.njol.util.Kleenean; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.event.Event; -import org.eclipse.jdt.annotation.Nullable; - -@Name("Unload World") -@Description("Unload a given world with optional saving") -@Examples({ - "unload \"world_nether\"", - "unload \"world_the_end\" without saving", - "unload all worlds" -}) -@Since("INSERT VERSION") -public class EffWorldUnload extends Effect { - - static { - Skript.registerEffect(EffWorldUnload.class, "unload %worlds% [:without saving]"); - } - - private boolean save; - private Expression worlds; - - @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - worlds = (Expression) exprs[0]; - save = !parseResult.hasTag("without saving"); - return true; - } - - @Override - protected void execute(Event event) { - World mainWorld = Bukkit.getWorlds().get(0); - for (World world : this.worlds.getArray(event)) { - Bukkit.unloadWorld(world, save); - } - } - - @Override - public String toString(@Nullable Event event, boolean debug) { - return "unload world(s) " + worlds.toString(event, debug) + " " + (save ? "with saving" : "without saving"); - } - -} From 3bd03f42af545771c07700f8c82992013626444a Mon Sep 17 00:00:00 2001 From: Fusezion Date: Fri, 14 Apr 2023 21:46:24 -0400 Subject: [PATCH 20/25] Apply formatting suggestions from review Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> --- .../ch/njol/skript/effects/EffWorldLoad.java | 8 ++-- .../ch/njol/skript/effects/EffWorldSave.java | 1 + .../java/ch/njol/skript/events/EvtWorld.java | 41 ++++++++++--------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffWorldLoad.java b/src/main/java/ch/njol/skript/effects/EffWorldLoad.java index 7b9c0573b65..7666536368d 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldLoad.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldLoad.java @@ -55,13 +55,14 @@ public class EffWorldLoad extends Effect { } private boolean save, load; - private Expression worlds; + private Expression worlds; @Nullable private Expression environment; @Override + @SuppressWarnings("unchecked") public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { - worlds = (Expression) exprs[0]; + worlds = exprs[0]; load = matchedPattern == 0; if (load) { environment = (Expression) exprs[1]; @@ -80,8 +81,7 @@ protected void execute(Event event) { if (environment != null) worldCreator.environment(environment); worldCreator.createWorld(); - } - else if (!load && world instanceof World) { + } else if (!load && world instanceof World) { Bukkit.unloadWorld((World) world, save); } } diff --git a/src/main/java/ch/njol/skript/effects/EffWorldSave.java b/src/main/java/ch/njol/skript/effects/EffWorldSave.java index 3e4c7df0e96..589dfb8b649 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldSave.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldSave.java @@ -50,6 +50,7 @@ public class EffWorldSave extends Effect { private Expression worlds; @Override + @SuppressWarnings("unchecked") public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { worlds = (Expression) exprs[0]; return true; diff --git a/src/main/java/ch/njol/skript/events/EvtWorld.java b/src/main/java/ch/njol/skript/events/EvtWorld.java index bcf5929d238..d5755a21c4b 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorld.java +++ b/src/main/java/ch/njol/skript/events/EvtWorld.java @@ -36,41 +36,42 @@ public class EvtWorld extends SkriptEvent { static { // World Save Event Skript.registerEvent("World Save", EvtWorld.class, WorldSaveEvent.class, "world sav(e|ing) [of %-worlds%]") - .description("Called when a world is saved to disk. Usually all worlds are saved simultaneously, but world management plugins could change this.") - .examples( - "on world save of \"world\":", - "\tbroadcast \"The world %event-world% has been saved\"") - .since("1.0, INSERT VERSION (defining worlds)"); + .description("Called when a world is saved to disk. Usually all worlds are saved simultaneously, but world management plugins could change this.") + .examples( + "on world save of \"world\":", + "\tbroadcast \"The world %event-world% has been saved\"") + .since("1.0, INSERT VERSION (defining worlds)"); // World Init Event Skript.registerEvent("World Init", EvtWorld.class, WorldInitEvent.class, "world init[ialization] [of %-worlds%]") - .description("Called when a world is initialized. As all default worlds are initialized before", - "any scripts are loaded, this event is only called for newly created worlds.", - "World management plugins might change the behaviour of this event though.") - .examples("on world init of \"world_the_end\":") - .since("1.0, INSERT VERSION (defining worlds)"); + .description("Called when a world is initialized. As all default worlds are initialized before", + "any scripts are loaded, this event is only called for newly created worlds.", + "World management plugins might change the behaviour of this event though.") + .examples("on world init of \"world_the_end\":") + .since("1.0, INSERT VERSION (defining worlds)"); // World Unload Event Skript.registerEvent("World Unload", EvtWorld.class, WorldUnloadEvent.class, "world unload[ing] [of %-worlds%]") - .description("Called when a world is unloaded. This event will never be called if you don't have a world management plugin.") - .examples( - "on world unload:", - "\tbroadcast \"the %event-world% has been unloaded!\"") - .since("1.0, INSERT VERSION (defining worlds)"); + .description("Called when a world is unloaded. This event will never be called if you don't have a world management plugin.") + .examples( + "on world unload:", + "\tbroadcast \"the %event-world% has been unloaded!\"") + .since("1.0, INSERT VERSION (defining worlds)"); // World Load Event Skript.registerEvent("World Load", EvtWorld.class, WorldLoadEvent.class, "world load[ing] [of %-worlds%]") - .description("Called when a world is loaded. As with the world init event, this event will not be called for the server's default world(s).") - .examples( - "on world load of \"world_nether\":", - "\tbroadcast \"The world %event-world% has been loaded!\"") - .since("1.0, INSERT VERSION (defining worlds)"); + .description("Called when a world is loaded. As with the world init event, this event will not be called for the server's default world(s).") + .examples( + "on world load of \"world_nether\":", + "\tbroadcast \"The world %event-world% has been loaded!\"") + .since("1.0, INSERT VERSION (defining worlds)"); } @Nullable private Literal worlds; @Override + @SuppressWarnings("unchecked") public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { worlds = (Literal) args[0]; if (worlds != null && worlds.getAnd()) { From 77769c02dc5b080c11916655fb67b380bc143525 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Mon, 1 Jan 2024 00:49:22 -0500 Subject: [PATCH 21/25] Update EvtWorld - Removed 'getAnd' - Removed plurality --- .../java/ch/njol/skript/events/EvtWorld.java | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/EvtWorld.java b/src/main/java/ch/njol/skript/events/EvtWorld.java index d5755a21c4b..5ad42d67461 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorld.java +++ b/src/main/java/ch/njol/skript/events/EvtWorld.java @@ -35,7 +35,7 @@ public class EvtWorld extends SkriptEvent { static { // World Save Event - Skript.registerEvent("World Save", EvtWorld.class, WorldSaveEvent.class, "world sav(e|ing) [of %-worlds%]") + Skript.registerEvent("World Save", EvtWorld.class, WorldSaveEvent.class, "world sav(e|ing) [of %-world%]") .description("Called when a world is saved to disk. Usually all worlds are saved simultaneously, but world management plugins could change this.") .examples( "on world save of \"world\":", @@ -43,7 +43,7 @@ public class EvtWorld extends SkriptEvent { .since("1.0, INSERT VERSION (defining worlds)"); // World Init Event - Skript.registerEvent("World Init", EvtWorld.class, WorldInitEvent.class, "world init[ialization] [of %-worlds%]") + Skript.registerEvent("World Init", EvtWorld.class, WorldInitEvent.class, "world init[ialization] [of %-world%]") .description("Called when a world is initialized. As all default worlds are initialized before", "any scripts are loaded, this event is only called for newly created worlds.", "World management plugins might change the behaviour of this event though.") @@ -51,7 +51,7 @@ public class EvtWorld extends SkriptEvent { .since("1.0, INSERT VERSION (defining worlds)"); // World Unload Event - Skript.registerEvent("World Unload", EvtWorld.class, WorldUnloadEvent.class, "world unload[ing] [of %-worlds%]") + Skript.registerEvent("World Unload", EvtWorld.class, WorldUnloadEvent.class, "world unload[ing] [of %-world%]") .description("Called when a world is unloaded. This event will never be called if you don't have a world management plugin.") .examples( "on world unload:", @@ -59,7 +59,7 @@ public class EvtWorld extends SkriptEvent { .since("1.0, INSERT VERSION (defining worlds)"); // World Load Event - Skript.registerEvent("World Load", EvtWorld.class, WorldLoadEvent.class, "world load[ing] [of %-worlds%]") + Skript.registerEvent("World Load", EvtWorld.class, WorldLoadEvent.class, "world load[ing] [of %-world%]") .description("Called when a world is loaded. As with the world init event, this event will not be called for the server's default world(s).") .examples( "on world load of \"world_nether\":", @@ -67,31 +67,26 @@ public class EvtWorld extends SkriptEvent { .since("1.0, INSERT VERSION (defining worlds)"); } - @Nullable - private Literal worlds; + private Literal world; @Override @SuppressWarnings("unchecked") public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { - worlds = (Literal) args[0]; - if (worlds != null && worlds.getAnd()) { - Skript.error("An \"and\" list cannot be used in this event as multiple worlds cannot be called at the same time"); - return false; - } + world = (Literal) args[0]; return true; } @Override public boolean check(Event event) { - if (worlds == null) + if (world == null) return true; World evtWorld = ((WorldEvent) event).getWorld(); - return worlds.check(event, world -> world.equals(evtWorld)); + return world.check(event, world -> world.equals(evtWorld)); } @Override public String toString(@Nullable Event event, boolean debug) { - return "world save/init/unload/load" + (worlds == null ? "" : " of " + worlds.toString(event,debug)); + return "world save/init/unload/load" + (world == null ? "" : " of " + world.toString(event,debug)); } } From 00575e277838a0065d4809b9011f2292c348e829 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Mon, 1 Jan 2024 01:12:44 -0500 Subject: [PATCH 22/25] Revert previous commit and implement sovde's actual suggestion --- .../java/ch/njol/skript/events/EvtWorld.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/ch/njol/skript/events/EvtWorld.java b/src/main/java/ch/njol/skript/events/EvtWorld.java index 5ad42d67461..1d6ddd01dea 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorld.java +++ b/src/main/java/ch/njol/skript/events/EvtWorld.java @@ -20,6 +20,7 @@ import ch.njol.skript.Skript; import ch.njol.skript.lang.Literal; +import ch.njol.skript.lang.LiteralList; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser.ParseResult; import org.bukkit.World; @@ -35,7 +36,7 @@ public class EvtWorld extends SkriptEvent { static { // World Save Event - Skript.registerEvent("World Save", EvtWorld.class, WorldSaveEvent.class, "world sav(e|ing) [of %-world%]") + Skript.registerEvent("World Save", EvtWorld.class, WorldSaveEvent.class, "world sav(e|ing) [of %-worlds%]") .description("Called when a world is saved to disk. Usually all worlds are saved simultaneously, but world management plugins could change this.") .examples( "on world save of \"world\":", @@ -43,7 +44,7 @@ public class EvtWorld extends SkriptEvent { .since("1.0, INSERT VERSION (defining worlds)"); // World Init Event - Skript.registerEvent("World Init", EvtWorld.class, WorldInitEvent.class, "world init[ialization] [of %-world%]") + Skript.registerEvent("World Init", EvtWorld.class, WorldInitEvent.class, "world init[ialization] [of %-worlds%]") .description("Called when a world is initialized. As all default worlds are initialized before", "any scripts are loaded, this event is only called for newly created worlds.", "World management plugins might change the behaviour of this event though.") @@ -51,7 +52,7 @@ public class EvtWorld extends SkriptEvent { .since("1.0, INSERT VERSION (defining worlds)"); // World Unload Event - Skript.registerEvent("World Unload", EvtWorld.class, WorldUnloadEvent.class, "world unload[ing] [of %-world%]") + Skript.registerEvent("World Unload", EvtWorld.class, WorldUnloadEvent.class, "world unload[ing] [of %-worlds%]") .description("Called when a world is unloaded. This event will never be called if you don't have a world management plugin.") .examples( "on world unload:", @@ -59,7 +60,7 @@ public class EvtWorld extends SkriptEvent { .since("1.0, INSERT VERSION (defining worlds)"); // World Load Event - Skript.registerEvent("World Load", EvtWorld.class, WorldLoadEvent.class, "world load[ing] [of %-world%]") + Skript.registerEvent("World Load", EvtWorld.class, WorldLoadEvent.class, "world load[ing] [of %-worlds%]") .description("Called when a world is loaded. As with the world init event, this event will not be called for the server's default world(s).") .examples( "on world load of \"world_nether\":", @@ -67,26 +68,29 @@ public class EvtWorld extends SkriptEvent { .since("1.0, INSERT VERSION (defining worlds)"); } - private Literal world; + private Literal worlds; @Override @SuppressWarnings("unchecked") public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { - world = (Literal) args[0]; + worlds = (Literal) args[0]; + if (worlds instanceof LiteralList) { + ((LiteralList) worlds).setAnd(false); + } return true; } @Override public boolean check(Event event) { - if (world == null) + if (worlds == null) return true; World evtWorld = ((WorldEvent) event).getWorld(); - return world.check(event, world -> world.equals(evtWorld)); + return worlds.check(event, world -> world.equals(evtWorld)); } @Override public String toString(@Nullable Event event, boolean debug) { - return "world save/init/unload/load" + (world == null ? "" : " of " + world.toString(event,debug)); + return "world save/init/unload/load" + (worlds == null ? "" : " of " + worlds.toString(event,debug)); } } From ecb6d21085c3448683d30104a578cb59a5075d2c Mon Sep 17 00:00:00 2001 From: Fusezion Date: Mon, 1 Jan 2024 01:28:12 -0500 Subject: [PATCH 23/25] Revert previous commit and implement sovde's actual suggestion --- src/main/java/ch/njol/skript/events/EvtWorld.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/events/EvtWorld.java b/src/main/java/ch/njol/skript/events/EvtWorld.java index 1d6ddd01dea..36a55d82d25 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorld.java +++ b/src/main/java/ch/njol/skript/events/EvtWorld.java @@ -75,7 +75,7 @@ public class EvtWorld extends SkriptEvent { public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { worlds = (Literal) args[0]; if (worlds instanceof LiteralList) { - ((LiteralList) worlds).setAnd(false); + ((LiteralList) worlds).invertAnd(); } return true; } From 2fa67ea3496067a6c9329dec347a61504e5f0a1e Mon Sep 17 00:00:00 2001 From: Fusezion Date: Mon, 1 Jan 2024 13:08:39 -0500 Subject: [PATCH 24/25] Update src/main/java/ch/njol/skript/events/EvtWorld.java Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com> --- src/main/java/ch/njol/skript/events/EvtWorld.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/events/EvtWorld.java b/src/main/java/ch/njol/skript/events/EvtWorld.java index 36a55d82d25..657d3f1a002 100644 --- a/src/main/java/ch/njol/skript/events/EvtWorld.java +++ b/src/main/java/ch/njol/skript/events/EvtWorld.java @@ -74,7 +74,7 @@ public class EvtWorld extends SkriptEvent { @SuppressWarnings("unchecked") public boolean init(Literal[] args, int matchedPattern, ParseResult parseResult) { worlds = (Literal) args[0]; - if (worlds instanceof LiteralList) { + if (worlds instanceof LiteralList && worlds.getAnd()) { ((LiteralList) worlds).invertAnd(); } return true; From 2189543326f472453ec4cc57711c8f4281424160 Mon Sep 17 00:00:00 2001 From: Fusezion Date: Mon, 1 Jan 2024 15:49:28 -0500 Subject: [PATCH 25/25] Ease the concerns of pickle with some cucumbers Address his desired reviews Co-authored-by: Patrick Miller --- src/main/java/ch/njol/skript/effects/EffWorldLoad.java | 9 ++++++--- src/main/java/ch/njol/skript/effects/EffWorldSave.java | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffWorldLoad.java b/src/main/java/ch/njol/skript/effects/EffWorldLoad.java index 7666536368d..1417789789f 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldLoad.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldLoad.java @@ -51,7 +51,10 @@ public class EffWorldLoad extends Effect { static { - Skript.registerEffect(EffWorldLoad.class, "load [[the] world] %strings% [with environment %-environment%]", "unload [[the] world] %worlds% [:without saving]"); + Skript.registerEffect(EffWorldLoad.class, + "load [[the] world[s]] %strings% [with environment %-environment%]", + "unload [[the] world[s]] %worlds% [:without saving]" + ); } private boolean save, load; @@ -90,8 +93,8 @@ protected void execute(Event event) { @Override public String toString(@Nullable Event event, boolean debug) { if (load) - return "load world(s) " + worlds.toString(event, debug) + (environment == null ? "" : " with environment " + environment.toString(event, debug)); - return "unload world(s) " + worlds.toString(event, debug) + " " + (save ? "with saving" : "without saving"); + return "load the world(s) " + worlds.toString(event, debug) + (environment == null ? "" : " with environment " + environment.toString(event, debug)); + return "unload the world(s) " + worlds.toString(event, debug) + " " + (save ? "with saving" : "without saving"); } } diff --git a/src/main/java/ch/njol/skript/effects/EffWorldSave.java b/src/main/java/ch/njol/skript/effects/EffWorldSave.java index 589dfb8b649..2281ba44dcc 100644 --- a/src/main/java/ch/njol/skript/effects/EffWorldSave.java +++ b/src/main/java/ch/njol/skript/effects/EffWorldSave.java @@ -44,7 +44,7 @@ public class EffWorldSave extends Effect { static { - Skript.registerEffect(EffWorldSave.class, "save %worlds%"); + Skript.registerEffect(EffWorldSave.class, "save [[the] world[s]] %worlds%"); } private Expression worlds; @@ -64,7 +64,7 @@ protected void execute(Event event) { @Override public String toString(@Nullable Event event, boolean debug) { - return "save world(s) " + worlds.toString(event, debug); + return "save the world(s) " + worlds.toString(event, debug); } }