Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to world events #5114

Merged
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0fe7372
Update to world events
Fusezion Sep 24, 2022
29404c3
Added unload world effect
Fusezion Sep 24, 2022
692c909
Removed world from effects
Fusezion Sep 24, 2022
481be81
Apply suggestions from code review
Fusezion Sep 29, 2022
375117c
Merge branch 'SkriptLang:master' into enhancment/worldupdates
Fusezion Sep 29, 2022
b75f1bb
Requested changes
Fusezion Sep 29, 2022
6c90aaf
Update EffWorldUnload.java
Fusezion Sep 29, 2022
c270768
Requested changes
Fusezion Oct 1, 2022
0ae6991
Hopefully final touches to this
Fusezion Nov 16, 2022
0b045a1
Requested change
Fusezion Nov 16, 2022
4c9bd6c
Merge branch 'master' into enhancment/worldupdates
Fusezion Nov 16, 2022
431823f
EvtWorld - Request and Changes
Fusezion Jan 27, 2023
6266bd2
Changes
Fusezion Jan 27, 2023
3f103ba
Merge branch 'SkriptLang:master' into enhancment/worldupdates
Fusezion Jan 27, 2023
369303a
Apply suggestions from code review
Fusezion Jan 27, 2023
121819e
Fixed mistakes in EffWorldUnload examples
Fusezion Jan 27, 2023
4b155c3
Merge branch 'enhancment/worldupdates' of https://github.com/Fusezion…
Fusezion Jan 27, 2023
30d2040
Forgotten import from a change
Fusezion Jan 27, 2023
013039a
Apply requested changes
Fusezion Jan 27, 2023
53fa92f
Merge branch 'master' into enhancment/worldupdates
Fusezion Jan 28, 2023
e8e064a
Addressed requested change
Fusezion Jan 28, 2023
10de7ad
Merge branch 'SkriptLang:master' into enhancment/worldupdates
Fusezion Feb 18, 2023
a437ca9
Update aliases I guess?
Fusezion Mar 30, 2023
296a944
Revert "Update aliases I guess?"
Fusezion Mar 30, 2023
8f861b8
Merge remote-tracking branch 'origin/master' into enhancment/worldupd…
Fusezion Mar 30, 2023
6030c34
After 2 months of abandonment
Fusezion Mar 30, 2023
3bd03f4
Apply formatting suggestions from review
Fusezion Apr 15, 2023
eca1247
Merge branch 'master' into enhancment/worldupdates
Fusezion Apr 17, 2023
c847a21
Merge branch 'master' into enhancment/worldupdates
Fusezion Jul 12, 2023
b0ed0b7
Merge branch 'SkriptLang:master' into enhancment/worldupdates
Fusezion Aug 8, 2023
354223b
Merge branch 'dev/feature' into enhancment/worldupdates
Fusezion Dec 31, 2023
56872e8
Merge branch 'dev/feature' into enhancment/worldupdates
Fusezion Jan 1, 2024
5710086
Merge remote-tracking branch 'origin/enhancment/worldupdates' into en…
Fusezion Jan 1, 2024
77769c0
Update EvtWorld
Fusezion Jan 1, 2024
7e2f37d
Merge branch 'dev/feature' into enhancment/worldupdates
Fusezion Jan 1, 2024
00575e2
Revert previous commit and implement sovde's actual suggestion
Fusezion Jan 1, 2024
6d03788
Merge remote-tracking branch 'origin/enhancment/worldupdates' into en…
Fusezion Jan 1, 2024
ecb6d21
Revert previous commit and implement sovde's actual suggestion
Fusezion Jan 1, 2024
2fa67ea
Update src/main/java/ch/njol/skript/events/EvtWorld.java
Fusezion Jan 1, 2024
2189543
Ease the concerns of pickle with some cucumbers
Fusezion Jan 1, 2024
c3aaa7a
Merge branch 'dev/feature' into enhancment/worldupdates
Fusezion Jan 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffWorldSave.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.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.World;
import org.bukkit.event.Event;
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 possibly cause the server to freeze."
})
@Examples({
"save \"world_nether\"",
"save all worlds"
})
@Since("INSERT VERSION")
public class EffWorldSave extends Effect {
Fusezion marked this conversation as resolved.
Show resolved Hide resolved

static {
Skript.registerEffect(EffWorldSave.class, "save %worlds%");
Fusezion marked this conversation as resolved.
Show resolved Hide resolved
}

private Expression<World> worlds;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
Fusezion marked this conversation as resolved.
Show resolved Hide resolved
worlds = (Expression<World>) exprs[0];
return true;
}

@Override
protected void execute(Event event) {
for (World world : worlds.getArray(event))
world.save();
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "save world(s) " + worlds.toString(event, debug);
Fusezion marked this conversation as resolved.
Show resolved Hide resolved
}

}
72 changes: 72 additions & 0 deletions src/main/java/ch/njol/skript/effects/EffWorldUnload.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.effects;

import ch.njol.skript.Skript;
import ch.njol.skript.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<World> worlds;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
worlds = (Expression<World>) 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);
Fusezion marked this conversation as resolved.
Show resolved Hide resolved
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "unload world(s) " + worlds.toString(event, debug) + " " + (save ? "with saving" : "without saving");
}
Fusezion marked this conversation as resolved.
Show resolved Hide resolved

}
96 changes: 96 additions & 0 deletions src/main/java/ch/njol/skript/events/EvtWorld.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
* 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.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 {

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)");
Fusezion marked this conversation as resolved.
Show resolved Hide resolved

// 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)");
Fusezion marked this conversation as resolved.
Show resolved Hide resolved

// 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)");
Fusezion marked this conversation as resolved.
Show resolved Hide resolved

// 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)");
Fusezion marked this conversation as resolved.
Show resolved Hide resolved
}

@Nullable
private Literal<World> worlds;

@Override
public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResult) {
Fusezion marked this conversation as resolved.
Show resolved Hide resolved
worlds = (Literal<World>) 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;
}
Fusezion marked this conversation as resolved.
Show resolved Hide resolved
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));
}

}
24 changes: 0 additions & 24 deletions src/main/java/ch/njol/skript/events/SimpleEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@
import org.bukkit.event.world.LootGenerateEvent;
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;

Expand Down Expand Up @@ -416,26 +412,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.")
Expand Down