mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-28 13:36:33 +01:00
Implement world events
This commit is contained in:
parent
6157df9703
commit
6d0b6f3b6e
@ -1,6 +1,10 @@
|
||||
package io.github.dre2n.dungeonsxl.dungeon;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.event.editworld.EditWorldGenerateEvent;
|
||||
import io.github.dre2n.dungeonsxl.event.editworld.EditWorldLoadEvent;
|
||||
import io.github.dre2n.dungeonsxl.event.editworld.EditWorldSaveEvent;
|
||||
import io.github.dre2n.dungeonsxl.event.editworld.EditWorldUnloadEvent;
|
||||
import io.github.dre2n.dungeonsxl.player.DPlayer;
|
||||
import io.github.dre2n.dungeonsxl.util.FileUtil;
|
||||
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
|
||||
@ -65,10 +69,22 @@ public class EditWorld {
|
||||
creator.type(WorldType.FLAT);
|
||||
creator.generateStructures(false);
|
||||
|
||||
EditWorldGenerateEvent event = new EditWorldGenerateEvent(this);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
world = plugin.getServer().createWorld(creator);
|
||||
}
|
||||
|
||||
public void save() {
|
||||
EditWorldSaveEvent event = new EditWorldSaveEvent(this);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
world.save();
|
||||
|
||||
try {
|
||||
@ -97,6 +113,12 @@ public class EditWorld {
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
EditWorldUnloadEvent event = new EditWorldUnloadEvent(this, true);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getEditWorlds().remove(this);
|
||||
for (Player player : world.getPlayers()) {
|
||||
DPlayer dPlayer = DPlayer.getByPlayer(player);
|
||||
@ -111,6 +133,12 @@ public class EditWorld {
|
||||
}
|
||||
|
||||
public void deleteNoSave() {
|
||||
EditWorldUnloadEvent event = new EditWorldUnloadEvent(this, false);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getEditWorlds().remove(this);
|
||||
for (Player player : world.getPlayers()) {
|
||||
DPlayer dPlayer = DPlayer.getByPlayer(player);
|
||||
@ -152,6 +180,12 @@ public class EditWorld {
|
||||
}
|
||||
|
||||
public static EditWorld load(String name) {
|
||||
EditWorldLoadEvent event = new EditWorldLoadEvent(name);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (EditWorld editWorld : plugin.getEditWorlds()) {
|
||||
|
||||
if (editWorld.mapName.equalsIgnoreCase(name)) {
|
||||
|
@ -5,7 +5,9 @@ import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
|
||||
import io.github.dre2n.dungeonsxl.dungeon.DungeonConfig;
|
||||
import io.github.dre2n.dungeonsxl.dungeon.WorldConfig;
|
||||
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
|
||||
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldLoadEvent;
|
||||
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldStartGameEvent;
|
||||
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldUnloadEvent;
|
||||
import io.github.dre2n.dungeonsxl.mob.DMob;
|
||||
import io.github.dre2n.dungeonsxl.player.DPlayer;
|
||||
import io.github.dre2n.dungeonsxl.requirement.Requirement;
|
||||
@ -498,6 +500,12 @@ public class GameWorld {
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
GameWorldUnloadEvent event = new GameWorldUnloadEvent(this);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getGameWorlds().remove(this);
|
||||
plugin.getServer().unloadWorld(world, true);
|
||||
File dir = new File("DXL_Game_" + id);
|
||||
@ -505,6 +513,11 @@ public class GameWorld {
|
||||
}
|
||||
|
||||
public static GameWorld load(String name) {
|
||||
GameWorldLoadEvent event = new GameWorldLoadEvent(name);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
File file = new File(plugin.getDataFolder(), "/maps/" + name);
|
||||
|
||||
|
@ -15,7 +15,7 @@ public abstract class DSignEvent extends Event {
|
||||
/**
|
||||
* @return the dSign
|
||||
*/
|
||||
public DSign getdSign() {
|
||||
public DSign getDSign() {
|
||||
return dSign;
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ public abstract class DSignEvent extends Event {
|
||||
* @param dSign
|
||||
* the dSign to set
|
||||
*/
|
||||
public void setdSign(DSign dSign) {
|
||||
public void setDSign(DSign dSign) {
|
||||
this.dSign = dSign;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,36 @@
|
||||
package io.github.dre2n.dungeonsxl.event.editworld;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class EditWorldGenerateEvent extends EditWorldEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
public EditWorldGenerateEvent(EditWorld editWorld) {
|
||||
super(editWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
}
|
@ -1,17 +1,33 @@
|
||||
package io.github.dre2n.dungeonsxl.event.editworld;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class EditWorldLoadEvent extends EditWorldEvent implements Cancellable {
|
||||
public class EditWorldLoadEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
public EditWorldLoadEvent(EditWorld editWorld) {
|
||||
super(editWorld);
|
||||
private String name;
|
||||
|
||||
public EditWorldLoadEvent(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,36 @@
|
||||
package io.github.dre2n.dungeonsxl.event.editworld;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class EditWorldSaveEvent extends EditWorldEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
public EditWorldSaveEvent(EditWorld editWorld) {
|
||||
super(editWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
}
|
@ -10,8 +10,26 @@ public class EditWorldUnloadEvent extends EditWorldEvent implements Cancellable
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
public EditWorldUnloadEvent(EditWorld editWorld) {
|
||||
private boolean save;
|
||||
|
||||
public EditWorldUnloadEvent(EditWorld editWorld, boolean save) {
|
||||
super(editWorld);
|
||||
this.save = save;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the save
|
||||
*/
|
||||
public boolean getSave() {
|
||||
return save;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param save
|
||||
* the save to set
|
||||
*/
|
||||
public void setSave(boolean save) {
|
||||
this.save = save;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,33 @@
|
||||
package io.github.dre2n.dungeonsxl.event.gameworld;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class GameWorldLoadEvent extends GameWorldEvent implements Cancellable {
|
||||
public class GameWorldLoadEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
public GameWorldLoadEvent(GameWorld gameWorld) {
|
||||
super(gameWorld);
|
||||
private String name;
|
||||
|
||||
public GameWorldLoadEvent(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user