2016-03-27 21:28:55 +02:00
|
|
|
/*
|
2022-01-08 23:02:57 +01:00
|
|
|
* Copyright (C) 2012-2022 Frank Baumann
|
2016-03-27 21:28:55 +02:00
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2018-05-03 21:54:25 +02:00
|
|
|
package de.erethon.dungeonsxl.player;
|
2016-03-27 21:28:55 +02:00
|
|
|
|
2018-05-03 21:54:25 +02:00
|
|
|
import de.erethon.dungeonsxl.DungeonsXL;
|
2020-04-11 02:02:42 +02:00
|
|
|
import de.erethon.dungeonsxl.api.Requirement;
|
|
|
|
import de.erethon.dungeonsxl.api.Reward;
|
2020-03-09 21:19:27 +01:00
|
|
|
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
2021-02-24 20:35:37 +01:00
|
|
|
import de.erethon.dungeonsxl.api.dungeon.Game;
|
2020-04-11 02:02:42 +02:00
|
|
|
import de.erethon.dungeonsxl.api.dungeon.GameRule;
|
|
|
|
import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer;
|
2021-02-27 22:37:39 +01:00
|
|
|
import de.erethon.dungeonsxl.api.event.group.GroupCreateEvent.Cause;
|
2020-04-13 20:51:15 +02:00
|
|
|
import de.erethon.dungeonsxl.api.event.requirement.RequirementCheckEvent;
|
2020-03-09 21:19:27 +01:00
|
|
|
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
|
|
|
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
|
|
|
import de.erethon.dungeonsxl.api.world.GameWorld;
|
2018-05-03 21:54:25 +02:00
|
|
|
import de.erethon.dungeonsxl.config.DMessage;
|
2020-03-09 21:19:27 +01:00
|
|
|
import de.erethon.dungeonsxl.dungeon.DGame;
|
2018-05-03 21:54:25 +02:00
|
|
|
import de.erethon.dungeonsxl.global.DPortal;
|
2020-04-16 22:01:55 +02:00
|
|
|
import de.erethon.dungeonsxl.util.LocationString;
|
2022-04-03 18:09:12 +02:00
|
|
|
import de.erethon.bedrock.chat.MessageUtil;
|
|
|
|
import de.erethon.bedrock.compatibility.Version;
|
2016-05-18 19:24:45 +02:00
|
|
|
import java.io.File;
|
2020-04-11 02:02:42 +02:00
|
|
|
import java.util.ArrayList;
|
2017-10-05 13:21:20 +02:00
|
|
|
import java.util.List;
|
2017-09-21 18:15:49 +02:00
|
|
|
import java.util.UUID;
|
2020-04-13 20:51:15 +02:00
|
|
|
import net.md_5.bungee.api.chat.BaseComponent;
|
2016-07-26 19:47:55 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2018-06-20 21:48:03 +02:00
|
|
|
import org.bukkit.Location;
|
2018-04-27 01:13:47 +02:00
|
|
|
import org.bukkit.attribute.Attribute;
|
2020-10-28 18:46:55 +01:00
|
|
|
import org.bukkit.attribute.AttributeInstance;
|
|
|
|
import org.bukkit.attribute.AttributeModifier;
|
2016-03-27 21:28:55 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2016-04-06 22:05:03 +02:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2016-07-26 19:47:55 +02:00
|
|
|
import org.bukkit.potion.PotionEffect;
|
2018-06-20 21:48:03 +02:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
2016-03-27 21:28:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Daniel Saukel
|
|
|
|
*/
|
2020-03-09 21:19:27 +01:00
|
|
|
public class DGlobalPlayer implements GlobalPlayer {
|
2016-03-27 21:28:55 +02:00
|
|
|
|
2018-08-18 16:52:51 +02:00
|
|
|
protected DungeonsXL plugin;
|
2016-04-29 16:42:52 +02:00
|
|
|
|
2022-04-03 18:09:12 +02:00
|
|
|
protected boolean is1_9 = Version.isAtLeast(Version.MC1_9);
|
2018-04-28 02:50:38 +02:00
|
|
|
|
2016-03-27 21:28:55 +02:00
|
|
|
protected Player player;
|
|
|
|
|
2017-02-19 23:52:11 +01:00
|
|
|
private DPlayerData data;
|
2016-05-18 19:24:45 +02:00
|
|
|
|
2017-02-20 18:05:03 +01:00
|
|
|
private boolean breakMode = false;
|
|
|
|
private boolean groupChat = false;
|
|
|
|
private boolean chatSpyMode = false;
|
2016-03-27 21:28:55 +02:00
|
|
|
private DPortal creatingPortal;
|
2017-02-20 18:55:56 +01:00
|
|
|
private ItemStack cachedItem;
|
2016-06-06 15:19:15 +02:00
|
|
|
private boolean announcerEnabled = true;
|
2016-03-27 21:28:55 +02:00
|
|
|
|
2017-10-05 13:21:20 +02:00
|
|
|
private List<ItemStack> rewardItems;
|
2016-04-06 22:05:03 +02:00
|
|
|
|
2018-08-18 16:52:51 +02:00
|
|
|
public DGlobalPlayer(DungeonsXL plugin, Player player) {
|
|
|
|
this(plugin, player, false);
|
2016-07-26 19:47:55 +02:00
|
|
|
}
|
|
|
|
|
2018-08-18 16:52:51 +02:00
|
|
|
public DGlobalPlayer(DungeonsXL plugin, Player player, boolean reset) {
|
|
|
|
this.plugin = plugin;
|
|
|
|
|
2016-03-27 21:28:55 +02:00
|
|
|
this.player = player;
|
2016-07-26 19:47:55 +02:00
|
|
|
|
2016-05-18 19:24:45 +02:00
|
|
|
loadPlayerData(new File(DungeonsXL.PLAYERS, player.getUniqueId().toString() + ".yml"));
|
2016-07-26 19:47:55 +02:00
|
|
|
if (reset && data.wasInGame()) {
|
|
|
|
reset(false);
|
|
|
|
}
|
2016-03-27 21:28:55 +02:00
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
plugin.getPlayerCache().add(player, this);
|
2016-03-27 21:28:55 +02:00
|
|
|
}
|
|
|
|
|
2016-04-06 22:05:03 +02:00
|
|
|
public DGlobalPlayer(DGlobalPlayer dPlayer) {
|
2018-08-18 16:52:51 +02:00
|
|
|
plugin = dPlayer.plugin;
|
2016-04-06 22:05:03 +02:00
|
|
|
player = dPlayer.getPlayer();
|
2018-08-18 16:52:51 +02:00
|
|
|
data = dPlayer.getData();
|
2016-04-06 22:05:03 +02:00
|
|
|
breakMode = dPlayer.isInBreakMode();
|
|
|
|
chatSpyMode = dPlayer.isInChatSpyMode();
|
|
|
|
creatingPortal = dPlayer.getPortal();
|
2016-06-05 13:42:10 +02:00
|
|
|
announcerEnabled = dPlayer.isAnnouncerEnabled();
|
2016-04-06 22:05:03 +02:00
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
plugin.getPlayerCache().add(player, this);
|
2016-04-06 22:05:03 +02:00
|
|
|
}
|
|
|
|
|
2016-07-26 19:47:55 +02:00
|
|
|
/* Getters and setters */
|
2017-09-21 18:15:49 +02:00
|
|
|
@Override
|
2016-08-02 20:15:03 +02:00
|
|
|
public String getName() {
|
|
|
|
return player.getName();
|
|
|
|
}
|
|
|
|
|
2017-09-21 18:15:49 +02:00
|
|
|
@Override
|
2016-03-27 21:28:55 +02:00
|
|
|
public Player getPlayer() {
|
|
|
|
return player;
|
|
|
|
}
|
|
|
|
|
2017-09-21 18:15:49 +02:00
|
|
|
@Override
|
|
|
|
public UUID getUniqueId() {
|
|
|
|
return player.getUniqueId();
|
|
|
|
}
|
|
|
|
|
2016-05-18 19:24:45 +02:00
|
|
|
/**
|
2020-03-09 21:19:27 +01:00
|
|
|
* Returns the saved data.
|
|
|
|
*
|
2016-05-18 19:24:45 +02:00
|
|
|
* @return the saved data
|
|
|
|
*/
|
2017-02-19 23:52:11 +01:00
|
|
|
public DPlayerData getData() {
|
2016-05-18 19:24:45 +02:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-09 21:19:27 +01:00
|
|
|
* Load / reload a new instance of DPlayerData.
|
2018-07-28 21:15:58 +02:00
|
|
|
*
|
|
|
|
* @param file the file to load from
|
2016-05-18 19:24:45 +02:00
|
|
|
*/
|
|
|
|
public void loadPlayerData(File file) {
|
2017-02-19 23:52:11 +01:00
|
|
|
data = new DPlayerData(file);
|
2016-05-18 19:24:45 +02:00
|
|
|
}
|
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
|
|
|
public PlayerGroup getGroup() {
|
|
|
|
return plugin.getPlayerGroup(player);
|
2019-03-07 21:22:40 +01:00
|
|
|
}
|
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
2017-02-20 18:05:03 +01:00
|
|
|
public boolean isInGroupChat() {
|
2017-10-04 23:57:12 +02:00
|
|
|
if (!plugin.getMainConfig().isChatEnabled()) {
|
2017-02-20 18:05:03 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return groupChat;
|
|
|
|
}
|
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
2017-02-20 18:05:03 +01:00
|
|
|
public void setInGroupChat(boolean groupChat) {
|
|
|
|
this.groupChat = groupChat;
|
|
|
|
}
|
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
2016-03-27 21:28:55 +02:00
|
|
|
public boolean isInChatSpyMode() {
|
2017-10-04 23:57:12 +02:00
|
|
|
if (!plugin.getMainConfig().isChatEnabled()) {
|
2017-02-20 18:05:03 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-03-27 21:28:55 +02:00
|
|
|
return chatSpyMode;
|
|
|
|
}
|
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
2016-03-27 21:28:55 +02:00
|
|
|
public void setInChatSpyMode(boolean chatSpyMode) {
|
|
|
|
this.chatSpyMode = chatSpyMode;
|
|
|
|
}
|
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
|
|
|
public boolean isInBreakMode() {
|
|
|
|
return breakMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setInBreakMode(boolean breakMode) {
|
|
|
|
this.breakMode = breakMode;
|
|
|
|
}
|
|
|
|
|
2016-03-27 21:28:55 +02:00
|
|
|
/**
|
2020-03-09 21:19:27 +01:00
|
|
|
* Returns if the player is creating a DPortal.
|
|
|
|
*
|
2016-03-27 21:28:55 +02:00
|
|
|
* @return if the player is creating a DPortal
|
|
|
|
*/
|
|
|
|
public boolean isCreatingPortal() {
|
|
|
|
return creatingPortal != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-09 21:19:27 +01:00
|
|
|
* Returns the portal the player is creating.
|
|
|
|
*
|
2016-03-27 21:28:55 +02:00
|
|
|
* @return the portal the player is creating
|
|
|
|
*/
|
|
|
|
public DPortal getPortal() {
|
|
|
|
return creatingPortal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-09 21:19:27 +01:00
|
|
|
* Sets the portal the player is creating.
|
|
|
|
*
|
2018-07-28 21:15:58 +02:00
|
|
|
* @param dPortal the portal to create
|
2016-03-27 21:28:55 +02:00
|
|
|
*/
|
|
|
|
public void setCreatingPortal(DPortal dPortal) {
|
|
|
|
creatingPortal = dPortal;
|
|
|
|
}
|
|
|
|
|
2017-02-20 18:55:56 +01:00
|
|
|
/**
|
2020-03-09 21:19:27 +01:00
|
|
|
* Returns the item the player had in his hand before he started to create a portal.
|
|
|
|
*
|
2017-02-20 18:55:56 +01:00
|
|
|
* @return the item the player had in his hand before he started to create a portal
|
|
|
|
*/
|
|
|
|
public ItemStack getCachedItem() {
|
|
|
|
return cachedItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-09 21:19:27 +01:00
|
|
|
* Sets the cached item.
|
|
|
|
*
|
2018-07-28 21:15:58 +02:00
|
|
|
* @param item the cached item to set
|
2017-02-20 18:55:56 +01:00
|
|
|
*/
|
|
|
|
public void setCachedItem(ItemStack item) {
|
|
|
|
cachedItem = item;
|
|
|
|
}
|
|
|
|
|
2016-06-05 13:42:10 +02:00
|
|
|
/**
|
2020-03-09 21:19:27 +01:00
|
|
|
* Returns if the player has announcers enabled.
|
|
|
|
*
|
2016-06-05 13:42:10 +02:00
|
|
|
* @return if the players receives announcer messages
|
|
|
|
*/
|
|
|
|
public boolean isAnnouncerEnabled() {
|
|
|
|
return announcerEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-09 21:19:27 +01:00
|
|
|
* Sets if the player has announcers enabled.
|
|
|
|
*
|
2018-07-28 21:15:58 +02:00
|
|
|
* @param enabled set if the players receives announcer messages
|
2016-06-05 13:42:10 +02:00
|
|
|
*/
|
|
|
|
public void setAnnouncerEnabled(boolean enabled) {
|
|
|
|
announcerEnabled = enabled;
|
|
|
|
}
|
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
2017-10-05 13:21:20 +02:00
|
|
|
public List<ItemStack> getRewardItems() {
|
2016-08-02 23:58:22 +02:00
|
|
|
return rewardItems;
|
|
|
|
}
|
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
2016-08-02 23:58:22 +02:00
|
|
|
public boolean hasRewardItemsLeft() {
|
|
|
|
return rewardItems != null;
|
|
|
|
}
|
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
2017-10-05 13:21:20 +02:00
|
|
|
public void setRewardItems(List<ItemStack> rewardItems) {
|
2016-08-02 23:58:22 +02:00
|
|
|
this.rewardItems = rewardItems;
|
|
|
|
}
|
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
2016-04-29 16:42:52 +02:00
|
|
|
public boolean hasPermission(String permission) {
|
2020-10-24 15:36:05 +02:00
|
|
|
return player.hasPermission(permission);
|
2016-04-29 16:42:52 +02:00
|
|
|
}
|
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
public boolean hasPermission(DPermission permission) {
|
|
|
|
return DPermission.hasPermission(player, permission);
|
|
|
|
}
|
|
|
|
|
2020-04-13 20:51:15 +02:00
|
|
|
@Override
|
2020-04-11 02:02:42 +02:00
|
|
|
public boolean checkRequirements(Dungeon dungeon) {
|
|
|
|
boolean fulfilled = true;
|
|
|
|
GameRuleContainer rules = dungeon.getRules();
|
|
|
|
|
2020-04-13 20:51:15 +02:00
|
|
|
List<BaseComponent[]> msgs = new ArrayList<>(rules.getState(GameRule.REQUIREMENTS).size());
|
2020-04-11 02:02:42 +02:00
|
|
|
for (Requirement requirement : rules.getState(GameRule.REQUIREMENTS)) {
|
2020-08-31 22:37:49 +02:00
|
|
|
if (requirement == null) {
|
|
|
|
MessageUtil.log(plugin, "The dungeon " + dungeon.getName() + " has an invalid requirement.");
|
|
|
|
continue;
|
|
|
|
}
|
2020-04-13 20:51:15 +02:00
|
|
|
RequirementCheckEvent event = new RequirementCheckEvent(requirement, dungeon, player, rules.getState(GameRule.KEEP_INVENTORY_ON_ENTER));
|
2020-04-11 02:02:42 +02:00
|
|
|
Bukkit.getPluginManager().callEvent(event);
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-04-13 20:51:15 +02:00
|
|
|
msgs.add(event.getCheckMessage());
|
2020-04-11 02:02:42 +02:00
|
|
|
if (!requirement.check(player)) {
|
|
|
|
fulfilled = false;
|
|
|
|
}
|
|
|
|
}
|
2021-08-12 08:13:16 +02:00
|
|
|
if (!fulfilled) {
|
2020-04-11 02:02:42 +02:00
|
|
|
MessageUtil.sendMessage(player, DMessage.ERROR_REQUIREMENTS.getMessage());
|
2022-04-03 18:09:12 +02:00
|
|
|
msgs.forEach(msg -> player.spigot().sendMessage(msg));
|
2020-04-11 02:02:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return fulfilled || DPermission.hasPermission(player, DPermission.IGNORE_REQUIREMENTS);
|
|
|
|
}
|
|
|
|
|
2020-04-25 21:49:44 +02:00
|
|
|
public void giveLoot(Dungeon dungeon, List<Reward> rewards) {
|
2020-04-11 02:02:42 +02:00
|
|
|
if (!canLoot(dungeon)) {
|
|
|
|
return;
|
|
|
|
}
|
2020-04-25 21:49:44 +02:00
|
|
|
rewards.forEach(r -> r.giveTo(player.getPlayer()));
|
2021-04-20 00:53:58 +02:00
|
|
|
if (dungeon != null) {
|
|
|
|
getData().logTimeLastLoot(dungeon.getName());
|
2020-04-11 02:02:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canLoot(Dungeon dungeon) {
|
|
|
|
return getTimeNextLoot(dungeon) <= getData().getTimeLastStarted(dungeon.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getTimeNextLoot(Dungeon dungeon) {
|
|
|
|
return dungeon.getRules().getState(GameRule.TIME_TO_NEXT_LOOT) * 60 * 60 * 1000 + getData().getTimeLastLoot(dungeon.getName());
|
|
|
|
}
|
|
|
|
|
2016-07-26 19:47:55 +02:00
|
|
|
/* Actions */
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
2017-02-20 18:05:03 +01:00
|
|
|
public void sendMessage(String message) {
|
|
|
|
MessageUtil.sendMessage(player, message);
|
|
|
|
}
|
|
|
|
|
2020-04-05 17:00:09 +02:00
|
|
|
public void heal() {
|
|
|
|
if (is1_9) {
|
|
|
|
player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
|
|
|
|
} else {
|
|
|
|
player.setHealth(player.getMaxHealth());
|
|
|
|
}
|
|
|
|
player.setFoodLevel(20);
|
|
|
|
player.setFireTicks(0);
|
|
|
|
for (PotionEffect effect : player.getActivePotionEffects()) {
|
|
|
|
player.removePotionEffect(effect.getType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
2020-04-16 22:01:55 +02:00
|
|
|
public void reset(boolean gameFinished) {
|
|
|
|
Location tpLoc;
|
|
|
|
boolean keepInventory;
|
|
|
|
if (getGroup() != null) {
|
|
|
|
Dungeon dungeon = getGroup().getDungeon();
|
|
|
|
GameRuleContainer rules = dungeon.getRules();
|
|
|
|
keepInventory = rules.getState(gameFinished ? GameRule.KEEP_INVENTORY_ON_FINISH : GameRule.KEEP_INVENTORY_ON_ESCAPE);
|
|
|
|
LocationString tpLocString = LocationString.fromString(rules.getState(gameFinished ? GameRule.FINISH_LOCATION : GameRule.ESCAPE_LOCATION));
|
|
|
|
if (tpLocString != null && tpLocString.getLocation() != null) {
|
|
|
|
tpLoc = tpLocString.getLocation();
|
|
|
|
} else {
|
|
|
|
if (data.getOldLocation().getWorld() != null) {
|
|
|
|
tpLoc = data.getOldLocation();
|
|
|
|
} else {
|
|
|
|
tpLoc = Bukkit.getWorlds().get(0).getSpawnLocation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (data.getOldLocation().getWorld() != null) {
|
|
|
|
tpLoc = data.getOldLocation();
|
|
|
|
} else {
|
|
|
|
tpLoc = Bukkit.getWorlds().get(0).getSpawnLocation();
|
|
|
|
}
|
|
|
|
keepInventory = false;
|
|
|
|
}
|
|
|
|
|
2018-06-20 21:48:03 +02:00
|
|
|
if (player.isDead()) {
|
|
|
|
new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2020-06-28 01:06:59 +02:00
|
|
|
player.spigot().respawn();
|
2018-06-20 21:48:03 +02:00
|
|
|
reset(tpLoc, keepInventory);
|
|
|
|
}
|
|
|
|
}.runTaskLater(plugin, 1L);
|
|
|
|
} else {
|
|
|
|
reset(tpLoc, keepInventory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-09 21:19:27 +01:00
|
|
|
@Override
|
|
|
|
public void reset(Location tpLoc, boolean keepInventory) {
|
2016-07-26 19:47:55 +02:00
|
|
|
try {
|
2020-06-28 01:06:59 +02:00
|
|
|
player.teleport(tpLoc);
|
2019-01-03 16:59:26 +01:00
|
|
|
player.setGameMode(data.getOldGameMode());
|
2016-07-26 19:47:55 +02:00
|
|
|
if (!keepInventory) {
|
|
|
|
while (data.getOldInventory().size() > 36) {
|
|
|
|
data.getOldInventory().remove(36);
|
|
|
|
}
|
|
|
|
player.getInventory().setContents(data.getOldInventory().toArray(new ItemStack[36]));
|
|
|
|
player.getInventory().setArmorContents(data.getOldArmor().toArray(new ItemStack[4]));
|
2018-04-28 02:50:38 +02:00
|
|
|
if (is1_9) {
|
2016-07-26 19:47:55 +02:00
|
|
|
player.getInventory().setItemInOffHand(data.getOldOffHand());
|
|
|
|
}
|
|
|
|
player.setLevel(data.getOldLevel());
|
|
|
|
player.setExp(data.getOldExp());
|
|
|
|
player.setFoodLevel(data.getOldFoodLevel());
|
|
|
|
player.setFireTicks(data.getOldFireTicks());
|
2020-10-28 18:46:55 +01:00
|
|
|
|
2016-07-26 19:47:55 +02:00
|
|
|
for (PotionEffect effect : player.getActivePotionEffects()) {
|
|
|
|
player.removePotionEffect(effect.getType());
|
|
|
|
}
|
|
|
|
player.addPotionEffects(data.getOldPotionEffects());
|
2018-08-11 18:30:59 +02:00
|
|
|
|
2019-02-17 16:47:39 +01:00
|
|
|
if (is1_9) {
|
|
|
|
player.setCollidable(data.getOldCollidabilityState());
|
|
|
|
player.setInvulnerable(data.getOldInvulnerabilityState());
|
2020-10-28 18:46:55 +01:00
|
|
|
for (Attribute attribute : Attribute.values()) {
|
|
|
|
AttributeInstance instance = player.getAttribute(attribute);
|
|
|
|
if (instance == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
instance.setBaseValue((double) data.getOldAttributeBases().get(attribute));
|
|
|
|
for (AttributeModifier mod : instance.getModifiers()) {
|
|
|
|
instance.removeModifier(mod);
|
|
|
|
}
|
|
|
|
for (/*AttributeModifier*/Object mod : data.getOldAttributeMods().get(attribute)) { // TODO Remove casts when 1.8 is dropped
|
|
|
|
instance.addModifier((AttributeModifier) mod);
|
|
|
|
}
|
|
|
|
}
|
2019-02-17 16:47:39 +01:00
|
|
|
}
|
|
|
|
player.setAllowFlight(data.getOldFlyingState());
|
|
|
|
|
2018-08-11 18:30:59 +02:00
|
|
|
} else {
|
2018-10-11 22:18:14 +02:00
|
|
|
for (ItemStack item : player.getInventory().getContents()) {
|
2018-08-11 18:30:59 +02:00
|
|
|
if (item == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-07-04 16:52:10 +02:00
|
|
|
if (plugin.isDungeonItem(item)) {
|
2018-08-11 18:30:59 +02:00
|
|
|
item.setAmount(0);
|
|
|
|
}
|
|
|
|
}
|
2016-07-26 19:47:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} catch (NullPointerException exception) {
|
|
|
|
exception.printStackTrace();
|
|
|
|
player.setHealth(0);
|
2020-02-02 03:03:29 +01:00
|
|
|
MessageUtil.log(plugin, "&4Killed player &6" + player.getName() + "&4 because the data to restore his main inventory is corrupted :(");
|
2016-07-26 19:47:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
data.clearPlayerState();
|
|
|
|
}
|
|
|
|
|
2016-08-25 15:48:13 +02:00
|
|
|
/**
|
|
|
|
* Starts the tutorial
|
|
|
|
*/
|
|
|
|
public void startTutorial() {
|
2018-08-10 19:51:54 +02:00
|
|
|
Dungeon dungeon = plugin.getMainConfig().getTutorialDungeon();
|
|
|
|
if (dungeon == null) {
|
2020-02-02 03:03:29 +01:00
|
|
|
MessageUtil.sendMessage(player, DMessage.ERROR_TUTORIAL_DOES_NOT_EXIST.getMessage());
|
2016-08-25 15:48:13 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-10 19:51:54 +02:00
|
|
|
if (plugin.getPermissionProvider() != null && plugin.getPermissionProvider().hasGroupSupport()) {
|
|
|
|
String startGroup = plugin.getMainConfig().getTutorialStartGroup();
|
|
|
|
if (startGroup == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (plugin.isGroupEnabled(startGroup)) {
|
|
|
|
plugin.getPermissionProvider().playerAddGroup(player, startGroup);
|
|
|
|
}
|
2016-08-25 15:48:13 +02:00
|
|
|
}
|
|
|
|
|
2021-02-27 22:37:39 +01:00
|
|
|
DGroup dGroup = DGroup.create(plugin, Cause.TUTORIAL, player, null, null, dungeon);
|
|
|
|
if (dGroup == null) {
|
2016-08-25 15:48:13 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-24 20:35:37 +01:00
|
|
|
Game game = new DGame(plugin, dungeon, dGroup);
|
|
|
|
game.setTutorial(true);
|
|
|
|
GameWorld gameWorld = game.ensureWorldIsLoaded(true);
|
2018-08-18 16:52:51 +02:00
|
|
|
new DGamePlayer(plugin, player, gameWorld);
|
2016-08-25 15:48:13 +02:00
|
|
|
}
|
|
|
|
|
2018-08-15 23:57:21 +02:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return getClass().getSimpleName() + "{player=" + player + "}";
|
|
|
|
}
|
|
|
|
|
2016-03-27 21:28:55 +02:00
|
|
|
}
|