mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2025-02-26 17:21:40 +01:00
Recoded tutorial system
Still issues with PEX + start group
This commit is contained in:
parent
385d32a181
commit
0ea47a47e5
@ -22,6 +22,7 @@ import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerLeaveDGroupEvent;
|
||||
import io.github.dre2n.dungeonsxl.event.dplayer.instance.game.DGamePlayerEscapeEvent;
|
||||
import io.github.dre2n.dungeonsxl.game.Game;
|
||||
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGlobalPlayer;
|
||||
@ -51,15 +52,13 @@ public class LeaveCommand extends BRCommand {
|
||||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player);
|
||||
Game game = Game.getByPlayer(player);
|
||||
|
||||
if (DGameWorld.getByWorld(player.getWorld()) != null) {
|
||||
if (DGameWorld.getByWorld(player.getWorld()).isTutorial()) {
|
||||
if (game.isTutorial()) {
|
||||
MessageUtil.sendMessage(player, DMessages.ERROR_NO_LEAVE_IN_TUTORIAL.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
|
||||
|
@ -47,6 +47,7 @@ public class Game {
|
||||
|
||||
static DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
|
||||
private boolean tutorial;
|
||||
private List<DGroup> dGroups = new ArrayList<>();
|
||||
private boolean started;
|
||||
private GameType type = GameTypeDefault.DEFAULT;
|
||||
@ -59,6 +60,7 @@ public class Game {
|
||||
public Game(DGroup dGroup) {
|
||||
plugin.getGames().add(this);
|
||||
|
||||
tutorial = false;
|
||||
started = false;
|
||||
|
||||
dGroups.add(dGroup);
|
||||
@ -72,6 +74,7 @@ public class Game {
|
||||
public Game(DGroup dGroup, DGameWorld world) {
|
||||
plugin.getGames().add(this);
|
||||
|
||||
tutorial = false;
|
||||
started = false;
|
||||
this.world = world;
|
||||
|
||||
@ -86,6 +89,7 @@ public class Game {
|
||||
public Game(DGroup dGroup, String worldName) {
|
||||
plugin.getGames().add(this);
|
||||
|
||||
tutorial = false;
|
||||
started = false;
|
||||
DResourceWorld resource = plugin.getDWorlds().getResourceByName(worldName);
|
||||
if (resource != null) {
|
||||
@ -110,6 +114,7 @@ public class Game {
|
||||
this.dGroups = dGroups;
|
||||
this.type = type;
|
||||
this.world = world;
|
||||
this.tutorial = false;
|
||||
this.started = true;
|
||||
|
||||
for (DGroup dGroup : dGroups) {
|
||||
@ -121,6 +126,21 @@ public class Game {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tutorial
|
||||
*/
|
||||
public boolean isTutorial() {
|
||||
return tutorial;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tutorial
|
||||
* if the DGameWorld is the tutorial
|
||||
*/
|
||||
public void setTutorial(boolean tutorial) {
|
||||
this.tutorial = tutorial;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dGroups
|
||||
*/
|
||||
@ -455,7 +475,7 @@ public class Game {
|
||||
|
||||
public static Game getByGameWorld(DGameWorld gameWorld) {
|
||||
for (Game game : plugin.getGames()) {
|
||||
if (game.getWorld().equals(gameWorld)) {
|
||||
if (gameWorld.equals(game.getWorld())) {
|
||||
return game;
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ public enum GameTypeDefault implements GameType {
|
||||
QUEST("Quest", "Quest", END, false, false, true, false, false, false, false, GameMode.SURVIVAL, true),
|
||||
QUEST_TIME_IS_RUNNING("Quest - Time is Running", "Quest TiR", END, false, false, true, true, false, false, false, GameMode.SURVIVAL, true),
|
||||
TEST("Test", "Test", HIGHSCORE, false, false, false, true, true, true, true, GameMode.SURVIVAL, false),
|
||||
TUTORIAL("Tutorial", "Tutorial", END, false, false, true, false, false, false, false, GameMode.SURVIVAL, false),
|
||||
DEFAULT("Default", "Default", END, false, false, true, false, false, false, false, GameMode.SURVIVAL, true),
|
||||
CUSTOM("Custom", "Custom");
|
||||
|
||||
|
@ -20,7 +20,6 @@ import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.config.MainConfig;
|
||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent;
|
||||
import io.github.dre2n.dungeonsxl.game.Game;
|
||||
import io.github.dre2n.dungeonsxl.global.DPortal;
|
||||
import io.github.dre2n.dungeonsxl.global.GameSign;
|
||||
@ -441,79 +440,25 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
plugin.debug.start("PlayerListener#onJoin");
|
||||
Player player = event.getPlayer();
|
||||
|
||||
new DGlobalPlayer(player);
|
||||
|
||||
// Check dPlayers
|
||||
DGamePlayer dPlayer = DGamePlayer.getByName(player.getName());
|
||||
if (dPlayer != null) {
|
||||
DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer());
|
||||
if (dGroup != null) {
|
||||
dGroup.removePlayer(dPlayer.getPlayer());
|
||||
dGroup.addPlayer(player);
|
||||
}
|
||||
dPlayer.setPlayer(player);
|
||||
|
||||
// Check offlineTime
|
||||
dPlayer.setOfflineTime(0);
|
||||
if (dPlayers.checkPlayer(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
DGlobalPlayer dPlayer = new DGlobalPlayer(player);
|
||||
if (player.hasPlayedBefore()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Tutorial Mode
|
||||
if (!plugin.getMainConfig().isTutorialActivated()) {
|
||||
plugin.debug.end("PlayerListener#onJoin", true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (DGamePlayer.getByPlayer(player) != null) {
|
||||
plugin.debug.end("PlayerListener#onJoin", true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getPermissionProvider() == null || !plugin.getPermissionProvider().hasGroupSupport()) {
|
||||
plugin.debug.end("PlayerListener#onJoin", true);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((plugin.getMainConfig().getTutorialDungeon() == null || plugin.getMainConfig().getTutorialStartGroup() == null || plugin.getMainConfig().getTutorialEndGroup() == null)) {
|
||||
plugin.debug.end("PlayerListener#onJoin", true);
|
||||
return;
|
||||
}
|
||||
|
||||
for (String group : plugin.getPermissionProvider().getPlayerGroups(player)) {
|
||||
if (!plugin.getMainConfig().getTutorialStartGroup().equalsIgnoreCase(group)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DGroup dGroup = new DGroup(player, plugin.getMainConfig().getTutorialDungeon(), false);
|
||||
|
||||
DGroupCreateEvent createEvent = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.GROUP_SIGN);
|
||||
plugin.getServer().getPluginManager().callEvent(createEvent);
|
||||
|
||||
if (createEvent.isCancelled()) {
|
||||
dGroup = null;
|
||||
}
|
||||
|
||||
if (dGroup == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dGroup.getGameWorld() == null) {
|
||||
dGroup.setGameWorld(plugin.getDWorlds().getResourceByName(DGroup.getByPlayer(player).getMapName()).instantiateAsGameWorld());
|
||||
dGroup.getGameWorld().setTutorial(true);
|
||||
}
|
||||
|
||||
if (dGroup.getGameWorld() == null) {
|
||||
MessageUtil.sendMessage(player, DMessages.ERROR_TUTORIAL_NOT_EXIST.getMessage());
|
||||
continue;
|
||||
}
|
||||
|
||||
DGamePlayer.create(player, dGroup.getGameWorld());
|
||||
plugin.debug.end("PlayerListener#onJoin", true);
|
||||
return;
|
||||
}
|
||||
plugin.debug.end("PlayerListener#onJoin", true);
|
||||
dPlayer.startTutorial();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
|
@ -465,7 +465,9 @@ public class DGamePlayer extends DInstancePlayer {
|
||||
* if messages should be sent
|
||||
*/
|
||||
public void leave(boolean message) {
|
||||
GameRules rules = Game.getByWorld(getWorld()).getRules();
|
||||
Game game = Game.getByWorld(getWorld());
|
||||
DGameWorld gameWorld = game.getWorld();
|
||||
GameRules rules = game.getRules();
|
||||
delete();
|
||||
|
||||
if (finished) {
|
||||
@ -485,11 +487,9 @@ public class DGamePlayer extends DInstancePlayer {
|
||||
dGroup.removePlayer(getPlayer(), message);
|
||||
}
|
||||
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(getWorld());
|
||||
Game game = Game.getByGameWorld(gameWorld);
|
||||
if (game != null) {
|
||||
if (finished) {
|
||||
if (game.getType().hasRewards()) {
|
||||
if (game.getType() == GameTypeDefault.CUSTOM || game.getType().hasRewards()) {
|
||||
for (Reward reward : rules.getRewards()) {
|
||||
reward.giveTo(getPlayer());
|
||||
}
|
||||
@ -497,7 +497,7 @@ public class DGamePlayer extends DInstancePlayer {
|
||||
getData().logTimeLastPlayed(getDGroup().getDungeon().getName());
|
||||
|
||||
// Tutorial Permissions
|
||||
if (gameWorld.isTutorial() && plugin.getPermissionProvider() != null && plugin.getPermissionProvider().hasGroupSupport()) {
|
||||
if (game.isTutorial() && plugin.getPermissionProvider().hasGroupSupport()) {
|
||||
String endGroup = plugin.getMainConfig().getTutorialEndGroup();
|
||||
if (plugin.isGroupEnabled(endGroup)) {
|
||||
plugin.getPermissionProvider().playerAddGroup(getPlayer(), endGroup);
|
||||
|
@ -23,13 +23,18 @@ import io.github.dre2n.commons.util.playerutil.PlayerUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.config.PlayerData;
|
||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent;
|
||||
import io.github.dre2n.dungeonsxl.game.Game;
|
||||
import io.github.dre2n.dungeonsxl.global.DPortal;
|
||||
import io.github.dre2n.dungeonsxl.world.DGameWorld;
|
||||
import io.github.dre2n.dungeonsxl.world.DResourceWorld;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* Represents a player in the non-DXL worlds of the server.
|
||||
@ -304,4 +309,51 @@ public class DGlobalPlayer {
|
||||
data.clearPlayerState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the tutorial
|
||||
*/
|
||||
public void startTutorial() {
|
||||
if (plugin.getPermissionProvider() == null || !plugin.getPermissionProvider().hasGroupSupport()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String startGroup = plugin.getMainConfig().getTutorialStartGroup();
|
||||
if ((plugin.getMainConfig().getTutorialDungeon() == null || startGroup == null)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.isGroupEnabled(startGroup)) {
|
||||
plugin.getPermissionProvider().playerAddGroup(player, startGroup);
|
||||
}
|
||||
|
||||
DGroup dGroup = new DGroup(player, plugin.getMainConfig().getTutorialDungeon(), false);
|
||||
|
||||
DGroupCreateEvent createEvent = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.GROUP_SIGN);
|
||||
plugin.getServer().getPluginManager().callEvent(createEvent);
|
||||
|
||||
if (createEvent.isCancelled()) {
|
||||
dGroup = null;
|
||||
}
|
||||
|
||||
if (dGroup == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DGameWorld gameWorld = null;
|
||||
|
||||
if (dGroup.getGameWorld() == null) {
|
||||
DResourceWorld resource = plugin.getDWorlds().getResourceByName(dGroup.getMapName());
|
||||
if (resource == null) {
|
||||
MessageUtil.sendMessage(player, DMessages.ERROR_TUTORIAL_NOT_EXIST.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
gameWorld = resource.instantiateAsGameWorld();
|
||||
dGroup.setGameWorld(gameWorld);
|
||||
}
|
||||
|
||||
new Game(dGroup, gameWorld).setTutorial(true);
|
||||
DGamePlayer.create(player, gameWorld);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -119,4 +119,28 @@ public class DPlayers {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an old DGamePlayer instance of the user exists.
|
||||
* If yes, the old Player of the user is replaced with the new object.
|
||||
*
|
||||
* @param player
|
||||
* the player to check
|
||||
* @return if the player exists
|
||||
*/
|
||||
public boolean checkPlayer(Player player) {
|
||||
DGamePlayer dPlayer = DGamePlayer.getByName(player.getName());
|
||||
if (dPlayer == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer());
|
||||
if (dGroup != null) {
|
||||
dGroup.removePlayer(dPlayer.getPlayer());
|
||||
dGroup.addPlayer(player);
|
||||
}
|
||||
dPlayer.setPlayer(player);
|
||||
dPlayer.setOfflineTime(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -73,7 +73,6 @@ public class DGameWorld extends DInstanceWorld {
|
||||
Game game;
|
||||
|
||||
// Variables
|
||||
private boolean tutorial;
|
||||
private boolean isPlaying = false;
|
||||
|
||||
// TO DO: Which lists actually need to be CopyOnWriteArrayLists?
|
||||
@ -117,21 +116,6 @@ public class DGameWorld extends DInstanceWorld {
|
||||
return game;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tutorial
|
||||
*/
|
||||
public boolean isTutorial() {
|
||||
return tutorial;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tutorial
|
||||
* if the DGameWorld is the tutorial
|
||||
*/
|
||||
public void setTutorial(boolean tutorial) {
|
||||
this.tutorial = tutorial;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the isPlaying
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user