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 8 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
67 changes: 67 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,67 @@
/**
* 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("Saves a world manually")
@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
public String toString(@Nullable Event event, boolean debug) {
Fusezion marked this conversation as resolved.
Show resolved Hide resolved
return "save world(s) " + worlds.toString(event, debug);
Fusezion marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
protected void execute(Event event) {
for (World world : worlds.getArray(event)) {
world.save();
}
Fusezion marked this conversation as resolved.
Show resolved Hide resolved
return;
}
}
77 changes: 77 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,77 @@
/**
* 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;

import java.util.Arrays;

@Name("Unload World")
@Description({"Unload a world"})
@Examples({
"unload \"world_nether\" and save",
"unload \"world_the_end\" and don't save",
Fusezion marked this conversation as resolved.
Show resolved Hide resolved
"unload all worlds"
})
@Since("INSERT VERSION")
public class EffWorldUnload extends Effect {

static {
Skript.registerEffect(EffWorldUnload.class, "unload %worlds% [and (save|1¦(do not|don't) save)]");
}

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.mark != 1;
return true;
}

@Override
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()));
}
Fusezion marked this conversation as resolved.
Show resolved Hide resolved
Bukkit.unloadWorld(world, save);
Fusezion marked this conversation as resolved.
Show resolved Hide resolved
}
return;
}

@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
}
65 changes: 65 additions & 0 deletions src/main/java/ch/njol/skript/events/EvtWorldInit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* 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.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
TheLimeGlass marked this conversation as resolved.
Show resolved Hide resolved
private World[] worlds;

@Override
public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResult) {
worlds = ((Literal<World>) args[0]).getArray();
return true;
}

@Override
public boolean check(Event event) {
if (worlds == null)
return true;
return Arrays.stream(worlds).anyMatch(world -> ((WorldInitEvent) event).getWorld().equals(world));
}


@Override
public String toString(@Nullable Event event, boolean debug) {
return "initialization of world" + (worlds == null ? "" : " " + worlds);
}

}
66 changes: 66 additions & 0 deletions src/main/java/ch/njol/skript/events/EvtWorldLoad.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* 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.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\":",
"\tbroadcast \"The world %event-world% has been loaded!\"")
.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<World>) args[0]).getArray();
Fusezion marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

@Override
public boolean check(Event event) {
if (worlds == null)
return true;
return Arrays.stream(worlds).anyMatch(world -> ((WorldLoadEvent) event).getWorld().equals(world));
}


@Override
public String toString(@Nullable Event event, boolean debug) {
return "loading of world" + (worlds == null ? "" : " " + worlds);
}

}
66 changes: 66 additions & 0 deletions src/main/java/ch/njol/skript/events/EvtWorldSave.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* 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.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<World>) args[0]).getArray();
Fusezion marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

@Override
public boolean check(Event event) {
if (worlds == null)
return true;
return Arrays.stream(worlds).anyMatch(world -> ((WorldSaveEvent) event).getWorld().equals(world));
}


@Override
public String toString(final @Nullable Event event, final boolean debug) {
return "saving of world" + (worlds == null ? "" : " " + worlds);
}

}
Loading