mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-06-26 06:44:53 +02:00
Implement all API except for new sign system
This commit is contained in:
parent
3ed42af0d1
commit
ba42e435ac
|
@ -21,8 +21,8 @@ import de.erethon.dungeonsxl.api.dungeon.Game;
|
|||
import de.erethon.dungeonsxl.api.dungeon.GameRule;
|
||||
import de.erethon.dungeonsxl.api.mob.DungeonMob;
|
||||
import de.erethon.dungeonsxl.api.mob.ExternalMobProvider;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.GroupAdapter;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerCache;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerClass;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.api.sign.DungeonSign;
|
||||
|
@ -32,7 +32,6 @@ import de.erethon.dungeonsxl.api.world.InstanceWorld;
|
|||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -59,7 +58,14 @@ public interface DungeonsAPI extends Plugin {
|
|||
*
|
||||
* @return a cache of player wrapper objects
|
||||
*/
|
||||
Registry<UUID, GlobalPlayer> getPlayerCache();
|
||||
PlayerCache getPlayerCache();
|
||||
|
||||
/**
|
||||
* Returns a cache of Game objects.
|
||||
*
|
||||
* @return a cache of Game objects
|
||||
*/
|
||||
Collection<Game> getGameCache();
|
||||
|
||||
/**
|
||||
* Returns a registry of the loaded classes.
|
||||
|
@ -75,15 +81,6 @@ public interface DungeonsAPI extends Plugin {
|
|||
*/
|
||||
Registry<String, Class<? extends DungeonSign>> getSignRegistry();
|
||||
|
||||
/**
|
||||
* Returns a registry of the trigger types.
|
||||
*
|
||||
* @return a registry of the trigger types
|
||||
* @deprecated stub
|
||||
*/
|
||||
@Deprecated
|
||||
Registry<String, Class<? extends Trigger>> getTriggerRegistry();
|
||||
|
||||
/**
|
||||
* Returns a registry of the requirement types.
|
||||
*
|
||||
|
@ -113,11 +110,11 @@ public interface DungeonsAPI extends Plugin {
|
|||
Registry<String, ResourceWorld> getMapRegistry();
|
||||
|
||||
/**
|
||||
* Returns a registry of the instance worlds.
|
||||
* Returns a cache of the instance worlds.
|
||||
*
|
||||
* @return a registry of the instance worlds
|
||||
* @return a cache of the instance worlds
|
||||
*/
|
||||
Registry<Integer, InstanceWorld> getInstanceRegistry();
|
||||
Registry<Integer, InstanceWorld> getInstanceCache();
|
||||
|
||||
/**
|
||||
* Returns a registry of the game rules.
|
||||
|
@ -133,6 +130,13 @@ public interface DungeonsAPI extends Plugin {
|
|||
*/
|
||||
Registry<String, ExternalMobProvider> getExternalMobProviderRegistry();
|
||||
|
||||
/**
|
||||
* Returns a cache of the player groups.
|
||||
*
|
||||
* @return a cache of the player groups
|
||||
*/
|
||||
Registry<String, PlayerGroup> getPlayerGroupCache();
|
||||
|
||||
/**
|
||||
* Makes DungeonsXL track external group and synchronize them with its own groups.
|
||||
*
|
||||
|
@ -187,15 +191,6 @@ public interface DungeonsAPI extends Plugin {
|
|||
*/
|
||||
PlayerGroup createGroup(Player leader, Collection<Player> members, String name, Dungeon dungeon);
|
||||
|
||||
/**
|
||||
* Wraps the given {@link LivingEntity} object in a {@link DungeonMob} object.
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param gameWorld the game world where the entity is
|
||||
* @return the wrapped DungeonMob
|
||||
*/
|
||||
DungeonMob wrapEntity(LivingEntity entity, GameWorld gameWorld);
|
||||
|
||||
/**
|
||||
* Wraps the given {@link LivingEntity} object in a {@link DungeonMob} object.
|
||||
*
|
||||
|
@ -237,12 +232,12 @@ public interface DungeonsAPI extends Plugin {
|
|||
DungeonMob getDungeonMob(LivingEntity entity);
|
||||
|
||||
/**
|
||||
* Returns the game the given group plays.
|
||||
* Returns the group the player is a member of or null if he is in none.
|
||||
*
|
||||
* @param group the group
|
||||
* @return the game the given group plays
|
||||
* @param member the player
|
||||
* @return the group the player is a member of or null if he is in none
|
||||
*/
|
||||
Game getGame(PlayerGroup group);
|
||||
PlayerGroup getPlayerGroup(Player member);
|
||||
|
||||
/**
|
||||
* Returns the game the given player plays.
|
||||
|
|
|
@ -14,11 +14,12 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.api.dungeon;
|
||||
|
||||
import de.erethon.commons.player.PlayerCollection;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Handles the rules of playing in a dungeon.
|
||||
|
@ -93,6 +94,20 @@ public interface Game {
|
|||
*/
|
||||
void setWorld(GameWorld gameWorld);
|
||||
|
||||
/**
|
||||
* Returns if the game has rewards.
|
||||
*
|
||||
* @return if the game has rewards
|
||||
*/
|
||||
boolean hasRewards();
|
||||
|
||||
/**
|
||||
* Sets if the game has rewards.
|
||||
*
|
||||
* @param enabled if the game has rewards
|
||||
*/
|
||||
void setRewards(boolean enabled);
|
||||
|
||||
/**
|
||||
* Returns the rules of the dungeon of this game.
|
||||
* <p>
|
||||
|
@ -130,7 +145,7 @@ public interface Game {
|
|||
*
|
||||
* @return the players playing the game
|
||||
*/
|
||||
PlayerCollection getPlayers();
|
||||
Collection<Player> getPlayers();
|
||||
|
||||
/**
|
||||
* Returns true if there are no groups in this game; false if not.
|
||||
|
|
|
@ -22,6 +22,7 @@ import de.erethon.commons.misc.EnumUtil;
|
|||
import de.erethon.dungeonsxl.api.DungeonsAPI;
|
||||
import de.erethon.dungeonsxl.api.Requirement;
|
||||
import de.erethon.dungeonsxl.api.Reward;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
@ -147,6 +148,10 @@ public class GameRule<V> {
|
|||
* The amount of goals to score before the game ends. -1 = not used.
|
||||
*/
|
||||
public static final GameRule<Integer> SCORE_GOAL = new GameRule<>(Integer.class, "scoreGoal", -1);
|
||||
/**
|
||||
* Maximum time in hours since the dungeons specified by other rules were finished. 0 = ignore.
|
||||
*/
|
||||
public static final GameRule<Integer> TIME_LAST_PLAYED_REQUIRED_DUNGEONS = new GameRule<>(Integer.class, "timeLastPlayedRequiredDungeons", 0);
|
||||
/**
|
||||
* Time in hours when the game may be played again after it has been started.
|
||||
*/
|
||||
|
@ -237,6 +242,28 @@ public class GameRule<V> {
|
|||
*/
|
||||
public static final GameRule<Boolean> GROUP_TAG_ENABLED = new GameRule<>(Boolean.class, "groupTagEnabled", false);
|
||||
|
||||
/**
|
||||
* An array of all game rules that exist natively in DungeonsXL.
|
||||
*/
|
||||
public static final GameRule[] VALUES = values();
|
||||
|
||||
private static GameRule[] values() {
|
||||
Field[] fields = GameRule.class.getFields();
|
||||
GameRule[] values = new GameRule[fields.length - 1];
|
||||
int i = 0;
|
||||
for (Field field : fields) {
|
||||
try {
|
||||
Object object = field.get(null);
|
||||
if (object instanceof GameRule) {
|
||||
values[i++] = (GameRule) object;
|
||||
}
|
||||
} catch (IllegalArgumentException | IllegalAccessException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
protected Class<V> type;
|
||||
private String key;
|
||||
private V defaultValue;
|
||||
|
@ -278,8 +305,7 @@ public class GameRule<V> {
|
|||
/**
|
||||
* Returns the state of the game rule fetched from the config.
|
||||
* <p>
|
||||
* If the type of this game rule is an enum, Strings as config values that are the {@link Enum#name()} of an enum value are converted
|
||||
* automatically.
|
||||
* If the type of this game rule is an enum, Strings as config values that are the {@link Enum#name()} of an enum value are converted automatically.
|
||||
*
|
||||
* @param api the API instance
|
||||
* @param caliburn the CaliburnAPI instance
|
||||
|
@ -297,7 +323,12 @@ public class GameRule<V> {
|
|||
value = EnumUtil.getEnumIgnoreCase((Class<? extends Enum>) type, (String) value);
|
||||
}
|
||||
|
||||
return isValidValue(value) ? (V) value : null;
|
||||
if (isValidValue(value)) {
|
||||
container.setState(this, (V) value);
|
||||
return (V) value;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,6 +24,32 @@ import java.util.Map;
|
|||
*/
|
||||
public class GameRuleContainer {
|
||||
|
||||
/**
|
||||
* A container of all rules with their default value. This is used internally as the most subsidiary container that fills missing rules if they are not set.
|
||||
*/
|
||||
public static final GameRuleContainer DEFAULT_VALUES = new GameRuleContainer();
|
||||
|
||||
static {
|
||||
for (GameRule rule : GameRule.VALUES) {
|
||||
DEFAULT_VALUES.setState(rule, rule.getDefaultValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes an emtpy GameRuleContainer.
|
||||
*/
|
||||
public GameRuleContainer() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a GameRuleContainer.
|
||||
*
|
||||
* @param container the container to copy
|
||||
*/
|
||||
public GameRuleContainer(GameRuleContainer container) {
|
||||
rules = new HashMap<>(container.rules);
|
||||
}
|
||||
|
||||
private Map<GameRule<?>, Object> rules = new HashMap<>();
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,7 +23,7 @@ import de.erethon.dungeonsxl.api.world.EditWorld;
|
|||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
// Implementation-specific methods: g/s lines copy, poke
|
||||
// Implementation-specific methods: poke
|
||||
public interface EditPlayer extends InstancePlayer {
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,7 +14,10 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.api.player;
|
||||
|
||||
import de.erethon.dungeonsxl.api.dungeon.Game;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Wolf;
|
||||
|
||||
/**
|
||||
* Represents a player in a game dungeon instance.
|
||||
|
@ -26,6 +29,24 @@ import org.bukkit.Location;
|
|||
// Implementation-specific methods: isInTestMode, setReady, [wolf, group tag, requirement, loot check methods], finishFloor
|
||||
public interface GamePlayer extends InstancePlayer {
|
||||
|
||||
/**
|
||||
* Returns the game the player's group plays.
|
||||
*
|
||||
* @return the game the player's group plays
|
||||
*/
|
||||
default Game getGame() {
|
||||
return getGroup().getGame();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the game world of the player's group.
|
||||
*
|
||||
* @return the game world of the player's group
|
||||
*/
|
||||
default GameWorld getGameWorld() {
|
||||
return getGroup().getGameWorld();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the player is ready to start the game.
|
||||
* <p>
|
||||
|
@ -127,6 +148,24 @@ public interface GamePlayer extends InstancePlayer {
|
|||
*/
|
||||
void setLives(int lives);
|
||||
|
||||
/**
|
||||
* Returns the player's wolf or null if he does not have one.
|
||||
*
|
||||
* @return the player's wolf or null if he does not have one
|
||||
* @deprecated More dynamic pet features might make this obsolete in the future.
|
||||
*/
|
||||
@Deprecated
|
||||
Wolf getWolf();
|
||||
|
||||
/**
|
||||
* Gives the player a wolf.
|
||||
*
|
||||
* @param wolf the wolf
|
||||
* @deprecated More dynamic pet features might make this obsolete in the future.
|
||||
*/
|
||||
@Deprecated
|
||||
void setWolf(Wolf wolf);
|
||||
|
||||
/**
|
||||
* Returns if the player is stealing another group's flag.
|
||||
*
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.bukkit.inventory.ItemStack;
|
|||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
// Implementation-specific methods: getters and setters: data, portal, cached item, announcer, reward items; startTutorial
|
||||
// Implementation-specific methods: getters and setters: data, portal, cached item, announcer; startTutorial
|
||||
public interface GlobalPlayer extends PlayerWrapper {
|
||||
|
||||
/**
|
||||
|
@ -74,23 +74,28 @@ public interface GlobalPlayer extends PlayerWrapper {
|
|||
* @param permission the permission
|
||||
* @return if the player has the given permission
|
||||
*/
|
||||
default boolean hasPermission(String permission) {
|
||||
return getPlayer().hasPermission(permission);
|
||||
}
|
||||
boolean hasPermission(String permission);
|
||||
|
||||
/**
|
||||
* Returns the reward items a player collected in a dungeon game.
|
||||
* Returns the reward items the player gets after leaving the dungeon.
|
||||
*
|
||||
* @return the reward items a player collected in a dungeon game
|
||||
* @return the reward items the player gets after leaving the dungeon
|
||||
*/
|
||||
public List<ItemStack> getRewardItems();
|
||||
List<ItemStack> getRewardItems();
|
||||
|
||||
/**
|
||||
* Sets the reward items the player gets after leaving the dungeon.
|
||||
*
|
||||
* @param rewardItems the reward items the player gets after leaving the dungeon
|
||||
*/
|
||||
void setRewardItems(List<ItemStack> rewardItems);
|
||||
|
||||
/**
|
||||
* Returns if the player has any reward items left.
|
||||
*
|
||||
* @return if the player has any reward items left
|
||||
*/
|
||||
public boolean hasRewardItemsLeft();
|
||||
boolean hasRewardItemsLeft();
|
||||
|
||||
/**
|
||||
* Returns if the player is currently breaking a global protection (=using /dxl break).
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.api.player;
|
||||
|
||||
import de.erethon.dungeonsxl.api.world.InstanceWorld;
|
||||
import org.bukkit.World;
|
||||
|
||||
/**
|
||||
|
@ -33,6 +34,13 @@ public interface InstancePlayer extends GlobalPlayer {
|
|||
*/
|
||||
World getWorld();
|
||||
|
||||
/**
|
||||
* The world of the instance, where the player is supposed to be.
|
||||
*
|
||||
* @return the instance world
|
||||
*/
|
||||
InstanceWorld getInstanceWorld();
|
||||
|
||||
/**
|
||||
* Makes the player leave his group and dungeon.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,204 @@
|
|||
/*
|
||||
* Copyright (C) 2014-2020 Daniel Saukel
|
||||
*
|
||||
* This library is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser 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 GNULesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.api.player;
|
||||
|
||||
import de.erethon.commons.misc.Registry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class PlayerCache extends Registry<Player, GlobalPlayer> {
|
||||
|
||||
public GlobalPlayer get(UUID uuid) {
|
||||
return getFirstIf(p -> p.getUniqueId().equals(uuid));
|
||||
}
|
||||
|
||||
public InstancePlayer getInstancePlayer(Player player) {
|
||||
return getFirstInstancePlayerIf(p -> p.getPlayer() == player);
|
||||
}
|
||||
|
||||
public EditPlayer getEditPlayer(Player player) {
|
||||
return getFirstEditPlayerIf(p -> p.getPlayer() == player);
|
||||
}
|
||||
|
||||
public GamePlayer getGamePlayer(Player player) {
|
||||
return getFirstGamePlayerIf(p -> p.getPlayer() == player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first InstancePlayer that satisfies the given predicate.
|
||||
*
|
||||
* @param predicate the predicate to check
|
||||
* @return the first InstancePlayer that satisfies the given predicate
|
||||
*/
|
||||
public InstancePlayer getFirstInstancePlayerIf(Predicate<InstancePlayer> predicate) {
|
||||
for (GlobalPlayer element : elements.values()) {
|
||||
if (!(element instanceof InstancePlayer)) {
|
||||
continue;
|
||||
}
|
||||
InstancePlayer instancePlayer = (InstancePlayer) element;
|
||||
if (predicate.test(instancePlayer)) {
|
||||
return instancePlayer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first EditPlayer that satisfies the given predicate.
|
||||
*
|
||||
* @param predicate the predicate to check
|
||||
* @return the first EditPlayer that satisfies the given predicate
|
||||
*/
|
||||
public EditPlayer getFirstEditPlayerIf(Predicate<EditPlayer> predicate) {
|
||||
for (GlobalPlayer element : elements.values()) {
|
||||
if (!(element instanceof EditPlayer)) {
|
||||
continue;
|
||||
}
|
||||
EditPlayer editPlayer = (EditPlayer) element;
|
||||
if (predicate.test(editPlayer)) {
|
||||
return editPlayer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first GamePlayer that satisfies the given predicate.
|
||||
*
|
||||
* @param predicate the predicate to check
|
||||
* @return the first GamePlayer that satisfies the given predicate
|
||||
*/
|
||||
public GamePlayer getFirstGamePlayerIf(Predicate<GamePlayer> predicate) {
|
||||
for (GlobalPlayer element : elements.values()) {
|
||||
if (!(element instanceof GamePlayer)) {
|
||||
continue;
|
||||
}
|
||||
GamePlayer gamePlayer = (GamePlayer) element;
|
||||
if (predicate.test(gamePlayer)) {
|
||||
return gamePlayer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all InstancePlayers that satisfy the given predicate.
|
||||
*
|
||||
* @param predicate the predicate to check
|
||||
* @return all InstancePlayers that satisfy the given predicate
|
||||
*/
|
||||
public Collection<InstancePlayer> getAllInstancePlayersIf(Predicate<InstancePlayer> predicate) {
|
||||
Collection<InstancePlayer> checked = new ArrayList<>();
|
||||
for (GlobalPlayer element : elements.values()) {
|
||||
if (!(element instanceof InstancePlayer)) {
|
||||
continue;
|
||||
}
|
||||
InstancePlayer instancePlayer = (InstancePlayer) element;
|
||||
if (predicate.test(instancePlayer)) {
|
||||
checked.add(instancePlayer);
|
||||
}
|
||||
}
|
||||
return checked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all EditPlayer that satisfy the given predicate.
|
||||
*
|
||||
* @param predicate the predicate to check
|
||||
* @return all EditPlayer that satisfy the given predicate
|
||||
*/
|
||||
public Collection<EditPlayer> getAllEditPlayersIf(Predicate<EditPlayer> predicate) {
|
||||
Collection<EditPlayer> checked = new ArrayList<>();
|
||||
for (GlobalPlayer element : elements.values()) {
|
||||
if (!(element instanceof EditPlayer)) {
|
||||
continue;
|
||||
}
|
||||
EditPlayer editPlayer = (EditPlayer) element;
|
||||
if (predicate.test(editPlayer)) {
|
||||
checked.add(editPlayer);
|
||||
}
|
||||
}
|
||||
return checked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all GamePlayer that satisfy the given predicate.
|
||||
*
|
||||
* @param predicate the predicate to check
|
||||
* @return all GamePlayer that satisfy the given predicate
|
||||
*/
|
||||
public Collection<GamePlayer> getAllGamePlayersIf(Predicate<GamePlayer> predicate) {
|
||||
Collection<GamePlayer> checked = new ArrayList<>();
|
||||
for (GlobalPlayer element : elements.values()) {
|
||||
GamePlayer gamePlayer = (GamePlayer) element;
|
||||
if (predicate.test(gamePlayer)) {
|
||||
checked.add(gamePlayer);
|
||||
}
|
||||
}
|
||||
return checked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all InstancePlayers.
|
||||
*
|
||||
* @return all InstancePlayers
|
||||
*/
|
||||
public Collection<InstancePlayer> getAllInstancePlayers() {
|
||||
Collection<InstancePlayer> checked = new ArrayList<>();
|
||||
for (GlobalPlayer element : elements.values()) {
|
||||
if (element instanceof InstancePlayer) {
|
||||
checked.add((InstancePlayer) element);
|
||||
}
|
||||
}
|
||||
return checked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all EditPlayers.
|
||||
*
|
||||
* @return all EditPlayers
|
||||
*/
|
||||
public Collection<EditPlayer> getAllEditPlayers() {
|
||||
Collection<EditPlayer> checked = new ArrayList<>();
|
||||
for (GlobalPlayer element : elements.values()) {
|
||||
if (element instanceof EditPlayer) {
|
||||
checked.add((EditPlayer) element);
|
||||
}
|
||||
}
|
||||
return checked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all GamePlayers.
|
||||
*
|
||||
* @return all GamePlayers
|
||||
*/
|
||||
public Collection<GamePlayer> getAllGamePlayers() {
|
||||
Collection<GamePlayer> checked = new ArrayList<>();
|
||||
for (GlobalPlayer element : elements.values()) {
|
||||
if (element instanceof GamePlayer) {
|
||||
checked.add((GamePlayer) element);
|
||||
}
|
||||
}
|
||||
return checked;
|
||||
}
|
||||
|
||||
}
|
|
@ -25,7 +25,7 @@ import org.bukkit.inventory.ItemStack;
|
|||
/**
|
||||
* Represents a class and a class script.
|
||||
*
|
||||
* @author Frank Baumann, Daniel Saukel
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class PlayerClass {
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import de.erethon.commons.compatibility.Version;
|
|||
import de.erethon.commons.player.PlayerCollection;
|
||||
import de.erethon.dungeonsxl.api.Reward;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Game;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -281,6 +282,15 @@ public interface PlayerGroup {
|
|||
*/
|
||||
void clearOfflineInvitedPlayers();
|
||||
|
||||
/**
|
||||
* Returns the game of the game world the group is in.
|
||||
*
|
||||
* @return the game of the game world the group is in.
|
||||
*/
|
||||
default Game getGame() {
|
||||
return getGameWorld() != null ? getGameWorld().getGame() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the game world the group is in.
|
||||
*
|
||||
|
|
|
@ -16,7 +16,9 @@ package de.erethon.dungeonsxl.api.world;
|
|||
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Game;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer;
|
||||
import de.erethon.dungeonsxl.api.mob.DungeonMob;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import java.util.Collection;
|
||||
import org.bukkit.Location;
|
||||
|
||||
|
@ -98,8 +100,9 @@ public interface GameWorld extends InstanceWorld {
|
|||
* Returns the start location of the world. This may be set by a start {@link de.erethon.dungeonsxl.api.sign.DungeonSign sign} or, if none exists, the
|
||||
* Vanilla spawn location of the {@link #getWorld() world}.
|
||||
*
|
||||
* @param group each group might have its own start location
|
||||
* @return the start location of the world
|
||||
*/
|
||||
Location getStartLocation();
|
||||
Location getStartLocation(PlayerGroup group);
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.io.File;
|
|||
import java.util.Collection;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
/**
|
||||
* Super interface for worlds that are instantiated by DungeonsXL.
|
||||
|
@ -83,12 +84,27 @@ public interface InstanceWorld {
|
|||
void addDungeonSign(DungeonSign sign);
|
||||
|
||||
/**
|
||||
* Removes a dungeon sign from this instance.
|
||||
* Removes the given dungeon sign from this instance.
|
||||
*
|
||||
* @param sign the sign
|
||||
*/
|
||||
void removeDungeonSign(DungeonSign sign);
|
||||
|
||||
/**
|
||||
* Removes the dungeon sign represented by the given sign block from this instance.
|
||||
*
|
||||
* @param sign the sign block
|
||||
*/
|
||||
void removeDungeonSign(Block sign);
|
||||
|
||||
/**
|
||||
* Returns the DungeonSign represented by the given sign block.
|
||||
*
|
||||
* @param sign the sign block
|
||||
* @return the DungeonSign represented by the given sign block
|
||||
*/
|
||||
DungeonSign getDungeonSign(Block sign);
|
||||
|
||||
/**
|
||||
* Returns the location of the lobby where players spawn by default when they are teleported into the dungeon.
|
||||
*
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package de.erethon.dungeonsxl.api.world;
|
||||
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer;
|
||||
import java.io.File;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World.Environment;
|
||||
|
@ -28,7 +29,7 @@ import org.bukkit.World.Environment;
|
|||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
// Implementation-specific methods: getConfig, getSignData, generate
|
||||
// Implementation-specific methods: getSignData, generate
|
||||
public interface ResourceWorld {
|
||||
|
||||
/**
|
||||
|
@ -54,6 +55,17 @@ public interface ResourceWorld {
|
|||
*/
|
||||
File getFolder();
|
||||
|
||||
/**
|
||||
* Returns the {@link de.erethon.dungeonsxl.api.dungeon.GameRule}s of this world.
|
||||
* <p>
|
||||
* Note that these are only the rules that are specific to the map itself. They are not the rules that are actually used in a game instance instantiated
|
||||
* from this resource world as these ones may be supplemented or overriden by other rules taken from the main config, dungeon config or the
|
||||
* {@link GameRuleContainer#DEFAULT_VALUES}.
|
||||
*
|
||||
* @return the {@link de.erethon.dungeonsxl.api.dungeon.GameRule}s of this world
|
||||
*/
|
||||
GameRuleContainer getRules();
|
||||
|
||||
/**
|
||||
* Returns the environment of the world as defined in the config or {@link org.bukkit.World.Environment#NORMAL} if nothing is set.
|
||||
*
|
||||
|
@ -68,6 +80,14 @@ public interface ResourceWorld {
|
|||
*/
|
||||
void addInvitedPlayer(OfflinePlayer player);
|
||||
|
||||
/**
|
||||
* Removes a player from the list of players that are invited to edit the resource.
|
||||
*
|
||||
* @param player the player
|
||||
* @return if the action was successful
|
||||
*/
|
||||
boolean removeInvitedPlayer(OfflinePlayer player);
|
||||
|
||||
/**
|
||||
* Returns if the player is invited to edit the resource.
|
||||
*
|
||||
|
@ -81,19 +101,28 @@ public interface ResourceWorld {
|
|||
*/
|
||||
void backup();
|
||||
|
||||
/**
|
||||
* Returns the loaded edit instance of this world or null if none exists.
|
||||
*
|
||||
* @return the loaded edit instance of this world or null if none exists
|
||||
*/
|
||||
EditWorld getEditWorld();
|
||||
|
||||
/**
|
||||
* Returns the loaded edit instance of this world or generates a new one if none exists.
|
||||
*
|
||||
* @param ignoreLimit if the instance limit set in the main config shall be ignored
|
||||
* @return the loaded edit instance of this world or generates a new one if none exists
|
||||
*/
|
||||
EditWorld getOrInstantiateEditWorld();
|
||||
EditWorld getOrInstantiateEditWorld(boolean ignoreLimit);
|
||||
|
||||
/**
|
||||
* Returns a new game instance of this resource.
|
||||
*
|
||||
* @param ignoreLimit if the instance limit set in the main config shall be ignored
|
||||
* @return a new game instance of this resource
|
||||
*/
|
||||
GameWorld instantiateGameWorld();
|
||||
GameWorld instantiateGameWorld(boolean ignoreLimit);
|
||||
|
||||
/**
|
||||
* Returns the single floor dungeon of this resource.
|
||||
|
|
|
@ -18,56 +18,87 @@ package de.erethon.dungeonsxl;
|
|||
|
||||
import de.erethon.caliburn.CaliburnAPI;
|
||||
import de.erethon.caliburn.loottable.LootTable;
|
||||
import de.erethon.caliburn.mob.ExMob;
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.commons.compatibility.Internals;
|
||||
import de.erethon.commons.compatibility.Version;
|
||||
import de.erethon.commons.javaplugin.DREPlugin;
|
||||
import de.erethon.commons.javaplugin.DREPluginSettings;
|
||||
import de.erethon.commons.misc.FileUtil;
|
||||
import de.erethon.commons.misc.Registry;
|
||||
import de.erethon.commons.spiget.comparator.VersionComparator;
|
||||
import de.erethon.dungeonsxl.adapter.block.BlockAdapter;
|
||||
import de.erethon.dungeonsxl.adapter.block.BlockAdapterBlockData;
|
||||
import de.erethon.dungeonsxl.adapter.block.BlockAdapterMagicValues;
|
||||
import de.erethon.dungeonsxl.announcer.AnnouncerCache;
|
||||
import de.erethon.dungeonsxl.api.DungeonsAPI;
|
||||
import de.erethon.dungeonsxl.api.Requirement;
|
||||
import de.erethon.dungeonsxl.api.Reward;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Game;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRule;
|
||||
import de.erethon.dungeonsxl.api.mob.DungeonMob;
|
||||
import de.erethon.dungeonsxl.api.mob.ExternalMobProvider;
|
||||
import de.erethon.dungeonsxl.api.player.GroupAdapter;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerCache;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerClass;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.api.sign.DungeonSign;
|
||||
import de.erethon.dungeonsxl.api.world.EditWorld;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import de.erethon.dungeonsxl.api.world.InstanceWorld;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import de.erethon.dungeonsxl.command.DCommandCache;
|
||||
import de.erethon.dungeonsxl.config.MainConfig;
|
||||
import de.erethon.dungeonsxl.dungeon.DungeonCache;
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import de.erethon.dungeonsxl.game.GameTypeCache;
|
||||
import de.erethon.dungeonsxl.config.MainConfig.BackupMode;
|
||||
import de.erethon.dungeonsxl.dungeon.DDungeon;
|
||||
import de.erethon.dungeonsxl.global.GlobalData;
|
||||
import de.erethon.dungeonsxl.global.GlobalProtectionCache;
|
||||
import de.erethon.dungeonsxl.global.GlobalProtectionListener;
|
||||
import de.erethon.dungeonsxl.mob.CitizensMobProvider;
|
||||
import de.erethon.dungeonsxl.mob.CustomExternalMobProvider;
|
||||
import de.erethon.dungeonsxl.mob.DMob;
|
||||
import de.erethon.dungeonsxl.mob.DMobListener;
|
||||
import de.erethon.dungeonsxl.mob.DMobType;
|
||||
import de.erethon.dungeonsxl.mob.ExternalMobProviderCache;
|
||||
import de.erethon.dungeonsxl.player.DClassCache;
|
||||
import de.erethon.dungeonsxl.mob.ExternalMobPlugin;
|
||||
import de.erethon.dungeonsxl.player.DGamePlayer;
|
||||
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.player.DPlayerCache;
|
||||
import de.erethon.dungeonsxl.requirement.RequirementTypeCache;
|
||||
import de.erethon.dungeonsxl.reward.RewardListener;
|
||||
import de.erethon.dungeonsxl.reward.RewardTypeCache;
|
||||
import de.erethon.dungeonsxl.sign.DSignTypeCache;
|
||||
import de.erethon.dungeonsxl.player.DPlayerListener;
|
||||
import de.erethon.dungeonsxl.player.SecureModeTask;
|
||||
import de.erethon.dungeonsxl.requirement.*;
|
||||
import de.erethon.dungeonsxl.reward.*;
|
||||
import de.erethon.dungeonsxl.sign.DSignListener;
|
||||
import de.erethon.dungeonsxl.sign.DSignTypeDefault;
|
||||
import de.erethon.dungeonsxl.sign.SignScriptCache;
|
||||
import de.erethon.dungeonsxl.trigger.TriggerListener;
|
||||
import de.erethon.dungeonsxl.trigger.TriggerTypeCache;
|
||||
import de.erethon.dungeonsxl.util.LWCUtil;
|
||||
import de.erethon.dungeonsxl.util.PlaceholderUtil;
|
||||
import de.erethon.dungeonsxl.world.DWorldCache;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import de.erethon.dungeonsxl.world.DWorldListener;
|
||||
import de.erethon.dungeonsxl.world.LWCIntegration;
|
||||
import de.erethon.dungeonsxl.world.WorldUnloadTask;
|
||||
import de.erethon.vignette.api.VignetteAPI;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* The main class of DungeonsXL. It contains several important instances and the actions when the plugin is enabled / disabled.
|
||||
*
|
||||
* @author Frank Baumann, Tobias Schmitz, Daniel Saukel
|
||||
*/
|
||||
public class DungeonsXL extends DREPlugin {
|
||||
public class DungeonsXL extends DREPlugin implements DungeonsAPI {
|
||||
|
||||
private static DungeonsXL instance;
|
||||
private CaliburnAPI caliburn;
|
||||
|
@ -75,16 +106,23 @@ public class DungeonsXL extends DREPlugin {
|
|||
public static final BlockAdapter BLOCK_ADAPTER = Version.isAtLeast(Version.MC1_13) ? new BlockAdapterBlockData() : new BlockAdapterMagicValues();
|
||||
|
||||
public static final String[] EXCLUDED_FILES = {"config.yml", "uid.dat", "DXLData.data", "data"};
|
||||
public static File BACKUPS;
|
||||
public static File MAPS;
|
||||
public static File PLAYERS;
|
||||
public static File SCRIPTS;
|
||||
public static File ANNOUNCERS;
|
||||
public static File CLASSES;
|
||||
public static File DUNGEONS;
|
||||
public static File LOOT_TABLES;
|
||||
public static File MOBS;
|
||||
public static File SIGNS;
|
||||
public static final File ANNOUNCERS = new File(SCRIPTS, "announcers");
|
||||
public static final File LOOT_TABLES = new File(SCRIPTS, "loottables");
|
||||
public static final File MOBS = new File(SCRIPTS, "mobs");
|
||||
public static final File SIGNS = new File(SCRIPTS, "signs");
|
||||
|
||||
private PlayerCache playerCache = new PlayerCache();
|
||||
private Collection<Game> gameCache = new ArrayList<>();
|
||||
private Registry<String, PlayerClass> classRegistry = new Registry<>();
|
||||
private Registry<String, Class<? extends DungeonSign>> signRegistry = new Registry<>();
|
||||
private Registry<String, Class<? extends Requirement>> requirementRegistry = new Registry<>();
|
||||
private Registry<String, Class<? extends Reward>> rewardRegistry = new Registry<>();
|
||||
private Registry<String, Dungeon> dungeonRegistry = new Registry<>();
|
||||
private Registry<String, ResourceWorld> mapRegistry = new Registry<>();
|
||||
private Registry<Integer, InstanceWorld> instanceCache = new Registry<>();
|
||||
private Registry<String, GameRule> gameRuleRegistry = new Registry<>();
|
||||
private Registry<String, ExternalMobProvider> externalMobProviderRegistry = new Registry<>();
|
||||
private Registry<String, PlayerGroup> playerGroupCache = new Registry<>();
|
||||
|
||||
private boolean loadingWorld;
|
||||
|
||||
|
@ -92,26 +130,14 @@ public class DungeonsXL extends DREPlugin {
|
|||
private MainConfig mainConfig;
|
||||
|
||||
private DCommandCache dCommands;
|
||||
private DSignTypeCache dSigns;
|
||||
private GameTypeCache gameTypes;
|
||||
private RequirementTypeCache requirementTypes;
|
||||
private RewardTypeCache rewardTypes;
|
||||
private TriggerTypeCache triggers;
|
||||
private DungeonCache dungeons;
|
||||
private GlobalProtectionCache protections;
|
||||
private ExternalMobProviderCache dMobProviders;
|
||||
private DPlayerCache dPlayers;
|
||||
private AnnouncerCache announcers;
|
||||
private DClassCache dClasses;
|
||||
private SignScriptCache signScripts;
|
||||
private DWorldCache dWorlds;
|
||||
|
||||
private CopyOnWriteArrayList<Game> games = new CopyOnWriteArrayList<>();
|
||||
private CopyOnWriteArrayList<DGroup> dGroups = new CopyOnWriteArrayList<>();
|
||||
|
||||
public DungeonsXL() {
|
||||
settings = DREPluginSettings.builder()
|
||||
.internals(Internals.andHigher(Internals.v1_8_R3))
|
||||
.internals(Internals.andHigher(Internals.v1_8_R1))
|
||||
.economy(true)
|
||||
.permissions(true)
|
||||
.metrics(true)
|
||||
|
@ -140,67 +166,25 @@ public class DungeonsXL extends DREPlugin {
|
|||
@Override
|
||||
public void onDisable() {
|
||||
saveData();
|
||||
dGroups.clear();
|
||||
dWorlds.deleteAllInstances();
|
||||
deleteAllInstances();
|
||||
HandlerList.unregisterAll(this);
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
}
|
||||
|
||||
// Init.
|
||||
public void initFolders() {
|
||||
if (!getDataFolder().exists()) {
|
||||
getDataFolder().mkdir();
|
||||
}
|
||||
|
||||
BACKUPS = new File(getDataFolder(), "backups");
|
||||
if (!BACKUPS.exists()) {
|
||||
BACKUPS.mkdir();
|
||||
}
|
||||
|
||||
MAPS = new File(getDataFolder(), "maps");
|
||||
if (!MAPS.exists()) {
|
||||
MAPS.mkdir();
|
||||
}
|
||||
|
||||
PLAYERS = new File(getDataFolder(), "players");
|
||||
if (!PLAYERS.exists()) {
|
||||
PLAYERS.mkdir();
|
||||
}
|
||||
|
||||
SCRIPTS = new File(getDataFolder(), "scripts");
|
||||
if (!SCRIPTS.exists()) {
|
||||
SCRIPTS.mkdir();
|
||||
}
|
||||
|
||||
ANNOUNCERS = new File(SCRIPTS, "announcers");
|
||||
if (!ANNOUNCERS.exists()) {
|
||||
ANNOUNCERS.mkdir();
|
||||
}
|
||||
|
||||
CLASSES = new File(SCRIPTS, "classes");
|
||||
if (!CLASSES.exists()) {
|
||||
CLASSES.mkdir();
|
||||
}
|
||||
|
||||
DUNGEONS = new File(SCRIPTS, "dungeons");
|
||||
if (!DUNGEONS.exists()) {
|
||||
DUNGEONS.mkdir();
|
||||
}
|
||||
|
||||
LOOT_TABLES = new File(SCRIPTS, "loottables");
|
||||
if (!LOOT_TABLES.exists()) {
|
||||
LOOT_TABLES.mkdir();
|
||||
}
|
||||
|
||||
MOBS = new File(SCRIPTS, "mobs");
|
||||
if (!MOBS.exists()) {
|
||||
MOBS.mkdir();
|
||||
}
|
||||
|
||||
SIGNS = new File(SCRIPTS, "signs");
|
||||
if (!SIGNS.exists()) {
|
||||
SIGNS.mkdir();
|
||||
}
|
||||
BACKUPS.mkdir();
|
||||
MAPS.mkdir();
|
||||
PLAYERS.mkdir();
|
||||
SCRIPTS.mkdir();
|
||||
ANNOUNCERS.mkdir();
|
||||
CLASSES.mkdir();
|
||||
DUNGEONS.mkdir();
|
||||
LOOT_TABLES.mkdir();
|
||||
MOBS.mkdir();
|
||||
SIGNS.mkdir();
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
|
@ -208,38 +192,112 @@ public class DungeonsXL extends DREPlugin {
|
|||
}
|
||||
|
||||
public void createCaches() {
|
||||
gameTypes = new GameTypeCache();
|
||||
requirementTypes = new RequirementTypeCache();
|
||||
rewardTypes = new RewardTypeCache();
|
||||
requirementRegistry.add("feeLevel", FeeLevelRequirement.class);
|
||||
requirementRegistry.add("feeMoney", FeeMoneyRequirement.class);
|
||||
requirementRegistry.add("forbiddenItems", ForbiddenItemsRequirement.class);
|
||||
requirementRegistry.add("groupSize", GroupSizeRequirement.class);
|
||||
requirementRegistry.add("keyItems", KeyItemsRequirement.class);
|
||||
requirementRegistry.add("permission", PermissionRequirement.class);
|
||||
|
||||
rewardRegistry.add("item", ItemReward.class);
|
||||
rewardRegistry.add("money", MoneyReward.class);
|
||||
rewardRegistry.add("level", LevelReward.class);
|
||||
|
||||
triggers = new TriggerTypeCache();
|
||||
dSigns = new DSignTypeCache(this);
|
||||
dWorlds = new DWorldCache(this);
|
||||
dungeons = new DungeonCache(this);
|
||||
protections = new GlobalProtectionCache(this);
|
||||
dMobProviders = new ExternalMobProviderCache(this);
|
||||
dPlayers = new DPlayerCache(this);
|
||||
announcers = new AnnouncerCache(this);
|
||||
dClasses = new DClassCache(this);
|
||||
signScripts = new SignScriptCache();
|
||||
dCommands = new DCommandCache(this);
|
||||
}
|
||||
|
||||
public void initCaches() {
|
||||
// Game types
|
||||
// Requirements
|
||||
Bukkit.getPluginManager().registerEvents(new RewardListener(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new TriggerListener(this), this);
|
||||
dSigns.init();
|
||||
dWorlds.init(MAPS);
|
||||
dungeons.init(DUNGEONS);
|
||||
|
||||
// Signs
|
||||
for (DSignTypeDefault sign : DSignTypeDefault.values()) {
|
||||
signRegistry.add(sign.getName(), sign.getHandler());
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvents(new DSignListener(this), this);
|
||||
|
||||
// Maps
|
||||
for (File file : MAPS.listFiles()) {
|
||||
if (file.isDirectory() && !file.getName().equals(".raw")) {
|
||||
mapRegistry.add(file.getName(), new DResourceWorld(this, file));
|
||||
}
|
||||
}
|
||||
if (!DResourceWorld.RAW.exists()) {
|
||||
DResourceWorld.createRaw();
|
||||
}
|
||||
new WorldUnloadTask(this).runTaskTimer(this, 20L, 20L);//1200L
|
||||
Bukkit.getPluginManager().registerEvents(new DWorldListener(this), this);
|
||||
if (LWCUtil.isLWCLoaded()) {
|
||||
new LWCIntegration(this);
|
||||
}
|
||||
|
||||
// Dungeons - Linked dungeons
|
||||
for (File file : DUNGEONS.listFiles()) {
|
||||
Dungeon dungeon = new DDungeon(this, file);
|
||||
|
||||
if (dungeon.isSetupCorrect()) {
|
||||
dungeonRegistry.add(dungeon.getName(), dungeon);
|
||||
} else {
|
||||
MessageUtil.log(this, "&4The setup of dungeon &6" + file.getName()
|
||||
+ "&4 is incorrect. See https://github.com/DRE2N/DungeonsXL/wiki/dungeon-configuration for reference.");
|
||||
}
|
||||
}
|
||||
// Dungeons - Map dungeons
|
||||
for (ResourceWorld resource : mapRegistry) {
|
||||
dungeonRegistry.add(resource.getName(), new DDungeon(this, resource));
|
||||
}
|
||||
|
||||
// Global
|
||||
Bukkit.getPluginManager().registerEvents(new GlobalProtectionListener(this), this);
|
||||
globalData = new GlobalData(this, new File(getDataFolder(), "data.yml"));
|
||||
globalData.load();
|
||||
dMobProviders.init();
|
||||
dPlayers.init();
|
||||
|
||||
// Mobs - Supported providers
|
||||
for (ExternalMobPlugin externalMobPlugin : ExternalMobPlugin.values()) {
|
||||
externalMobProviderRegistry.add(externalMobPlugin.getIdentifier(), externalMobPlugin);
|
||||
}
|
||||
if (Bukkit.getPluginManager().getPlugin("Citizens") != null) {
|
||||
CitizensMobProvider citizensMobProvider = new CitizensMobProvider();
|
||||
externalMobProviderRegistry.add("CI", citizensMobProvider);
|
||||
Bukkit.getPluginManager().registerEvents(citizensMobProvider, this);
|
||||
} else {
|
||||
MessageUtil.log(this, "Could not find compatible Citizens plugin. The mob provider Citizens (\"CI\") will not get enabled...");
|
||||
}
|
||||
// Mobs - Custom providers
|
||||
for (Entry<String, Object> customExternalMobProvider : mainConfig.getExternalMobProviders().entrySet()) {
|
||||
externalMobProviderRegistry.add(customExternalMobProvider.getKey(), new CustomExternalMobProvider(customExternalMobProvider));
|
||||
}
|
||||
|
||||
// Players
|
||||
if (mainConfig.isSecureModeEnabled()) {
|
||||
new SecureModeTask(this).runTaskTimer(this, mainConfig.getSecureModeCheckInterval(), mainConfig.getSecureModeCheckInterval());
|
||||
}
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
playerCache.getAllGamePlayers().forEach(p -> ((DGamePlayer) p).update(false));
|
||||
}
|
||||
}.runTaskTimer(this, 2L, 2L);
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
playerCache.getAllGamePlayers().forEach(p -> ((DGamePlayer) p).update(true));
|
||||
}
|
||||
}.runTaskTimer(this, 20L, 20L);
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new DPlayerListener(this), this);
|
||||
|
||||
announcers.init(ANNOUNCERS);
|
||||
dClasses.init(CLASSES);
|
||||
Bukkit.getPluginManager().registerEvents(new DMobListener(), this);
|
||||
for (File script : FileUtil.getFilesForFolder(CLASSES)) {
|
||||
PlayerClass clss = new PlayerClass(caliburn, script);
|
||||
classRegistry.add(clss.getName(), clss);
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvents(new DMobListener(this), this);
|
||||
signScripts.init(SIGNS);
|
||||
dCommands.register(this);
|
||||
}
|
||||
|
@ -247,12 +305,45 @@ public class DungeonsXL extends DREPlugin {
|
|||
// Save and load
|
||||
public void saveData() {
|
||||
protections.saveAll();
|
||||
dWorlds.saveAll();
|
||||
instanceCache.getAllIf(i -> i instanceof EditWorld).forEach(i -> ((EditWorld) i).save());
|
||||
}
|
||||
|
||||
public void loadData() {
|
||||
dPlayers.loadAll();
|
||||
dWorlds.check();
|
||||
Bukkit.getOnlinePlayers().forEach(p -> new DGlobalPlayer(this, p));
|
||||
|
||||
for (File file : Bukkit.getWorldContainer().listFiles()) {
|
||||
if (!file.getName().startsWith("DXL_") || !file.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (file.getName().startsWith("DXL_Edit_")) {
|
||||
for (File mapFile : file.listFiles()) {
|
||||
if (!mapFile.getName().startsWith(".id_")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = mapFile.getName().substring(4);
|
||||
|
||||
File resource = new File(DungeonsXL.MAPS, name);
|
||||
File backup = new File(DungeonsXL.BACKUPS, resource.getName() + "-" + System.currentTimeMillis() + "_crashbackup");
|
||||
FileUtil.copyDir(resource, backup);
|
||||
// Remove all files from the backupped resource world but not the config & data that we cannot fetch from the instance.
|
||||
remove:
|
||||
for (File remove : FileUtil.getFilesForFolder(resource)) {
|
||||
for (String nope : DungeonsXL.EXCLUDED_FILES) {
|
||||
if (remove.getName().equals(nope)) {
|
||||
continue remove;
|
||||
}
|
||||
}
|
||||
remove.delete();
|
||||
}
|
||||
DResourceWorld.deleteUnusedFiles(file);
|
||||
FileUtil.copyDir(file, resource, DungeonsXL.EXCLUDED_FILES);
|
||||
}
|
||||
}
|
||||
|
||||
FileUtil.removeDir(file);
|
||||
}
|
||||
}
|
||||
|
||||
/* Getters and loaders */
|
||||
|
@ -280,8 +371,74 @@ public class DungeonsXL extends DREPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerCache getPlayerCache() {
|
||||
return playerCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Game> getGameCache() {
|
||||
return gameCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<String, PlayerClass> getClassRegistry() {
|
||||
return classRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<String, Class<? extends DungeonSign>> getSignRegistry() {
|
||||
return signRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<String, Class<? extends Requirement>> getRequirementRegistry() {
|
||||
return requirementRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<String, Class<? extends Reward>> getRewardRegistry() {
|
||||
return rewardRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<String, Dungeon> getDungeonRegistry() {
|
||||
return dungeonRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<String, ResourceWorld> getMapRegistry() {
|
||||
return mapRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<Integer, InstanceWorld> getInstanceCache() {
|
||||
return instanceCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<String, GameRule> getGameRuleRegistry() {
|
||||
return gameRuleRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<String, ExternalMobProvider> getExternalMobProviderRegistry() {
|
||||
return externalMobProviderRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<String, PlayerGroup> getPlayerGroupCache() {
|
||||
return playerGroupCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerGroupAdapter(GroupAdapter groupAdapter) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the plugin is currently loading a world, false if not.<p>
|
||||
* Returns true if the plugin is currently loading a world, false if not.
|
||||
* <p>
|
||||
* If the plugin is loading a world, it is locked in order to prevent loading two at once.
|
||||
*
|
||||
* @return true if the plugin is currently loading a world, false if not
|
||||
|
@ -291,7 +448,8 @@ public class DungeonsXL extends DREPlugin {
|
|||
}
|
||||
|
||||
/**
|
||||
* Notifies the plugin that a world is being loaded.<p>
|
||||
* Notifies the plugin that a world is being loaded.
|
||||
* <p>
|
||||
* If the plugin is loading a world, it is locked in order to prevent loading two at once.
|
||||
*
|
||||
* @param loadingWorld if a world is being loaded
|
||||
|
@ -319,34 +477,6 @@ public class DungeonsXL extends DREPlugin {
|
|||
return mainConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dSigns
|
||||
*/
|
||||
public DSignTypeCache getDSignCache() {
|
||||
return dSigns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the game types
|
||||
*/
|
||||
public GameTypeCache getGameTypeCache() {
|
||||
return gameTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the requirement types
|
||||
*/
|
||||
public RequirementTypeCache getRequirementTypeCache() {
|
||||
return requirementTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the reward types
|
||||
*/
|
||||
public RewardTypeCache getRewardTypeCache() {
|
||||
return rewardTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the triggers
|
||||
*/
|
||||
|
@ -354,13 +484,6 @@ public class DungeonsXL extends DREPlugin {
|
|||
return triggers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of DungeonCache
|
||||
*/
|
||||
public DungeonCache getDungeonCache() {
|
||||
return dungeons;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of GlobalProtectionCache
|
||||
*/
|
||||
|
@ -368,20 +491,6 @@ public class DungeonsXL extends DREPlugin {
|
|||
return protections;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of ExternalMobProviderCache
|
||||
*/
|
||||
public ExternalMobProviderCache getExternalMobProviderCache() {
|
||||
return dMobProviders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of DPlayerCache
|
||||
*/
|
||||
public DPlayerCache getDPlayerCache() {
|
||||
return dPlayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of AnnouncerCache
|
||||
*/
|
||||
|
@ -389,13 +498,6 @@ public class DungeonsXL extends DREPlugin {
|
|||
return announcers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of DClassCache
|
||||
*/
|
||||
public DClassCache getDClassCache() {
|
||||
return dClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of SignScriptCache
|
||||
*/
|
||||
|
@ -403,27 +505,6 @@ public class DungeonsXL extends DREPlugin {
|
|||
return signScripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of DWorldCache
|
||||
*/
|
||||
public DWorldCache getDWorldCache() {
|
||||
return dWorlds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the games
|
||||
*/
|
||||
public List<Game> getGameCache() {
|
||||
return games;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dGroups
|
||||
*/
|
||||
public List<DGroup> getDGroupCache() {
|
||||
return dGroups;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private Set<Inventory> guis = new HashSet<>();
|
||||
|
||||
|
@ -432,4 +513,155 @@ public class DungeonsXL extends DREPlugin {
|
|||
return guis;
|
||||
}
|
||||
|
||||
/* Object initialization */
|
||||
@Override
|
||||
public PlayerGroup createGroup(Player leader) {
|
||||
return new DGroup(this, leader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerGroup createGroup(Player leader, PlayerGroup.Color color) {
|
||||
return new DGroup(this, leader, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerGroup createGroup(Player leader, String name) {
|
||||
return new DGroup(this, name, leader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerGroup createGroup(Player leader, Dungeon dungeon) {
|
||||
return new DGroup(this, leader, dungeon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerGroup createGroup(Player leader, Collection<Player> members, String name, Dungeon dungeon) {
|
||||
return new DGroup(this, name, leader, members, dungeon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DungeonMob wrapEntity(LivingEntity entity, GameWorld gameWorld, String triggerId) {
|
||||
DungeonMob mob = getDungeonMob(entity);
|
||||
if (mob != null) {
|
||||
return mob;
|
||||
} else {
|
||||
return new DMob(entity, gameWorld, triggerId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DungeonMob wrapEntity(LivingEntity entity, GameWorld gameWorld, ExMob type) {
|
||||
DungeonMob mob = getDungeonMob(entity);
|
||||
if (mob != null) {
|
||||
return mob;
|
||||
} else {
|
||||
return new DMob(entity, gameWorld, type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DungeonMob wrapEntity(LivingEntity entity, GameWorld gameWorld, ExMob type, String triggerId) {
|
||||
DungeonMob mob = getDungeonMob(entity);
|
||||
if (mob != null) {
|
||||
return mob;
|
||||
} else {
|
||||
return new DMob(entity, gameWorld, type, triggerId);
|
||||
}
|
||||
}
|
||||
|
||||
/* Getters */
|
||||
@Override
|
||||
public DungeonMob getDungeonMob(LivingEntity entity) {
|
||||
GameWorld gameWorld = getGameWorld(entity.getWorld());
|
||||
for (DungeonMob mob : gameWorld.getMobs()) {
|
||||
if (mob.getEntity() == entity) {
|
||||
return mob;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerGroup getPlayerGroup(Player member) {
|
||||
for (PlayerGroup group : playerGroupCache) {
|
||||
if (group.getMembers().contains(member)) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game getGame(Player player) {
|
||||
for (Game game : gameCache) {
|
||||
if (game.getPlayers().contains(player)) {
|
||||
return game;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Game getGame(World world) {
|
||||
GameWorld gameWorld = getGameWorld(world);
|
||||
return gameWorld != null ? gameWorld.getGame() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameWorld getGameWorld(World world) {
|
||||
InstanceWorld instance = getInstanceWorld(world);
|
||||
return instance instanceof GameWorld ? (GameWorld) instance : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditWorld getEditWorld(World world) {
|
||||
InstanceWorld instance = getInstanceWorld(world);
|
||||
return instance instanceof EditWorld ? (EditWorld) instance : null;
|
||||
}
|
||||
|
||||
public InstanceWorld getInstanceWorld(World world) {
|
||||
for (InstanceWorld instance : instanceCache) {
|
||||
if (instance.getWorld().equals(world)) {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInstance(World world) {
|
||||
return world.getName().startsWith("DXL_Game_") || world.getName().startsWith("DXL_Edit_");
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up all instances.
|
||||
*/
|
||||
public void deleteAllInstances() {
|
||||
BackupMode backupMode = mainConfig.getBackupMode();
|
||||
for (InstanceWorld instance : instanceCache.getAll()) {
|
||||
if (backupMode == BackupMode.ON_DISABLE | backupMode == BackupMode.ON_DISABLE_AND_SAVE && instance instanceof EditWorld) {
|
||||
instance.getResource().backup();
|
||||
}
|
||||
|
||||
instance.delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an old player wrapper 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) playerCache.getFirstGamePlayerIf(p -> p.getUniqueId().equals(player.getUniqueId()));
|
||||
if (dPlayer == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dPlayer.setPlayer(player);
|
||||
dPlayer.setOfflineTimeMillis(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,9 +19,9 @@ package de.erethon.dungeonsxl.announcer;
|
|||
import de.erethon.commons.chat.DefaultFontInfo;
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup.Color;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.event.dgroup.DGroupCreateEvent;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.util.GUIUtil;
|
||||
|
@ -96,9 +96,9 @@ public class Announcer {
|
|||
if (multiFloor) {
|
||||
dungeonName = identifier;
|
||||
|
||||
Dungeon dungeon = plugin.getDungeonCache().getByName(identifier);
|
||||
Dungeon dungeon = plugin.getDungeonRegistry().get(identifier);
|
||||
if (dungeon != null) {
|
||||
mapName = dungeon.getConfig().getStartFloor().getName();
|
||||
mapName = dungeon.getStartFloor().getName();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -130,9 +130,9 @@ public class Announcer {
|
|||
if (multiFloor) {
|
||||
dungeonName = identifier;
|
||||
|
||||
Dungeon dungeon = plugin.getDungeonCache().getByName(identifier);
|
||||
Dungeon dungeon = plugin.getDungeonRegistry().get(identifier);
|
||||
if (dungeon != null) {
|
||||
mapName = dungeon.getConfig().getStartFloor().getName();
|
||||
mapName = dungeon.getStartFloor().getName();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -291,7 +291,7 @@ public class Announcer {
|
|||
public boolean areRequirementsFulfilled() {
|
||||
int i = 0;
|
||||
for (DGroup group : dGroups) {
|
||||
if (group != null && group.getPlayers().size() >= minPlayersPerGroup) {
|
||||
if (group != null && group.getMembers().size() >= minPlayersPerGroup) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
@ -349,21 +349,21 @@ public class Announcer {
|
|||
*/
|
||||
public void clickGroupButton(Player player, ItemStack button) {
|
||||
DGroup dGroup = getDGroupByButton(button);
|
||||
DGroup pGroup = DGroup.getByPlayer(player);
|
||||
DGroup pGroup = (DGroup) plugin.getPlayerGroup(player);
|
||||
Color color = Color.getByWoolType(plugin.getCaliburn().getExItem(button));
|
||||
|
||||
for (DGroup group : dGroups) {
|
||||
if (dGroups.contains(pGroup) && pGroup != null && pGroup.isCustom() && pGroup.getCaptain() == player) {
|
||||
if (dGroups.contains(pGroup) && pGroup != null && pGroup.isCustom() && pGroup.getLeader() == player) {
|
||||
dGroups.set(dGroups.indexOf(pGroup), null);
|
||||
}
|
||||
|
||||
if (group != null && group.getPlayers().contains(player)) {
|
||||
if (group != null && group.getMembers().contains(player)) {
|
||||
group.removePlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (dGroup != null && pGroup == null) {
|
||||
if (dGroup.getPlayers().size() < maxPlayersPerGroup) {
|
||||
if (dGroup.getMembers().size() < maxPlayersPerGroup) {
|
||||
dGroup.addPlayer(player);
|
||||
}
|
||||
|
||||
|
@ -409,14 +409,14 @@ public class Announcer {
|
|||
List<String> lore = new ArrayList<>();
|
||||
|
||||
DGroup dGroup = dGroups.get(groupCount);
|
||||
if (!plugin.getDGroupCache().contains(dGroup)) {
|
||||
if (!plugin.getPlayerGroupCache().contains(dGroup)) {
|
||||
dGroups.set(groupCount, null);
|
||||
|
||||
} else if (dGroup != null) {
|
||||
name = ChatColor.AQUA + dGroup.getName();
|
||||
playerCount = dGroup.getPlayers().size();
|
||||
for (Player player : dGroup.getPlayers().getOnlinePlayers()) {
|
||||
lore.add((dGroup.getCaptain().equals(player) ? ChatColor.GOLD : ChatColor.GRAY) + player.getName());
|
||||
playerCount = dGroup.getMembers().size();
|
||||
for (Player player : dGroup.getMembers().getOnlinePlayers()) {
|
||||
lore.add((dGroup.getLeader().equals(player) ? ChatColor.GOLD : ChatColor.GRAY) + player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,13 +17,13 @@
|
|||
package de.erethon.dungeonsxl.announcer;
|
||||
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import de.erethon.dungeonsxl.dungeon.DGame;
|
||||
import de.erethon.dungeonsxl.player.DGamePlayer;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.util.ProgressBar;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import java.util.HashSet;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
@ -47,7 +47,7 @@ public class AnnouncerStartGameTask extends BukkitRunnable {
|
|||
if (dGroup == null) {
|
||||
continue;
|
||||
}
|
||||
for (Player player : dGroup.getPlayers().getOnlinePlayers()) {
|
||||
for (Player player : dGroup.getMembers().getOnlinePlayers()) {
|
||||
players.add(player);
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ public class AnnouncerStartGameTask extends BukkitRunnable {
|
|||
return;
|
||||
}
|
||||
|
||||
Game game = null;
|
||||
DGame game = null;
|
||||
|
||||
for (DGroup dGroup : announcer.getDGroups()) {
|
||||
if (dGroup == null) {
|
||||
|
@ -77,21 +77,21 @@ public class AnnouncerStartGameTask extends BukkitRunnable {
|
|||
}
|
||||
|
||||
if (game == null) {
|
||||
DResourceWorld resource = plugin.getDWorldCache().getResourceByName(announcer.getMapName());
|
||||
ResourceWorld resource = plugin.getMapRegistry().get(announcer.getMapName());
|
||||
if (resource == null) {
|
||||
dGroup.sendMessage(DMessage.ERROR_NO_SUCH_MAP.getMessage(announcer.getMapName()));
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
DGameWorld gameWorld = resource.instantiateAsGameWorld(false);
|
||||
GameWorld gameWorld = resource.instantiateGameWorld(false);
|
||||
if (gameWorld == null) {
|
||||
dGroup.sendMessage(DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
game = new Game(plugin, dGroup, gameWorld);
|
||||
game = new DGame(plugin, dGroup, gameWorld);
|
||||
} else {
|
||||
game.getDGroups().add(dGroup);
|
||||
game.addGroup(dGroup);
|
||||
}
|
||||
|
||||
dGroup.setDungeon(announcer.getDungeonName() == null ? announcer.getMapName() : announcer.getDungeonName());
|
||||
|
|
|
@ -46,7 +46,7 @@ public class AnnouncerTask extends BukkitRunnable {
|
|||
Announcer announcer = announcers.get(index);
|
||||
List<String> worlds = announcer.getWorlds();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
DGlobalPlayer dPlayer = plugin.getDPlayerCache().getByPlayer(player);
|
||||
DGlobalPlayer dPlayer = (DGlobalPlayer) plugin.getPlayerCache().get(player);
|
||||
if (!(dPlayer instanceof DInstancePlayer) && dPlayer.isAnnouncerEnabled()) {
|
||||
if (worlds.isEmpty() || worlds.contains(player.getWorld().getName())) {
|
||||
announcer.send(player);
|
||||
|
|
|
@ -18,8 +18,8 @@ package de.erethon.dungeonsxl.command;
|
|||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -42,7 +42,7 @@ public class BreakCommand extends DCommand {
|
|||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
DGlobalPlayer dGlobalPlayer = dPlayers.getByPlayer(player);
|
||||
GlobalPlayer dGlobalPlayer = dPlayers.get(player);
|
||||
|
||||
if (dGlobalPlayer.isInBreakMode()) {
|
||||
dGlobalPlayer.setInBreakMode(false);
|
||||
|
|
|
@ -18,10 +18,9 @@ package de.erethon.dungeonsxl.command;
|
|||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DEditPlayer;
|
||||
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -44,9 +43,9 @@ public class ChatCommand extends DCommand {
|
|||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
|
||||
GlobalPlayer dPlayer = dPlayers.get(player);
|
||||
|
||||
if (DGroup.getByPlayer(player) == null && !(dPlayer instanceof DEditPlayer)) {
|
||||
if (plugin.getPlayerGroup(player) == null && !(dPlayer instanceof DEditPlayer)) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_JOIN_GROUP.getMessage());
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ package de.erethon.dungeonsxl.command;
|
|||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -42,7 +42,7 @@ public class ChatSpyCommand extends DCommand {
|
|||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
|
||||
GlobalPlayer dPlayer = dPlayers.get(player);
|
||||
|
||||
dPlayer.setInChatSpyMode(!dPlayer.isInChatSpyMode());
|
||||
MessageUtil.sendMessage(player, (dPlayer.isInChatSpyMode() ? DMessage.CMD_CHATSPY_STARTED : DMessage.CMD_CHATSPY_STOPPED).getMessage());
|
||||
|
|
|
@ -19,8 +19,8 @@ package de.erethon.dungeonsxl.command;
|
|||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.dungeon.DDungeon;
|
||||
import de.erethon.dungeonsxl.player.DEditPlayer;
|
||||
import de.erethon.dungeonsxl.player.DGamePlayer;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.world.DEditWorld;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
|
@ -60,41 +60,35 @@ public class CreateCommand extends DCommand {
|
|||
}
|
||||
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
// Msg create
|
||||
MessageUtil.log(plugin, "&6Creating new map.");
|
||||
MessageUtil.log(plugin, "&6Generating new world...");
|
||||
|
||||
// Create World
|
||||
DResourceWorld resource = new DResourceWorld(plugin, name);
|
||||
instances.addResource(resource);
|
||||
plugin.getMapRegistry().add(name, resource);
|
||||
DEditWorld editWorld = resource.generate();
|
||||
editWorld.save();
|
||||
editWorld.delete();
|
||||
|
||||
// MSG Done
|
||||
MessageUtil.log(plugin, "&6World generation finished.");
|
||||
|
||||
} else if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (DGamePlayer.getByPlayer(player) != null) {
|
||||
if (dPlayers.getGamePlayer(player) != null) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
// Msg create
|
||||
MessageUtil.log(plugin, "&6Creating new map.");
|
||||
MessageUtil.log(plugin, "&6Generating new world...");
|
||||
|
||||
// Create World
|
||||
DResourceWorld resource = new DResourceWorld(plugin, name);
|
||||
instances.addResource(resource);
|
||||
plugin.getMapRegistry().add(name, resource);
|
||||
plugin.getDungeonRegistry().add(name, new DDungeon(plugin, resource));
|
||||
DEditWorld editWorld = resource.generate();
|
||||
|
||||
// MSG Done
|
||||
MessageUtil.log(plugin, "&6World generation finished.");
|
||||
|
||||
// Tp Player
|
||||
new DEditPlayer(plugin, player, editWorld);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,8 @@ package de.erethon.dungeonsxl.command;
|
|||
|
||||
import de.erethon.commons.command.DRECommand;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerCache;
|
||||
import de.erethon.dungeonsxl.config.MainConfig;
|
||||
import de.erethon.dungeonsxl.player.DPlayerCache;
|
||||
import de.erethon.dungeonsxl.world.DWorldCache;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
|
@ -29,14 +28,12 @@ public abstract class DCommand extends DRECommand {
|
|||
|
||||
protected DungeonsXL plugin;
|
||||
protected MainConfig config;
|
||||
protected DPlayerCache dPlayers;
|
||||
protected DWorldCache instances;
|
||||
protected PlayerCache dPlayers;
|
||||
|
||||
protected DCommand(DungeonsXL plugin) {
|
||||
this.plugin = plugin;
|
||||
config = plugin.getMainConfig();
|
||||
dPlayers = plugin.getDPlayerCache();
|
||||
instances = plugin.getDWorldCache();
|
||||
dPlayers = plugin.getPlayerCache();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,10 +19,9 @@ package de.erethon.dungeonsxl.command;
|
|||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.commons.misc.FileUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.world.DEditWorld;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import java.io.File;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
@ -47,7 +46,7 @@ public class DeleteCommand extends DCommand {
|
|||
|
||||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
DResourceWorld resource = instances.getResourceByName(args[1]);
|
||||
ResourceWorld resource = plugin.getMapRegistry().get(args[1]);
|
||||
if (resource == null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(args[1]));
|
||||
return;
|
||||
|
@ -68,12 +67,10 @@ public class DeleteCommand extends DCommand {
|
|||
return;
|
||||
}
|
||||
|
||||
for (DEditWorld editWorld : instances.getEditWorlds()) {
|
||||
if (editWorld.getResource().equals(resource)) {
|
||||
editWorld.delete(false);
|
||||
}
|
||||
if (resource.getEditWorld() != null) {
|
||||
resource.getEditWorld().delete(false);
|
||||
}
|
||||
instances.removeResource(resource);
|
||||
plugin.getMapRegistry().remove(resource);
|
||||
FileUtil.removeDir(resource.getFolder());
|
||||
|
||||
if (args[2].equalsIgnoreCase("true")) {
|
||||
|
|
|
@ -19,14 +19,14 @@ package de.erethon.dungeonsxl.command;
|
|||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.commons.config.CommonMessage;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.InstancePlayer;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.api.world.EditWorld;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DEditPlayer;
|
||||
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.player.DInstancePlayer;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.world.DEditWorld;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -34,7 +34,7 @@ import org.bukkit.entity.Player;
|
|||
* @author Frank Baumann, Milan Albrecht, Daniel Saukel
|
||||
*/
|
||||
public class EditCommand extends DCommand {
|
||||
|
||||
|
||||
public EditCommand(DungeonsXL plugin) {
|
||||
super(plugin);
|
||||
setCommand("edit");
|
||||
|
@ -43,48 +43,42 @@ public class EditCommand extends DCommand {
|
|||
setHelp(DMessage.CMD_EDIT_HELP.getMessage());
|
||||
setPlayerCommand(true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
String mapName = args[1];
|
||||
|
||||
if (!instances.exists(mapName)) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_NO_SUCH_DUNGEON.getMessage(mapName));
|
||||
return;
|
||||
}
|
||||
|
||||
DResourceWorld resource = instances.getResourceByName(mapName);
|
||||
|
||||
ResourceWorld resource = plugin.getMapRegistry().getFirstIf(d -> d.getName().equalsIgnoreCase(args[1]));
|
||||
if (resource == null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(mapName));
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(args[1]));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!resource.isInvitedPlayer(player) && !DPermission.hasPermission(player, DPermission.EDIT)) {
|
||||
MessageUtil.sendMessage(player, CommonMessage.CMD_NO_PERMISSION.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
DEditWorld editWorld = resource.instantiateAsEditWorld(false);
|
||||
|
||||
EditWorld editWorld = resource.getOrInstantiateEditWorld(false);
|
||||
if (editWorld == null) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
|
||||
|
||||
if (dPlayer instanceof DInstancePlayer) {
|
||||
|
||||
PlayerGroup dGroup = plugin.getPlayerGroup(player);
|
||||
GlobalPlayer dPlayer = dPlayers.get(player);
|
||||
|
||||
if (dPlayer instanceof InstancePlayer) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (dGroup != null) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_GROUP.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
new DEditPlayer(plugin, player, editWorld);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,8 +18,9 @@ package de.erethon.dungeonsxl.command;
|
|||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Game;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import de.erethon.dungeonsxl.player.DGamePlayer;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
|
@ -47,13 +48,13 @@ public class EnterCommand extends DCommand {
|
|||
Player captain = (Player) sender;
|
||||
String targetName = args.length == 3 ? args[2] : args[1];
|
||||
|
||||
DGroup joining = args.length == 3 ? DGroup.getByName(args[1]) : DGroup.getByPlayer(captain);
|
||||
DGroup target = DGroup.getByName(targetName);
|
||||
PlayerGroup joining = args.length == 3 ? plugin.getPlayerGroupCache().get(args[1]) : plugin.getPlayerGroup(captain);
|
||||
PlayerGroup target = plugin.getPlayerGroupCache().get(targetName);
|
||||
|
||||
if (target == null) {
|
||||
Player targetPlayer = Bukkit.getPlayer(targetName);
|
||||
if (targetPlayer != null) {
|
||||
target = DGroup.getByPlayer(targetPlayer);
|
||||
target = plugin.getPlayerGroup(targetPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,13 +63,13 @@ public class EnterCommand extends DCommand {
|
|||
return;
|
||||
}
|
||||
|
||||
Game game = Game.getByDGroup(target);
|
||||
Game game = target.getGame();
|
||||
if (game == null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_NOT_IN_GAME.getMessage(targetName));
|
||||
return;
|
||||
}
|
||||
|
||||
if (Game.getByDGroup(joining) != null) {
|
||||
if (joining.getGame() != null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_LEAVE_GAME.getMessage());
|
||||
return;
|
||||
}
|
||||
|
@ -77,17 +78,17 @@ public class EnterCommand extends DCommand {
|
|||
joining = new DGroup(plugin, captain, game.getDungeon());
|
||||
}
|
||||
|
||||
if (joining.getCaptain() != captain && !DPermission.hasPermission(sender, DPermission.BYPASS)) {
|
||||
if (joining.getLeader() != captain && !DPermission.hasPermission(sender, DPermission.BYPASS)) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_NOT_LEADER.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
joining.setGameWorld(game.getWorld());
|
||||
game.addDGroup(joining);
|
||||
game.addGroup(joining);
|
||||
joining.sendMessage(DMessage.CMD_ENTER_SUCCESS.getMessage(joining.getName(), target.getName()));
|
||||
|
||||
for (Player player : joining.getPlayers().getOnlinePlayers()) {
|
||||
new DGamePlayer(plugin, player, game.getWorld(), game.getType());
|
||||
for (Player player : joining.getMembers().getOnlinePlayers()) {
|
||||
new DGamePlayer(plugin, player, game.getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,12 +18,11 @@ package de.erethon.dungeonsxl.command;
|
|||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.EditPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.api.world.EditWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DEditPlayer;
|
||||
import de.erethon.dungeonsxl.player.DGamePlayer;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.world.DEditWorld;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -45,15 +44,15 @@ public class EscapeCommand extends DCommand {
|
|||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
DEditPlayer dPlayer = DEditPlayer.getByPlayer(player);
|
||||
EditPlayer editPlayer = dPlayers.getEditPlayer(player);
|
||||
|
||||
if (DGamePlayer.getByPlayer(player) != null) {
|
||||
if (dPlayers.getGamePlayer(player) != null) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage());
|
||||
|
||||
} else if (dPlayer != null) {
|
||||
dPlayer.escape();
|
||||
} else if (editPlayer != null) {
|
||||
editPlayer.escape();
|
||||
|
||||
DEditWorld editWorld = DEditWorld.getByWorld(dPlayer.getWorld());
|
||||
EditWorld editWorld = editPlayer.getEditWorld();
|
||||
if (editWorld == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -63,7 +62,7 @@ public class EscapeCommand extends DCommand {
|
|||
}
|
||||
|
||||
} else {
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
PlayerGroup dGroup = plugin.getPlayerGroup(player);
|
||||
if (dGroup != null) {
|
||||
dGroup.removePlayer(player);
|
||||
MessageUtil.sendMessage(player, DMessage.CMD_LEAVE_SUCCESS.getMessage());
|
||||
|
|
|
@ -18,11 +18,11 @@ package de.erethon.dungeonsxl.command;
|
|||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.dungeon.DGame;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -44,19 +44,19 @@ public class GameCommand extends DCommand {
|
|||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
PlayerGroup dGroup = plugin.getPlayerGroup(player);
|
||||
if (dGroup == null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_JOIN_GROUP.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
DGameWorld gameWorld = dGroup.getGameWorld();
|
||||
GameWorld gameWorld = dGroup.getGameWorld();
|
||||
if (gameWorld == null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_NO_GAME.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
Game game = gameWorld.getGame();
|
||||
DGame game = (DGame) gameWorld.getGame();
|
||||
if (game == null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_NO_GAME.getMessage());
|
||||
return;
|
||||
|
@ -64,13 +64,12 @@ public class GameCommand extends DCommand {
|
|||
|
||||
MessageUtil.sendCenteredMessage(sender, "&4&l[ &6Game &4&l]");
|
||||
String groups = "";
|
||||
for (DGroup group : game.getDGroups()) {
|
||||
groups += (group == game.getDGroups().get(0) ? "" : "&b, &e") + group.getName();
|
||||
for (PlayerGroup group : game.getGroups()) {
|
||||
groups += (group == game.getGroups().get(0) ? "" : "&b, &e") + group.getName();
|
||||
}
|
||||
MessageUtil.sendMessage(sender, "&bGroups: &e" + groups);
|
||||
MessageUtil.sendMessage(sender, "&bGame type: &e" + (game.getType() == null ? "Not started yet" : game.getType()));
|
||||
MessageUtil.sendMessage(sender, "&bDungeon: &e" + (dGroup.getDungeonName() == null ? "N/A" : dGroup.getDungeonName()));
|
||||
MessageUtil.sendMessage(sender, "&bMap: &e" + (dGroup.getMapName() == null ? "N/A" : dGroup.getMapName()));
|
||||
MessageUtil.sendMessage(sender, "&bDungeon: &e" + (dGroup.getDungeon().getName() == null ? "N/A" : dGroup.getDungeon().getName()));
|
||||
MessageUtil.sendMessage(sender, "&bMap: &e" + (dGroup.getGameWorld() == null ? "N/A" : dGroup.getGameWorld().getName()));
|
||||
MessageUtil.sendMessage(sender, "&bWaves finished: &e" + game.getWaveCount());
|
||||
MessageUtil.sendMessage(sender, "&bKills: &e" + game.getGameKills() + " / Game; " + game.getWaveKills() + " / Wave");
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import de.erethon.dungeonsxl.config.DMessage;
|
|||
import de.erethon.dungeonsxl.event.dgroup.DGroupCreateEvent;
|
||||
import de.erethon.dungeonsxl.event.dgroup.DGroupDisbandEvent;
|
||||
import de.erethon.dungeonsxl.event.dplayer.DPlayerKickEvent;
|
||||
import de.erethon.dungeonsxl.player.DGamePlayer;
|
||||
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -54,7 +54,7 @@ public class GroupCommand extends DCommand {
|
|||
this.player = (Player) sender;
|
||||
this.args = args;
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
DGroup dGroup = (DGroup) plugin.getPlayerGroup(player);
|
||||
|
||||
if (args.length == 2) {
|
||||
|
||||
|
@ -90,18 +90,18 @@ public class GroupCommand extends DCommand {
|
|||
return;
|
||||
|
||||
} else if (args[1].equalsIgnoreCase("disband") && DPermission.hasPermission(sender, DPermission.GROUP_ADMIN)) {
|
||||
disbandGroup(DGroup.getByName(args[2]), args[2]);
|
||||
disbandGroup((DGroup) plugin.getPlayerGroupCache().get(args[2]), args[2]);
|
||||
return;
|
||||
|
||||
} else if (args[1].equalsIgnoreCase("join")) {
|
||||
joinGroup(DGroup.getByName(args[2]));
|
||||
joinGroup((DGroup) plugin.getPlayerGroupCache().get(args[2]));
|
||||
return;
|
||||
|
||||
} else if (args[1].equalsIgnoreCase("show") && DPermission.hasPermission(sender, DPermission.GROUP_ADMIN)) {
|
||||
DGroup group = DGroup.getByName(args[2]);
|
||||
DGroup group = (DGroup) plugin.getPlayerGroupCache().get(args[2]);
|
||||
Player player = Bukkit.getPlayer(args[2]);
|
||||
if (group == null && player != null) {
|
||||
group = DGroup.getByPlayer(player);
|
||||
group = (DGroup) plugin.getPlayerGroup(player);
|
||||
}
|
||||
showGroup(group);
|
||||
return;
|
||||
|
@ -112,12 +112,12 @@ public class GroupCommand extends DCommand {
|
|||
}
|
||||
|
||||
public void createGroup() {
|
||||
if (DGroup.getByPlayer(player) != null) {
|
||||
if (plugin.getPlayerGroup(player) != null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_LEAVE_GROUP.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (DGroup.getByName(args[2]) != null) {
|
||||
if (plugin.getPlayerGroupCache().get(args[2]) != null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_NAME_IN_USE.getMessage(args[2]));
|
||||
return;
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ public class GroupCommand extends DCommand {
|
|||
return;
|
||||
}
|
||||
|
||||
if (DGroup.getByPlayer(player) != null) {
|
||||
if (plugin.getPlayerGroup(player) != null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_LEAVE_GROUP.getMessage());
|
||||
return;
|
||||
}
|
||||
|
@ -224,11 +224,11 @@ public class GroupCommand extends DCommand {
|
|||
|
||||
Player toKick = Bukkit.getPlayer(args[2]);
|
||||
if (toKick != null) {
|
||||
DPlayerKickEvent event = new DPlayerKickEvent(DGamePlayer.getByPlayer(toKick.getPlayer()), DPlayerKickEvent.Cause.COMMAND);
|
||||
DPlayerKickEvent event = new DPlayerKickEvent((DGlobalPlayer) dPlayers.get(toKick.getPlayer()), DPlayerKickEvent.Cause.COMMAND);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
if (dGroup.getPlayers().contains(toKick)) {
|
||||
if (dGroup.getMembers().contains(toKick)) {
|
||||
dGroup.removePlayer(toKick);
|
||||
MessageUtil.sendMessage(sender, DMessage.GROUP_KICKED_PLAYER.getMessage(sender.getName(), args[2], dGroup.getName()));
|
||||
|
||||
|
@ -255,9 +255,9 @@ public class GroupCommand extends DCommand {
|
|||
}
|
||||
|
||||
MessageUtil.sendCenteredMessage(sender, "&4&l[ &6" + dGroup.getName() + " &4&l]");
|
||||
MessageUtil.sendMessage(sender, "&bCaptain: &e" + dGroup.getCaptain().getName());
|
||||
MessageUtil.sendMessage(sender, "&bCaptain: &e" + dGroup.getLeader().getName());
|
||||
String players = "";
|
||||
for (String player : dGroup.getPlayers().getNames()) {
|
||||
for (String player : dGroup.getMembers().getNames()) {
|
||||
players += (players.isEmpty() ? "" : "&b, &e") + player;
|
||||
}
|
||||
MessageUtil.sendMessage(sender, "&bPlayers: &e" + players);
|
||||
|
|
|
@ -20,8 +20,10 @@ import de.erethon.commons.chat.MessageUtil;
|
|||
import de.erethon.commons.misc.FileUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.dungeon.DDungeon;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import de.erethon.dungeonsxl.world.WorldConfig;
|
||||
import java.io.File;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
@ -70,11 +72,13 @@ public class ImportCommand extends DCommand {
|
|||
FileUtil.copyDir(source, target, "playerdata", "stats");
|
||||
|
||||
DResourceWorld resource = new DResourceWorld(plugin, args[1]);
|
||||
plugin.getDungeonRegistry().add(args[1], new DDungeon(plugin, resource));
|
||||
if (world.getEnvironment() != Environment.NORMAL) {
|
||||
resource.getConfig(true).setWorldEnvironment(world.getEnvironment());
|
||||
resource.getConfig().save();
|
||||
WorldConfig config = resource.getConfig(true);
|
||||
config.setWorldEnvironment(world.getEnvironment());
|
||||
config.save();
|
||||
}
|
||||
instances.addResource(resource);
|
||||
plugin.getMapRegistry().add(resource.getName(), resource);
|
||||
MessageUtil.sendMessage(sender, DMessage.CMD_IMPORT_SUCCESS.getMessage(args[1]));
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@ package de.erethon.dungeonsxl.command;
|
|||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -43,7 +43,7 @@ public class InviteCommand extends DCommand {
|
|||
|
||||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
DResourceWorld resource = instances.getResourceByName(args[2]);
|
||||
ResourceWorld resource = plugin.getMapRegistry().get(args[2]);
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
|
||||
|
||||
if (resource != null) {
|
||||
|
|
|
@ -19,8 +19,8 @@ package de.erethon.dungeonsxl.command;
|
|||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.announcer.Announcer;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
||||
import de.erethon.dungeonsxl.player.DInstancePlayer;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -43,7 +43,7 @@ public class JoinCommand extends DCommand {
|
|||
|
||||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
DGlobalPlayer player = dPlayers.getByPlayer((Player) sender);
|
||||
GlobalPlayer player = dPlayers.get((Player) sender);
|
||||
if (player instanceof DInstancePlayer) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_LEAVE_GAME.getMessage());
|
||||
return;
|
||||
|
|
|
@ -18,10 +18,11 @@ package de.erethon.dungeonsxl.command;
|
|||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Game;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.event.dplayer.DPlayerLeaveDGroupEvent;
|
||||
import de.erethon.dungeonsxl.event.dplayer.instance.game.DGamePlayerEscapeEvent;
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import de.erethon.dungeonsxl.player.DEditPlayer;
|
||||
import de.erethon.dungeonsxl.player.DGamePlayer;
|
||||
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
||||
|
@ -50,15 +51,15 @@ public class LeaveCommand extends DCommand {
|
|||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
|
||||
Game game = Game.getByPlayer(player);
|
||||
DGlobalPlayer dPlayer = (DGlobalPlayer) dPlayers.get(player);
|
||||
Game game = plugin.getGame(player);
|
||||
|
||||
if (game != null && game.isTutorial()) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_NO_LEAVE_IN_TUTORIAL.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
PlayerGroup dGroup = dPlayer.getGroup();
|
||||
|
||||
if (dGroup == null && !(dPlayer instanceof DEditPlayer)) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_JOIN_GROUP.getMessage());
|
||||
|
@ -73,7 +74,7 @@ public class LeaveCommand extends DCommand {
|
|||
}
|
||||
}
|
||||
|
||||
DPlayerLeaveDGroupEvent dPlayerLeaveDGroupEvent = new DPlayerLeaveDGroupEvent(dPlayer, dGroup);
|
||||
DPlayerLeaveDGroupEvent dPlayerLeaveDGroupEvent = new DPlayerLeaveDGroupEvent(dPlayer, (DGroup) dGroup);
|
||||
Bukkit.getPluginManager().callEvent(dPlayerLeaveDGroupEvent);
|
||||
if (dPlayerLeaveDGroupEvent.isCancelled()) {
|
||||
return;
|
||||
|
|
|
@ -19,14 +19,15 @@ package de.erethon.dungeonsxl.command;
|
|||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.commons.misc.NumberUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.world.EditWorld;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import de.erethon.dungeonsxl.api.world.InstanceWorld;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.dungeon.DungeonConfig;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.world.DEditWorld;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import de.erethon.dungeonsxl.world.DWorldCache;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -51,20 +52,20 @@ public class ListCommand extends DCommand {
|
|||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
ArrayList<String> dungeonList = new ArrayList<>();
|
||||
for (Dungeon dungeon : plugin.getDungeonCache().getDungeons()) {
|
||||
for (Dungeon dungeon : plugin.getDungeonRegistry()) {
|
||||
dungeonList.add(dungeon.getName());
|
||||
}
|
||||
ArrayList<String> mapList = new ArrayList<>();
|
||||
for (File file : DungeonsXL.MAPS.listFiles()) {
|
||||
if (!file.equals(DWorldCache.RAW)) {
|
||||
if (!file.equals(DResourceWorld.RAW)) {
|
||||
mapList.add(file.getName());
|
||||
}
|
||||
}
|
||||
ArrayList<String> loadedList = new ArrayList<>();
|
||||
for (DEditWorld editWorld : instances.getEditWorlds()) {
|
||||
for (InstanceWorld editWorld : plugin.getInstanceCache().getAllIf(i -> i instanceof EditWorld)) {
|
||||
loadedList.add(editWorld.getWorld().getWorldFolder().getName() + " / " + editWorld.getName());
|
||||
}
|
||||
for (DGameWorld gameWorld : instances.getGameWorlds()) {
|
||||
for (InstanceWorld gameWorld : plugin.getInstanceCache().getAllIf(i -> i instanceof GameWorld)) {
|
||||
loadedList.add(gameWorld.getWorld().getWorldFolder().getName() + " / " + gameWorld.getName());
|
||||
}
|
||||
ArrayList<String> toSend = new ArrayList<>();
|
||||
|
@ -75,15 +76,22 @@ public class ListCommand extends DCommand {
|
|||
if (args.length >= 2) {
|
||||
if (args[1].equalsIgnoreCase("dungeons") || args[1].equalsIgnoreCase("d")) {
|
||||
if (args.length >= 3) {
|
||||
Dungeon dungeon = plugin.getDungeonCache().getByName(args[2]);
|
||||
Dungeon dungeon = plugin.getDungeonRegistry().get(args[2]);
|
||||
if (dungeon != null) {
|
||||
MessageUtil.sendPluginTag(sender, plugin);
|
||||
MessageUtil.sendCenteredMessage(sender, "&4&l[ &6" + dungeon.getName() + " &4&l]");
|
||||
MessageUtil.sendMessage(sender, "&eFloors: &o" + dungeon.getConfig().getFloors());
|
||||
MessageUtil.sendMessage(sender, "&estartFloor: &o[" + dungeon.getConfig().getStartFloor() + "]");
|
||||
MessageUtil.sendMessage(sender, "&eendFloor: &o[" + dungeon.getConfig().getEndFloor() + "]");
|
||||
MessageUtil.sendMessage(sender, "&efloorCount: &o[" + dungeon.getConfig().getFloorCount() + "]");
|
||||
MessageUtil.sendMessage(sender, "&eremoveWhenPlayed: &o[" + dungeon.getConfig().getRemoveWhenPlayed() + "]");
|
||||
StringBuilder floorList = new StringBuilder();
|
||||
for (int i = 0; i < dungeon.getFloors().size(); i++) {
|
||||
if (i != 0) {
|
||||
floorList.append(", ");
|
||||
}
|
||||
floorList.append(dungeon.getFloors().get(i).getName());
|
||||
}
|
||||
MessageUtil.sendMessage(sender, "&eFloors: &o" + floorList.toString());
|
||||
MessageUtil.sendMessage(sender, "&estartFloor: &o[" + dungeon.getStartFloor().getName() + "]");
|
||||
MessageUtil.sendMessage(sender, "&eendFloor: &o[" + dungeon.getEndFloor().getName() + "]");
|
||||
MessageUtil.sendMessage(sender, "&efloorCount: &o[" + dungeon.getFloorCount() + "]");
|
||||
MessageUtil.sendMessage(sender, "&eremoveWhenPlayed: &o[" + dungeon.getRemoveWhenPlayed() + "]");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -130,7 +138,7 @@ public class ListCommand extends DCommand {
|
|||
for (String map : toSend) {
|
||||
boolean invited = false;
|
||||
if (sender instanceof Player) {
|
||||
DResourceWorld resource = instances.getResourceByName(map);
|
||||
ResourceWorld resource = plugin.getMapRegistry().get(map);
|
||||
if (resource != null) {
|
||||
invited = resource.isInvitedPlayer((Player) sender);
|
||||
}
|
||||
|
|
|
@ -19,10 +19,10 @@ package de.erethon.dungeonsxl.command;
|
|||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.commons.config.CommonMessage;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.GamePlayer;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DGamePlayer;
|
||||
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -61,19 +61,19 @@ public class LivesCommand extends DCommand {
|
|||
return;
|
||||
}
|
||||
|
||||
DGlobalPlayer globalPlayer = dPlayers.getByPlayer(player);
|
||||
if (!(globalPlayer instanceof DGamePlayer)) {
|
||||
GlobalPlayer globalPlayer = dPlayers.get(player);
|
||||
if (!(globalPlayer instanceof GamePlayer)) {
|
||||
MessageUtil.sendMessage(sender, args.length == 1 ? DMessage.ERROR_NO_GAME.getMessage() : DMessage.ERROR_NO_SUCH_PLAYER.getMessage(args[1]));
|
||||
return;
|
||||
}
|
||||
|
||||
DGamePlayer gamePlayer = (DGamePlayer) globalPlayer;
|
||||
DGroup dGroup = gamePlayer != null ? gamePlayer.getDGroup() : DGroup.getByName(args[1]);
|
||||
GamePlayer gamePlayer = (GamePlayer) globalPlayer;
|
||||
PlayerGroup group = gamePlayer != null ? gamePlayer.getGroup() : plugin.getPlayerGroupCache().get(args[1]);
|
||||
if (gamePlayer != null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.CMD_LIVES_PLAYER.getMessage(gamePlayer.getName(), gamePlayer.getLives() == -1 ? DMessage.MISC_UNLIMITED.getMessage() : String.valueOf(gamePlayer.getLives())));
|
||||
|
||||
} else if (dGroup != null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.CMD_LIVES_GROUP.getMessage(dGroup.getName(), String.valueOf(dGroup.getLives() == -1 ? "UNLIMITED" : dGroup.getLives())));
|
||||
} else if (group != null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.CMD_LIVES_GROUP.getMessage(group.getName(), String.valueOf(group.getLives() == -1 ? "UNLIMITED" : group.getLives())));
|
||||
|
||||
} else {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_PLAYER.getMessage(args[1]));
|
||||
|
|
|
@ -47,8 +47,8 @@ public class MainCommand extends DCommand {
|
|||
|
||||
int maps = DungeonsXL.MAPS.listFiles().length - 1;
|
||||
int dungeons = DungeonsXL.DUNGEONS.listFiles().length;
|
||||
int loaded = instances.getEditWorlds().size() + instances.getGameWorlds().size();
|
||||
int players = dPlayers.getDGamePlayers().size();
|
||||
int loaded = plugin.getInstanceCache().size();
|
||||
int players = dPlayers.getAllInstancePlayers().size();
|
||||
Internals internals = CompatibilityHandler.getInstance().getInternals();
|
||||
String vault = "";
|
||||
if (plugins.getPlugin("Vault") != null) {
|
||||
|
|
|
@ -18,10 +18,13 @@ package de.erethon.dungeonsxl.command;
|
|||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRule;
|
||||
import de.erethon.dungeonsxl.api.world.EditWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.world.DEditWorld;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import de.erethon.dungeonsxl.world.WorldConfig;
|
||||
import java.util.Map;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -44,7 +47,7 @@ public class MsgCommand extends DCommand {
|
|||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
DEditWorld editWorld = DEditWorld.getByWorld(player.getWorld());
|
||||
EditWorld editWorld = plugin.getEditWorld(player.getWorld());
|
||||
|
||||
if (editWorld == null) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_NOT_IN_DUNGEON.getMessage());
|
||||
|
@ -59,10 +62,11 @@ public class MsgCommand extends DCommand {
|
|||
try {
|
||||
int id = Integer.parseInt(args[1]);
|
||||
|
||||
WorldConfig config = editWorld.getResource().getConfig(true);
|
||||
WorldConfig config = ((DResourceWorld) editWorld.getResource()).getConfig(true);
|
||||
Map<Integer, String> msgs = config.getState(GameRule.MESSAGES);
|
||||
|
||||
if (args.length == 2) {
|
||||
String msg = config.getMessage(id);
|
||||
String msg = msgs.get(id);
|
||||
|
||||
if (msg != null) {
|
||||
MessageUtil.sendMessage(player, ChatColor.WHITE + msg);
|
||||
|
@ -85,7 +89,7 @@ public class MsgCommand extends DCommand {
|
|||
|
||||
if (splitMsg.length > 1) {
|
||||
msg = splitMsg[1];
|
||||
String old = config.getMessage(id);
|
||||
String old = msgs.get(id);
|
||||
if (old == null) {
|
||||
MessageUtil.sendMessage(player, DMessage.CMD_MSG_ADDED.getMessage(String.valueOf(id)));
|
||||
|
||||
|
@ -93,7 +97,7 @@ public class MsgCommand extends DCommand {
|
|||
MessageUtil.sendMessage(player, DMessage.CMD_MSG_UPDATED.getMessage(String.valueOf(id)));
|
||||
}
|
||||
|
||||
config.setMessage(id, msg);
|
||||
msgs.put(id, msg);
|
||||
config.save();
|
||||
|
||||
} else {
|
||||
|
|
|
@ -18,17 +18,16 @@ package de.erethon.dungeonsxl.command;
|
|||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.dungeon.DGame;
|
||||
import de.erethon.dungeonsxl.event.dgroup.DGroupCreateEvent;
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import de.erethon.dungeonsxl.player.DGamePlayer;
|
||||
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.player.DInstancePlayer;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -52,50 +51,44 @@ public class PlayCommand extends DCommand {
|
|||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
|
||||
GlobalPlayer dPlayer = dPlayers.get(player);
|
||||
if (dPlayer instanceof DInstancePlayer) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
Dungeon dungeon = plugin.getDungeonCache().getByName(args[1]);
|
||||
Dungeon dungeon = plugin.getDungeonRegistry().get(args[1]);
|
||||
if (dungeon == null) {
|
||||
DResourceWorld resource = instances.getResourceByName(args[1]);
|
||||
if (resource != null) {
|
||||
dungeon = new Dungeon(plugin, resource);
|
||||
} else {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_NO_SUCH_DUNGEON.getMessage(args[1]));
|
||||
return;
|
||||
}
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_NO_SUCH_DUNGEON.getMessage(args[1]));
|
||||
}
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
if (dGroup != null && dGroup.isPlaying()) {
|
||||
DGroup group = (DGroup) dPlayer.getGroup();
|
||||
if (group != null && group.isPlaying()) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_GROUP.getMessage());
|
||||
return;
|
||||
} else if (dGroup == null) {
|
||||
dGroup = new DGroup(plugin, player, dungeon);
|
||||
DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND);
|
||||
} else if (group == null) {
|
||||
group = new DGroup(plugin, player, dungeon);
|
||||
DGroupCreateEvent event = new DGroupCreateEvent(group, player, DGroupCreateEvent.Cause.COMMAND);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
plugin.getDGroupCache().remove(dGroup);
|
||||
dGroup = null;
|
||||
plugin.getPlayerGroupCache().remove(group);
|
||||
group = null;
|
||||
}
|
||||
}
|
||||
if (!dGroup.getCaptain().equals(player) && !DPermission.hasPermission(player, DPermission.BYPASS)) {
|
||||
if (!group.getLeader().equals(player) && !DPermission.hasPermission(player, DPermission.BYPASS)) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_NOT_LEADER.getMessage());
|
||||
return;
|
||||
}
|
||||
dGroup.setDungeon(dungeon);
|
||||
group.setDungeon(dungeon);
|
||||
|
||||
DGameWorld gameWorld = dungeon.getMap().instantiateAsGameWorld(false);
|
||||
GameWorld gameWorld = dungeon.getMap().instantiateGameWorld(false);
|
||||
if (gameWorld == null) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
|
||||
return;
|
||||
}
|
||||
new Game(plugin, dGroup, gameWorld);
|
||||
for (Player groupPlayer : dGroup.getPlayers().getOnlinePlayers()) {
|
||||
new DGamePlayer(plugin, groupPlayer, dGroup.getGameWorld());
|
||||
new DGame(plugin, group, gameWorld);
|
||||
for (Player groupPlayer : group.getMembers().getOnlinePlayers()) {
|
||||
new DGamePlayer(plugin, groupPlayer, group.getGameWorld());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ public class PortalCommand extends DCommand {
|
|||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
DGlobalPlayer dGlobalPlayer = dPlayers.getByPlayer(player);
|
||||
DGlobalPlayer dGlobalPlayer = (DGlobalPlayer) dPlayers.get(player);
|
||||
|
||||
if (dGlobalPlayer instanceof DGamePlayer) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_DUNGEON.getMessage());
|
||||
|
|
|
@ -21,11 +21,11 @@ import de.erethon.commons.chat.MessageUtil;
|
|||
import de.erethon.commons.compatibility.CompatibilityHandler;
|
||||
import de.erethon.commons.compatibility.Internals;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.InstancePlayer;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.event.DataReloadEvent;
|
||||
import de.erethon.dungeonsxl.player.DInstancePlayer;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -51,7 +51,7 @@ public class ReloadCommand extends DCommand {
|
|||
|
||||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
List<DInstancePlayer> dPlayers = this.dPlayers.getDInstancePlayers();
|
||||
Collection<InstancePlayer> dPlayers = this.dPlayers.getAllInstancePlayers();
|
||||
if (!dPlayers.isEmpty() && args.length == 1 && sender instanceof Player) {
|
||||
MessageUtil.sendMessage(sender, DMessage.CMD_RELOAD_PLAYERS.getMessage());
|
||||
ClickEvent onClick = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/dungeonsxl reload -force");
|
||||
|
@ -70,14 +70,12 @@ public class ReloadCommand extends DCommand {
|
|||
return;
|
||||
}
|
||||
|
||||
for (DInstancePlayer dPlayer : dPlayers) {
|
||||
dPlayer.leave();
|
||||
}
|
||||
dPlayers.forEach(InstancePlayer::leave);
|
||||
|
||||
int maps = DungeonsXL.MAPS.listFiles().length - 1;
|
||||
int dungeons = DungeonsXL.DUNGEONS.listFiles().length;
|
||||
int loaded = instances.getEditWorlds().size() + instances.getGameWorlds().size();
|
||||
int players = this.dPlayers.getDGamePlayers().size();
|
||||
int loaded = plugin.getInstanceCache().size();
|
||||
int players = this.dPlayers.getAllGamePlayers().size();
|
||||
Internals internals = CompatibilityHandler.getInstance().getInternals();
|
||||
String vault = "";
|
||||
if (plugins.getPlugin("Vault") != null) {
|
||||
|
|
|
@ -18,13 +18,14 @@ package de.erethon.dungeonsxl.command;
|
|||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.dungeon.DDungeon;
|
||||
import de.erethon.dungeonsxl.dungeon.DungeonConfig;
|
||||
import de.erethon.dungeonsxl.global.GlobalProtection;
|
||||
import de.erethon.dungeonsxl.global.JoinSign;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.world.DEditWorld;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -50,7 +51,7 @@ public class RenameCommand extends DCommand {
|
|||
|
||||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
DResourceWorld resource = instances.getResourceByName(args[1]);
|
||||
DResourceWorld resource = (DResourceWorld) plugin.getMapRegistry().get(args[1]);
|
||||
if (resource == null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(args[1]));
|
||||
return;
|
||||
|
@ -60,14 +61,12 @@ public class RenameCommand extends DCommand {
|
|||
resource.getFolder().renameTo(new File(DungeonsXL.MAPS, args[2]));
|
||||
resource.getSignData().updateFile(resource);
|
||||
|
||||
for (DEditWorld editWorld : instances.getEditWorlds()) {
|
||||
if (editWorld.getResource() == resource) {
|
||||
editWorld.delete(true);
|
||||
}
|
||||
if (resource.getEditWorld() != null) {
|
||||
resource.getEditWorld().delete(true);
|
||||
}
|
||||
|
||||
for (Dungeon dungeon : plugin.getDungeonCache().getDungeons()) {
|
||||
DungeonConfig dConfig = dungeon.getConfig();
|
||||
for (Dungeon dungeon : plugin.getDungeonRegistry()) {
|
||||
DungeonConfig dConfig = ((DDungeon) dungeon).getConfig();
|
||||
FileConfiguration config = dConfig.getConfig();
|
||||
File file = dConfig.getFile();
|
||||
|
||||
|
@ -81,7 +80,7 @@ public class RenameCommand extends DCommand {
|
|||
|
||||
List<String> list = config.getStringList("floors");
|
||||
int i = 0;
|
||||
for (DResourceWorld floor : dConfig.getFloors()) {
|
||||
for (ResourceWorld floor : dConfig.getFloors()) {
|
||||
if (floor == resource) {
|
||||
list.set(i, args[2]);
|
||||
}
|
||||
|
|
|
@ -18,10 +18,10 @@ package de.erethon.dungeonsxl.command;
|
|||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.world.EditWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.config.MainConfig.BackupMode;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.world.DEditWorld;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class SaveCommand extends DCommand {
|
|||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
DEditWorld editWorld = DEditWorld.getByWorld(player.getWorld());
|
||||
EditWorld editWorld = plugin.getEditWorld(player.getWorld());
|
||||
if (editWorld != null) {
|
||||
BackupMode backupMode = config.getBackupMode();
|
||||
if (backupMode == BackupMode.ON_SAVE || backupMode == BackupMode.ON_DISABLE_AND_SAVE) {
|
||||
|
|
|
@ -18,17 +18,18 @@ package de.erethon.dungeonsxl.command;
|
|||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Game;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import de.erethon.dungeonsxl.game.GameTypeDefault;
|
||||
import de.erethon.dungeonsxl.dungeon.DGame;
|
||||
import de.erethon.dungeonsxl.player.DEditPlayer;
|
||||
import de.erethon.dungeonsxl.player.DGamePlayer;
|
||||
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -51,21 +52,21 @@ public class TestCommand extends DCommand {
|
|||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
|
||||
GlobalPlayer dPlayer = dPlayers.get(player);
|
||||
|
||||
if (!(dPlayer instanceof DEditPlayer)) {
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
PlayerGroup dGroup = dPlayer.getGroup();
|
||||
if (dGroup == null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_JOIN_GROUP.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dGroup.getCaptain().equals(player) && !DPermission.hasPermission(player, DPermission.BYPASS)) {
|
||||
if (!dGroup.getLeader().equals(player) && !DPermission.hasPermission(player, DPermission.BYPASS)) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_NOT_LEADER.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
DGameWorld gameWorld = dGroup.getGameWorld();
|
||||
GameWorld gameWorld = dGroup.getGameWorld();
|
||||
if (gameWorld == null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_NOT_IN_DUNGEON.getMessage());
|
||||
return;
|
||||
|
@ -77,22 +78,22 @@ public class TestCommand extends DCommand {
|
|||
return;
|
||||
}
|
||||
|
||||
for (Player groupPlayer : dGroup.getPlayers().getOnlinePlayers()) {
|
||||
DGamePlayer.getByPlayer(groupPlayer).ready(GameTypeDefault.TEST);
|
||||
for (Player groupPlayer : dGroup.getMembers().getOnlinePlayers()) {
|
||||
((DGamePlayer) dPlayers.getGamePlayer(groupPlayer)).ready();
|
||||
}
|
||||
|
||||
} else {
|
||||
DEditPlayer editPlayer = (DEditPlayer) dPlayer;
|
||||
editPlayer.leave();
|
||||
DResourceWorld resource = editPlayer.getEditWorld().getResource();
|
||||
Dungeon dungeon = new Dungeon(plugin, resource);
|
||||
DGameWorld instance = resource.instantiateAsGameWorld(false);
|
||||
ResourceWorld resource = editPlayer.getEditWorld().getResource();
|
||||
Dungeon dungeon = resource.getSingleFloorDungeon();
|
||||
GameWorld instance = resource.instantiateGameWorld(false);
|
||||
if (instance == null) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
|
||||
return;
|
||||
}
|
||||
Game game = new Game(plugin, new DGroup(plugin, player, dungeon), GameTypeDefault.TEST, instance);
|
||||
new DGamePlayer(plugin, player, game.getWorld(), GameTypeDefault.TEST);
|
||||
DGame game = new DGame(plugin, new DGroup(plugin, player, dungeon), instance);
|
||||
new DGamePlayer(plugin, player, game.getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@ package de.erethon.dungeonsxl.command;
|
|||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -43,7 +43,7 @@ public class UninviteCommand extends DCommand {
|
|||
|
||||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
DResourceWorld resource = instances.getResourceByName(args[2]);
|
||||
ResourceWorld resource = plugin.getMapRegistry().get(args[2]);
|
||||
if (resource == null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(args[2]));
|
||||
return;
|
||||
|
|
|
@ -19,9 +19,9 @@ package de.erethon.dungeonsxl.config;
|
|||
import de.erethon.commons.config.DREConfig;
|
||||
import de.erethon.commons.misc.EnumUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup.Color;
|
||||
import static de.erethon.dungeonsxl.api.player.PlayerGroup.Color.*;
|
||||
import de.erethon.dungeonsxl.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.world.WorldConfig;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -107,7 +107,7 @@ public class MainConfig extends DREConfig {
|
|||
/* Permissions bridge */
|
||||
private List<String> editPermissions;
|
||||
|
||||
/* Default Dungeon Settings */
|
||||
/* Default DDungeon Settings */
|
||||
private WorldConfig defaultWorldConfig;
|
||||
|
||||
public MainConfig(DungeonsXL plugin, File file) {
|
||||
|
@ -238,7 +238,7 @@ public class MainConfig extends DREConfig {
|
|||
*/
|
||||
public Dungeon getTutorialDungeon() {
|
||||
if (tutorialDungeon == null) {
|
||||
tutorialDungeon = plugin.getDungeonCache().getByName(tutorialDungeonName, true);
|
||||
tutorialDungeon = plugin.getDungeonRegistry().get(tutorialDungeonName);
|
||||
}
|
||||
return tutorialDungeon;
|
||||
}
|
||||
|
@ -568,7 +568,7 @@ public class MainConfig extends DREConfig {
|
|||
config.set("editPermissions", editPermissions);
|
||||
}
|
||||
|
||||
/* Default Dungeon Config */
|
||||
/* Default DDungeon Config */
|
||||
if (!config.contains("default")) {
|
||||
config.createSection("default");
|
||||
}
|
||||
|
|
215
core/src/main/java/de/erethon/dungeonsxl/dungeon/DDungeon.java
Normal file
215
core/src/main/java/de/erethon/dungeonsxl/dungeon/DDungeon.java
Normal file
|
@ -0,0 +1,215 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.dungeon;
|
||||
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class DDungeon implements Dungeon {
|
||||
|
||||
private DungeonsXL plugin;
|
||||
|
||||
private String name;
|
||||
private DungeonConfig config;
|
||||
private ResourceWorld map;
|
||||
private GameRuleContainer rules;
|
||||
|
||||
/**
|
||||
* Real dungeon
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
* @param file the file to load from
|
||||
*/
|
||||
public DDungeon(DungeonsXL plugin, File file) {
|
||||
this.plugin = plugin;
|
||||
|
||||
name = file.getName().replaceAll(".yml", "");
|
||||
config = new DungeonConfig(plugin, file);
|
||||
map = config.getStartFloor();
|
||||
setupRules();
|
||||
}
|
||||
|
||||
/**
|
||||
* Artificial dungeon
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
* @param resource the only resource world
|
||||
*/
|
||||
public DDungeon(DungeonsXL plugin, ResourceWorld resource) {
|
||||
this.plugin = plugin;
|
||||
|
||||
name = resource.getName();
|
||||
map = resource;
|
||||
setupRules();
|
||||
}
|
||||
|
||||
public DungeonConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMultiFloor() {
|
||||
return config != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceWorld getStartFloor() {
|
||||
return config.getStartFloor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStartFloor(ResourceWorld startFloor) {
|
||||
config.setStartFloor(startFloor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceWorld getEndFloor() {
|
||||
return config.getEndFloor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEndFloor(ResourceWorld endFloor) {
|
||||
config.setEndFloor(endFloor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceWorld> getFloors() {
|
||||
if (isMultiFloor()) {
|
||||
return config.getFloors();
|
||||
} else {
|
||||
return new ArrayList<>(Arrays.asList(map));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFloor(ResourceWorld resource) {
|
||||
config.addFloor(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFloor(ResourceWorld resource) {
|
||||
config.removeFloor(resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFloorCount() {
|
||||
return config.getFloorCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFloorCount(int floorCount) {
|
||||
config.setFloorCount(floorCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRemoveWhenPlayed() {
|
||||
return config.getRemoveWhenPlayed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRemoveWhenPlayed(boolean removeWhenPlayed) {
|
||||
config.setRemoveWhenPlayed(removeWhenPlayed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameRuleContainer getOverrideValues() {
|
||||
return config.getOverrideValues();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOverrideValues(GameRuleContainer rules) {
|
||||
config.setOverrideValues(rules);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameRuleContainer getDefaultValues() {
|
||||
return config.getDefaultValues();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultValues(GameRuleContainer rules) {
|
||||
config.setDefaultValues(rules);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameRuleContainer getRules() {
|
||||
return rules;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRules(GameRuleContainer rules) {
|
||||
this.rules = rules;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupRules() {
|
||||
if (rules != null) {
|
||||
return;
|
||||
}
|
||||
if (isMultiFloor()) {
|
||||
rules = new GameRuleContainer(getOverrideValues());
|
||||
if (map.getRules() != null) {
|
||||
rules.merge(map.getRules());
|
||||
}
|
||||
rules.merge(getDefaultValues());
|
||||
} else if (map.getRules() != null) {
|
||||
rules = new GameRuleContainer(map.getRules());
|
||||
}
|
||||
rules.merge(plugin.getMainConfig().getDefaultWorldConfig());
|
||||
rules.merge(GameRuleContainer.DEFAULT_VALUES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSetupCorrect() {
|
||||
for (ResourceWorld resource : plugin.getMapRegistry()) {
|
||||
if (resource.getName().equals(name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return config.getStartFloor() != null && config.getEndFloor() != null;
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static File getFileFromName(String name) {
|
||||
return new File(DungeonsXL.DUNGEONS, name + ".yml");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "{name=" + name + "; multiFloor=" + isMultiFloor() + "}";
|
||||
}
|
||||
|
||||
}
|
324
core/src/main/java/de/erethon/dungeonsxl/dungeon/DGame.java
Normal file
324
core/src/main/java/de/erethon/dungeonsxl/dungeon/DGame.java
Normal file
|
@ -0,0 +1,324 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.dungeon;
|
||||
|
||||
import de.erethon.commons.player.PlayerUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Game;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRule;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.api.sign.DungeonSign;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.global.GameSign;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.sign.MobSign;
|
||||
import de.erethon.dungeonsxl.trigger.ProgressTrigger;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class DGame implements Game {
|
||||
|
||||
private DungeonsXL plugin;
|
||||
|
||||
private boolean tutorial;
|
||||
private boolean test;
|
||||
private List<PlayerGroup> groups = new ArrayList<>();
|
||||
private boolean started;
|
||||
private GameWorld world;
|
||||
private int waveCount;
|
||||
private Map<String, Integer> gameKills = new HashMap<>();
|
||||
private Map<String, Integer> waveKills = new HashMap<>();
|
||||
|
||||
public DGame(DungeonsXL plugin, PlayerGroup group) {
|
||||
this.plugin = plugin;
|
||||
plugin.getGameCache().add(this);
|
||||
|
||||
tutorial = false;
|
||||
started = false;
|
||||
|
||||
groups.add(group);
|
||||
group.setGameWorld(world);
|
||||
group.setInitialLives(getRules().getState(GameRule.INITIAL_GROUP_LIVES));
|
||||
group.setLives(getRules().getState(GameRule.INITIAL_GROUP_LIVES));
|
||||
group.setScore(getRules().getState(GameRule.INITIAL_SCORE));
|
||||
}
|
||||
|
||||
public DGame(DungeonsXL plugin, PlayerGroup group, GameWorld world) {
|
||||
this.plugin = plugin;
|
||||
plugin.getGameCache().add(this);
|
||||
|
||||
tutorial = false;
|
||||
started = false;
|
||||
this.world = world;
|
||||
|
||||
addGroup(group);
|
||||
}
|
||||
|
||||
public DGame(DungeonsXL plugin, List<PlayerGroup> groups, GameWorld world) {
|
||||
this.plugin = plugin;
|
||||
plugin.getGameCache().add(this);
|
||||
|
||||
this.groups = groups;
|
||||
this.world = world;
|
||||
tutorial = false;
|
||||
started = true;
|
||||
|
||||
groups.forEach(this::addGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTutorial() {
|
||||
return tutorial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTutorial(boolean tutorial) {
|
||||
this.tutorial = tutorial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlayerGroup> getGroups() {
|
||||
return new ArrayList<>(groups);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroup(PlayerGroup group) {
|
||||
groups.add(group);
|
||||
|
||||
group.setGameWorld(world);
|
||||
group.setInitialLives(getRules().getState(GameRule.INITIAL_GROUP_LIVES));
|
||||
group.setLives(getRules().getState(GameRule.INITIAL_GROUP_LIVES));
|
||||
group.setScore(getRules().getState(GameRule.INITIAL_SCORE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(PlayerGroup group) {
|
||||
groups.remove(group);
|
||||
|
||||
if (groups.isEmpty()) {
|
||||
delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasStarted() {
|
||||
return started;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStarted(boolean started) {
|
||||
this.started = started;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameWorld getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWorld(GameWorld gameWorld) {
|
||||
world = gameWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasRewards() {
|
||||
return test;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRewards(boolean enabled) {
|
||||
test = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceWorld> getUnplayedFloors() {
|
||||
List<ResourceWorld> unplayedFloors = null;
|
||||
for (PlayerGroup group : groups) {
|
||||
DGroup dGroup = (DGroup) group;
|
||||
if (unplayedFloors == null || dGroup.getUnplayedFloors().size() < unplayedFloors.size()) {
|
||||
unplayedFloors = dGroup.getUnplayedFloors();
|
||||
}
|
||||
}
|
||||
if (unplayedFloors == null) {
|
||||
unplayedFloors = new ArrayList<>();
|
||||
}
|
||||
return unplayedFloors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFloorCount() {
|
||||
int floorCount = 0;
|
||||
for (PlayerGroup group : groups) {
|
||||
DGroup dGroup = (DGroup) group;
|
||||
if (dGroup.getFloorCount() > floorCount) {
|
||||
floorCount = dGroup.getFloorCount();
|
||||
}
|
||||
}
|
||||
return floorCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dungeon getDungeon() {
|
||||
return groups.get(0).getDungeon();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the waveCount
|
||||
*/
|
||||
public int getWaveCount() {
|
||||
return waveCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param waveCount the waveCount to set
|
||||
*/
|
||||
public void setWaveCount(int waveCount) {
|
||||
this.waveCount = waveCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return how many mobs have been killed in the game
|
||||
*/
|
||||
public int getGameKills() {
|
||||
int count = 0;
|
||||
for (String killer : gameKills.keySet()) {
|
||||
count += gameKills.get(killer);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return how many mobs have been killed in the last game
|
||||
*/
|
||||
public int getWaveKills() {
|
||||
int count = 0;
|
||||
for (String killer : waveKills.keySet()) {
|
||||
count += waveKills.get(killer);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param killer the killer; null if the killer is not a player
|
||||
*/
|
||||
public void addKill(String killer) {
|
||||
if (killer == null) {
|
||||
killer = "N/A";
|
||||
}
|
||||
waveKills.put(killer, waveKills.get(killer) == null ? 1 : waveKills.get(killer) + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the values of the wave kills map to the game kills map and resets the wave kills.
|
||||
*/
|
||||
public void resetWaveKills() {
|
||||
gameKills.putAll(waveKills);
|
||||
waveKills.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Player> getPlayers() {
|
||||
Set<Player> toReturn = new HashSet<>();
|
||||
for (PlayerGroup group : groups) {
|
||||
toReturn.addAll(group.getMembers().getOnlinePlayers());
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return groups.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
GameSign gameSign = GameSign.getByGame(plugin, this);
|
||||
|
||||
plugin.getGameCache().remove(this);
|
||||
|
||||
if (gameSign != null) {
|
||||
gameSign.update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mobCountIncreaseRate the new mob count will be increased by this rate
|
||||
* @param teleport whether or not to teleport the players to the start location
|
||||
*/
|
||||
public void finishWave(final double mobCountIncreaseRate, final boolean teleport) {
|
||||
waveCount++;
|
||||
resetWaveKills();
|
||||
|
||||
Set<ProgressTrigger> triggers = ProgressTrigger.getByGameWorld((DGameWorld) world);
|
||||
for (ProgressTrigger trigger : triggers) {
|
||||
if (getWaveCount() >= trigger.getWaveCount() & getFloorCount() >= trigger.getFloorCount() - 1 || !getUnplayedFloors().contains(trigger.getFloor()) & trigger.getFloor() != null) {
|
||||
trigger.onTrigger();
|
||||
}
|
||||
}
|
||||
|
||||
int delay = getRules().getState(GameRule.TIME_TO_NEXT_WAVE);
|
||||
sendMessage(DMessage.GROUP_WAVE_FINISHED.getMessage(String.valueOf(waveCount), String.valueOf(delay)));
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (teleport) {
|
||||
groups.forEach(g -> g.getMembers().getOnlinePlayers()
|
||||
.forEach(p -> PlayerUtil.secureTeleport(p, world.getStartLocation(plugin.getPlayerGroup(p)))));
|
||||
}
|
||||
|
||||
for (DungeonSign dSign : world.getDungeonSigns()) {
|
||||
if (!(dSign instanceof MobSign)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
MobSign mobSign = (MobSign) dSign;
|
||||
int newAmount = (int) Math.ceil(mobSign.getInitialAmount() * mobCountIncreaseRate);
|
||||
|
||||
mobSign.setAmount(newAmount);
|
||||
mobSign.setInitialAmount(newAmount);
|
||||
mobSign.initializeTask();
|
||||
}
|
||||
}
|
||||
}.runTaskLater(plugin, delay * 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return groups.stream().allMatch(PlayerGroup::isFinished);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "{dungeon=" + getDungeon() + "}";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.dungeon;
|
||||
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a dungeon. While multi floor dungeon scripts are represented by {@link de.erethon.dungeonsxl.config.DungeonConfig}, single floor dungeons also get
|
||||
* a dungeon object without a config file as a placeholder.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class Dungeon {
|
||||
|
||||
private DungeonsXL plugin;
|
||||
|
||||
private String name;
|
||||
private DungeonConfig config;
|
||||
private DResourceWorld map;
|
||||
|
||||
/**
|
||||
* Real dungeon
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
* @param file the file to load from
|
||||
*/
|
||||
public Dungeon(DungeonsXL plugin, File file) {
|
||||
this.plugin = plugin;
|
||||
|
||||
name = file.getName().replaceAll(".yml", "");
|
||||
config = new DungeonConfig(plugin, file);
|
||||
map = config.getStartFloor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Artificial dungeon
|
||||
*
|
||||
* @param plugin the plugin instance
|
||||
* @param resource the only resource world
|
||||
*/
|
||||
public Dungeon(DungeonsXL plugin, DResourceWorld resource) {
|
||||
this.plugin = plugin;
|
||||
|
||||
name = resource.getName();
|
||||
map = resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the config
|
||||
*/
|
||||
public DungeonConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if this dungeon has multiple floors
|
||||
*/
|
||||
public boolean isMultiFloor() {
|
||||
return config != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the floors of the dungeon
|
||||
*/
|
||||
public List<DResourceWorld> getFloors() {
|
||||
if (isMultiFloor()) {
|
||||
return config.getFloors();
|
||||
} else {
|
||||
return new ArrayList<>(Arrays.asList(map));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the SFD map / start floor
|
||||
*/
|
||||
public DResourceWorld getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param map the SFD map / start floor to set
|
||||
*/
|
||||
public void setMap(DResourceWorld map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false if there are setup errors
|
||||
*/
|
||||
public boolean isSetupCorrect() {
|
||||
for (DResourceWorld resource : plugin.getDWorldCache().getResources()) {
|
||||
if (resource.getName().equals(name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return config.getStartFloor() != null && config.getEndFloor() != null;
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
/**
|
||||
* @param name the name of the dungeon
|
||||
* @return the file. Might not exist
|
||||
*/
|
||||
public static File getFileFromName(String name) {
|
||||
return new File(DungeonsXL.DUNGEONS, name + ".yml");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "{name=" + name + "; multiFloor=" + isMultiFloor() + "}";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,120 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.dungeon;
|
||||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Dungeon instance manager.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class DungeonCache {
|
||||
|
||||
private DungeonsXL plugin;
|
||||
|
||||
private List<Dungeon> dungeons = new ArrayList<>();
|
||||
|
||||
public DungeonCache(DungeonsXL plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void init(File folder) {
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
}
|
||||
|
||||
for (File file : folder.listFiles()) {
|
||||
Dungeon dungeon = new Dungeon(plugin, file);
|
||||
|
||||
if (dungeon.isSetupCorrect()) {
|
||||
dungeons.add(dungeon);
|
||||
|
||||
} else {
|
||||
MessageUtil.log(plugin, "&4The setup of dungeon &6" + file.getName()
|
||||
+ "&4 is incorrect. See https://github.com/DRE2N/DungeonsXL/wiki/dungeon-configuration for reference.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name of the Dungeon
|
||||
* @return the Dungeon that has the name
|
||||
*/
|
||||
public Dungeon getByName(String name) {
|
||||
return getByName(name, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name of the Dungeon
|
||||
* @param artificial if artificial Dungeons shall be included in the check
|
||||
* @return the Dungeon that has the name
|
||||
*/
|
||||
public Dungeon getByName(String name, boolean artificial) {
|
||||
for (Dungeon dungeon : dungeons) {
|
||||
if (dungeon.getName().equalsIgnoreCase(name)) {
|
||||
return dungeon;
|
||||
}
|
||||
}
|
||||
|
||||
if (artificial) {
|
||||
DResourceWorld resource = plugin.getDWorldCache().getResourceByName(name);
|
||||
if (resource != null) {
|
||||
return new Dungeon(plugin, resource);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dungeons
|
||||
*/
|
||||
public List<Dungeon> getDungeons() {
|
||||
return dungeons;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name of the Dungeon
|
||||
* @return the Dungeon that has the name
|
||||
*/
|
||||
public Dungeon loadDungeon(String name) {
|
||||
Dungeon dungeon = new Dungeon(plugin, Dungeon.getFileFromName(name));
|
||||
dungeons.add(dungeon);
|
||||
return dungeon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dungeon the dungeon to add
|
||||
*/
|
||||
public void addDungeon(Dungeon dungeon) {
|
||||
dungeons.add(dungeon);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dungeon the dungeon to remove
|
||||
*/
|
||||
public void removeDungeon(Dungeon dungeon) {
|
||||
dungeons.remove(dungeon);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,7 +18,8 @@ package de.erethon.dungeonsxl.dungeon;
|
|||
|
||||
import de.erethon.commons.config.DREConfig;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import de.erethon.dungeonsxl.world.WorldConfig;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
@ -26,7 +27,7 @@ import java.util.List;
|
|||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
/**
|
||||
* Represents a dungeon script. See {@link de.erethon.dungeonsxl.dungeon.Dungeon}.
|
||||
* Represents a dungeon script. See {@link de.erethon.dungeonsxl.dungeon.DDungeon}.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
|
@ -36,13 +37,13 @@ public class DungeonConfig extends DREConfig {
|
|||
|
||||
public static final int CONFIG_VERSION = 1;
|
||||
|
||||
private DResourceWorld startFloor;
|
||||
private DResourceWorld endFloor;
|
||||
private List<DResourceWorld> floors = new ArrayList<>();
|
||||
private ResourceWorld startFloor;
|
||||
private ResourceWorld endFloor;
|
||||
private List<ResourceWorld> floors = new ArrayList<>();
|
||||
private int floorCount;
|
||||
private boolean removeWhenPlayed;
|
||||
private WorldConfig overrideValues;
|
||||
private WorldConfig defaultValues;
|
||||
private GameRuleContainer overrideValues;
|
||||
private GameRuleContainer defaultValues;
|
||||
|
||||
public DungeonConfig(DungeonsXL plugin, File file) {
|
||||
super(file, CONFIG_VERSION);
|
||||
|
@ -55,142 +56,84 @@ public class DungeonConfig extends DREConfig {
|
|||
load();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the startFloor
|
||||
*/
|
||||
public DResourceWorld getStartFloor() {
|
||||
public ResourceWorld getStartFloor() {
|
||||
return startFloor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param startFloor the startFloor to set
|
||||
*/
|
||||
public void setStartFloor(DResourceWorld startFloor) {
|
||||
public void setStartFloor(ResourceWorld startFloor) {
|
||||
this.startFloor = startFloor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the endFloor
|
||||
*/
|
||||
public DResourceWorld getEndFloor() {
|
||||
public ResourceWorld getEndFloor() {
|
||||
return endFloor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param endFloor the endFloor to set
|
||||
*/
|
||||
public void setEndFloor(DResourceWorld endFloor) {
|
||||
public void setEndFloor(ResourceWorld endFloor) {
|
||||
this.endFloor = endFloor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the floors
|
||||
*/
|
||||
public List<DResourceWorld> getFloors() {
|
||||
public List<ResourceWorld> getFloors() {
|
||||
return floors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource the resource to add
|
||||
*/
|
||||
public void addFloor(DResourceWorld resource) {
|
||||
public void addFloor(ResourceWorld resource) {
|
||||
floors.add(resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource the resource to remove
|
||||
*/
|
||||
public void removeFloor(DResourceWorld resource) {
|
||||
public void removeFloor(ResourceWorld resource) {
|
||||
floors.remove(resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the floorCount
|
||||
*/
|
||||
public int getFloorCount() {
|
||||
return floorCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param floorCount the floorCount to set
|
||||
*/
|
||||
public void setFloorCount(int floorCount) {
|
||||
this.floorCount = floorCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the removeWhenPlayed
|
||||
*/
|
||||
public boolean getRemoveWhenPlayed() {
|
||||
return removeWhenPlayed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param removeWhenPlayed the removeWhenPlayed to set
|
||||
*/
|
||||
public void setRemoveWhenPlayed(boolean removeWhenPlayed) {
|
||||
this.removeWhenPlayed = removeWhenPlayed;
|
||||
}
|
||||
|
||||
/**
|
||||
* The values from this WorldConfig will override all values of the WorldConfigs of inherited maps.
|
||||
*
|
||||
* @return the override values
|
||||
*/
|
||||
public WorldConfig getOverrideValues() {
|
||||
public GameRuleContainer getOverrideValues() {
|
||||
return overrideValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param worldConfig the WorldConfig to set
|
||||
*/
|
||||
public void setOverrideValues(WorldConfig worldConfig) {
|
||||
public void setOverrideValues(GameRuleContainer worldConfig) {
|
||||
overrideValues = worldConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* The values from this WorldConfig will get overriden by values of the WorldConfigs of inherited maps. They will still override the values from the main
|
||||
* config, though.
|
||||
*
|
||||
* @return the default values
|
||||
*/
|
||||
public WorldConfig getDefaultValues() {
|
||||
public GameRuleContainer getDefaultValues() {
|
||||
return defaultValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param worldConfig the WorldConfig to set
|
||||
*/
|
||||
public void setDefaultValues(WorldConfig worldConfig) {
|
||||
public void setDefaultValues(GameRuleContainer worldConfig) {
|
||||
defaultValues = worldConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource the DResourceWorld to check
|
||||
* @return true if the floor is either in the list or the start / end floor.
|
||||
*/
|
||||
public boolean containsFloor(DResourceWorld resource) {
|
||||
public boolean containsFloor(ResourceWorld resource) {
|
||||
return floors.contains(resource) || startFloor.equals(resource) || endFloor.equals(resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mapName the name of the map to check
|
||||
* @return true if the floor is either in the list or the start / end floor.
|
||||
*/
|
||||
public boolean containsFloor(String mapName) {
|
||||
return containsFloor(plugin.getDWorldCache().getResourceByName(mapName));
|
||||
return containsFloor(plugin.getMapRegistry().get(mapName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
for (String floor : config.getStringList("floors")) {
|
||||
DResourceWorld resource = plugin.getDWorldCache().getResourceByName(floor);
|
||||
ResourceWorld resource = plugin.getMapRegistry().get(floor);
|
||||
if (resource != null) {
|
||||
floors.add(resource);
|
||||
}
|
||||
}
|
||||
startFloor = plugin.getDWorldCache().getResourceByName(config.getString("startFloor"));
|
||||
endFloor = plugin.getDWorldCache().getResourceByName(config.getString("endFloor"));
|
||||
startFloor = plugin.getMapRegistry().get(config.getString("startFloor"));
|
||||
endFloor = plugin.getMapRegistry().get(config.getString("endFloor"));
|
||||
floorCount = config.getInt("floorCount", floors.size() + 2);
|
||||
removeWhenPlayed = config.getBoolean("removeWhenPlayed", removeWhenPlayed);
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.event.dgroup;
|
||||
|
||||
import de.erethon.dungeonsxl.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.dungeon.DDungeon;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
@ -29,9 +29,9 @@ public class DGroupFinishDungeonEvent extends DGroupEvent implements Cancellable
|
|||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
private Dungeon dungeon;
|
||||
private DDungeon dungeon;
|
||||
|
||||
public DGroupFinishDungeonEvent(Dungeon dungeon, DGroup dGroup) {
|
||||
public DGroupFinishDungeonEvent(DDungeon dungeon, DGroup dGroup) {
|
||||
super(dGroup);
|
||||
this.dungeon = dungeon;
|
||||
}
|
||||
|
@ -39,14 +39,14 @@ public class DGroupFinishDungeonEvent extends DGroupEvent implements Cancellable
|
|||
/**
|
||||
* @return the dungeon
|
||||
*/
|
||||
public Dungeon getDungeon() {
|
||||
public DDungeon getDungeon() {
|
||||
return dungeon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dungeon the dungeon to set
|
||||
*/
|
||||
public void setDisbander(Dungeon dungeon) {
|
||||
public void setDisbander(DDungeon dungeon) {
|
||||
this.dungeon = dungeon;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.event.dplayer.instance.game;
|
||||
|
||||
import de.erethon.dungeonsxl.api.Reward;
|
||||
import de.erethon.dungeonsxl.player.DGamePlayer;
|
||||
import de.erethon.dungeonsxl.reward.Reward;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -37,7 +37,7 @@ public class DGamePlayerRewardEvent extends DGamePlayerEvent implements Cancella
|
|||
|
||||
public DGamePlayerRewardEvent(DGamePlayer dPlayer) {
|
||||
super(dPlayer);
|
||||
this.rewards = dPlayer.getDGroup().getRewards();
|
||||
this.rewards = dPlayer.getGroup().getRewards();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.event.gameworld;
|
||||
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import de.erethon.dungeonsxl.dungeon.DGame;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
@ -29,9 +29,9 @@ public class GameWorldStartGameEvent extends GameWorldEvent implements Cancellab
|
|||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
private Game game;
|
||||
private DGame game;
|
||||
|
||||
public GameWorldStartGameEvent(DGameWorld gameWorld, Game game) {
|
||||
public GameWorldStartGameEvent(DGameWorld gameWorld, DGame game) {
|
||||
super(gameWorld);
|
||||
this.game = game;
|
||||
}
|
||||
|
@ -39,14 +39,14 @@ public class GameWorldStartGameEvent extends GameWorldEvent implements Cancellab
|
|||
/**
|
||||
* @return the game
|
||||
*/
|
||||
public Game getGame() {
|
||||
public DGame getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param game the game to set
|
||||
*/
|
||||
public void setGame(Game game) {
|
||||
public void setGame(DGame game) {
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.event.requirement;
|
||||
|
||||
import de.erethon.dungeonsxl.requirement.Requirement;
|
||||
import de.erethon.dungeonsxl.api.Requirement;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.event.requirement;
|
||||
|
||||
import de.erethon.dungeonsxl.requirement.Requirement;
|
||||
import de.erethon.dungeonsxl.api.Requirement;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.event.requirement;
|
||||
|
||||
import de.erethon.dungeonsxl.requirement.Requirement;
|
||||
import de.erethon.dungeonsxl.api.Requirement;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.event.requirement;
|
||||
|
||||
import de.erethon.dungeonsxl.requirement.Requirement;
|
||||
import de.erethon.dungeonsxl.api.Requirement;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.event.reward;
|
||||
|
||||
import de.erethon.dungeonsxl.api.Reward;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.reward.Reward;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.event.reward;
|
||||
|
||||
import de.erethon.dungeonsxl.reward.Reward;
|
||||
import de.erethon.dungeonsxl.api.Reward;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.event.reward;
|
||||
|
||||
import de.erethon.dungeonsxl.reward.Reward;
|
||||
import de.erethon.dungeonsxl.api.Reward;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
|
|
@ -1,478 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.game;
|
||||
|
||||
import de.erethon.commons.player.PlayerUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.dungeon.DungeonConfig;
|
||||
import de.erethon.dungeonsxl.global.GameSign;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.sign.DSign;
|
||||
import de.erethon.dungeonsxl.sign.MobSign;
|
||||
import de.erethon.dungeonsxl.trigger.ProgressTrigger;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import de.erethon.dungeonsxl.world.WorldConfig;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* Game mostly stores for which purposes and how a {@link de.erethon.dungeonsxl.dungeon.Dungeon} is used, the player groups and the progress.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class Game {
|
||||
|
||||
private DungeonsXL plugin;
|
||||
|
||||
private boolean tutorial;
|
||||
private List<DGroup> dGroups = new ArrayList<>();
|
||||
private boolean started;
|
||||
private GameType type = GameTypeDefault.DEFAULT;
|
||||
private DGameWorld world;
|
||||
private GameRuleProvider rules;
|
||||
private int waveCount;
|
||||
private Map<String, Integer> gameKills = new HashMap<>();
|
||||
private Map<String, Integer> waveKills = new HashMap<>();
|
||||
|
||||
public Game(DungeonsXL plugin, DGroup dGroup) {
|
||||
this.plugin = plugin;
|
||||
plugin.getGameCache().add(this);
|
||||
|
||||
tutorial = false;
|
||||
started = false;
|
||||
|
||||
dGroups.add(dGroup);
|
||||
dGroup.setGameWorld(world);
|
||||
fetchRules();
|
||||
dGroup.setInitialLives(rules.getInitialGroupLives());
|
||||
dGroup.setLives(rules.getInitialGroupLives());
|
||||
dGroup.setScore(rules.getInitialScore());
|
||||
}
|
||||
|
||||
public Game(DungeonsXL plugin, DGroup dGroup, DGameWorld world) {
|
||||
this.plugin = plugin;
|
||||
plugin.getGameCache().add(this);
|
||||
|
||||
tutorial = false;
|
||||
started = false;
|
||||
this.world = world;
|
||||
|
||||
dGroups.add(dGroup);
|
||||
dGroup.setGameWorld(world);
|
||||
fetchRules();
|
||||
dGroup.setInitialLives(rules.getInitialGroupLives());
|
||||
dGroup.setLives(rules.getInitialGroupLives());
|
||||
dGroup.setScore(rules.getInitialScore());
|
||||
}
|
||||
|
||||
public Game(DungeonsXL plugin, DGroup dGroup, GameType type, DGameWorld world) {
|
||||
this(plugin, new ArrayList<>(Arrays.asList(dGroup)), type, world);
|
||||
}
|
||||
|
||||
public Game(DungeonsXL plugin, List<DGroup> dGroups, GameType type, DGameWorld world) {
|
||||
this.plugin = plugin;
|
||||
plugin.getGameCache().add(this);
|
||||
|
||||
this.dGroups = dGroups;
|
||||
this.type = type;
|
||||
this.world = world;
|
||||
this.tutorial = false;
|
||||
this.started = true;
|
||||
|
||||
for (DGroup dGroup : dGroups) {
|
||||
dGroup.setGameWorld(world);
|
||||
fetchRules();
|
||||
dGroup.setInitialLives(rules.getInitialGroupLives());
|
||||
dGroup.setLives(rules.getInitialGroupLives());
|
||||
dGroup.setScore(rules.getInitialScore());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public List<DGroup> getDGroups() {
|
||||
return dGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dGroup the dGroups to add
|
||||
*/
|
||||
public void addDGroup(DGroup dGroup) {
|
||||
dGroups.add(dGroup);
|
||||
|
||||
dGroup.setGameWorld(world);
|
||||
dGroup.setInitialLives(rules.getInitialGroupLives());
|
||||
dGroup.setLives(rules.getInitialGroupLives());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dGroup the dGroups to remove
|
||||
*/
|
||||
public void removeDGroup(DGroup dGroup) {
|
||||
dGroups.remove(dGroup);
|
||||
|
||||
if (dGroups.isEmpty()) {
|
||||
delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the Game has started yet
|
||||
*/
|
||||
public boolean hasStarted() {
|
||||
return started;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param started set if the Game has started yet
|
||||
*/
|
||||
public void setStarted(boolean started) {
|
||||
this.started = started;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
public GameType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the type to set
|
||||
*/
|
||||
public void setType(GameType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the DGameWorld connected to the Game
|
||||
*/
|
||||
public DGameWorld getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world the DGameWorld to connect to the Game
|
||||
*/
|
||||
public void setWorld(DGameWorld world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the GameRules
|
||||
*/
|
||||
public GameRuleProvider getRules() {
|
||||
return rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rules the GameRules to set
|
||||
*/
|
||||
public void setRules(GameRuleProvider rules) {
|
||||
this.rules = rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetchs the rules with the following priority: 1. Game type 2. Dungeon config: Override values 3. Floor config 4. Dungeon config: Default values 5. Main
|
||||
* config: Default values 6. The default values
|
||||
*/
|
||||
public void fetchRules() {
|
||||
DungeonConfig dungeonConfig = null;
|
||||
if (getDungeon() != null) {
|
||||
dungeonConfig = getDungeon().getConfig();
|
||||
}
|
||||
|
||||
WorldConfig floorConfig = null;
|
||||
if (world != null) {
|
||||
floorConfig = world.getConfig();
|
||||
}
|
||||
|
||||
GameRuleProvider finalRules = new GameRuleProvider();
|
||||
|
||||
if (type != null) {
|
||||
finalRules.apply(type);
|
||||
}
|
||||
|
||||
if (dungeonConfig != null && dungeonConfig.getOverrideValues() != null) {
|
||||
finalRules.apply(dungeonConfig.getOverrideValues());
|
||||
}
|
||||
|
||||
if (floorConfig != null) {
|
||||
finalRules.apply(floorConfig);
|
||||
}
|
||||
|
||||
if (dungeonConfig != null && dungeonConfig.getDefaultValues() != null) {
|
||||
finalRules.apply(dungeonConfig.getDefaultValues());
|
||||
}
|
||||
|
||||
finalRules.apply(plugin.getMainConfig().getDefaultWorldConfig());
|
||||
|
||||
finalRules.apply(GameRuleProvider.DEFAULT_VALUES);
|
||||
|
||||
rules = finalRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refers to the DGroup with the best progress.
|
||||
*
|
||||
* @return the unplayed floors
|
||||
*/
|
||||
public List<DResourceWorld> getUnplayedFloors() {
|
||||
List<DResourceWorld> unplayedFloors = null;
|
||||
for (DGroup dGroup : dGroups) {
|
||||
if (unplayedFloors == null || dGroup.getUnplayedFloors().size() < unplayedFloors.size()) {
|
||||
unplayedFloors = dGroup.getUnplayedFloors();
|
||||
}
|
||||
}
|
||||
if (unplayedFloors == null) {
|
||||
unplayedFloors = new ArrayList<>();
|
||||
}
|
||||
return unplayedFloors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refers to the DGroup with the best progress.
|
||||
*
|
||||
* @return the floorCount
|
||||
*/
|
||||
public int getFloorCount() {
|
||||
int floorCount = 0;
|
||||
for (DGroup dGroup : dGroups) {
|
||||
if (dGroup.getFloorCount() > floorCount) {
|
||||
floorCount = dGroup.getFloorCount();
|
||||
}
|
||||
}
|
||||
return floorCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the waveCount
|
||||
*/
|
||||
public int getWaveCount() {
|
||||
return waveCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param waveCount the waveCount to set
|
||||
*/
|
||||
public void setWaveCount(int waveCount) {
|
||||
this.waveCount = waveCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return how many mobs have been killed in the game
|
||||
*/
|
||||
public int getGameKills() {
|
||||
int count = 0;
|
||||
for (String killer : gameKills.keySet()) {
|
||||
count += gameKills.get(killer);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return how many mobs have been killed in the last game
|
||||
*/
|
||||
public int getWaveKills() {
|
||||
int count = 0;
|
||||
for (String killer : waveKills.keySet()) {
|
||||
count += waveKills.get(killer);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param killer the killer; null if the killer is not a player
|
||||
*/
|
||||
public void addKill(String killer) {
|
||||
if (killer == null) {
|
||||
killer = "N/A";
|
||||
}
|
||||
waveKills.put(killer, waveKills.get(killer) == null ? 1 : waveKills.get(killer) + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the values of the wave kills map to the game kills map and resets the wave kills.
|
||||
*/
|
||||
public void resetWaveKills() {
|
||||
gameKills.putAll(waveKills);
|
||||
waveKills.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Refers to a DGroup.
|
||||
*
|
||||
* @return the dungeon
|
||||
*/
|
||||
public Dungeon getDungeon() {
|
||||
return dGroups.get(0).getDungeon();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the players in all dGroups
|
||||
*/
|
||||
public Set<Player> getPlayers() {
|
||||
Set<Player> toReturn = new HashSet<>();
|
||||
for (DGroup dGroup : dGroups) {
|
||||
toReturn.addAll(dGroup.getPlayers().getOnlinePlayers());
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the DGroup list is empty
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return dGroups.isEmpty();
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
/**
|
||||
* Remove the Game from the List
|
||||
*/
|
||||
public void delete() {
|
||||
GameSign gameSign = GameSign.getByGame(plugin, this);
|
||||
|
||||
plugin.getGameCache().remove(this);
|
||||
|
||||
if (gameSign != null) {
|
||||
gameSign.update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mobCountIncreaseRate the new mob count will be increased by this rate
|
||||
* @param teleport whether or not to teleport the players to the start location
|
||||
*/
|
||||
public void finishWave(final double mobCountIncreaseRate, final boolean teleport) {
|
||||
waveCount++;
|
||||
resetWaveKills();
|
||||
|
||||
Set<ProgressTrigger> triggers = ProgressTrigger.getByGameWorld(world);
|
||||
for (ProgressTrigger trigger : triggers) {
|
||||
if (getWaveCount() >= trigger.getWaveCount() & getFloorCount() >= trigger.getFloorCount() - 1 || !getUnplayedFloors().contains(trigger.getFloor()) & trigger.getFloor() != null) {
|
||||
trigger.onTrigger();
|
||||
}
|
||||
}
|
||||
|
||||
int delay = rules.getTimeToNextWave();
|
||||
sendMessage(DMessage.GROUP_WAVE_FINISHED.getMessage(String.valueOf(waveCount), String.valueOf(delay)));
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (teleport) {
|
||||
for (Player player : getPlayers()) {
|
||||
PlayerUtil.secureTeleport(player, world.getStartLocation(DGroup.getByPlayer(player)));
|
||||
}
|
||||
}
|
||||
|
||||
for (DSign dSign : world.getDSigns()) {
|
||||
if (!(dSign instanceof MobSign)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
MobSign mobSign = (MobSign) dSign;
|
||||
int newAmount = (int) Math.ceil(mobSign.getInitialAmount() * mobCountIncreaseRate);
|
||||
|
||||
mobSign.setAmount(newAmount);
|
||||
mobSign.setInitialAmount(newAmount);
|
||||
mobSign.initializeTask();
|
||||
}
|
||||
}
|
||||
}.runTaskLater(plugin, delay * 20);
|
||||
}
|
||||
|
||||
public boolean isFinished() {
|
||||
return dGroups.stream().allMatch(DGroup::isFinished);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message the message to send
|
||||
*/
|
||||
public void sendMessage(String message) {
|
||||
for (DGroup dGroup : dGroups) {
|
||||
dGroup.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static Game getByDGroup(DGroup dGroup) {
|
||||
for (Game game : DungeonsXL.getInstance().getGameCache()) {
|
||||
if (game.getDGroups().contains(dGroup)) {
|
||||
return game;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Game getByPlayer(Player player) {
|
||||
return getByDGroup(DGroup.getByPlayer(player));
|
||||
}
|
||||
|
||||
public static Game getByGameWorld(DGameWorld gameWorld) {
|
||||
for (Game game : DungeonsXL.getInstance().getGameCache()) {
|
||||
if (gameWorld.equals(game.getWorld())) {
|
||||
return game;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Game getByWorld(World world) {
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(world);
|
||||
if (gameWorld != null) {
|
||||
return getByGameWorld(gameWorld);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "{dungeon=" + getDungeon() + "}";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.game;
|
||||
|
||||
/**
|
||||
* A game goal defines what the players have to do in order to finish the game.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public enum GameGoal {
|
||||
|
||||
/**
|
||||
* The default goal. The game ends when the end is reached.
|
||||
*/
|
||||
END,
|
||||
/**
|
||||
* The game does not end. Instead, the goal is to survive as long as possible to beat a highscore.
|
||||
*/
|
||||
HIGHSCORE,
|
||||
/**
|
||||
* The game ends when a player dies and only one group is left.
|
||||
*/
|
||||
LAST_MAN_STANDING,
|
||||
/**
|
||||
* The game ends when a group reachs a specific score.
|
||||
*/
|
||||
REACH_SCORE,
|
||||
/**
|
||||
* The game ends after a specific time. The goal is to get the highest score until then.
|
||||
*/
|
||||
TIME_SCORE,
|
||||
/**
|
||||
* The game ends after a specific time. The goal is to survive until then.
|
||||
*/
|
||||
TIME_SURVIVAL;
|
||||
|
||||
}
|
|
@ -1,880 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.game;
|
||||
|
||||
import de.erethon.caliburn.item.ExItem;
|
||||
import de.erethon.caliburn.mob.ExMob;
|
||||
import de.erethon.caliburn.mob.VanillaMob;
|
||||
import de.erethon.dungeonsxl.requirement.Requirement;
|
||||
import de.erethon.dungeonsxl.reward.Reward;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
/**
|
||||
* See {@link de.erethon.dungeonsxl.config.WorldConfig}
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class GameRuleProvider {
|
||||
|
||||
public static final GameRuleProvider DEFAULT_VALUES = new GameRuleProvider();
|
||||
|
||||
static {
|
||||
/* keepInventory */
|
||||
DEFAULT_VALUES.keepInventoryOnEnter = false;
|
||||
DEFAULT_VALUES.keepInventoryOnEscape = false;
|
||||
DEFAULT_VALUES.keepInventoryOnFinish = false;
|
||||
DEFAULT_VALUES.keepInventoryOnDeath = true;
|
||||
DEFAULT_VALUES.lobbyDisabled = false;
|
||||
|
||||
/* World */
|
||||
DEFAULT_VALUES.gameMode = GameMode.SURVIVAL;
|
||||
DEFAULT_VALUES.fly = false;
|
||||
DEFAULT_VALUES.breakBlocks = false;
|
||||
DEFAULT_VALUES.breakPlacedBlocks = false;
|
||||
DEFAULT_VALUES.breakWhitelist = null;
|
||||
DEFAULT_VALUES.damageProtectedEntities = new HashSet<>(Arrays.asList(
|
||||
VanillaMob.ARMOR_STAND,
|
||||
VanillaMob.ITEM_FRAME,
|
||||
VanillaMob.PAINTING
|
||||
));
|
||||
DEFAULT_VALUES.interactionProtectedEntities = new HashSet<>(Arrays.asList(
|
||||
VanillaMob.ARMOR_STAND,
|
||||
VanillaMob.ITEM_FRAME
|
||||
));
|
||||
DEFAULT_VALUES.placeBlocks = false;
|
||||
DEFAULT_VALUES.placeWhitelist = null;
|
||||
DEFAULT_VALUES.rain = null;
|
||||
DEFAULT_VALUES.thunder = null;
|
||||
DEFAULT_VALUES.time = null;
|
||||
|
||||
/* Fighting */
|
||||
DEFAULT_VALUES.playerVersusPlayer = false;
|
||||
DEFAULT_VALUES.friendlyFire = false;
|
||||
DEFAULT_VALUES.initialLives = -1;
|
||||
DEFAULT_VALUES.initialGroupLives = -1;
|
||||
DEFAULT_VALUES.initialScore = 3;
|
||||
DEFAULT_VALUES.scoreGoal = -1;
|
||||
|
||||
/* Timer */
|
||||
DEFAULT_VALUES.timeLastPlayed = 0;
|
||||
DEFAULT_VALUES.timeToNextPlayAfterStart = 0;
|
||||
DEFAULT_VALUES.timeToNextPlayAfterFinish = 0;
|
||||
DEFAULT_VALUES.timeToNextLoot = 0;
|
||||
DEFAULT_VALUES.timeToNextWave = 10;
|
||||
DEFAULT_VALUES.timeToFinish = -1;
|
||||
DEFAULT_VALUES.timeUntilKickOfflinePlayer = 0;
|
||||
|
||||
/* Requirements and rewards */
|
||||
DEFAULT_VALUES.requirements = new ArrayList<>();
|
||||
DEFAULT_VALUES.finishedOne = null;
|
||||
DEFAULT_VALUES.finishedAll = null;
|
||||
DEFAULT_VALUES.rewards = new ArrayList<>();
|
||||
|
||||
/* Commands and permissions */
|
||||
DEFAULT_VALUES.gameCommandWhitelist = new ArrayList<>();
|
||||
DEFAULT_VALUES.gamePermissions = new ArrayList<>();
|
||||
|
||||
/* Title */
|
||||
DEFAULT_VALUES.titleFadeIn = 20;
|
||||
DEFAULT_VALUES.titleFadeOut = 20;
|
||||
DEFAULT_VALUES.titleShow = 60;
|
||||
|
||||
/* Misc */
|
||||
DEFAULT_VALUES.msgs = new HashMap<>();
|
||||
DEFAULT_VALUES.secureObjects = new ArrayList<>();
|
||||
DEFAULT_VALUES.groupTagEnabled = false;
|
||||
}
|
||||
|
||||
/* keepInventory */
|
||||
protected Boolean keepInventoryOnEnter;
|
||||
protected Boolean keepInventoryOnEscape;
|
||||
protected Boolean keepInventoryOnFinish;
|
||||
protected Boolean keepInventoryOnDeath;
|
||||
protected Boolean lobbyDisabled;
|
||||
|
||||
/* World */
|
||||
protected GameMode gameMode;
|
||||
protected Boolean fly;
|
||||
protected Boolean breakBlocks;
|
||||
protected Boolean breakPlacedBlocks;
|
||||
protected Map<ExItem, HashSet<ExItem>> breakWhitelist;
|
||||
protected Set<ExMob> damageProtectedEntities;
|
||||
protected Set<ExMob> interactionProtectedEntities;
|
||||
protected Boolean placeBlocks;
|
||||
protected Set<ExItem> placeWhitelist;
|
||||
protected Boolean rain;
|
||||
protected Boolean thunder;
|
||||
protected Long time;
|
||||
|
||||
/* Fighting */
|
||||
protected Boolean playerVersusPlayer;
|
||||
protected Boolean friendlyFire;
|
||||
protected Integer initialLives;
|
||||
protected Integer initialGroupLives;
|
||||
protected Integer initialScore;
|
||||
protected Integer scoreGoal;
|
||||
|
||||
/* Timer */
|
||||
protected Integer timeLastPlayed;
|
||||
protected Integer timeToNextPlayAfterStart;
|
||||
protected Integer timeToNextPlayAfterFinish;
|
||||
protected Integer timeToNextLoot;
|
||||
protected Integer timeToNextWave;
|
||||
protected Integer timeToFinish;
|
||||
protected Integer timeUntilKickOfflinePlayer;
|
||||
|
||||
/* Requirements and rewards */
|
||||
protected List<Requirement> requirements;
|
||||
protected List<String> finishedOne;
|
||||
protected List<String> finishedAll;
|
||||
protected List<Reward> rewards;
|
||||
|
||||
/* Commands and permissions */
|
||||
protected List<String> gameCommandWhitelist;
|
||||
protected List<String> gamePermissions;
|
||||
|
||||
/* Title */
|
||||
protected String title;
|
||||
protected String subtitle;
|
||||
protected String actionBar;
|
||||
protected String chat;
|
||||
protected Integer titleFadeIn;
|
||||
protected Integer titleFadeOut;
|
||||
protected Integer titleShow;
|
||||
|
||||
/* Misc */
|
||||
protected Map<Integer, String> msgs;
|
||||
protected List<ExItem> secureObjects;
|
||||
protected Boolean groupTagEnabled;
|
||||
|
||||
/* Getters and setters */
|
||||
// keepInventory
|
||||
/**
|
||||
* @return if the inventory shall be kept when the player enters the dungeon
|
||||
*/
|
||||
public boolean getKeepInventoryOnEnter() {
|
||||
return keepInventoryOnEnter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the inventory shall be kept when the player leaves the dungeon successlessly
|
||||
*/
|
||||
public boolean getKeepInventoryOnEscape() {
|
||||
return keepInventoryOnEscape;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the inventory shall be kept when the player finishs the dungeon
|
||||
*/
|
||||
public boolean getKeepInventoryOnFinish() {
|
||||
return keepInventoryOnFinish;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the inventory shall be kept on death
|
||||
*/
|
||||
public boolean getKeepInventoryOnDeath() {
|
||||
return keepInventoryOnDeath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the lobby is disabled
|
||||
*/
|
||||
public boolean isLobbyDisabled() {
|
||||
return lobbyDisabled;
|
||||
}
|
||||
|
||||
// World
|
||||
/**
|
||||
* @return the gameMode
|
||||
*/
|
||||
public GameMode getGameMode() {
|
||||
return gameMode;
|
||||
}
|
||||
|
||||
public boolean canFly() {
|
||||
return fly;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if all blocks may be destroyed
|
||||
*/
|
||||
public boolean canBreakBlocks() {
|
||||
return breakBlocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if blocks placed in game may be destroyed
|
||||
*/
|
||||
public boolean canBreakPlacedBlocks() {
|
||||
return breakPlacedBlocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the destroyable materials and the materials that may be used to break them or null if any
|
||||
*/
|
||||
public Map<ExItem, HashSet<ExItem>> getBreakWhitelist() {
|
||||
return breakWhitelist;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a Set of all entity types that cannot be damaged
|
||||
*/
|
||||
public Set<ExMob> getDamageProtectedEntities() {
|
||||
return damageProtectedEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a Set of all entity types that cannot be damaged
|
||||
*/
|
||||
public Set<ExMob> getInteractionProtectedEntities() {
|
||||
return interactionProtectedEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if blocks may be placed
|
||||
*/
|
||||
public boolean canPlaceBlocks() {
|
||||
return placeBlocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the placeable materials
|
||||
*/
|
||||
public Set<ExItem> getPlaceWhitelist() {
|
||||
return placeWhitelist;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if it's raining permanently in this dungeon, null if random
|
||||
*/
|
||||
public Boolean isRaining() {
|
||||
return rain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rain set if it's raining permanently in this dungeon
|
||||
*/
|
||||
public void setRaining(Boolean rain) {
|
||||
this.rain = rain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return You've been... THUNDERSTRUCK!
|
||||
*/
|
||||
public Boolean isThundering() {
|
||||
return thunder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param thunder You've been... THUNDERSTRUCK!
|
||||
*/
|
||||
public void setThundering(Boolean thunder) {
|
||||
this.thunder = thunder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the locked day time in this dungeon, null if not locked
|
||||
*/
|
||||
public Long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param time the locked day time to set
|
||||
*/
|
||||
public void setTime(Long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
// Fight
|
||||
/**
|
||||
* @return if players may attack each other
|
||||
*/
|
||||
public boolean isPlayerVersusPlayer() {
|
||||
return playerVersusPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if players may attack group members
|
||||
*/
|
||||
public boolean isFriendlyFire() {
|
||||
return friendlyFire;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the initial amount of lives
|
||||
*/
|
||||
public int getInitialLives() {
|
||||
return initialLives;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the initial amount of group lives
|
||||
*/
|
||||
public int getInitialGroupLives() {
|
||||
return initialGroupLives;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the initial score
|
||||
*/
|
||||
public int getInitialScore() {
|
||||
return initialScore;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the score goal
|
||||
*/
|
||||
public int getScoreGoal() {
|
||||
return scoreGoal;
|
||||
}
|
||||
|
||||
// Timer
|
||||
/**
|
||||
* @return the timeLastPlayed
|
||||
*/
|
||||
public int getTimeLastPlayed() {
|
||||
return timeLastPlayed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the time until a player can play again after he started the dungeon the last time
|
||||
*/
|
||||
public int getTimeToNextPlayAfterStart() {
|
||||
return timeToNextPlayAfterStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the time until a player can play again after he finished the dungeon the last time
|
||||
*/
|
||||
public int getTimeToNextPlayAfterFinish() {
|
||||
return timeToNextPlayAfterFinish;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the time until a player can get loot again
|
||||
*/
|
||||
public int getTimeToNextLoot() {
|
||||
return timeToNextLoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the break between two waves
|
||||
*/
|
||||
public int getTimeToNextWave() {
|
||||
return timeToNextWave;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the time until a player gets kicked from his group
|
||||
*/
|
||||
public int getTimeToFinish() {
|
||||
return timeToFinish;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the time until a player gets kicked from his group if he is offline
|
||||
*/
|
||||
public int getTimeUntilKickOfflinePlayer() {
|
||||
return timeUntilKickOfflinePlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the game is "time is running"
|
||||
*/
|
||||
public boolean isTimeIsRunning() {
|
||||
return timeToFinish != -1;
|
||||
}
|
||||
|
||||
// Requirements and rewards
|
||||
/**
|
||||
* @return the requirements
|
||||
*/
|
||||
public List<Requirement> getRequirements() {
|
||||
if (requirements == null) {
|
||||
requirements = new ArrayList<>();
|
||||
}
|
||||
return requirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all maps needed to be finished to play this map
|
||||
*/
|
||||
public List<String> getFinishedAll() {
|
||||
if (finishedAll == null) {
|
||||
finishedAll = new ArrayList<>();
|
||||
}
|
||||
return finishedAll;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all maps needed to be finished to play this map and a collection of maps of which at least one has to be finished
|
||||
*/
|
||||
public List<String> getFinished() {
|
||||
if (finishedAll == null) {
|
||||
finishedAll = new ArrayList<>();
|
||||
}
|
||||
if (finishedOne == null) {
|
||||
finishedOne = new ArrayList<>();
|
||||
}
|
||||
|
||||
List<String> merge = new ArrayList<>();
|
||||
merge.addAll(finishedAll);
|
||||
merge.addAll(finishedOne);
|
||||
return merge;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the rewards
|
||||
*/
|
||||
public List<Reward> getRewards() {
|
||||
if (rewards == null) {
|
||||
rewards = new ArrayList<>();
|
||||
}
|
||||
return rewards;
|
||||
}
|
||||
|
||||
// Commands and permissions
|
||||
/**
|
||||
* @return the gameCommandWhitelist
|
||||
*/
|
||||
public List<String> getGameCommandWhitelist() {
|
||||
if (gameCommandWhitelist == null) {
|
||||
gameCommandWhitelist = new ArrayList<>();
|
||||
}
|
||||
return gameCommandWhitelist;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the gamePermissions
|
||||
*/
|
||||
public List<String> getGamePermissions() {
|
||||
if (gamePermissions == null) {
|
||||
gamePermissions = new ArrayList<>();
|
||||
}
|
||||
return gamePermissions;
|
||||
}
|
||||
|
||||
// Title
|
||||
/**
|
||||
* @return the main title string or null for the default one
|
||||
*/
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param text the text to set
|
||||
*/
|
||||
public void setTitle(String text) {
|
||||
title = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the subtitle string or null for the default one
|
||||
*/
|
||||
public String getSubTitle() {
|
||||
return subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param text the text to set
|
||||
*/
|
||||
public void setSubTitle(String text) {
|
||||
subtitle = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the action bar string or null for the default one
|
||||
*/
|
||||
public String getActionBar() {
|
||||
return actionBar;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param text the text to set
|
||||
*/
|
||||
public void setActionBar(String text) {
|
||||
actionBar = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the chat message string or null for the default one
|
||||
*/
|
||||
public String getChatText() {
|
||||
return chat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param text the text to set
|
||||
*/
|
||||
public void setChatText(String text) {
|
||||
chat = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the title fade in time in ticks
|
||||
*/
|
||||
public int getTitleFadeIn() {
|
||||
return titleFadeIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param time the time to set
|
||||
*/
|
||||
public void setTitleFadeIn(int time) {
|
||||
titleFadeIn = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the title fade out time in ticks
|
||||
*/
|
||||
public int getTitleFadeOut() {
|
||||
return titleFadeOut;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param time the time to set
|
||||
*/
|
||||
public void setTitleFadeOut(int time) {
|
||||
titleFadeOut = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the time until the title disappears in ticks
|
||||
*/
|
||||
public int getTitleShow() {
|
||||
return titleShow;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param time the time to set
|
||||
*/
|
||||
public void setTitleShow(int time) {
|
||||
titleShow = time;
|
||||
}
|
||||
|
||||
// Misc
|
||||
/**
|
||||
* @param id the id of the message
|
||||
* @return the message
|
||||
*/
|
||||
public String getMessage(int id) {
|
||||
if (msgs == null) {
|
||||
msgs = new HashMap<>();
|
||||
}
|
||||
return msgs.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the ID of the message
|
||||
* @param msg the message to set
|
||||
*/
|
||||
public void setMessage(int id, String msg) {
|
||||
if (msgs == null) {
|
||||
msgs = new HashMap<>();
|
||||
}
|
||||
msgs.put(id, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the objects to get passed to another player of the group when this player leaves
|
||||
*/
|
||||
public List<ExItem> getSecureObjects() {
|
||||
if (secureObjects == null) {
|
||||
secureObjects = new ArrayList<>();
|
||||
}
|
||||
return secureObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the group tag is enabled. Returns false if HolographicDisplays isn't loaded
|
||||
*/
|
||||
public boolean isGroupTagEnabled() {
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) {
|
||||
return false;
|
||||
}
|
||||
return groupTagEnabled;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
/**
|
||||
* @param defaultValues the GameType that overrides the values that are null.
|
||||
*/
|
||||
public void apply(GameType defaultValues) {
|
||||
if (playerVersusPlayer == null) {
|
||||
playerVersusPlayer = defaultValues.isPlayerVersusPlayer();
|
||||
}
|
||||
|
||||
if (friendlyFire == null) {
|
||||
friendlyFire = defaultValues.isFriendlyFire();
|
||||
}
|
||||
|
||||
if (timeToFinish == null && defaultValues.getShowTime() != null) {
|
||||
timeToFinish = defaultValues.getShowTime() ? null : -1;
|
||||
}
|
||||
|
||||
if (breakBlocks == null) {
|
||||
breakBlocks = defaultValues.canBreakBlocks();
|
||||
}
|
||||
|
||||
if (breakPlacedBlocks == null) {
|
||||
breakPlacedBlocks = defaultValues.canBreakPlacedBlocks();
|
||||
}
|
||||
|
||||
if (placeBlocks == null) {
|
||||
placeBlocks = defaultValues.canPlaceBlocks();
|
||||
}
|
||||
|
||||
if (gameMode == null) {
|
||||
gameMode = defaultValues.getGameMode();
|
||||
}
|
||||
|
||||
if (initialLives == null) {
|
||||
if (defaultValues.hasLives() != null) {
|
||||
initialLives = defaultValues.hasLives() ? null : -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param defaultValues the GameRules that override the values that are null.
|
||||
*/
|
||||
public void apply(GameRuleProvider defaultValues) {
|
||||
/* keepInventory */
|
||||
if (keepInventoryOnEnter == null) {
|
||||
keepInventoryOnEnter = defaultValues.keepInventoryOnEnter;
|
||||
}
|
||||
|
||||
if (keepInventoryOnEscape == null) {
|
||||
keepInventoryOnEscape = defaultValues.keepInventoryOnEscape;
|
||||
}
|
||||
|
||||
if (keepInventoryOnFinish == null) {
|
||||
keepInventoryOnFinish = defaultValues.keepInventoryOnFinish;
|
||||
}
|
||||
|
||||
if (keepInventoryOnDeath == null) {
|
||||
keepInventoryOnDeath = defaultValues.keepInventoryOnDeath;
|
||||
}
|
||||
|
||||
if (lobbyDisabled == null) {
|
||||
lobbyDisabled = defaultValues.lobbyDisabled;
|
||||
}
|
||||
|
||||
/* World */
|
||||
if (gameMode == null) {
|
||||
gameMode = defaultValues.gameMode;
|
||||
}
|
||||
|
||||
if (fly == null) {
|
||||
fly = defaultValues.fly;
|
||||
}
|
||||
|
||||
if (breakBlocks == null) {
|
||||
breakBlocks = defaultValues.breakBlocks;
|
||||
}
|
||||
|
||||
if (breakPlacedBlocks == null) {
|
||||
breakPlacedBlocks = defaultValues.breakPlacedBlocks;
|
||||
}
|
||||
|
||||
if (breakWhitelist == null) {
|
||||
breakWhitelist = defaultValues.breakWhitelist;
|
||||
}
|
||||
|
||||
if (damageProtectedEntities == null) {
|
||||
// If nothing is specialized for protected entites yet (=> damageProtectedEntites == null and DEFAULT_VALUES are used)
|
||||
// and if blocks may be broken, it makes no sense to assume the user wants to have paintings etc. protected.
|
||||
if (defaultValues == DEFAULT_VALUES && breakBlocks) {
|
||||
damageProtectedEntities = new HashSet<>();
|
||||
} else {
|
||||
damageProtectedEntities = defaultValues.damageProtectedEntities;
|
||||
}
|
||||
}
|
||||
|
||||
if (interactionProtectedEntities == null) {
|
||||
// If nothing is specialized for protected entites yet (=> interactionProtectedEntites == null and DEFAULT_VALUES are used)
|
||||
// and if blocks may be broken, it makes no sense to assume the user wants to have paintings etc. protected.
|
||||
if (defaultValues == DEFAULT_VALUES && breakBlocks) {
|
||||
interactionProtectedEntities = new HashSet<>();
|
||||
} else {
|
||||
interactionProtectedEntities = defaultValues.interactionProtectedEntities;
|
||||
}
|
||||
}
|
||||
|
||||
if (placeBlocks == null) {
|
||||
placeBlocks = defaultValues.placeBlocks;
|
||||
}
|
||||
|
||||
if (placeWhitelist == null) {
|
||||
placeWhitelist = defaultValues.placeWhitelist;
|
||||
}
|
||||
|
||||
if (rain == null) {
|
||||
rain = defaultValues.rain;
|
||||
}
|
||||
|
||||
if (thunder == null) {
|
||||
thunder = defaultValues.thunder;
|
||||
}
|
||||
|
||||
if (time == null) {
|
||||
time = defaultValues.time;
|
||||
}
|
||||
|
||||
/* Fighting */
|
||||
if (playerVersusPlayer == null) {
|
||||
playerVersusPlayer = defaultValues.playerVersusPlayer;
|
||||
}
|
||||
|
||||
if (friendlyFire == null) {
|
||||
friendlyFire = defaultValues.friendlyFire;
|
||||
}
|
||||
|
||||
if (initialLives == null) {
|
||||
initialLives = defaultValues.initialLives;
|
||||
}
|
||||
|
||||
if (initialGroupLives == null) {
|
||||
initialGroupLives = defaultValues.initialGroupLives;
|
||||
}
|
||||
|
||||
if (initialScore == null) {
|
||||
initialScore = defaultValues.initialScore;
|
||||
}
|
||||
|
||||
if (scoreGoal == null) {
|
||||
scoreGoal = defaultValues.scoreGoal;
|
||||
}
|
||||
|
||||
/* Timer */
|
||||
if (timeLastPlayed == null) {
|
||||
timeLastPlayed = defaultValues.timeLastPlayed;
|
||||
}
|
||||
|
||||
if (timeToNextPlayAfterStart == null) {
|
||||
timeToNextPlayAfterStart = defaultValues.timeToNextPlayAfterStart;
|
||||
}
|
||||
|
||||
if (timeToNextPlayAfterFinish == null) {
|
||||
timeToNextPlayAfterFinish = defaultValues.timeToNextPlayAfterFinish;
|
||||
}
|
||||
|
||||
if (timeToNextLoot == null) {
|
||||
timeToNextLoot = defaultValues.timeToNextLoot;
|
||||
}
|
||||
|
||||
if (timeToNextWave == null) {
|
||||
timeToNextWave = defaultValues.timeToNextWave;
|
||||
}
|
||||
|
||||
if (timeToFinish == null) {
|
||||
timeToFinish = defaultValues.timeToFinish;
|
||||
}
|
||||
|
||||
if (timeUntilKickOfflinePlayer == null) {
|
||||
timeUntilKickOfflinePlayer = defaultValues.timeUntilKickOfflinePlayer;
|
||||
}
|
||||
|
||||
/* Requirements and rewards */
|
||||
if (requirements == null) {
|
||||
requirements = defaultValues.requirements;
|
||||
}
|
||||
|
||||
if (finishedOne == null) {
|
||||
finishedOne = defaultValues.finishedOne;
|
||||
}
|
||||
|
||||
if (finishedAll == null) {
|
||||
finishedAll = defaultValues.finishedAll;
|
||||
}
|
||||
|
||||
if (rewards == null) {
|
||||
rewards = defaultValues.rewards;
|
||||
}
|
||||
|
||||
/* Commands and permissions */
|
||||
if (gameCommandWhitelist == null) {
|
||||
gameCommandWhitelist = defaultValues.gameCommandWhitelist;
|
||||
} else if (defaultValues.gameCommandWhitelist != null) {
|
||||
gameCommandWhitelist.addAll(defaultValues.gameCommandWhitelist);
|
||||
}
|
||||
|
||||
if (gamePermissions == null) {
|
||||
gamePermissions = defaultValues.gamePermissions;
|
||||
} else if (defaultValues.gamePermissions != null) {
|
||||
gamePermissions.addAll(defaultValues.gamePermissions);
|
||||
}
|
||||
|
||||
/* Title */
|
||||
if (title == null) {
|
||||
title = defaultValues.title;
|
||||
}
|
||||
|
||||
if (subtitle == null) {
|
||||
subtitle = defaultValues.subtitle;
|
||||
}
|
||||
|
||||
if (actionBar == null) {
|
||||
actionBar = defaultValues.actionBar;
|
||||
}
|
||||
|
||||
if (chat == null) {
|
||||
chat = defaultValues.chat;
|
||||
}
|
||||
|
||||
if (titleFadeIn == null) {
|
||||
titleFadeIn = defaultValues.titleFadeIn;
|
||||
}
|
||||
|
||||
if (titleFadeOut == null) {
|
||||
titleFadeOut = defaultValues.titleFadeOut;
|
||||
}
|
||||
|
||||
if (titleShow == null) {
|
||||
titleShow = defaultValues.titleShow;
|
||||
}
|
||||
|
||||
/* Misc */
|
||||
if (msgs == null) {
|
||||
msgs = defaultValues.msgs;
|
||||
} else if (defaultValues.msgs != null) {
|
||||
msgs.putAll(defaultValues.msgs);
|
||||
}
|
||||
|
||||
if (secureObjects == null) {
|
||||
secureObjects = defaultValues.secureObjects;
|
||||
} else if (defaultValues.secureObjects != null) {
|
||||
secureObjects.addAll(defaultValues.secureObjects);
|
||||
}
|
||||
|
||||
if (groupTagEnabled == null) {
|
||||
groupTagEnabled = defaultValues.groupTagEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,148 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.game;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
/**
|
||||
* Implement this to create custom game types.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public interface GameType {
|
||||
|
||||
/**
|
||||
* @return the displayName
|
||||
*/
|
||||
String getDisplayName();
|
||||
|
||||
/**
|
||||
* @param displayName the displayName to set
|
||||
*/
|
||||
void setDisplayName(String displayName);
|
||||
|
||||
/**
|
||||
* @return the signName
|
||||
*/
|
||||
String getSignName();
|
||||
|
||||
/**
|
||||
* @param signName the signName to set
|
||||
*/
|
||||
void setSignName(String signName);
|
||||
|
||||
/**
|
||||
* @return the goal of the game
|
||||
*/
|
||||
GameGoal getGameGoal();
|
||||
|
||||
/**
|
||||
* @param gameGoal the goal of the game to set
|
||||
*/
|
||||
void setGameGoal(GameGoal gameGoal);
|
||||
|
||||
/**
|
||||
* @return the playerVersusPlayer
|
||||
*/
|
||||
Boolean isPlayerVersusPlayer();
|
||||
|
||||
/**
|
||||
* @param playerVersusPlayer the playerVersusPlayer to set
|
||||
*/
|
||||
void setPlayerVersusPlayer(Boolean playerVersusPlayer);
|
||||
|
||||
/**
|
||||
* @return the friendlyFire
|
||||
*/
|
||||
Boolean isFriendlyFire();
|
||||
|
||||
/**
|
||||
* @param friendlyFire the friendlyFire to set
|
||||
*/
|
||||
void setFriendlyFire(Boolean friendlyFire);
|
||||
|
||||
/**
|
||||
* @return if players get rewards after the dungeon
|
||||
*/
|
||||
Boolean hasRewards();
|
||||
|
||||
/**
|
||||
* @param rewards enable / disable rewards
|
||||
*/
|
||||
void setRewards(Boolean rewards);
|
||||
|
||||
/**
|
||||
* @return if players shall see how long they play
|
||||
*/
|
||||
Boolean getShowTime();
|
||||
|
||||
/**
|
||||
* @param showTime set if players shall see how long they play
|
||||
*/
|
||||
void setShowTime(Boolean showTime);
|
||||
|
||||
/**
|
||||
* @return if all blocks may be destroyed
|
||||
*/
|
||||
Boolean canBreakBlocks();
|
||||
|
||||
/**
|
||||
* @param breakBlocks if blocks may be destroyed
|
||||
*/
|
||||
void setBreakBlocks(Boolean breakBlocks);
|
||||
|
||||
/**
|
||||
* @return if blocks placed in game may be destroyed
|
||||
*/
|
||||
Boolean canBreakPlacedBlocks();
|
||||
|
||||
/**
|
||||
* @param breakPlacedBlocks if placed blocks may be destroyed
|
||||
*/
|
||||
void setBreakPlacedBlocks(Boolean breakPlacedBlocks);
|
||||
|
||||
/**
|
||||
* @return if blocks may be placed
|
||||
*/
|
||||
Boolean canPlaceBlocks();
|
||||
|
||||
/**
|
||||
* @param placeBlocks if blocks may be placed
|
||||
*/
|
||||
void setPlaceBlocks(Boolean placeBlocks);
|
||||
|
||||
/**
|
||||
* @return the gameMode
|
||||
*/
|
||||
GameMode getGameMode();
|
||||
|
||||
/**
|
||||
* @param gameMode the gameMode to set
|
||||
*/
|
||||
void setGameMode(GameMode gameMode);
|
||||
|
||||
/**
|
||||
* @return if players lose lives
|
||||
*/
|
||||
Boolean hasLives();
|
||||
|
||||
/**
|
||||
* @param lives set if the gametype uses player lives
|
||||
*/
|
||||
void setLives(Boolean lives);
|
||||
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.game;
|
||||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.sign.DSign;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* GameType instance manager.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class GameTypeCache {
|
||||
|
||||
private List<GameType> types = new ArrayList<>();
|
||||
|
||||
public GameTypeCache() {
|
||||
for (GameType type : GameTypeDefault.values()) {
|
||||
if (type == GameTypeDefault.PVP_FACTIONS_BATTLEFIELD) {
|
||||
try {
|
||||
Class.forName("com.massivecraft.factions.Patch");
|
||||
|
||||
} catch (ClassNotFoundException exception) {
|
||||
MessageUtil.log("Could not find compatible Factions plugin. The game type PVP_FACTIONS_BATTLEFIELD will not get enabled...");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
types.add(type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to check
|
||||
* @return the game type which has the enum value name
|
||||
*/
|
||||
public GameType getByName(String name) {
|
||||
for (GameType type : types) {
|
||||
if (type.toString().equals(name)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sign the sign to check
|
||||
* @return the game type which has the enum value sign text in the second line of the sign
|
||||
*/
|
||||
public GameType getBySign(DSign sign) {
|
||||
String[] lines = sign.getLines();
|
||||
|
||||
for (GameType type : types) {
|
||||
if (type.getSignName().equals(lines[1])) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the game types
|
||||
*/
|
||||
public List<GameType> getGameTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the game type to add
|
||||
*/
|
||||
public void addGameType(GameType type) {
|
||||
types.add(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the game type to remove
|
||||
*/
|
||||
public void removeGameType(GameType type) {
|
||||
types.remove(type);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,201 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.game;
|
||||
|
||||
import static de.erethon.dungeonsxl.game.GameGoal.*;
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
/**
|
||||
* Default implementation of {@link de.erethon.dungeonsxl.game.GameType}.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public enum GameTypeDefault implements GameType {
|
||||
|
||||
ADVENTURE("Adventure", "Adventure", END, false, false, true, false, true, true, true, GameMode.ADVENTURE, true),
|
||||
ADVENTURE_TIME_IS_RUNNING("Adventure - Time is Running", "Adventure TiR", TIME_SCORE, false, false, true, true, true, true, true, GameMode.ADVENTURE, true),
|
||||
APOCALYPSE("Apocalypse", "Apocalypse", HIGHSCORE, true, true, true, false, false, false, false, GameMode.SURVIVAL, true),
|
||||
APOCALYPSE_LAST_MAN_STANDING("Apocalypse", "Apocalypse LMS", LAST_MAN_STANDING, true, true, true, false, false, false, false, GameMode.SURVIVAL, true),
|
||||
APOCALYPSE_LIMITED_MOBS("Apocalypse - Limited Mobs", "Apc Limited", END, true, true, true, false, false, false, false, GameMode.SURVIVAL, true),
|
||||
APOCALYPSE_TIME_IS_RUNNING("Apocalypse - Time is Running", "Apocalypse TiR", TIME_SURVIVAL, true, true, true, true, false, false, false, GameMode.SURVIVAL, true),
|
||||
BEDWARS("Bedwars", "Bedwars", LAST_MAN_STANDING, true, false, false, false, false, true, true, GameMode.SURVIVAL, false),
|
||||
PVE_LAST_MAN_STANDING("Player versus Environment - Last Man Standing", "PvE LMS", LAST_MAN_STANDING, false, false, true, false, false, false, false, GameMode.SURVIVAL, true),
|
||||
PVE_LIMITED_MOBS("Player versus Environment - Limited Mobs", "PvE Limited", END, false, false, true, false, false, false, false, GameMode.SURVIVAL, true),
|
||||
PVE_TIME_IS_RUNNING("Player versus Environment - Time is Running", "PvE TiR", TIME_SURVIVAL, false, false, true, true, false, false, false, GameMode.SURVIVAL, true),
|
||||
PVP_FACTIONS_BATTLEFIELD("Player versus Player - Factions Battlefield", "FactionsPvP", LAST_MAN_STANDING, true, false, false, false, false, false, false, GameMode.SURVIVAL, true),
|
||||
PVP_LAST_MAN_STANDING("Player versus Player - Last Man Standing", "PvP LMS", LAST_MAN_STANDING, true, false, false, false, false, false, false, GameMode.SURVIVAL, true),
|
||||
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),
|
||||
DEFAULT("Default", "Default", END, false, false, true, false, false, false, false, GameMode.SURVIVAL, true),
|
||||
CUSTOM("Custom", "Custom");
|
||||
|
||||
private String displayName;
|
||||
private String signName;
|
||||
private GameGoal gameGoal;
|
||||
private Boolean playerVersusPlayer;
|
||||
private Boolean friendlyFire;
|
||||
private Boolean rewards;
|
||||
private Boolean showTime;
|
||||
private Boolean breakBlocks;
|
||||
private Boolean breakPlacedBlocks;
|
||||
private Boolean placeBlocks;
|
||||
private GameMode gameMode;
|
||||
private Boolean lives;
|
||||
|
||||
GameTypeDefault(String displayName, String signName, GameGoal gameGoal, Boolean playerVersusPlayer, Boolean friendlyFire, Boolean rewards,
|
||||
Boolean showTime, Boolean breakBlocks, Boolean breakPlacedBlocks, Boolean placeBlocks, GameMode gameMode, Boolean lives) {
|
||||
this.displayName = displayName;
|
||||
this.signName = signName;
|
||||
this.gameGoal = gameGoal;
|
||||
this.playerVersusPlayer = playerVersusPlayer;
|
||||
this.friendlyFire = friendlyFire;
|
||||
this.rewards = rewards;
|
||||
this.showTime = showTime;
|
||||
this.breakBlocks = breakBlocks;
|
||||
this.breakPlacedBlocks = breakPlacedBlocks;
|
||||
this.placeBlocks = placeBlocks;
|
||||
this.gameMode = gameMode;
|
||||
this.lives = lives;
|
||||
}
|
||||
|
||||
GameTypeDefault(String displayName, String signName) {
|
||||
this.displayName = displayName;
|
||||
this.signName = signName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameGoal getGameGoal() {
|
||||
return gameGoal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGameGoal(GameGoal gameGoal) {
|
||||
this.gameGoal = gameGoal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSignName() {
|
||||
return signName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSignName(String signName) {
|
||||
this.signName = signName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isPlayerVersusPlayer() {
|
||||
return playerVersusPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerVersusPlayer(Boolean playerVersusPlayer) {
|
||||
this.playerVersusPlayer = playerVersusPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isFriendlyFire() {
|
||||
return friendlyFire;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFriendlyFire(Boolean friendlyFire) {
|
||||
this.friendlyFire = friendlyFire;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean hasRewards() {
|
||||
return rewards;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRewards(Boolean rewards) {
|
||||
this.rewards = rewards;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getShowTime() {
|
||||
return showTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShowTime(Boolean showTime) {
|
||||
this.showTime = showTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean canBreakBlocks() {
|
||||
return breakBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBreakBlocks(Boolean breakBlocks) {
|
||||
this.breakBlocks = breakBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean canBreakPlacedBlocks() {
|
||||
return breakPlacedBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBreakPlacedBlocks(Boolean breakPlacedBlocks) {
|
||||
this.breakPlacedBlocks = breakPlacedBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean canPlaceBlocks() {
|
||||
return placeBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlaceBlocks(Boolean placeBlocks) {
|
||||
this.placeBlocks = placeBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameMode getGameMode() {
|
||||
return gameMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGameMode(GameMode gameMode) {
|
||||
this.gameMode = gameMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean hasLives() {
|
||||
return lives;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLives(Boolean lives) {
|
||||
this.lives = lives;
|
||||
}
|
||||
|
||||
}
|
|
@ -21,13 +21,14 @@ import de.erethon.caliburn.item.VanillaItem;
|
|||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.commons.misc.BlockUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Game;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import de.erethon.dungeonsxl.dungeon.DGame;
|
||||
import de.erethon.dungeonsxl.player.DGamePlayer;
|
||||
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Location;
|
||||
|
@ -209,14 +210,14 @@ public class DPortal extends GlobalProtection {
|
|||
return;
|
||||
}
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
if (dGroup == null) {
|
||||
PlayerGroup group = plugin.getPlayerGroup(player);
|
||||
if (group == null) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_JOIN_GROUP.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
DGameWorld target = dGroup.getGameWorld();
|
||||
Game game = Game.getByDGroup(dGroup);
|
||||
GameWorld target = group.getGameWorld();
|
||||
Game game = group.getGame();
|
||||
|
||||
if (target == null && game != null) {
|
||||
target = game.getWorld();
|
||||
|
@ -224,7 +225,7 @@ public class DPortal extends GlobalProtection {
|
|||
|
||||
if (target == null) {
|
||||
if (game != null) {
|
||||
for (DGroup otherTeam : game.getDGroups()) {
|
||||
for (PlayerGroup otherTeam : game.getGroups()) {
|
||||
if (otherTeam.getGameWorld() != null) {
|
||||
target = otherTeam.getGameWorld();
|
||||
break;
|
||||
|
@ -233,15 +234,15 @@ public class DPortal extends GlobalProtection {
|
|||
}
|
||||
}
|
||||
|
||||
if (target == null && dGroup.getDungeon() != null) {
|
||||
DResourceWorld resource = dGroup.getDungeon().getMap();
|
||||
if (target == null && group.getDungeon() != null) {
|
||||
ResourceWorld resource = group.getDungeon().getMap();
|
||||
if (resource != null) {
|
||||
target = resource.instantiateAsGameWorld(false);
|
||||
target = resource.instantiateGameWorld(false);
|
||||
if (target == null) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
|
||||
return;
|
||||
}
|
||||
dGroup.setGameWorld(target);
|
||||
group.setGameWorld(target);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,11 +252,11 @@ public class DPortal extends GlobalProtection {
|
|||
}
|
||||
|
||||
if (game == null) {
|
||||
game = new Game(plugin, dGroup, target);
|
||||
game = new DGame(plugin, group, target);
|
||||
|
||||
} else {
|
||||
game.setWorld(target);
|
||||
dGroup.setGameWorld(target);
|
||||
group.setGameWorld(target);
|
||||
}
|
||||
|
||||
new DGamePlayer(plugin, player, target);
|
||||
|
|
|
@ -20,8 +20,9 @@ import de.erethon.caliburn.category.Category;
|
|||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.commons.misc.NumberUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import de.erethon.dungeonsxl.dungeon.DGame;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
@ -39,7 +40,7 @@ public class GameSign extends JoinSign {
|
|||
|
||||
public static final String GAME_SIGN_TAG = "Game";
|
||||
|
||||
private Game game;
|
||||
private DGame game;
|
||||
|
||||
public GameSign(DungeonsXL plugin, int id, Block startSign, String identifier, int maxGroupsPerGame, int startIfElementsAtLeast) {
|
||||
super(plugin, id, startSign, identifier, maxGroupsPerGame, startIfElementsAtLeast);
|
||||
|
@ -52,14 +53,14 @@ public class GameSign extends JoinSign {
|
|||
/**
|
||||
* @return the attached game
|
||||
*/
|
||||
public Game getGame() {
|
||||
public DGame getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param game the game to set
|
||||
*/
|
||||
public void setGame(Game game) {
|
||||
public void setGame(DGame game) {
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
|
@ -75,22 +76,22 @@ public class GameSign extends JoinSign {
|
|||
super.update();
|
||||
Sign sign = (Sign) startSign.getState();
|
||||
|
||||
if (game == null || game.getDGroups().isEmpty()) {
|
||||
if (game == null || game.getGroups().isEmpty()) {
|
||||
loadedWorld = false;
|
||||
sign.setLine(0, DMessage.SIGN_GLOBAL_NEW_GAME.getMessage());
|
||||
sign.update();
|
||||
return;
|
||||
}
|
||||
|
||||
if (game.getDGroups().size() >= startIfElementsAtLeast && startIfElementsAtLeast != -1) {
|
||||
if (game.getGroups().size() >= startIfElementsAtLeast && startIfElementsAtLeast != -1) {
|
||||
loadedWorld = true;
|
||||
game.getDGroups().forEach(g -> g.teleport());
|
||||
game.getGroups().forEach(g -> ((DGroup) g).teleport());
|
||||
}
|
||||
|
||||
if (game.getDGroups().get(0).isPlaying()) {
|
||||
if (game.getGroups().get(0).isPlaying()) {
|
||||
sign.setLine(0, DMessage.SIGN_GLOBAL_IS_PLAYING.getMessage());
|
||||
|
||||
} else if (game.getDGroups().size() >= maxElements) {
|
||||
} else if (game.getGroups().size() >= maxElements) {
|
||||
sign.setLine(0, DMessage.SIGN_GLOBAL_FULL.getMessage());
|
||||
|
||||
} else {
|
||||
|
@ -100,7 +101,7 @@ public class GameSign extends JoinSign {
|
|||
int j = 1;
|
||||
Sign rowSign = sign;
|
||||
|
||||
for (DGroup dGroup : game.getDGroups()) {
|
||||
for (PlayerGroup dGroup : game.getGroups()) {
|
||||
if (j > 3) {
|
||||
j = 0;
|
||||
rowSign = (Sign) sign.getBlock().getRelative(0, -1, 0).getState();
|
||||
|
@ -123,17 +124,17 @@ public class GameSign extends JoinSign {
|
|||
}
|
||||
|
||||
public void onPlayerInteract(Block block, Player player) {
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
DGroup dGroup = (DGroup) plugin.getPlayerGroup(player);
|
||||
if (dGroup == null) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_JOIN_GROUP.getMessage());
|
||||
return;
|
||||
}
|
||||
if (!dGroup.getCaptain().equals(player)) {
|
||||
if (!dGroup.getLeader().equals(player)) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_NOT_LEADER.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (Game.getByDGroup(dGroup) != null) {
|
||||
if (dGroup.getGame() != null) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_GAME.getMessage());
|
||||
return;
|
||||
}
|
||||
|
@ -151,12 +152,12 @@ public class GameSign extends JoinSign {
|
|||
return;
|
||||
}
|
||||
|
||||
game = new Game(plugin, dGroup);
|
||||
game = new DGame(plugin, dGroup);
|
||||
dGroup.setDungeon(dungeon);
|
||||
update();
|
||||
|
||||
} else if (topSign.getLine(0).equals(DMessage.SIGN_GLOBAL_JOIN_GAME.getMessage())) {
|
||||
game.addDGroup(dGroup);
|
||||
game.addGroup(dGroup);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
@ -188,7 +189,7 @@ public class GameSign extends JoinSign {
|
|||
* @param game the game to check
|
||||
* @return the game that this sign creates
|
||||
*/
|
||||
public static GameSign getByGame(DungeonsXL plugin, Game game) {
|
||||
public static GameSign getByGame(DungeonsXL plugin, DGame game) {
|
||||
for (GlobalProtection protection : plugin.getGlobalProtectionCache().getProtections(GameSign.class)) {
|
||||
GameSign gameSign = (GameSign) protection;
|
||||
if (gameSign.game == game) {
|
||||
|
|
|
@ -22,7 +22,6 @@ import de.erethon.dungeonsxl.DungeonsXL;
|
|||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.world.DEditWorld;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -87,7 +86,7 @@ public class GlobalProtectionListener implements Listener {
|
|||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Player player = event.getPlayer();
|
||||
DGlobalPlayer dGlobalPlayer = plugin.getDPlayerCache().getByPlayer(player);
|
||||
DGlobalPlayer dGlobalPlayer = (DGlobalPlayer) plugin.getPlayerCache().get(player);
|
||||
|
||||
GlobalProtection protection = plugin.getGlobalProtectionCache().getByBlock(block);
|
||||
if (protection != null) {
|
||||
|
@ -182,7 +181,7 @@ public class GlobalProtectionListener implements Listener {
|
|||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onPortalCreation(PlayerInteractEvent event) {
|
||||
DGlobalPlayer dPlayer = plugin.getDPlayerCache().getByPlayer(event.getPlayer());
|
||||
DGlobalPlayer dPlayer = (DGlobalPlayer) plugin.getPlayerCache().get(event.getPlayer());
|
||||
if (!dPlayer.isCreatingPortal()) {
|
||||
return;
|
||||
}
|
||||
|
@ -217,7 +216,7 @@ public class GlobalProtectionListener implements Listener {
|
|||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (plugin.getDPlayerCache().getByPlayer(player).isInBreakMode()) {
|
||||
if (plugin.getPlayerCache().get(player).isInBreakMode()) {
|
||||
return;
|
||||
}
|
||||
Block clickedBlock = event.getClickedBlock();
|
||||
|
@ -258,7 +257,7 @@ public class GlobalProtectionListener implements Listener {
|
|||
String[] lines = event.getLines();
|
||||
|
||||
// Group Signs
|
||||
if (DEditWorld.getByWorld(player.getWorld()) == null) {
|
||||
if (plugin.getEditWorld(player.getWorld()) == null) {
|
||||
if (!DPermission.hasPermission(player, DPermission.SIGN)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ public class GroupSign extends JoinSign {
|
|||
return;
|
||||
}
|
||||
|
||||
if (group.getPlayers().size() >= startIfElementsAtLeast && startIfElementsAtLeast != -1 && !loadedWorld) {
|
||||
if (group.getMembers().size() >= startIfElementsAtLeast && startIfElementsAtLeast != -1 && !loadedWorld) {
|
||||
loadedWorld = true;
|
||||
group.teleport();
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public class GroupSign extends JoinSign {
|
|||
if (group.isPlaying()) {
|
||||
sign.setLine(0, DMessage.SIGN_GLOBAL_IS_PLAYING.getMessage());
|
||||
|
||||
} else if (group.getPlayers().size() >= maxElements) {
|
||||
} else if (group.getMembers().size() >= maxElements) {
|
||||
sign.setLine(0, DMessage.SIGN_GLOBAL_FULL.getMessage());
|
||||
|
||||
} else {
|
||||
|
@ -103,7 +103,7 @@ public class GroupSign extends JoinSign {
|
|||
int j = 1;
|
||||
Sign rowSign = sign;
|
||||
|
||||
for (Player player : group.getPlayers().getOnlinePlayers()) {
|
||||
for (Player player : group.getMembers().getOnlinePlayers()) {
|
||||
if (j > 3) {
|
||||
j = 0;
|
||||
rowSign = (Sign) sign.getBlock().getRelative(0, -1, 0).getState();
|
||||
|
@ -133,7 +133,7 @@ public class GroupSign extends JoinSign {
|
|||
}
|
||||
|
||||
public void onPlayerInteract(Block block, Player player) {
|
||||
if (DGroup.getByPlayer(player) != null) {
|
||||
if (plugin.getPlayerGroup(player) != null) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_GROUP.getMessage());
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -18,9 +18,8 @@ package de.erethon.dungeonsxl.global;
|
|||
|
||||
import de.erethon.commons.misc.BlockUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.util.LWCUtil;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.bukkit.World;
|
||||
|
@ -47,14 +46,7 @@ public abstract class JoinSign extends GlobalProtection {
|
|||
super(plugin, startSign.getWorld(), id);
|
||||
|
||||
this.startSign = startSign;
|
||||
dungeon = plugin.getDungeonCache().getByName(identifier);
|
||||
if (dungeon == null) {
|
||||
DResourceWorld resource = plugin.getDWorldCache().getResourceByName(identifier);
|
||||
if (resource != null) {
|
||||
dungeon = new Dungeon(plugin, resource);
|
||||
}
|
||||
}
|
||||
|
||||
dungeon = plugin.getDungeonRegistry().get(identifier);
|
||||
verticalSigns = (int) Math.ceil((float) (1 + maxElements) / 4);
|
||||
|
||||
this.maxElements = maxElements;
|
||||
|
@ -70,13 +62,7 @@ public abstract class JoinSign extends GlobalProtection {
|
|||
|
||||
startSign = world.getBlockAt(config.getInt("x"), config.getInt("y"), config.getInt("z"));
|
||||
String identifier = config.getString("dungeon");
|
||||
dungeon = plugin.getDungeonCache().getByName(identifier);
|
||||
if (dungeon == null) {
|
||||
DResourceWorld resource = plugin.getDWorldCache().getResourceByName(identifier);
|
||||
if (resource != null) {
|
||||
dungeon = new Dungeon(plugin, resource);
|
||||
}
|
||||
}
|
||||
dungeon = plugin.getDungeonRegistry().get(identifier);
|
||||
|
||||
// LEGACY
|
||||
if (config.contains("maxElements")) {
|
||||
|
|
|
@ -19,9 +19,9 @@ package de.erethon.dungeonsxl.global;
|
|||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.commons.misc.BlockUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.GamePlayer;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DGamePlayer;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.util.LWCUtil;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -91,13 +91,13 @@ public class LeaveSign extends GlobalProtection {
|
|||
}
|
||||
|
||||
public void onPlayerInteract(Player player) {
|
||||
DGamePlayer dplayer = DGamePlayer.getByPlayer(player);
|
||||
GamePlayer gamePlayer = plugin.getPlayerCache().getGamePlayer(player);
|
||||
|
||||
if (dplayer != null) {
|
||||
dplayer.leave();
|
||||
if (gamePlayer != null) {
|
||||
gamePlayer.leave();
|
||||
|
||||
} else {
|
||||
DGroup group = DGroup.getByPlayer(player);
|
||||
PlayerGroup group = gamePlayer.getGroup();
|
||||
if (group != null) {
|
||||
group.removePlayer(player);
|
||||
MessageUtil.sendMessage(player, DMessage.PLAYER_LEAVE_GROUP.getMessage());
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
package de.erethon.dungeonsxl.mob;
|
||||
|
||||
import de.erethon.commons.misc.NumberUtil;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.mob.ExternalMobProvider;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
|
@ -99,7 +101,7 @@ public class CitizensMobProvider implements ExternalMobProvider, Listener {
|
|||
npc.spawn(location);
|
||||
spawnedNPCs.add(npc);
|
||||
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(location.getWorld());
|
||||
GameWorld gameWorld = DungeonsXL.getInstance().getGameWorld(location.getWorld());
|
||||
if (gameWorld == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.mob;
|
||||
|
||||
import de.erethon.dungeonsxl.api.mob.ExternalMobProvider;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,16 +19,18 @@ package de.erethon.dungeonsxl.mob;
|
|||
import de.erethon.caliburn.mob.ExMob;
|
||||
import de.erethon.caliburn.mob.VanillaMob;
|
||||
import de.erethon.caliburn.util.compatibility.Version;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.mob.DungeonMob;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import de.erethon.dungeonsxl.dungeon.DGame;
|
||||
import de.erethon.dungeonsxl.event.dmob.DMobDeathEvent;
|
||||
import de.erethon.dungeonsxl.event.dmob.DMobSpawnEvent;
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import de.erethon.dungeonsxl.trigger.MobTrigger;
|
||||
import de.erethon.dungeonsxl.trigger.WaveTrigger;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
@ -36,89 +38,74 @@ import org.bukkit.inventory.ItemStack;
|
|||
/**
|
||||
* @author Frank Baumann, Milan Albrecht, Daniel Saukel
|
||||
*/
|
||||
public class DMob {
|
||||
public class DMob implements DungeonMob {
|
||||
|
||||
// Variables
|
||||
private LivingEntity entity;
|
||||
private ExMob type;
|
||||
|
||||
private String trigger;
|
||||
|
||||
private DMob(LivingEntity entity, DGameWorld gameWorld) {
|
||||
gameWorld.addDMob(this);
|
||||
|
||||
private DMob(LivingEntity entity, GameWorld gameWorld) {
|
||||
this.entity = entity;
|
||||
|
||||
/* Remove DropChance of equipment */
|
||||
if (!isExternalMob()) {
|
||||
this.entity.getEquipment().setHelmetDropChance(0);
|
||||
this.entity.getEquipment().setChestplateDropChance(0);
|
||||
this.entity.getEquipment().setLeggingsDropChance(0);
|
||||
this.entity.getEquipment().setBootsDropChance(0);
|
||||
this.entity.getEquipment().setItemInHandDropChance(0);
|
||||
entity.getEquipment().setHelmetDropChance(0);
|
||||
entity.getEquipment().setChestplateDropChance(0);
|
||||
entity.getEquipment().setLeggingsDropChance(0);
|
||||
entity.getEquipment().setBootsDropChance(0);
|
||||
if (Version.isAtLeast(Version.MC1_9)) {
|
||||
this.entity.getEquipment().setItemInOffHandDropChance(0);
|
||||
entity.getEquipment().setItemInMainHandDropChance(0);
|
||||
entity.getEquipment().setItemInOffHandDropChance(0);
|
||||
} else {
|
||||
entity.getEquipment().setItemInHandDropChance(0);
|
||||
}
|
||||
}
|
||||
|
||||
DMobSpawnEvent event = new DMobSpawnEvent(this, entity);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
gameWorld.removeDMob(this);
|
||||
if (!event.isCancelled()) {
|
||||
gameWorld.addMob(this);
|
||||
}
|
||||
}
|
||||
|
||||
public DMob(LivingEntity entity, DGameWorld gameWorld, String trigger) {
|
||||
public DMob(LivingEntity entity, GameWorld gameWorld, String trigger) {
|
||||
this(entity, gameWorld);
|
||||
this.trigger = trigger;
|
||||
}
|
||||
|
||||
public DMob(LivingEntity entity, DGameWorld gameWorld, ExMob type) {
|
||||
public DMob(LivingEntity entity, GameWorld gameWorld, ExMob type) {
|
||||
this(entity, gameWorld);
|
||||
this.type = type;
|
||||
this.trigger = type.getId();
|
||||
}
|
||||
|
||||
public DMob(LivingEntity entity, DGameWorld gameWorld, ExMob type, String trigger) {
|
||||
public DMob(LivingEntity entity, GameWorld gameWorld, ExMob type, String trigger) {
|
||||
this(entity, gameWorld);
|
||||
this.type = type;
|
||||
this.trigger = trigger;
|
||||
}
|
||||
|
||||
/* Getters */
|
||||
/**
|
||||
* @return the represented LivingEntity
|
||||
*/
|
||||
@Override
|
||||
public LivingEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the DMobType or null if the mob is an external mob
|
||||
*/
|
||||
@Override
|
||||
public ExMob getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the mob is spawned by an external plugin
|
||||
*/
|
||||
public boolean isExternalMob() {
|
||||
return type == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the trigger String
|
||||
*/
|
||||
public String getTrigger() {
|
||||
@Override
|
||||
public String getTriggerId() {
|
||||
return trigger;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
public void onDeath(EntityDeathEvent event) {
|
||||
public void onDeath(DungeonsXL plugin, EntityDeathEvent event) {
|
||||
LivingEntity victim = event.getEntity();
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(victim.getWorld());
|
||||
DGameWorld gameWorld = (DGameWorld) plugin.getGameWorld(victim.getWorld());
|
||||
String name = null;
|
||||
|
||||
if (gameWorld == null) {
|
||||
|
@ -160,25 +147,12 @@ public class DMob {
|
|||
|
||||
Set<WaveTrigger> waveTriggers = WaveTrigger.getByGameWorld(gameWorld);
|
||||
for (WaveTrigger waveTrigger : waveTriggers) {
|
||||
if (Game.getByGameWorld(gameWorld).getWaveKills() >= Math.ceil(gameWorld.getMobCount() * waveTrigger.getMustKillRate())) {
|
||||
if (((DGame) gameWorld.getGame()).getWaveKills() >= Math.ceil(gameWorld.getMobCount() * waveTrigger.getMustKillRate())) {
|
||||
waveTrigger.onTrigger();
|
||||
}
|
||||
}
|
||||
|
||||
gameWorld.removeDMob(this);
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static DMob getByEntity(Entity entity) {
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(entity.getWorld());
|
||||
|
||||
for (DMob dMob : gameWorld.getDMobs()) {
|
||||
if (dMob.entity == entity) {
|
||||
return dMob;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
gameWorld.removeMob(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,8 +16,9 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.mob;
|
||||
|
||||
import de.erethon.dungeonsxl.world.DEditWorld;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.world.EditWorld;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -32,12 +33,18 @@ import org.bukkit.event.entity.EntityDeathEvent;
|
|||
*/
|
||||
public class DMobListener implements Listener {
|
||||
|
||||
private DungeonsXL plugin;
|
||||
|
||||
public DMobListener(DungeonsXL plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
World world = event.getLocation().getWorld();
|
||||
|
||||
DEditWorld editWorld = DEditWorld.getByWorld(world);
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(world);
|
||||
EditWorld editWorld = plugin.getEditWorld(world);
|
||||
GameWorld gameWorld = plugin.getGameWorld(world);
|
||||
|
||||
if (editWorld != null || gameWorld != null) {
|
||||
switch (event.getSpawnReason()) {
|
||||
|
@ -56,12 +63,12 @@ public class DMobListener implements Listener {
|
|||
|
||||
if (event.getEntity() instanceof LivingEntity) {
|
||||
LivingEntity entity = event.getEntity();
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(world);
|
||||
GameWorld gameWorld = plugin.getGameWorld(world);
|
||||
if (gameWorld != null) {
|
||||
if (gameWorld.isPlaying()) {
|
||||
DMob dMob = DMob.getByEntity(entity);
|
||||
DMob dMob = (DMob) plugin.getDungeonMob(entity);
|
||||
if (dMob != null) {
|
||||
dMob.onDeath(event);
|
||||
dMob.onDeath(plugin, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,8 +78,7 @@ public class DMobListener implements Listener {
|
|||
// Zombie / Skeleton combustion from the sun.
|
||||
@EventHandler
|
||||
public void onEntityCombust(EntityCombustEvent event) {
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld());
|
||||
if (gameWorld != null) {
|
||||
if (plugin.getGameWorld(event.getEntity().getWorld()) != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -80,8 +86,7 @@ public class DMobListener implements Listener {
|
|||
// Allow other combustion
|
||||
@EventHandler
|
||||
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld());
|
||||
if (gameWorld != null) {
|
||||
if (plugin.getGameWorld(event.getEntity().getWorld()) != null) {
|
||||
if (event.isCancelled()) {
|
||||
event.setCancelled(false);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import de.erethon.commons.chat.MessageUtil;
|
|||
import de.erethon.commons.misc.EnumUtil;
|
||||
import de.erethon.commons.misc.NumberUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
@ -50,6 +50,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||
@Deprecated
|
||||
public class DMobType extends ExMob {
|
||||
|
||||
private DungeonsXL plugin;
|
||||
private CaliburnAPI caliburn;
|
||||
|
||||
private String name;
|
||||
|
@ -83,6 +84,7 @@ public class DMobType extends ExMob {
|
|||
* @param config the config that stores the information
|
||||
*/
|
||||
public DMobType(DungeonsXL plugin, String name, FileConfiguration config) {
|
||||
this.plugin = plugin;
|
||||
caliburn = plugin.getCaliburn();
|
||||
|
||||
this.name = name;
|
||||
|
@ -356,7 +358,7 @@ public class DMobType extends ExMob {
|
|||
@Override
|
||||
public Entity toEntity(Location loc) {
|
||||
World world = loc.getWorld();
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(world);
|
||||
GameWorld gameWorld = plugin.getGameWorld(world);
|
||||
if (gameWorld == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.mob;
|
||||
|
||||
import de.erethon.dungeonsxl.api.mob.ExternalMobProvider;
|
||||
|
||||
/**
|
||||
* Officially supported external mob plugins.
|
||||
*
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.mob;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
* Implement this to create custom ExternalMobProviders.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public interface ExternalMobProvider {
|
||||
|
||||
/**
|
||||
* @return the name of the provider plugin
|
||||
*/
|
||||
String getIdentifier();
|
||||
|
||||
/**
|
||||
* @return the raw command without replaced variables
|
||||
*/
|
||||
String getRawCommand();
|
||||
|
||||
/**
|
||||
* @param mob the mob identifier
|
||||
* @param world the game world
|
||||
* @param x the x coordinate
|
||||
* @param y the y coordinate
|
||||
* @param z the z coordinate
|
||||
* @return the command with replaced variables
|
||||
*/
|
||||
default String getCommand(String mob, String world, double x, double y, double z) {
|
||||
return getRawCommand().replace("%mob%", mob).replace("%world%", world)
|
||||
.replace("%x%", String.valueOf(x)).replace("%y%", String.valueOf(y)).replace("%z%", String.valueOf(z))
|
||||
.replace("%block_x%", String.valueOf(Location.locToBlock(x)))
|
||||
.replace("%block_y%", String.valueOf(Location.locToBlock(y)))
|
||||
.replace("%block_z%", String.valueOf(Location.locToBlock(z)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mob the mob identifier
|
||||
* @param location the location where the mob will be spawned
|
||||
*/
|
||||
default void summon(String mob, Location location) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), getCommand(mob, location.getWorld().getName(), location.getX(), location.getY(), location.getZ()));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.mob;
|
||||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* ExternalMobProvider instance manager.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class ExternalMobProviderCache {
|
||||
|
||||
private DungeonsXL plugin;
|
||||
|
||||
private Set<ExternalMobProvider> providers = new HashSet<>();
|
||||
private CitizensMobProvider citizensMobProvider;
|
||||
|
||||
public ExternalMobProviderCache(DungeonsXL plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
// Supported providers
|
||||
providers.addAll(Arrays.asList(ExternalMobPlugin.values()));
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("Citizens") != null) {
|
||||
citizensMobProvider = new CitizensMobProvider();
|
||||
providers.add(citizensMobProvider);
|
||||
Bukkit.getPluginManager().registerEvents(citizensMobProvider, plugin);
|
||||
} else {
|
||||
MessageUtil.log(plugin, "Could not find compatible Citizens plugin. The mob provider Citizens (\"CI\") will not get enabled...");
|
||||
}
|
||||
|
||||
// Custom providers
|
||||
for (Entry<String, Object> customExternalMobProvider : plugin.getMainConfig().getExternalMobProviders().entrySet()) {
|
||||
providers.add(new CustomExternalMobProvider(customExternalMobProvider));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param identifier the identifier to check
|
||||
* @return the ExternalMobProvider represented by the identifier
|
||||
*/
|
||||
public ExternalMobProvider getByIdentifier(String identifier) {
|
||||
for (ExternalMobProvider provider : providers) {
|
||||
if (provider.getIdentifier().equals(identifier)) {
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded ExternalMobProviders
|
||||
*/
|
||||
public Set<ExternalMobProvider> getProviders() {
|
||||
return providers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Citizens provider
|
||||
*/
|
||||
public CitizensMobProvider getCitizensMobProvider() {
|
||||
return citizensMobProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param provider the provider to register
|
||||
*/
|
||||
public void addExternalMobProvider(ExternalMobProvider provider) {
|
||||
providers.add(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param provider the provider to unregister
|
||||
*/
|
||||
public void removeExternalMobProvider(ExternalMobProvider provider) {
|
||||
providers.remove(provider);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.player;
|
||||
|
||||
import de.erethon.caliburn.CaliburnAPI;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Represents a class and a class script.
|
||||
*
|
||||
* @author Frank Baumann, Daniel Saukel
|
||||
*/
|
||||
public class DClass {
|
||||
|
||||
private CaliburnAPI caliburn;
|
||||
|
||||
private String name;
|
||||
|
||||
private List<ItemStack> items = new ArrayList<>();
|
||||
private boolean dog;
|
||||
|
||||
public DClass(DungeonsXL plugin, File file) {
|
||||
this(plugin, file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file));
|
||||
}
|
||||
|
||||
public DClass(DungeonsXL plugin, String name, FileConfiguration config) {
|
||||
caliburn = plugin.getCaliburn();
|
||||
|
||||
this.name = name;
|
||||
|
||||
if (config.contains("items")) {
|
||||
items = caliburn.deserializeStackList(config, "items");
|
||||
}
|
||||
|
||||
if (config.contains("dog")) {
|
||||
dog = config.getBoolean("dog");
|
||||
}
|
||||
}
|
||||
|
||||
public DClass(String name, List<ItemStack> items, boolean dog) {
|
||||
this.items = items;
|
||||
this.name = name;
|
||||
this.dog = dog;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the items
|
||||
*/
|
||||
public List<ItemStack> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemStack the ItemStack to add
|
||||
*/
|
||||
public void addItem(ItemStack itemStack) {
|
||||
items.add(itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemStack the ItemStack to remove
|
||||
*/
|
||||
public void removeItem(ItemStack itemStack) {
|
||||
items.remove(itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the class has a dog
|
||||
*/
|
||||
public boolean hasDog() {
|
||||
return dog;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dog set if the class has a dog
|
||||
*/
|
||||
public void setDog(boolean dog) {
|
||||
this.dog = dog;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.player;
|
||||
|
||||
import de.erethon.commons.misc.FileUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* DClass instance manager.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class DClassCache {
|
||||
|
||||
private DungeonsXL plugin;
|
||||
|
||||
private List<DClass> dClasses = new ArrayList<>();
|
||||
|
||||
public DClassCache(DungeonsXL plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void init(File file) {
|
||||
if (file.isDirectory()) {
|
||||
for (File script : FileUtil.getFilesForFolder(file)) {
|
||||
dClasses.add(new DClass(plugin, script));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to check
|
||||
* @return the dClass that has the name
|
||||
*/
|
||||
public DClass getByName(String name) {
|
||||
for (DClass dClass : dClasses) {
|
||||
if (dClass.getName().equalsIgnoreCase(name)) {
|
||||
return dClass;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dClasses
|
||||
*/
|
||||
public List<DClass> getDClasses() {
|
||||
return dClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dClass the DClass to add
|
||||
*/
|
||||
public void addDClass(DClass dClass) {
|
||||
dClasses.add(dClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dClass the DClass to remove
|
||||
*/
|
||||
public void removeDClass(DClass dClass) {
|
||||
dClasses.remove(dClass);
|
||||
}
|
||||
|
||||
}
|
|
@ -19,14 +19,13 @@ package de.erethon.dungeonsxl.player;
|
|||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.commons.player.PlayerUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.EditPlayer;
|
||||
import de.erethon.dungeonsxl.api.world.EditWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.event.dplayer.instance.DInstancePlayerUpdateEvent;
|
||||
import de.erethon.dungeonsxl.world.DEditWorld;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -34,17 +33,15 @@ import org.bukkit.event.block.SignChangeEvent;
|
|||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* Represents a player in a DEditWorld.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class DEditPlayer extends DInstancePlayer {
|
||||
public class DEditPlayer extends DInstancePlayer implements EditPlayer {
|
||||
|
||||
private String[] linesCopy;
|
||||
private DEditWorld editWorld;
|
||||
private EditWorld editWorld;
|
||||
|
||||
public DEditPlayer(DungeonsXL plugin, Player player, DEditWorld world) {
|
||||
super(plugin, player, world.getWorld());
|
||||
public DEditPlayer(DungeonsXL plugin, Player player, EditWorld world) {
|
||||
super(plugin, player, world);
|
||||
editWorld = world;
|
||||
|
||||
// Set gamemode a few ticks later to avoid incompatibilities with plugins that force a gamemode
|
||||
|
@ -74,27 +71,21 @@ public class DEditPlayer extends DInstancePlayer {
|
|||
|
||||
|
||||
/* Getters and setters */
|
||||
/**
|
||||
* @return the linesCopy
|
||||
*/
|
||||
public String[] getLinesCopy() {
|
||||
@Override
|
||||
public EditWorld getEditWorld() {
|
||||
return editWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCopiedLines() {
|
||||
return linesCopy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param linesCopy the linesCopy to set
|
||||
*/
|
||||
public void setLinesCopy(String[] linesCopy) {
|
||||
@Override
|
||||
public void setCopiedLines(String[] linesCopy) {
|
||||
this.linesCopy = linesCopy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the DEditWorld
|
||||
*/
|
||||
public DEditWorld getEditWorld() {
|
||||
return editWorld;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
@Override
|
||||
public void delete() {
|
||||
|
@ -111,6 +102,7 @@ public class DEditPlayer extends DInstancePlayer {
|
|||
/**
|
||||
* Escape the DEditWorld without saving.
|
||||
*/
|
||||
@Override
|
||||
public void escape() {
|
||||
delete();
|
||||
reset(false);
|
||||
|
@ -151,7 +143,6 @@ public class DEditPlayer extends DInstancePlayer {
|
|||
|
||||
reset(false);
|
||||
|
||||
DEditWorld editWorld = DEditWorld.getByWorld(getWorld());
|
||||
if (editWorld != null) {
|
||||
editWorld.save();
|
||||
}
|
||||
|
@ -162,8 +153,6 @@ public class DEditPlayer extends DInstancePlayer {
|
|||
boolean locationValid = true;
|
||||
Location teleportLocation = player.getLocation();
|
||||
|
||||
DEditWorld editWorld = DEditWorld.getByWorld(getWorld());
|
||||
|
||||
if (!getPlayer().getWorld().equals(getWorld())) {
|
||||
locationValid = false;
|
||||
}
|
||||
|
@ -188,35 +177,4 @@ public class DEditPlayer extends DInstancePlayer {
|
|||
}
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static DEditPlayer getByPlayer(Player player) {
|
||||
for (DEditPlayer dPlayer : DungeonsXL.getInstance().getDPlayerCache().getDEditPlayers()) {
|
||||
if (dPlayer.getPlayer().equals(player)) {
|
||||
return dPlayer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DEditPlayer getByName(String name) {
|
||||
for (DEditPlayer dPlayer : DungeonsXL.getInstance().getDPlayerCache().getDEditPlayers()) {
|
||||
if (dPlayer.getName().equalsIgnoreCase(name)) {
|
||||
return dPlayer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static CopyOnWriteArrayList<DEditPlayer> getByWorld(World world) {
|
||||
CopyOnWriteArrayList<DEditPlayer> dPlayers = new CopyOnWriteArrayList<>();
|
||||
|
||||
for (DEditPlayer dPlayer : DungeonsXL.getInstance().getDPlayerCache().getDEditPlayers()) {
|
||||
if (dPlayer.getWorld() == world) {
|
||||
dPlayers.add(dPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
return dPlayers;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,22 +20,26 @@ import de.erethon.caliburn.item.VanillaItem;
|
|||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.commons.player.PlayerUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.Requirement;
|
||||
import de.erethon.dungeonsxl.api.Reward;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Game;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameGoal;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRule;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer;
|
||||
import de.erethon.dungeonsxl.api.mob.DungeonMob;
|
||||
import de.erethon.dungeonsxl.api.player.GamePlayer;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerClass;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.dungeon.DGame;
|
||||
import de.erethon.dungeonsxl.event.dplayer.DPlayerKickEvent;
|
||||
import de.erethon.dungeonsxl.event.dplayer.instance.DInstancePlayerUpdateEvent;
|
||||
import de.erethon.dungeonsxl.event.dplayer.instance.game.DGamePlayerDeathEvent;
|
||||
import de.erethon.dungeonsxl.event.dplayer.instance.game.DGamePlayerFinishEvent;
|
||||
import de.erethon.dungeonsxl.event.dplayer.instance.game.DGamePlayerRewardEvent;
|
||||
import de.erethon.dungeonsxl.event.requirement.RequirementCheckEvent;
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import de.erethon.dungeonsxl.game.GameGoal;
|
||||
import de.erethon.dungeonsxl.game.GameRuleProvider;
|
||||
import de.erethon.dungeonsxl.game.GameType;
|
||||
import de.erethon.dungeonsxl.game.GameTypeDefault;
|
||||
import de.erethon.dungeonsxl.mob.DMob;
|
||||
import de.erethon.dungeonsxl.requirement.Requirement;
|
||||
import de.erethon.dungeonsxl.reward.Reward;
|
||||
import de.erethon.dungeonsxl.trigger.DistanceTrigger;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
|
@ -46,7 +50,6 @@ import java.util.List;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Damageable;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -56,19 +59,16 @@ import org.bukkit.inventory.ItemStack;
|
|||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
/**
|
||||
* Represents a player in a DGameWorld.
|
||||
*
|
||||
* @author Frank Baumann, Tobias Schmitz, Milan Albrecht, Daniel Saukel
|
||||
*/
|
||||
public class DGamePlayer extends DInstancePlayer {
|
||||
public class DGamePlayer extends DInstancePlayer implements GamePlayer {
|
||||
|
||||
// Variables
|
||||
private DGroup dGroup;
|
||||
|
||||
private boolean ready = false;
|
||||
private boolean finished = false;
|
||||
|
||||
private DClass dClass;
|
||||
private PlayerClass dClass;
|
||||
private Location checkpoint;
|
||||
private Wolf wolf;
|
||||
private int wolfRespawnTime = 30;
|
||||
|
@ -78,31 +78,32 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
private int lives;
|
||||
|
||||
private ItemStack oldHelmet;
|
||||
private DGroup stealing;
|
||||
private PlayerGroup stealing;
|
||||
|
||||
private DGroupTag groupTag;
|
||||
|
||||
public DGamePlayer(DungeonsXL plugin, Player player, DGameWorld world) {
|
||||
super(plugin, player, world.getWorld());
|
||||
public DGamePlayer(DungeonsXL plugin, Player player, GameWorld world) {
|
||||
super(plugin, player, world);
|
||||
|
||||
Game game = Game.getByGameWorld(world);
|
||||
Game game = world.getGame();
|
||||
dGroup = (DGroup) plugin.getPlayerGroup(player);
|
||||
if (game == null) {
|
||||
game = new Game(plugin, DGroup.getByPlayer(player));
|
||||
game = new DGame(plugin, dGroup);
|
||||
}
|
||||
|
||||
GameRuleProvider rules = game.getRules();
|
||||
GameRuleContainer rules = game.getRules();
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
|
||||
if (!rules.getKeepInventoryOnEnter()) {
|
||||
if (!rules.getState(GameRule.KEEP_INVENTORY_ON_ENTER)) {
|
||||
clearPlayerData();
|
||||
}
|
||||
player.setAllowFlight(rules.canFly());
|
||||
player.setAllowFlight(rules.getState(GameRule.FLY));
|
||||
|
||||
if (rules.isLobbyDisabled()) {
|
||||
if (rules.getState(GameRule.IS_LOBBY_DISABLED)) {
|
||||
ready();
|
||||
}
|
||||
|
||||
initialLives = rules.getInitialLives();
|
||||
initialLives = rules.getState(GameRule.INITIAL_LIVES);
|
||||
lives = initialLives;
|
||||
|
||||
Location teleport = world.getLobbyLocation();
|
||||
|
@ -113,34 +114,21 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
}
|
||||
}
|
||||
|
||||
public DGamePlayer(DungeonsXL plugin, Player player, DGameWorld world, GameType ready) {
|
||||
this(plugin, player, world);
|
||||
if (ready != null) {
|
||||
ready(ready);
|
||||
}
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
@Override
|
||||
public String getName() {
|
||||
String name = player.getName();
|
||||
if (getDGroup() != null && dGroup.getDColor() != null) {
|
||||
name = getDGroup().getDColor().getChatColor() + name;
|
||||
if (getGroup() != null && dGroup.getDColor() != null) {
|
||||
name = getGroup().getDColor().getChatColor() + name;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DGroup getDGroup() {
|
||||
if (dGroup == null) {
|
||||
dGroup = DGroup.getByPlayer(player);
|
||||
}
|
||||
public DGroup getGroup() {
|
||||
return dGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player the player to set
|
||||
*/
|
||||
public void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
@ -149,77 +137,44 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
* @return if the player is in test mode
|
||||
*/
|
||||
public boolean isInTestMode() {
|
||||
if (getDGroup() == null) {
|
||||
if (getGroup() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DGameWorld gameWorld = dGroup.getGameWorld();
|
||||
if (gameWorld == null) {
|
||||
if (getGame() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Game game = gameWorld.getGame();
|
||||
if (game == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GameType gameType = game.getType();
|
||||
if (gameType == GameTypeDefault.TEST) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return getGame().hasRewards();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the isReady
|
||||
*/
|
||||
@Override
|
||||
public boolean isReady() {
|
||||
return ready;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ready If the player is ready to play the dungeon
|
||||
*/
|
||||
public void setReady(boolean ready) {
|
||||
this.ready = ready;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the finished
|
||||
*/
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return finished;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param finished the finished to set
|
||||
*/
|
||||
@Override
|
||||
public void setFinished(boolean finished) {
|
||||
this.finished = finished;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dClass
|
||||
*/
|
||||
public DClass getDClass() {
|
||||
@Override
|
||||
public PlayerClass getPlayerClass() {
|
||||
return dClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param className the name of the class to set
|
||||
*/
|
||||
public void setDClass(String className) {
|
||||
Game game = Game.getByWorld(getPlayer().getWorld());
|
||||
if (game == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DClass dClass = plugin.getDClassCache().getByName(className);
|
||||
if (dClass == null || this.dClass == dClass) {
|
||||
return;
|
||||
}
|
||||
this.dClass = dClass;
|
||||
@Override
|
||||
public void setPlayerClass(PlayerClass playerClass) {
|
||||
dClass = playerClass;
|
||||
|
||||
/* Set Dog */
|
||||
if (wolf != null) {
|
||||
|
@ -275,153 +230,116 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the checkpoint
|
||||
*/
|
||||
public Location getCheckpoint() {
|
||||
@Override
|
||||
public Location getLastCheckpoint() {
|
||||
return checkpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param checkpoint the checkpoint to set
|
||||
*/
|
||||
public void setCheckpoint(Location checkpoint) {
|
||||
@Override
|
||||
public void setLastCheckpoint(Location checkpoint) {
|
||||
this.checkpoint = checkpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the wolf
|
||||
*/
|
||||
public Wolf getWolf() {
|
||||
return wolf;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param wolf the wolf to set
|
||||
*/
|
||||
public void setWolf(Wolf wolf) {
|
||||
this.wolf = wolf;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the wolfRespawnTime
|
||||
*/
|
||||
public int getWolfRespawnTime() {
|
||||
return wolfRespawnTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param wolfRespawnTime the wolfRespawnTime to set
|
||||
*/
|
||||
public void setWolfRespawnTime(int wolfRespawnTime) {
|
||||
this.wolfRespawnTime = wolfRespawnTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the offlineTime
|
||||
*/
|
||||
public long getOfflineTime() {
|
||||
@Override
|
||||
public long getOfflineTimeMillis() {
|
||||
return offlineTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param offlineTime the offlineTime to set
|
||||
*/
|
||||
public void setOfflineTime(long offlineTime) {
|
||||
@Override
|
||||
public void setOfflineTimeMillis(long offlineTime) {
|
||||
this.offlineTime = offlineTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the initialLives
|
||||
*/
|
||||
@Override
|
||||
public int getInitialLives() {
|
||||
return initialLives;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param initialLives the initialLives to set
|
||||
*/
|
||||
@Override
|
||||
public void setInitialLives(int initialLives) {
|
||||
this.initialLives = initialLives;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the lives
|
||||
*/
|
||||
@Override
|
||||
public int getLives() {
|
||||
return lives;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lives the lives to set
|
||||
*/
|
||||
@Override
|
||||
public void setLives(int lives) {
|
||||
this.lives = lives;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the player is stealing a flag
|
||||
*/
|
||||
public boolean isStealing() {
|
||||
@Override
|
||||
public Wolf getWolf() {
|
||||
return wolf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWolf(Wolf wolf) {
|
||||
this.wolf = wolf;
|
||||
}
|
||||
|
||||
public int getWolfRespawnTime() {
|
||||
return wolfRespawnTime;
|
||||
}
|
||||
|
||||
public void setWolfRespawnTime(int wolfRespawnTime) {
|
||||
this.wolfRespawnTime = wolfRespawnTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStealingFlag() {
|
||||
return stealing != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the group whose flag is stolen
|
||||
*/
|
||||
public DGroup getRobbedGroup() {
|
||||
@Override
|
||||
public PlayerGroup getRobbedGroup() {
|
||||
return stealing;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dGroup the group whose flag is stolen
|
||||
*/
|
||||
public void setRobbedGroup(DGroup dGroup) {
|
||||
if (dGroup != null) {
|
||||
@Override
|
||||
public void setRobbedGroup(PlayerGroup group) {
|
||||
if (group != null) {
|
||||
oldHelmet = player.getInventory().getHelmet();
|
||||
player.getInventory().setHelmet(getDGroup().getDColor().getWoolMaterial().toItemStack());
|
||||
player.getInventory().setHelmet(getGroup().getDColor().getWoolMaterial().toItemStack());
|
||||
}
|
||||
|
||||
stealing = dGroup;
|
||||
stealing = group;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the player's group tag
|
||||
*/
|
||||
public DGroupTag getDGroupTag() {
|
||||
return groupTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new group tag for the player.
|
||||
*/
|
||||
public void initDGroupTag() {
|
||||
groupTag = new DGroupTag(plugin, this);
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
@Override
|
||||
public void captureFlag() {
|
||||
if (stealing == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Game game = Game.getByWorld(getWorld());
|
||||
Game game = plugin.getGame(getWorld());
|
||||
if (game == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
game.sendMessage(DMessage.GROUP_FLAG_CAPTURED.getMessage(getName(), stealing.getName()));
|
||||
|
||||
GameRuleProvider rules = game.getRules();
|
||||
GameRuleContainer rules = game.getRules();
|
||||
|
||||
getDGroup().setScore(getDGroup().getScore() + 1);
|
||||
if (rules.getScoreGoal() == dGroup.getScore()) {
|
||||
dGroup.winGame();
|
||||
getGroup().setScore(getGroup().getScore() + 1);
|
||||
if (rules.getState(GameRule.SCORE_GOAL) == getGroup().getScore()) {
|
||||
getGroup().winGame();
|
||||
}
|
||||
|
||||
stealing.setScore(stealing.getScore() - 1);
|
||||
if (stealing.getScore() == -1) {
|
||||
for (DGamePlayer member : stealing.getDGamePlayers()) {
|
||||
for (GamePlayer member : ((DGroup) stealing).getDGamePlayers()) {
|
||||
member.kill();
|
||||
}
|
||||
game.sendMessage(DMessage.GROUP_DEFEATED.getMessage(stealing.getName()));
|
||||
|
@ -430,7 +348,7 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
stealing = null;
|
||||
player.getInventory().setHelmet(oldHelmet);
|
||||
|
||||
if (game.getDGroups().size() == 1) {
|
||||
if (game.getGroups().size() == 1) {
|
||||
dGroup.winGame();
|
||||
}
|
||||
}
|
||||
|
@ -440,71 +358,65 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
leave(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message if messages should be sent
|
||||
*/
|
||||
@Override
|
||||
public void leave(boolean message) {
|
||||
Game game = Game.getByWorld(getWorld());
|
||||
Game game = plugin.getGame(getWorld());
|
||||
if (game == null) {
|
||||
return;
|
||||
}
|
||||
DGameWorld gameWorld = game.getWorld();
|
||||
DGameWorld gameWorld = (DGameWorld) game.getWorld();
|
||||
if (gameWorld == null) {
|
||||
return;
|
||||
}
|
||||
GameRuleProvider rules = game.getRules();
|
||||
GameRuleContainer rules = game.getRules();
|
||||
delete();
|
||||
|
||||
if (player.isOnline()) {
|
||||
if (finished) {
|
||||
reset(rules.getKeepInventoryOnFinish());
|
||||
reset(rules.getState(GameRule.KEEP_INVENTORY_ON_FINISH));
|
||||
} else {
|
||||
reset(rules.getKeepInventoryOnEscape());
|
||||
reset(rules.getState(GameRule.KEEP_INVENTORY_ON_ESCAPE));
|
||||
}
|
||||
}
|
||||
|
||||
// Permission bridge
|
||||
if (plugin.getPermissionProvider() != null) {
|
||||
for (String permission : rules.getGamePermissions()) {
|
||||
for (String permission : rules.getState(GameRule.GAME_PERMISSIONS)) {
|
||||
plugin.getPermissionProvider().playerRemoveTransient(getWorld().getName(), player, permission);
|
||||
}
|
||||
}
|
||||
|
||||
if (getDGroup() != null) {
|
||||
if (getGroup() != null) {
|
||||
dGroup.removePlayer(getPlayer(), message);
|
||||
}
|
||||
|
||||
if (game != null) {
|
||||
if (finished) {
|
||||
if (game.getType() == GameTypeDefault.CUSTOM || game.getType().hasRewards()) {
|
||||
DGamePlayerRewardEvent dGroupRewardEvent = new DGamePlayerRewardEvent(this);
|
||||
Bukkit.getPluginManager().callEvent(dGroupRewardEvent);
|
||||
if (!dGroupRewardEvent.isCancelled()) {
|
||||
giveLoot(rules, rules.getRewards(), dGroup.getRewards());
|
||||
if (game != null && finished && game.hasRewards()) {
|
||||
DGamePlayerRewardEvent dGroupRewardEvent = new DGamePlayerRewardEvent(this);
|
||||
Bukkit.getPluginManager().callEvent(dGroupRewardEvent);
|
||||
if (!dGroupRewardEvent.isCancelled()) {
|
||||
giveLoot(rules, rules.getState(GameRule.REWARDS), dGroup.getRewards());
|
||||
}
|
||||
|
||||
getData().logTimeLastFinished(getGroup().getDungeonName());
|
||||
|
||||
// Tutorial Permissions
|
||||
if (game.isTutorial()) {
|
||||
getData().setFinishedTutorial(true);
|
||||
if (plugin.getPermissionProvider() != null && plugin.getPermissionProvider().hasGroupSupport()) {
|
||||
String endGroup = plugin.getMainConfig().getTutorialEndGroup();
|
||||
if (plugin.isGroupEnabled(endGroup)) {
|
||||
plugin.getPermissionProvider().playerAddGroup(getPlayer(), endGroup);
|
||||
}
|
||||
|
||||
getData().logTimeLastFinished(getDGroup().getDungeonName());
|
||||
|
||||
// Tutorial Permissions
|
||||
if (game.isTutorial()) {
|
||||
getData().setFinishedTutorial(true);
|
||||
if (plugin.getPermissionProvider() != null && plugin.getPermissionProvider().hasGroupSupport()) {
|
||||
String endGroup = plugin.getMainConfig().getTutorialEndGroup();
|
||||
if (plugin.isGroupEnabled(endGroup)) {
|
||||
plugin.getPermissionProvider().playerAddGroup(getPlayer(), endGroup);
|
||||
}
|
||||
|
||||
String startGroup = plugin.getMainConfig().getTutorialStartGroup();
|
||||
if (plugin.isGroupEnabled(startGroup)) {
|
||||
plugin.getPermissionProvider().playerRemoveGroup(getPlayer(), startGroup);
|
||||
}
|
||||
}
|
||||
String startGroup = plugin.getMainConfig().getTutorialStartGroup();
|
||||
if (plugin.isGroupEnabled(startGroup)) {
|
||||
plugin.getPermissionProvider().playerRemoveGroup(getPlayer(), startGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (getDGroup() != null) {
|
||||
if (getGroup() != null) {
|
||||
if (!dGroup.isEmpty()) {
|
||||
/*if (dGroup.finishIfMembersFinished()) {
|
||||
return;
|
||||
|
@ -512,7 +424,7 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
|
||||
// Give secure objects to other players
|
||||
Player groupPlayer = null;
|
||||
for (Player player : dGroup.getPlayers().getOnlinePlayers()) {
|
||||
for (Player player : dGroup.getMembers().getOnlinePlayers()) {
|
||||
if (player.isOnline()) {
|
||||
groupPlayer = player;
|
||||
break;
|
||||
|
@ -529,16 +441,16 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
}
|
||||
}
|
||||
|
||||
if (dGroup.getCaptain().equals(getPlayer()) && dGroup.getPlayers().size() > 0) {
|
||||
if (dGroup.getLeader().equals(getPlayer()) && dGroup.getMembers().size() > 0) {
|
||||
// Captain here!
|
||||
Player newCaptain = null;
|
||||
for (Player player : dGroup.getPlayers().getOnlinePlayers()) {
|
||||
for (Player player : dGroup.getMembers().getOnlinePlayers()) {
|
||||
if (player.isOnline()) {
|
||||
newCaptain = player;
|
||||
break;
|
||||
}
|
||||
}
|
||||
dGroup.setCaptain(newCaptain);
|
||||
dGroup.setLeader(newCaptain);
|
||||
if (message) {
|
||||
MessageUtil.sendMessage(newCaptain, DMessage.PLAYER_NEW_LEADER.getMessage());
|
||||
}
|
||||
|
@ -547,15 +459,16 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kill() {
|
||||
DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(this, DPlayerKickEvent.Cause.DEATH);
|
||||
Bukkit.getPluginManager().callEvent(dPlayerKickEvent);
|
||||
|
||||
if (!dPlayerKickEvent.isCancelled()) {
|
||||
DGameWorld gameWorld = getDGroup().getGameWorld();
|
||||
GameWorld gameWorld = getGroup().getGameWorld();
|
||||
if (lives != -1) {
|
||||
gameWorld.sendMessage(DMessage.PLAYER_DEATH_KICK.getMessage(getName()));
|
||||
} else if (getDGroup().getLives() != -1) {
|
||||
} else if (getGroup().getLives() != -1) {
|
||||
gameWorld.sendMessage(DMessage.GROUP_DEATH_KICK.getMessage(getName(), dGroup.getName()));
|
||||
}
|
||||
|
||||
|
@ -563,28 +476,29 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean checkRequirements(Game game) {
|
||||
public boolean checkRequirements(Dungeon dungeon) {
|
||||
if (DPermission.hasPermission(player, DPermission.IGNORE_REQUIREMENTS)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
GameRuleProvider rules = game.getRules();
|
||||
GameRuleContainer rules = dungeon.getRules();
|
||||
|
||||
if (!checkTimeAfterStart(game) && !checkTimeAfterFinish(game)) {
|
||||
int longestTime = rules.getTimeToNextPlayAfterStart() >= rules.getTimeToNextPlayAfterFinish() ? rules.getTimeToNextPlayAfterStart() : rules.getTimeToNextPlayAfterFinish();
|
||||
if (!checkTimeAfterStart(dungeon) && !checkTimeAfterFinish(dungeon)) {
|
||||
int longestTime = rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_START) >= rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_FINISH)
|
||||
? rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_START) : rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_FINISH);
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_COOLDOWN.getMessage(String.valueOf(longestTime)));
|
||||
return false;
|
||||
|
||||
} else if (!checkTimeAfterStart(game)) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_COOLDOWN.getMessage(String.valueOf(rules.getTimeToNextPlayAfterStart())));
|
||||
} else if (!checkTimeAfterStart(dungeon)) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_COOLDOWN.getMessage(String.valueOf(rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_START))));
|
||||
return false;
|
||||
|
||||
} else if (!checkTimeAfterFinish(game)) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_COOLDOWN.getMessage(String.valueOf(rules.getTimeToNextPlayAfterFinish())));
|
||||
} else if (!checkTimeAfterFinish(dungeon)) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_COOLDOWN.getMessage(String.valueOf(rules.getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_FINISH))));
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Requirement requirement : rules.getRequirements()) {
|
||||
for (Requirement requirement : rules.getState(GameRule.REQUIREMENTS)) {
|
||||
RequirementCheckEvent event = new RequirementCheckEvent(requirement, player);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
|
@ -597,25 +511,30 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
}
|
||||
}
|
||||
|
||||
if (rules.getFinished() != null && rules.getFinishedAll() != null) {
|
||||
if (!rules.getFinished().isEmpty()) {
|
||||
if (rules.getState(GameRule.MUST_FINISH_ALL) != null) {
|
||||
List<String> finished = new ArrayList<>(rules.getState(GameRule.MUST_FINISH_ALL));
|
||||
if (rules.getState(GameRule.MUST_FINISH_ONE) != null) {
|
||||
finished.addAll(rules.getState(GameRule.MUST_FINISH_ONE));
|
||||
}
|
||||
|
||||
if (!finished.isEmpty()) {
|
||||
|
||||
long bestTime = 0;
|
||||
int numOfNeeded = 0;
|
||||
boolean doneTheOne = false;
|
||||
|
||||
if (rules.getFinished().size() == rules.getFinishedAll().size()) {
|
||||
if (finished.size() == rules.getState(GameRule.MUST_FINISH_ALL).size()) {
|
||||
doneTheOne = true;
|
||||
}
|
||||
|
||||
for (String played : rules.getFinished()) {
|
||||
for (String played : finished) {
|
||||
for (String dungeonName : DungeonsXL.MAPS.list()) {
|
||||
if (new File(DungeonsXL.MAPS, dungeonName).isDirectory()) {
|
||||
if (played.equalsIgnoreCase(dungeonName) || played.equalsIgnoreCase("any")) {
|
||||
|
||||
Long time = getData().getTimeLastFinished(dungeonName);
|
||||
if (time != -1) {
|
||||
if (rules.getFinishedAll().contains(played)) {
|
||||
if (rules.getState(GameRule.MUST_FINISH_ALL).contains(played)) {
|
||||
numOfNeeded++;
|
||||
} else {
|
||||
doneTheOne = true;
|
||||
|
@ -634,13 +553,13 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
if (bestTime == 0) {
|
||||
return false;
|
||||
|
||||
} else if (rules.getTimeLastPlayed() != 0) {
|
||||
if (System.currentTimeMillis() - bestTime > rules.getTimeLastPlayed() * (long) 3600000) {
|
||||
} else if (rules.getState(GameRule.TIME_LAST_PLAYED_REQUIRED_DUNGEONS) != 0) {
|
||||
if (System.currentTimeMillis() - bestTime > rules.getState(GameRule.TIME_LAST_PLAYED_REQUIRED_DUNGEONS) * (long) 3600000) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (numOfNeeded < rules.getFinishedAll().size() || !doneTheOne) {
|
||||
if (numOfNeeded < rules.getState(GameRule.MUST_FINISH_ALL).size() || !doneTheOne) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -650,12 +569,14 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean checkTimeAfterStart(Game game) {
|
||||
return checkTime(game.getDungeon(), game.getRules().getTimeToNextPlayAfterStart(), getData().getTimeLastStarted(game.getDungeon().getName()));
|
||||
public boolean checkTimeAfterStart(Dungeon dungeon) {
|
||||
return checkTime(dungeon, dungeon.getRules().getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_START),
|
||||
getData().getTimeLastStarted(dungeon.getName()));
|
||||
}
|
||||
|
||||
public boolean checkTimeAfterFinish(Game game) {
|
||||
return checkTime(game.getDungeon(), game.getRules().getTimeToNextPlayAfterFinish(), getData().getTimeLastFinished(game.getDungeon().getName()));
|
||||
public boolean checkTimeAfterFinish(Dungeon dungeon) {
|
||||
return checkTime(dungeon, dungeon.getRules().getState(GameRule.TIME_TO_NEXT_PLAY_AFTER_FINISH),
|
||||
getData().getTimeLastFinished(dungeon.getName()));
|
||||
}
|
||||
|
||||
public boolean checkTime(Dungeon dungeon, int requirement, long dataTime) {
|
||||
|
@ -666,42 +587,40 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
return dataTime == -1 || dataTime + requirement * 1000 * 60 * 60 <= System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void giveLoot(GameRuleProvider rules, List<Reward> ruleRewards, List<Reward> groupRewards) {
|
||||
public void giveLoot(GameRuleContainer rules, List<Reward> ruleRewards, List<Reward> groupRewards) {
|
||||
if (!canLoot(rules)) {
|
||||
return;
|
||||
}
|
||||
ruleRewards.forEach(r -> r.giveTo(player.getPlayer()));
|
||||
groupRewards.forEach(r -> r.giveTo(player.getPlayer()));
|
||||
getData().logTimeLastLoot(dGroup.getDungeonName());
|
||||
getData().logTimeLastLoot(dGroup.getDungeon().getName());
|
||||
}
|
||||
|
||||
public boolean canLoot(GameRuleProvider rules) {
|
||||
return getTimeNextLoot(rules) <= getData().getTimeLastStarted(getDGroup().getDungeonName());
|
||||
public boolean canLoot(GameRuleContainer rules) {
|
||||
return getTimeNextLoot(rules) <= getData().getTimeLastStarted(getGroup().getDungeonName());
|
||||
}
|
||||
|
||||
public long getTimeNextLoot(GameRuleProvider rules) {
|
||||
return rules.getTimeToNextLoot() * 60 * 60 * 1000 + getData().getTimeLastLoot(getDGroup().getDungeonName());
|
||||
public long getTimeNextLoot(GameRuleContainer rules) {
|
||||
return rules.getState(GameRule.TIME_TO_NEXT_LOOT) * 60 * 60 * 1000 + getData().getTimeLastLoot(getGroup().getDungeonName());
|
||||
}
|
||||
|
||||
public void ready() {
|
||||
ready(GameTypeDefault.DEFAULT);
|
||||
@Override
|
||||
public boolean ready() {
|
||||
return ready(true);
|
||||
}
|
||||
|
||||
public boolean ready(GameType gameType) {
|
||||
if (getDGroup() == null) {
|
||||
public boolean ready(boolean rewards) {
|
||||
if (dGroup == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Game game = Game.getByGameWorld(dGroup.getGameWorld());
|
||||
Game game = dGroup.getGame();
|
||||
if (game == null) {
|
||||
game = new Game(plugin, dGroup, gameType, dGroup.getGameWorld());
|
||||
|
||||
} else {
|
||||
game.setType(gameType);
|
||||
game = new DGame(plugin, dGroup, dGroup.getGameWorld());
|
||||
}
|
||||
game.fetchRules();
|
||||
game.setRewards(rewards);
|
||||
|
||||
if (!checkRequirements(game)) {
|
||||
if (!checkRequirements(game.getDungeon())) {
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_REQUIREMENTS.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
@ -709,9 +628,9 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
ready = true;
|
||||
|
||||
boolean start = true;
|
||||
for (DGroup gameGroup : game.getDGroups()) {
|
||||
for (PlayerGroup gameGroup : game.getGroups()) {
|
||||
if (!gameGroup.isPlaying()) {
|
||||
if (!gameGroup.startGame(game)) {
|
||||
if (!((DGroup) gameGroup).startGame(game)) {
|
||||
start = false;
|
||||
}
|
||||
} else {
|
||||
|
@ -723,11 +642,12 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
return start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void respawn() {
|
||||
Location respawn = checkpoint;
|
||||
|
||||
if (respawn == null) {
|
||||
respawn = getDGroup().getGameWorld().getStartLocation(dGroup);
|
||||
respawn = getGroup().getGameWorld().getStartLocation(dGroup);
|
||||
}
|
||||
|
||||
if (respawn == null) {
|
||||
|
@ -757,7 +677,7 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
finished = true;
|
||||
|
||||
boolean hasToWait = false;
|
||||
if (getDGroup() == null) {
|
||||
if (getGroup() == null) {
|
||||
return;
|
||||
}
|
||||
if (!dGroup.isPlaying()) {
|
||||
|
@ -778,16 +698,12 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The DGamePlayer finishs the current game.
|
||||
*/
|
||||
@Override
|
||||
public void finish() {
|
||||
finish(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message if messages should be sent
|
||||
*/
|
||||
@Override
|
||||
public void finish(boolean message) {
|
||||
if (message) {
|
||||
MessageUtil.sendMessage(getPlayer(), DMessage.PLAYER_FINISHED_DUNGEON.getMessage());
|
||||
|
@ -795,7 +711,7 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
finished = true;
|
||||
|
||||
boolean hasToWait = false;
|
||||
if (!getDGroup().isPlaying()) {
|
||||
if (!getGroup().isPlaying()) {
|
||||
return;
|
||||
}
|
||||
if (dGroup.isFinished()) {
|
||||
|
@ -815,12 +731,12 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
}
|
||||
|
||||
public void onDeath(PlayerDeathEvent event) {
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(player.getLocation().getWorld());
|
||||
DGameWorld gameWorld = (DGameWorld) getGameWorld();
|
||||
if (gameWorld == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Game game = Game.getByGameWorld(gameWorld);
|
||||
DGame game = (DGame) getGame();
|
||||
if (game == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -836,14 +752,14 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
event.setDeathMessage(null);
|
||||
}
|
||||
|
||||
if (game.getRules().getKeepInventoryOnDeath()) {
|
||||
if (game.getRules().getState(GameRule.KEEP_INVENTORY_ON_DEATH)) {
|
||||
event.setKeepInventory(true);
|
||||
event.getDrops().clear();
|
||||
event.setKeepLevel(true);
|
||||
event.setDroppedExp(0);
|
||||
}
|
||||
|
||||
if (getDGroup() != null && dGroup.getLives() != -1) {
|
||||
if (getGroup() != null && dGroup.getLives() != -1) {
|
||||
int newLives = dGroup.getLives() - dPlayerDeathEvent.getLostLives();
|
||||
dGroup.setLives(newLives < 0 ? 0 : newLives);// If the group already has 0 lives, don't remove any
|
||||
gameWorld.sendMessage(DMessage.GROUP_DEATH.getMessage(getName(), dGroup.getName(), String.valueOf(dGroup.getLives())));
|
||||
|
@ -853,7 +769,7 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
lives = lives - dPlayerDeathEvent.getLostLives();
|
||||
}
|
||||
|
||||
DGamePlayer killer = DGamePlayer.getByPlayer(player.getKiller());
|
||||
GamePlayer killer = plugin.getPlayerCache().getGamePlayer(player.getKiller());
|
||||
String newLives = lives == -1 ? DMessage.MISC_UNLIMITED.getMessage() : String.valueOf(this.lives);
|
||||
if (killer != null) {
|
||||
gameWorld.sendMessage(DMessage.PLAYER_KILLED.getMessage(getName(), killer.getName(), newLives));
|
||||
|
@ -862,7 +778,7 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
}
|
||||
}
|
||||
|
||||
if (isStealing()) {
|
||||
if (isStealingFlag()) {
|
||||
for (TeamFlag teamFlag : gameWorld.getTeamFlags()) {
|
||||
if (teamFlag.getOwner().equals(stealing)) {
|
||||
teamFlag.reset();
|
||||
|
@ -879,8 +795,8 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
GameType gameType = game.getType();
|
||||
if (gameType != null && gameType != GameTypeDefault.CUSTOM) {
|
||||
if (gameType.getGameGoal() == GameGoal.LAST_MAN_STANDING) {
|
||||
if (game.getDGroups().size() == 1) {
|
||||
game.getDGroups().get(0).winGame();
|
||||
if (game.getGroups().size() == 1) {
|
||||
((DGroup) game.getGroups().get(0)).winGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -895,17 +811,15 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
boolean kick = false;
|
||||
boolean triggerAllInDistance = false;
|
||||
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(getWorld());
|
||||
|
||||
if (!updateSecond) {
|
||||
if (!getPlayer().getWorld().equals(getWorld())) {
|
||||
locationValid = false;
|
||||
|
||||
if (gameWorld != null) {
|
||||
teleportLocation = getCheckpoint();
|
||||
if (getGameWorld() != null) {
|
||||
teleportLocation = getLastCheckpoint();
|
||||
|
||||
if (teleportLocation == null) {
|
||||
teleportLocation = getDGroup().getGameWorld().getStartLocation(getDGroup());
|
||||
teleportLocation = getGameWorld().getStartLocation(getGroup());
|
||||
}
|
||||
|
||||
// Don't forget Doge!
|
||||
|
@ -915,7 +829,7 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
}
|
||||
}
|
||||
|
||||
} else if (gameWorld != null) {
|
||||
} else if (getGameWorld() != null) {
|
||||
// Update Wolf
|
||||
if (getWolf() != null) {
|
||||
if (getWolf().isDead()) {
|
||||
|
@ -928,17 +842,18 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
wolfRespawnTime--;
|
||||
}
|
||||
|
||||
DMob dMob = DMob.getByEntity(getWolf());
|
||||
// TODO Is doge even DMob?
|
||||
DungeonMob dMob = plugin.getDungeonMob(getWolf());
|
||||
if (dMob != null) {
|
||||
gameWorld.removeDMob(dMob);
|
||||
getGameWorld().removeMob(dMob);
|
||||
}
|
||||
}
|
||||
|
||||
// Kick offline players
|
||||
if (getOfflineTime() > 0) {
|
||||
if (getOfflineTimeMillis() > 0) {
|
||||
offline = true;
|
||||
|
||||
if (getOfflineTime() < System.currentTimeMillis()) {
|
||||
if (getOfflineTimeMillis() < System.currentTimeMillis()) {
|
||||
kick = true;
|
||||
}
|
||||
}
|
||||
|
@ -971,40 +886,8 @@ public class DGamePlayer extends DInstancePlayer {
|
|||
}
|
||||
|
||||
if (triggerAllInDistance) {
|
||||
DistanceTrigger.triggerAllInDistance(getPlayer(), gameWorld);
|
||||
DistanceTrigger.triggerAllInDistance(getPlayer(), (DGameWorld) getGameWorld());
|
||||
}
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static DGamePlayer getByPlayer(Player player) {
|
||||
for (DGamePlayer dPlayer : DungeonsXL.getInstance().getDPlayerCache().getDGamePlayers()) {
|
||||
if (dPlayer.getPlayer().equals(player)) {
|
||||
return dPlayer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DGamePlayer getByName(String name) {
|
||||
for (DGamePlayer dPlayer : DungeonsXL.getInstance().getDPlayerCache().getDGamePlayers()) {
|
||||
if (dPlayer.getPlayer().getName().equalsIgnoreCase(name) || dPlayer.getName().equalsIgnoreCase(name)) {
|
||||
return dPlayer;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<DGamePlayer> getByWorld(World world) {
|
||||
List<DGamePlayer> dPlayers = new ArrayList<>();
|
||||
|
||||
for (DGamePlayer dPlayer : DungeonsXL.getInstance().getDPlayerCache().getDGamePlayers()) {
|
||||
if (dPlayer.getWorld() == world) {
|
||||
dPlayers.add(dPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
return dPlayers;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,15 +19,16 @@ package de.erethon.dungeonsxl.player;
|
|||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.commons.compatibility.Internals;
|
||||
import de.erethon.commons.player.PlayerUtil;
|
||||
import de.erethon.commons.player.PlayerWrapper;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.dungeon.DGame;
|
||||
import de.erethon.dungeonsxl.event.dgroup.DGroupCreateEvent;
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import de.erethon.dungeonsxl.global.DPortal;
|
||||
import de.erethon.dungeonsxl.util.NBTUtil;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
@ -40,11 +41,9 @@ import org.bukkit.potion.PotionEffect;
|
|||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* Represents a player in the non-DXL worlds of the server.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class DGlobalPlayer implements PlayerWrapper {
|
||||
public class DGlobalPlayer implements GlobalPlayer {
|
||||
|
||||
protected DungeonsXL plugin;
|
||||
|
||||
|
@ -77,7 +76,7 @@ public class DGlobalPlayer implements PlayerWrapper {
|
|||
reset(false);
|
||||
}
|
||||
|
||||
plugin.getDPlayerCache().addPlayer(this);
|
||||
plugin.getPlayerCache().add(player, this);
|
||||
}
|
||||
|
||||
public DGlobalPlayer(DGlobalPlayer dPlayer) {
|
||||
|
@ -89,7 +88,7 @@ public class DGlobalPlayer implements PlayerWrapper {
|
|||
creatingPortal = dPlayer.getPortal();
|
||||
announcerEnabled = dPlayer.isAnnouncerEnabled();
|
||||
|
||||
plugin.getDPlayerCache().addPlayer(this);
|
||||
plugin.getPlayerCache().add(player, this);
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
|
@ -109,6 +108,8 @@ public class DGlobalPlayer implements PlayerWrapper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the saved data.
|
||||
*
|
||||
* @return the saved data
|
||||
*/
|
||||
public DPlayerData getData() {
|
||||
|
@ -116,7 +117,7 @@ public class DGlobalPlayer implements PlayerWrapper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Load / reload a new instance of DPlayerData
|
||||
* Load / reload a new instance of DPlayerData.
|
||||
*
|
||||
* @param file the file to load from
|
||||
*/
|
||||
|
@ -124,30 +125,12 @@ public class DGlobalPlayer implements PlayerWrapper {
|
|||
data = new DPlayerData(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the player is in break mode
|
||||
*/
|
||||
public boolean isInBreakMode() {
|
||||
return breakMode;
|
||||
@Override
|
||||
public PlayerGroup getGroup() {
|
||||
return plugin.getPlayerGroup(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param breakMode sets if the player is in break mode
|
||||
*/
|
||||
public void setInBreakMode(boolean breakMode) {
|
||||
this.breakMode = breakMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the DGroup of this player
|
||||
*/
|
||||
public DGroup getDGroup() {
|
||||
return DGroup.getByPlayer(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the player is in group chat
|
||||
*/
|
||||
@Override
|
||||
public boolean isInGroupChat() {
|
||||
if (!plugin.getMainConfig().isChatEnabled()) {
|
||||
return false;
|
||||
|
@ -155,16 +138,12 @@ public class DGlobalPlayer implements PlayerWrapper {
|
|||
return groupChat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param groupChat set if the player is in group chat
|
||||
*/
|
||||
@Override
|
||||
public void setInGroupChat(boolean groupChat) {
|
||||
this.groupChat = groupChat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the player spies the DXL chat channels
|
||||
*/
|
||||
@Override
|
||||
public boolean isInChatSpyMode() {
|
||||
if (!plugin.getMainConfig().isChatEnabled()) {
|
||||
return false;
|
||||
|
@ -172,14 +151,24 @@ public class DGlobalPlayer implements PlayerWrapper {
|
|||
return chatSpyMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param chatSpyMode sets if the player is in chat spy mode
|
||||
*/
|
||||
@Override
|
||||
public void setInChatSpyMode(boolean chatSpyMode) {
|
||||
this.chatSpyMode = chatSpyMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInBreakMode() {
|
||||
return breakMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInBreakMode(boolean breakMode) {
|
||||
this.breakMode = breakMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the player is creating a DPortal.
|
||||
*
|
||||
* @return if the player is creating a DPortal
|
||||
*/
|
||||
public boolean isCreatingPortal() {
|
||||
|
@ -187,6 +176,8 @@ public class DGlobalPlayer implements PlayerWrapper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the portal the player is creating.
|
||||
*
|
||||
* @return the portal the player is creating
|
||||
*/
|
||||
public DPortal getPortal() {
|
||||
|
@ -194,6 +185,8 @@ public class DGlobalPlayer implements PlayerWrapper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the portal the player is creating.
|
||||
*
|
||||
* @param dPortal the portal to create
|
||||
*/
|
||||
public void setCreatingPortal(DPortal dPortal) {
|
||||
|
@ -201,6 +194,8 @@ public class DGlobalPlayer implements PlayerWrapper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the item the player had in his hand before he started to create a portal.
|
||||
*
|
||||
* @return the item the player had in his hand before he started to create a portal
|
||||
*/
|
||||
public ItemStack getCachedItem() {
|
||||
|
@ -208,6 +203,8 @@ public class DGlobalPlayer implements PlayerWrapper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the cached item.
|
||||
*
|
||||
* @param item the cached item to set
|
||||
*/
|
||||
public void setCachedItem(ItemStack item) {
|
||||
|
@ -215,6 +212,8 @@ public class DGlobalPlayer implements PlayerWrapper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns if the player has announcers enabled.
|
||||
*
|
||||
* @return if the players receives announcer messages
|
||||
*/
|
||||
public boolean isAnnouncerEnabled() {
|
||||
|
@ -222,64 +221,45 @@ public class DGlobalPlayer implements PlayerWrapper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets if the player has announcers enabled.
|
||||
*
|
||||
* @param enabled set if the players receives announcer messages
|
||||
*/
|
||||
public void setAnnouncerEnabled(boolean enabled) {
|
||||
announcerEnabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param permission the permission to check
|
||||
* @return if the player has the permission
|
||||
*/
|
||||
public boolean hasPermission(DPermission permission) {
|
||||
return DPermission.hasPermission(player, permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the reward items
|
||||
*/
|
||||
@Override
|
||||
public List<ItemStack> getRewardItems() {
|
||||
return rewardItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the player has reward items left
|
||||
*/
|
||||
@Override
|
||||
public boolean hasRewardItemsLeft() {
|
||||
return rewardItems != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rewardItems the reward items to set
|
||||
*/
|
||||
@Override
|
||||
public void setRewardItems(List<ItemStack> rewardItems) {
|
||||
this.rewardItems = rewardItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param permission the permission to check
|
||||
* @return if the player has the permission
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
return DPermission.hasPermission(player, permission);
|
||||
}
|
||||
|
||||
public boolean hasPermission(DPermission permission) {
|
||||
return DPermission.hasPermission(player, permission);
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
/**
|
||||
* Sends a message to the player
|
||||
*
|
||||
* @param message the message to send
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
MessageUtil.sendMessage(player, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Respawns the player at his old position before he was in a dungeon
|
||||
*
|
||||
* @param keepInventory if the inventory shall be reset
|
||||
*/
|
||||
@Override
|
||||
public void reset(boolean keepInventory) {
|
||||
final Location tpLoc = data.getOldLocation().getWorld() != null ? data.getOldLocation() : Bukkit.getWorlds().get(0).getSpawnLocation();
|
||||
if (player.isDead()) {
|
||||
|
@ -295,7 +275,8 @@ public class DGlobalPlayer implements PlayerWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
private void reset(Location tpLoc, boolean keepInventory) {
|
||||
@Override
|
||||
public void reset(Location tpLoc, boolean keepInventory) {
|
||||
try {
|
||||
PlayerUtil.secureTeleport(player, tpLoc);
|
||||
player.setGameMode(data.getOldGameMode());
|
||||
|
@ -380,9 +361,9 @@ public class DGlobalPlayer implements PlayerWrapper {
|
|||
}
|
||||
|
||||
// The maxInstances check is already done in the listener
|
||||
DGameWorld gameWorld = dungeon.getMap().instantiateAsGameWorld(true);
|
||||
GameWorld gameWorld = dungeon.getMap().instantiateGameWorld(true);
|
||||
dGroup.setGameWorld(gameWorld);
|
||||
new Game(plugin, dGroup, gameWorld).setTutorial(true);
|
||||
new DGame(plugin, dGroup, gameWorld).setTutorial(true);
|
||||
new DGamePlayer(plugin, player, gameWorld);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,22 @@ package de.erethon.dungeonsxl.player;
|
|||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.commons.player.PlayerCollection;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.Requirement;
|
||||
import de.erethon.dungeonsxl.api.Reward;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Game;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRule;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.InstancePlayer;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerCache;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup.Color;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.dungeon.DDungeon;
|
||||
import de.erethon.dungeonsxl.dungeon.DGame;
|
||||
import de.erethon.dungeonsxl.dungeon.DungeonConfig;
|
||||
import de.erethon.dungeonsxl.event.dgroup.DGroupDisbandEvent;
|
||||
import de.erethon.dungeonsxl.event.dgroup.DGroupFinishDungeonEvent;
|
||||
|
@ -30,14 +43,10 @@ import de.erethon.dungeonsxl.event.dgroup.DGroupStartFloorEvent;
|
|||
import de.erethon.dungeonsxl.event.dplayer.DPlayerJoinDGroupEvent;
|
||||
import de.erethon.dungeonsxl.event.requirement.RequirementDemandEvent;
|
||||
import de.erethon.dungeonsxl.event.reward.RewardAdditionEvent;
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import de.erethon.dungeonsxl.game.GameRuleProvider;
|
||||
import de.erethon.dungeonsxl.requirement.Requirement;
|
||||
import de.erethon.dungeonsxl.reward.Reward;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
@ -49,14 +58,12 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
* Represents a group of players.
|
||||
*
|
||||
* @author Frank Baumann, Daniel Saukel
|
||||
*/
|
||||
public class DGroup {
|
||||
public class DGroup implements PlayerGroup {
|
||||
|
||||
DungeonsXL plugin;
|
||||
DPlayerCache dPlayers;
|
||||
private DungeonsXL plugin;
|
||||
private PlayerCache dPlayers;
|
||||
|
||||
private static int counter;
|
||||
|
||||
|
@ -66,13 +73,13 @@ public class DGroup {
|
|||
private PlayerCollection players = new PlayerCollection();
|
||||
private PlayerCollection invitedPlayers = new PlayerCollection();
|
||||
private Dungeon dungeon;
|
||||
private List<DResourceWorld> unplayedFloors = new ArrayList<>();
|
||||
private DGameWorld gameWorld;
|
||||
private List<ResourceWorld> unplayedFloors = new ArrayList<>();
|
||||
private GameWorld gameWorld;
|
||||
private boolean playing;
|
||||
private int floorCount;
|
||||
private List<Reward> rewards = new ArrayList<>();
|
||||
private BukkitTask timeIsRunningTask;
|
||||
private DResourceWorld nextFloor;
|
||||
private ResourceWorld nextFloor;
|
||||
private Color color;
|
||||
private int score = 0;
|
||||
private int initialLives = -1;
|
||||
|
@ -88,12 +95,12 @@ public class DGroup {
|
|||
|
||||
public DGroup(DungeonsXL plugin, String name, Player player) {
|
||||
this.plugin = plugin;
|
||||
dPlayers = plugin.getDPlayerCache();
|
||||
dPlayers = plugin.getPlayerCache();
|
||||
|
||||
plugin.getDGroupCache().add(this);
|
||||
plugin.getPlayerGroupCache().add(name, this);
|
||||
this.name = name;
|
||||
|
||||
setCaptain(player);
|
||||
setLeader(player);
|
||||
addPlayer(player);
|
||||
|
||||
playing = false;
|
||||
|
@ -110,14 +117,14 @@ public class DGroup {
|
|||
this(plugin, name, player, new ArrayList<Player>(), dungeon);
|
||||
}
|
||||
|
||||
public DGroup(DungeonsXL plugin, String name, Player captain, List<Player> players, Dungeon dungeon) {
|
||||
public DGroup(DungeonsXL plugin, String name, Player captain, Collection<Player> players, Dungeon dungeon) {
|
||||
this.plugin = plugin;
|
||||
dPlayers = plugin.getDPlayerCache();
|
||||
dPlayers = plugin.getPlayerCache();
|
||||
|
||||
plugin.getDGroupCache().add(this);
|
||||
plugin.getPlayerGroupCache().add(name, this);
|
||||
this.name = name;
|
||||
|
||||
DPlayerJoinDGroupEvent event = new DPlayerJoinDGroupEvent(plugin.getDPlayerCache().getByPlayer(captain), true, this);
|
||||
DPlayerJoinDGroupEvent event = new DPlayerJoinDGroupEvent((DGlobalPlayer) dPlayers.get(captain), true, this);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
|
@ -139,59 +146,38 @@ public class DGroup {
|
|||
}
|
||||
|
||||
// Getters and setters
|
||||
/**
|
||||
* @return the group ID
|
||||
*/
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name; formatted
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return getDColor().getChatColor() + name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name; not formatted
|
||||
*/
|
||||
@Override
|
||||
public String getRawName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param color the color to fetch the name from
|
||||
*/
|
||||
public void setName(Color color) {
|
||||
name = color.toString() + "#" + id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the captain
|
||||
*/
|
||||
public Player getCaptain() {
|
||||
@Override
|
||||
public Player getLeader() {
|
||||
return captain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param captain the captain to set
|
||||
*/
|
||||
public void setCaptain(Player captain) {
|
||||
this.captain = captain;
|
||||
@Override
|
||||
public void setLeader(Player player) {
|
||||
captain = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the players
|
||||
*/
|
||||
public PlayerCollection getPlayers() {
|
||||
@Override
|
||||
public PlayerCollection getMembers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
|
@ -201,18 +187,15 @@ public class DGroup {
|
|||
public Set<DGlobalPlayer> getDGlobalPlayers() {
|
||||
Set<DGlobalPlayer> players = new HashSet<>();
|
||||
for (UUID uuid : this.players) {
|
||||
players.add(dPlayers.getByUniqueId(uuid));
|
||||
players.add((DGlobalPlayer) dPlayers.get(uuid));
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the players as a Set<DGamePlayer>
|
||||
*/
|
||||
public Set<DGamePlayer> getDGamePlayers() {
|
||||
Set<DGamePlayer> players = new HashSet<>();
|
||||
for (UUID uuid : this.players) {
|
||||
DGlobalPlayer dPlayer = dPlayers.getByUniqueId(uuid);
|
||||
GlobalPlayer dPlayer = dPlayers.get(uuid);
|
||||
if (dPlayer instanceof DGamePlayer) {
|
||||
players.add((DGamePlayer) dPlayer);
|
||||
}
|
||||
|
@ -220,21 +203,9 @@ public class DGroup {
|
|||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages by default.
|
||||
*
|
||||
* @param player the player to add
|
||||
*/
|
||||
public void addPlayer(Player player) {
|
||||
addPlayer(player, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player the player to add
|
||||
* @param message if messages should be sent
|
||||
*/
|
||||
@Override
|
||||
public void addPlayer(Player player, boolean message) {
|
||||
DPlayerJoinDGroupEvent event = new DPlayerJoinDGroupEvent(DGamePlayer.getByPlayer(player), false, this);
|
||||
DPlayerJoinDGroupEvent event = new DPlayerJoinDGroupEvent((DGlobalPlayer) dPlayers.getGamePlayer(player), false, this);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
|
@ -247,19 +218,12 @@ public class DGroup {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends messages by default.
|
||||
*
|
||||
* @param player the player to remove
|
||||
*/
|
||||
@Override
|
||||
public void removePlayer(Player player) {
|
||||
removePlayer(player, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player the player to remove
|
||||
* @param message if messages should be sent
|
||||
*/
|
||||
@Override
|
||||
public void removePlayer(Player player, boolean message) {
|
||||
players.remove(player.getUniqueId());
|
||||
plugin.getGlobalProtectionCache().updateGroupSigns(this);
|
||||
|
@ -278,54 +242,46 @@ public class DGroup {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the players
|
||||
*/
|
||||
@Override
|
||||
public PlayerCollection getInvitedPlayers() {
|
||||
return invitedPlayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player the player to add
|
||||
* @param silent if messages shall be sent
|
||||
*/
|
||||
@Override
|
||||
public void addInvitedPlayer(Player player, boolean silent) {
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (DGroup.getByPlayer(player) != null) {
|
||||
if (plugin.getPlayerGroup(player) != null) {
|
||||
if (!silent) {
|
||||
MessageUtil.sendMessage(getCaptain(), DMessage.ERROR_IN_GROUP.getMessage(player.getName()));
|
||||
MessageUtil.sendMessage(getLeader(), DMessage.ERROR_IN_GROUP.getMessage(player.getName()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!silent) {
|
||||
MessageUtil.sendMessage(player, DMessage.PLAYER_INVITED.getMessage(getCaptain().getName(), name));
|
||||
MessageUtil.sendMessage(player, DMessage.PLAYER_INVITED.getMessage(getLeader().getName(), name));
|
||||
}
|
||||
|
||||
// Send message
|
||||
if (!silent) {
|
||||
sendMessage(DMessage.GROUP_INVITED_PLAYER.getMessage(getCaptain().getName(), player.getName(), name));
|
||||
sendMessage(DMessage.GROUP_INVITED_PLAYER.getMessage(getLeader().getName(), player.getName(), name));
|
||||
}
|
||||
|
||||
// Add player
|
||||
invitedPlayers.add(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player the player to remove
|
||||
* @param silent if messages shall be sent
|
||||
*/
|
||||
@Override
|
||||
public void removeInvitedPlayer(Player player, boolean silent) {
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (DGroup.getByPlayer(player) != this) {
|
||||
if (plugin.getPlayerGroup(player) != this) {
|
||||
if (!silent) {
|
||||
MessageUtil.sendMessage(getCaptain(), DMessage.ERROR_NOT_IN_GROUP.getMessage(player.getName(), name));
|
||||
MessageUtil.sendMessage(getLeader(), DMessage.ERROR_NOT_IN_GROUP.getMessage(player.getName(), name));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -337,16 +293,14 @@ public class DGroup {
|
|||
// Send message
|
||||
if (!silent) {
|
||||
for (Player groupPlayer : players.getOnlinePlayers()) {
|
||||
MessageUtil.sendMessage(groupPlayer, DMessage.GROUP_UNINVITED_PLAYER.getMessage(getCaptain().getName(), player.getName(), name));
|
||||
MessageUtil.sendMessage(groupPlayer, DMessage.GROUP_UNINVITED_PLAYER.getMessage(getLeader().getName(), player.getName(), name));
|
||||
}
|
||||
}
|
||||
|
||||
invitedPlayers.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all invitations for players who are not online
|
||||
*/
|
||||
@Override
|
||||
public void clearOfflineInvitedPlayers() {
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
for (UUID uuid : invitedPlayers.getUniqueIds()) {
|
||||
|
@ -357,23 +311,17 @@ public class DGroup {
|
|||
invitedPlayers.removeAll(toRemove);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the gameWorld
|
||||
*/
|
||||
public DGameWorld getGameWorld() {
|
||||
@Override
|
||||
public GameWorld getGameWorld() {
|
||||
return gameWorld;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param gameWorld the gameWorld to set
|
||||
*/
|
||||
public void setGameWorld(DGameWorld gameWorld) {
|
||||
@Override
|
||||
public void setGameWorld(GameWorld gameWorld) {
|
||||
this.gameWorld = gameWorld;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dungeon
|
||||
*/
|
||||
@Override
|
||||
public Dungeon getDungeon() {
|
||||
return dungeon;
|
||||
}
|
||||
|
@ -386,7 +334,7 @@ public class DGroup {
|
|||
public void setDungeon(Dungeon dungeon) {
|
||||
this.dungeon = dungeon;
|
||||
if (dungeon.isMultiFloor()) {
|
||||
unplayedFloors = new ArrayList<>(dungeon.getConfig().getFloors());
|
||||
unplayedFloors = new ArrayList<>(dungeon.getFloors());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -397,24 +345,21 @@ public class DGroup {
|
|||
* @return if the action was successful
|
||||
*/
|
||||
public boolean setDungeon(String name) {
|
||||
dungeon = plugin.getDungeonCache().getByName(name);
|
||||
dungeon = plugin.getDungeonRegistry().get(name);
|
||||
if (dungeon != null) {
|
||||
unplayedFloors = dungeon.getConfig().getFloors();
|
||||
unplayedFloors = dungeon.getFloors();
|
||||
return true;
|
||||
|
||||
} else {
|
||||
DResourceWorld resource = plugin.getDWorldCache().getResourceByName(name);
|
||||
ResourceWorld resource = plugin.getMapRegistry().get(name);
|
||||
if (resource != null) {
|
||||
dungeon = new Dungeon(plugin, resource);
|
||||
dungeon = resource.getSingleFloorDungeon();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dungeonName
|
||||
*/
|
||||
public String getDungeonName() {
|
||||
if (dungeon == null) {
|
||||
return null;
|
||||
|
@ -422,17 +367,11 @@ public class DGroup {
|
|||
return dungeon.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the group is playing
|
||||
*/
|
||||
public String getMapName() {
|
||||
return gameWorld == null ? null : gameWorld.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the unplayed floors
|
||||
*/
|
||||
public List<DResourceWorld> getUnplayedFloors() {
|
||||
public List<ResourceWorld> getUnplayedFloors() {
|
||||
return unplayedFloors;
|
||||
}
|
||||
|
||||
|
@ -448,49 +387,34 @@ public class DGroup {
|
|||
* @param force remove the floor even if removeWhenPlayed is disabled
|
||||
*/
|
||||
public void removeUnplayedFloor(DResourceWorld unplayedFloor, boolean force) {
|
||||
if (getDungeon().getConfig().getRemoveWhenPlayed() || force) {
|
||||
if (getDungeon().getRemoveWhenPlayed() || force) {
|
||||
unplayedFloors.remove(unplayedFloor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the group is playing
|
||||
*/
|
||||
@Override
|
||||
public boolean isPlaying() {
|
||||
return playing;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playing set if the group is playing
|
||||
*/
|
||||
public void setPlaying(boolean playing) {
|
||||
this.playing = playing;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the floorCount
|
||||
*/
|
||||
public int getFloorCount() {
|
||||
return floorCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param floorCount the floorCount to set
|
||||
*/
|
||||
public void setFloorCount(int floorCount) {
|
||||
this.floorCount = floorCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the rewards
|
||||
*/
|
||||
@Override
|
||||
public List<Reward> getRewards() {
|
||||
return rewards;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param reward the rewards to add
|
||||
*/
|
||||
@Override
|
||||
public void addReward(Reward reward) {
|
||||
RewardAdditionEvent event = new RewardAdditionEvent(reward, this);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
@ -502,56 +426,38 @@ public class DGroup {
|
|||
rewards.add(reward);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param reward the rewards to remove
|
||||
*/
|
||||
@Override
|
||||
public void removeReward(Reward reward) {
|
||||
rewards.remove(reward);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the "Time is Running" task of the game
|
||||
*/
|
||||
public BukkitTask getTimeIsRunningTask() {
|
||||
return timeIsRunningTask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param task the task to set
|
||||
*/
|
||||
public void setTimeIsRunningTask(BukkitTask task) {
|
||||
this.timeIsRunningTask = task;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether there are players in the group
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return players.size() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the group has been customized with a command
|
||||
*/
|
||||
public boolean isCustom() {
|
||||
return !name.matches("Group#[0-9]{1,}");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the next floor the group will enter
|
||||
*/
|
||||
public DResourceWorld getNextFloor() {
|
||||
public ResourceWorld getNextFloor() {
|
||||
return nextFloor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param floor the next floor to set
|
||||
*/
|
||||
public void setNextFloor(DResourceWorld floor) {
|
||||
nextFloor = floor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color that represents this group.
|
||||
*
|
||||
* @return the color that represents this group
|
||||
*/
|
||||
public Color getDColor() {
|
||||
|
@ -563,60 +469,48 @@ public class DGroup {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the color that represents this group.
|
||||
*
|
||||
* @param color the group color to set
|
||||
*/
|
||||
public void setDColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current score
|
||||
*/
|
||||
@Override
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param score the score to set
|
||||
*/
|
||||
@Override
|
||||
public void setScore(int score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the initial group lives
|
||||
*/
|
||||
@Override
|
||||
public int getInitialLives() {
|
||||
return initialLives;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param initialLives the initial group lives to set
|
||||
*/
|
||||
@Override
|
||||
public void setInitialLives(int initialLives) {
|
||||
this.initialLives = initialLives;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the group lives
|
||||
*/
|
||||
@Override
|
||||
public int getLives() {
|
||||
return lives;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lives the group lives to set
|
||||
*/
|
||||
@Override
|
||||
public void setLives(int lives) {
|
||||
this.lives = lives;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if all players are finished
|
||||
*/
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
for (DGamePlayer dPlayer : getDGamePlayers()) {
|
||||
if (!dPlayer.isFinished()) {
|
||||
for (DGamePlayer player : getDGamePlayers()) {
|
||||
if (!player.isFinished()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -630,8 +524,8 @@ public class DGroup {
|
|||
return false;
|
||||
}
|
||||
|
||||
DGameWorld target = dungeon.getMap().instantiateAsGameWorld(false);
|
||||
Game game = Game.getByDGroup(this);
|
||||
GameWorld target = dungeon.getMap().instantiateGameWorld(false);
|
||||
Game game = getGame();
|
||||
|
||||
if (target == null && game != null) {
|
||||
target = game.getWorld();
|
||||
|
@ -639,7 +533,7 @@ public class DGroup {
|
|||
|
||||
if (target == null) {
|
||||
if (game != null) {
|
||||
for (DGroup otherTeam : game.getDGroups()) {
|
||||
for (PlayerGroup otherTeam : game.getGroups()) {
|
||||
if (otherTeam.getGameWorld() != null) {
|
||||
target = otherTeam.getGameWorld();
|
||||
break;
|
||||
|
@ -649,9 +543,9 @@ public class DGroup {
|
|||
}
|
||||
|
||||
if (target == null && dungeon != null) {
|
||||
DResourceWorld resource = dungeon.getMap();
|
||||
ResourceWorld resource = dungeon.getMap();
|
||||
if (resource != null) {
|
||||
target = resource.instantiateAsGameWorld(false);
|
||||
target = resource.instantiateGameWorld(false);
|
||||
if (target == null) {
|
||||
sendMessage(DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
|
||||
return false;
|
||||
|
@ -666,7 +560,7 @@ public class DGroup {
|
|||
}
|
||||
|
||||
if (game == null) {
|
||||
game = new Game(plugin, this, target);
|
||||
game = new DGame(plugin, this, target);
|
||||
|
||||
} else {
|
||||
game.setWorld(target);
|
||||
|
@ -687,13 +581,13 @@ public class DGroup {
|
|||
* The group finishs the dungeon.
|
||||
*/
|
||||
public void finish() {
|
||||
DGroupFinishDungeonEvent dGroupFinishDungeonEvent = new DGroupFinishDungeonEvent(dungeon, this);
|
||||
DGroupFinishDungeonEvent dGroupFinishDungeonEvent = new DGroupFinishDungeonEvent((DDungeon) dungeon, this);
|
||||
Bukkit.getPluginManager().callEvent(dGroupFinishDungeonEvent);
|
||||
if (dGroupFinishDungeonEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Game.getByDGroup(this).resetWaveKills();
|
||||
((DGame) getGame()).resetWaveKills();
|
||||
getDGamePlayers().forEach(p -> p.leave(false));
|
||||
}
|
||||
|
||||
|
@ -703,65 +597,63 @@ public class DGroup {
|
|||
* @param specifiedFloor the name of the next floor
|
||||
*/
|
||||
public void finishFloor(DResourceWorld specifiedFloor) {
|
||||
DungeonConfig dConfig = dungeon.getConfig();
|
||||
DungeonConfig dConfig = ((DDungeon) dungeon).getConfig();
|
||||
int floorsLeft = getDungeon().getFloors().size() + 1 - floorCount;//floorCount contains start floor, but dungeon floor list doesn't
|
||||
DResourceWorld newFloor = null;
|
||||
DGameWorld.Type type = null;
|
||||
if (gameWorld.getType() == DGameWorld.Type.END_FLOOR) {
|
||||
ResourceWorld newFloor = null;
|
||||
GameWorld.Type type = null;
|
||||
if (gameWorld.getType() == GameWorld.Type.END_FLOOR) {
|
||||
finish();
|
||||
return;
|
||||
} else if (specifiedFloor != null) {
|
||||
newFloor = specifiedFloor;
|
||||
type = DGameWorld.Type.DEFAULT;
|
||||
type = GameWorld.Type.DEFAULT;
|
||||
} else if (floorsLeft > 0) {
|
||||
int random = new Random().nextInt(floorsLeft);
|
||||
newFloor = getUnplayedFloors().get(random);
|
||||
type = DGameWorld.Type.DEFAULT;
|
||||
type = GameWorld.Type.DEFAULT;
|
||||
} else {
|
||||
newFloor = dConfig.getEndFloor();
|
||||
type = DGameWorld.Type.END_FLOOR;
|
||||
type = GameWorld.Type.END_FLOOR;
|
||||
}
|
||||
|
||||
DGroupFinishFloorEvent event = new DGroupFinishFloorEvent(this, gameWorld, newFloor);
|
||||
DGroupFinishFloorEvent event = new DGroupFinishFloorEvent(this, (DGameWorld) gameWorld, (DResourceWorld) newFloor);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Game game = gameWorld.getGame();
|
||||
removeUnplayedFloor(gameWorld.getResource(), false);
|
||||
DGameWorld gameWorld = newFloor.instantiateAsGameWorld(true);
|
||||
Game game = getGame();
|
||||
removeUnplayedFloor((DResourceWorld) gameWorld.getResource(), false);
|
||||
GameWorld gameWorld = newFloor.instantiateGameWorld(true);
|
||||
gameWorld.setType(type);
|
||||
this.gameWorld = gameWorld;
|
||||
game.setWorld(gameWorld);
|
||||
|
||||
for (DGamePlayer player : getDGamePlayers()) {
|
||||
player.setWorld(gameWorld.getWorld());
|
||||
player.setCheckpoint(gameWorld.getStartLocation(this));
|
||||
player.setLastCheckpoint(gameWorld.getStartLocation(this));
|
||||
if (player.getWolf() != null) {
|
||||
player.getWolf().teleport(player.getCheckpoint());
|
||||
player.getWolf().teleport(player.getLastCheckpoint());
|
||||
}
|
||||
player.setFinished(false);
|
||||
}
|
||||
startGame(game);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the group from the List
|
||||
*/
|
||||
@Override
|
||||
public void delete() {
|
||||
Game game = Game.getByDGroup(this);
|
||||
Game game = getGame();
|
||||
|
||||
plugin.getDGroupCache().remove(this);
|
||||
plugin.getPlayerGroupCache().remove(this);
|
||||
|
||||
if (game != null) {
|
||||
game.removeDGroup(this);
|
||||
game.removeGroup(this);
|
||||
}
|
||||
|
||||
for (UUID uuid : players.getUniqueIds()) {
|
||||
DGlobalPlayer member = dPlayers.getByUniqueId(uuid);
|
||||
if (member instanceof DInstancePlayer) {
|
||||
((DInstancePlayer) member).leave();
|
||||
GlobalPlayer member = dPlayers.get(uuid);
|
||||
if (member instanceof InstancePlayer) {
|
||||
((InstancePlayer) member).leave();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -776,26 +668,26 @@ public class DGroup {
|
|||
if (game == null) {
|
||||
return false;
|
||||
}
|
||||
game.fetchRules();
|
||||
GameRuleProvider rules = game.getRules();
|
||||
gameWorld.setWeather(rules);
|
||||
GameRuleContainer rules = game.getRules();
|
||||
((DGameWorld) gameWorld).setWeather(rules);
|
||||
|
||||
if (color == null) {
|
||||
color = plugin.getMainConfig().getGroupColorPriority((game.getDGroups().indexOf(this)));
|
||||
color = plugin.getMainConfig().getGroupColorPriority((game.getGroups().indexOf(this)));
|
||||
}
|
||||
|
||||
for (DGroup dGroup : game.getDGroups()) {
|
||||
for (PlayerGroup group : game.getGroups()) {
|
||||
DGroup dGroup = (DGroup) group;
|
||||
if (dGroup == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean ready = true;
|
||||
for (Player player : dGroup.getPlayers().getOnlinePlayers()) {
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
for (Player player : dGroup.getMembers().getOnlinePlayers()) {
|
||||
DGamePlayer dPlayer = (DGamePlayer) dPlayers.get(player);
|
||||
if (dPlayer == null) {
|
||||
dPlayer = new DGamePlayer(plugin, player, gameWorld);
|
||||
}
|
||||
if (rules.isGroupTagEnabled()) {
|
||||
if (rules.getState(GameRule.GROUP_TAG_ENABLED)) {
|
||||
dPlayer.initDGroupTag();
|
||||
}
|
||||
if (!dPlayer.isReady()) {
|
||||
|
@ -808,7 +700,7 @@ public class DGroup {
|
|||
}
|
||||
}
|
||||
|
||||
DGroupStartFloorEvent event = new DGroupStartFloorEvent(this, gameWorld);
|
||||
DGroupStartFloorEvent event = new DGroupStartFloorEvent(this, (DGameWorld) gameWorld);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
|
@ -819,28 +711,29 @@ public class DGroup {
|
|||
|
||||
if (gameWorld != null) {
|
||||
if (!gameWorld.isPlaying()) {
|
||||
gameWorld.startGame();
|
||||
((DGameWorld) gameWorld).startGame();
|
||||
}
|
||||
}
|
||||
|
||||
floorCount++;
|
||||
|
||||
for (Player player : players.getOnlinePlayers()) {
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
DGamePlayer dPlayer = (DGamePlayer) dPlayers.getGamePlayer(player);
|
||||
if (dPlayer == null) {
|
||||
continue;
|
||||
}
|
||||
dPlayer.getData().logTimeLastStarted(getDungeonName());
|
||||
dPlayer.getData().setKeepInventoryAfterLogout(rules.getKeepInventoryOnEscape());
|
||||
dPlayer.getData().setKeepInventoryAfterLogout(rules.getState(GameRule.KEEP_INVENTORY_ON_ESCAPE));
|
||||
|
||||
dPlayer.respawn();
|
||||
|
||||
if (plugin.getMainConfig().isSendFloorTitleEnabled()) {
|
||||
if (rules.getTitle() != null || rules.getSubTitle() != null) {
|
||||
String title = rules.getTitle() == null ? "" : rules.getTitle();
|
||||
String subtitle = rules.getSubTitle() == null ? "" : rules.getSubTitle();
|
||||
if (rules.getState(GameRule.TITLE) != null || rules.getState(GameRule.SUBTITLE) != null) {
|
||||
String title = rules.getState(GameRule.TITLE) == null ? "" : rules.getState(GameRule.TITLE);
|
||||
String subtitle = rules.getState(GameRule.SUBTITLE) == null ? "" : rules.getState(GameRule.SUBTITLE);
|
||||
|
||||
MessageUtil.sendTitleMessage(player, title, subtitle, rules.getTitleFadeIn(), rules.getTitleShow(), rules.getTitleFadeOut());
|
||||
MessageUtil.sendTitleMessage(player, title, subtitle,
|
||||
rules.getState(GameRule.TITLE_FADE_IN), rules.getState(GameRule.TITLE_SHOW), rules.getState(GameRule.TITLE_FADE_OUT));
|
||||
|
||||
} else if (!getDungeonName().equals(getMapName())) {
|
||||
MessageUtil.sendTitleMessage(player, "&b&l" + getDungeonName().replaceAll("_", " "), "&4&l" + getMapName().replaceAll("_", " "));
|
||||
|
@ -849,16 +742,16 @@ public class DGroup {
|
|||
MessageUtil.sendTitleMessage(player, "&4&l" + getMapName().replaceAll("_", " "));
|
||||
}
|
||||
|
||||
if (rules.getActionBar() != null) {
|
||||
MessageUtil.sendActionBarMessage(player, rules.getActionBar());
|
||||
if (rules.getState(GameRule.ACTION_BAR) != null) {
|
||||
MessageUtil.sendActionBarMessage(player, rules.getState(GameRule.ACTION_BAR));
|
||||
}
|
||||
|
||||
if (rules.getChatText() != null) {
|
||||
MessageUtil.sendCenteredMessage(player, rules.getChatText());
|
||||
if (rules.getState(GameRule.CHAT) != null) {
|
||||
MessageUtil.sendCenteredMessage(player, rules.getState(GameRule.CHAT));
|
||||
}
|
||||
}
|
||||
|
||||
for (Requirement requirement : rules.getRequirements()) {
|
||||
for (Requirement requirement : rules.getState(GameRule.REQUIREMENTS)) {
|
||||
RequirementDemandEvent requirementDemandEvent = new RequirementDemandEvent(requirement, player);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
|
@ -871,14 +764,14 @@ public class DGroup {
|
|||
}
|
||||
}
|
||||
|
||||
player.setGameMode(rules.getGameMode());
|
||||
if (rules.isTimeIsRunning()) {
|
||||
timeIsRunningTask = new TimeIsRunningTask(this, rules.getTimeToFinish()).runTaskTimer(plugin, 20, 20);
|
||||
player.setGameMode(rules.getState(GameRule.GAME_MODE));
|
||||
if (rules.getState(GameRule.TIME_TO_FINISH) != -1) {
|
||||
timeIsRunningTask = new TimeIsRunningTask(plugin, this, rules.getState(GameRule.TIME_TO_FINISH)).runTaskTimer(plugin, 20, 20);
|
||||
}
|
||||
|
||||
// Permission bridge
|
||||
if (plugin.getPermissionProvider() != null) {
|
||||
for (String permission : rules.getGamePermissions()) {
|
||||
for (String permission : rules.getState(GameRule.GAME_PERMISSIONS)) {
|
||||
plugin.getPermissionProvider().playerRemoveTransient(gameWorld.getWorld().getName(), player, permission);
|
||||
}
|
||||
}
|
||||
|
@ -886,7 +779,7 @@ public class DGroup {
|
|||
|
||||
plugin.getGlobalProtectionCache().updateGroupSigns(this);
|
||||
nextFloor = null;
|
||||
initialLives = rules.getInitialGroupLives();
|
||||
initialLives = rules.getState(GameRule.INITIAL_GROUP_LIVES);
|
||||
lives = initialLives;
|
||||
return true;
|
||||
}
|
||||
|
@ -900,13 +793,13 @@ public class DGroup {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean checkTime(Game game) {
|
||||
if (DPermission.hasPermission(getCaptain(), DPermission.IGNORE_TIME_LIMIT)) {
|
||||
public boolean checkTime() {
|
||||
if (DPermission.hasPermission(getLeader(), DPermission.IGNORE_TIME_LIMIT)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (DGamePlayer dPlayer : getDGamePlayers()) {
|
||||
if (!dPlayer.checkTimeAfterStart(game) || !dPlayer.checkTimeAfterFinish(game)) {
|
||||
if (!dPlayer.checkTimeAfterStart(dungeon) || !dPlayer.checkTimeAfterFinish(dungeon)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -914,13 +807,13 @@ public class DGroup {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean checkRequirements(Game game) {
|
||||
if (DPermission.hasPermission(getCaptain(), DPermission.IGNORE_REQUIREMENTS)) {
|
||||
public boolean checkRequirements() {
|
||||
if (DPermission.hasPermission(getLeader(), DPermission.IGNORE_REQUIREMENTS)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (DGamePlayer dPlayer : getDGamePlayers()) {
|
||||
if (!dPlayer.checkRequirements(game)) {
|
||||
if (!dPlayer.checkRequirements(dungeon)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -941,65 +834,6 @@ public class DGroup {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to all players in the group.
|
||||
*
|
||||
* @param message the message to sent
|
||||
* @param except Players who shall not receive the message
|
||||
*/
|
||||
public void sendMessage(String message, Player... except) {
|
||||
HashSet<Player> exceptSet = new HashSet<>(Arrays.asList(except));
|
||||
for (Player player : players.getOnlinePlayers()) {
|
||||
if (player.isOnline() && !exceptSet.contains(player)) {
|
||||
MessageUtil.sendMessage(player, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static DGroup getByName(String name) {
|
||||
for (DGroup dGroup : DungeonsXL.getInstance().getDGroupCache()) {
|
||||
if (dGroup.getName().equalsIgnoreCase(name) || dGroup.getRawName().equalsIgnoreCase(name)) {
|
||||
return dGroup;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DGroup getByPlayer(Player player) {
|
||||
for (DGroup dGroup : DungeonsXL.getInstance().getDGroupCache()) {
|
||||
if (dGroup.getPlayers().contains(player)) {
|
||||
return dGroup;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void leaveGroup(Player player) {
|
||||
for (DGroup dGroup : DungeonsXL.getInstance().getDGroupCache()) {
|
||||
if (dGroup.getPlayers().contains(player)) {
|
||||
dGroup.getPlayers().remove(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param gameWorld the DGameWorld to check
|
||||
* @return a List of DGroups in this DGameWorld
|
||||
*/
|
||||
public static List<DGroup> getByGameWorld(DGameWorld gameWorld) {
|
||||
List<DGroup> dGroups = new ArrayList<>();
|
||||
for (DGroup dGroup : DungeonsXL.getInstance().getDGroupCache()) {
|
||||
if (dGroup.getGameWorld().equals(gameWorld)) {
|
||||
dGroups.add(dGroup);
|
||||
}
|
||||
}
|
||||
|
||||
return dGroups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "{name=" + name + "; captain=" + captain + "}";
|
||||
|
|
|
@ -30,7 +30,7 @@ public class DGroupTag {
|
|||
|
||||
public DGroupTag(DungeonsXL plugin, DGamePlayer player) {
|
||||
this.player = player;
|
||||
DGroup group = player.getDGroup();
|
||||
DGroup group = player.getGroup();
|
||||
if (group != null) {
|
||||
hologram = HologramsAPI.createHologram(plugin, player.getPlayer().getLocation().clone().add(0, 3.5, 0));
|
||||
hologram.appendItemLine(group.getDColor().getWoolMaterial().toItemStack());
|
||||
|
|
|
@ -17,45 +17,47 @@
|
|||
package de.erethon.dungeonsxl.player;
|
||||
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.InstancePlayer;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import de.erethon.dungeonsxl.api.world.InstanceWorld;
|
||||
import de.erethon.dungeonsxl.config.MainConfig;
|
||||
import de.erethon.dungeonsxl.util.ParsingUtil;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import de.erethon.dungeonsxl.world.DInstanceWorld;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
/**
|
||||
* Represents a player in an instance.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public abstract class DInstancePlayer extends DGlobalPlayer {
|
||||
public abstract class DInstancePlayer extends DGlobalPlayer implements InstancePlayer {
|
||||
|
||||
MainConfig config;
|
||||
protected MainConfig config;
|
||||
|
||||
private InstanceWorld instanceWorld;
|
||||
private World world;
|
||||
|
||||
DInstancePlayer(DungeonsXL plugin, Player player, World world) {
|
||||
DInstancePlayer(DungeonsXL plugin, Player player, InstanceWorld world) {
|
||||
super(plugin, player, false);
|
||||
|
||||
config = plugin.getMainConfig();
|
||||
|
||||
this.world = world;
|
||||
instanceWorld = world;
|
||||
this.world = world.getWorld();
|
||||
getData().savePlayerState(player);
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
/**
|
||||
* @return the instance
|
||||
*/
|
||||
@Override
|
||||
public InstanceWorld getInstanceWorld() {
|
||||
return instanceWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param instance the instance to set
|
||||
*/
|
||||
public void setWorld(World instance) {
|
||||
world = instance;
|
||||
}
|
||||
|
@ -98,7 +100,7 @@ public abstract class DInstancePlayer extends DGlobalPlayer {
|
|||
new DGlobalPlayer(this);
|
||||
|
||||
} else {
|
||||
plugin.getDPlayerCache().removePlayer(this);
|
||||
plugin.getPlayerCache().remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,16 +110,12 @@ public abstract class DInstancePlayer extends DGlobalPlayer {
|
|||
* @param message the message to send
|
||||
*/
|
||||
public void chat(String message) {
|
||||
DInstanceWorld instance = plugin.getDWorldCache().getInstanceByWorld(world);
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
String chatFormat = instance instanceof DGameWorld ? config.getChatFormatGame() : config.getChatFormatEdit();
|
||||
instance.sendMessage(ParsingUtil.replaceChatPlaceholders(chatFormat, this) + message);
|
||||
String chatFormat = instanceWorld instanceof GameWorld ? config.getChatFormatGame() : config.getChatFormatEdit();
|
||||
instanceWorld.sendMessage(ParsingUtil.replaceChatPlaceholders(chatFormat, this) + message);
|
||||
|
||||
for (DGlobalPlayer player : plugin.getDPlayerCache().getDGlobalPlayers()) {
|
||||
for (GlobalPlayer player : plugin.getPlayerCache()) {
|
||||
if (player.isInChatSpyMode()) {
|
||||
if (!instance.getWorld().getPlayers().contains(player.getPlayer())) {
|
||||
if (!world.getPlayers().contains(player.getPlayer())) {
|
||||
player.sendMessage(ParsingUtil.replaceChatPlaceholders(config.getChatFormatSpy(), this) + message);
|
||||
}
|
||||
}
|
||||
|
@ -125,11 +123,6 @@ public abstract class DInstancePlayer extends DGlobalPlayer {
|
|||
}
|
||||
|
||||
/* Abstracts */
|
||||
/**
|
||||
* The player leaves the dungeon and / or his group.
|
||||
*/
|
||||
public abstract void leave();
|
||||
|
||||
/**
|
||||
* Repeating checks for the player.
|
||||
*
|
||||
|
|
|
@ -1,197 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.player;
|
||||
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.config.MainConfig;
|
||||
import de.erethon.dungeonsxl.world.DInstanceWorld;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* DGlobalPlayer instance manager.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class DPlayerCache {
|
||||
|
||||
private DungeonsXL plugin;
|
||||
private MainConfig config;
|
||||
|
||||
private CopyOnWriteArrayList<DGlobalPlayer> dGlobalPlayers = new CopyOnWriteArrayList<>();
|
||||
|
||||
public DPlayerCache(DungeonsXL plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
config = plugin.getMainConfig();
|
||||
|
||||
if (config.isSecureModeEnabled()) {
|
||||
new SecureModeTask(plugin).runTaskTimer(plugin, config.getSecureModeCheckInterval(), config.getSecureModeCheckInterval());
|
||||
}
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
plugin.getDPlayerCache().getDGamePlayers().forEach(p -> p.update(false));
|
||||
}
|
||||
}.runTaskTimer(plugin, 2L, 2L);
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
plugin.getDPlayerCache().getDGamePlayers().forEach(p -> p.update(true));
|
||||
}
|
||||
}.runTaskTimer(plugin, 20L, 20L);
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new DPlayerListener(plugin), plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player the player to check
|
||||
* @return the DGlobalPlayer which represents the player
|
||||
*/
|
||||
public DGlobalPlayer getByPlayer(Player player) {
|
||||
for (DGlobalPlayer dGlobalPlayer : dGlobalPlayers) {
|
||||
if (dGlobalPlayer.getPlayer() == player) {
|
||||
return dGlobalPlayer;
|
||||
}
|
||||
}
|
||||
return new DGlobalPlayer(plugin, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uuid the unique ID to check
|
||||
* @return the DGlobalPlayer which represents the player with this UUID
|
||||
*/
|
||||
public DGlobalPlayer getByUniqueId(UUID uuid) {
|
||||
for (DGlobalPlayer dGlobalPlayer : dGlobalPlayers) {
|
||||
if (dGlobalPlayer.getUniqueId().equals(uuid)) {
|
||||
return dGlobalPlayer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param instance the instance to check
|
||||
* @return a Collection of DInstancePlayers in this instance
|
||||
*/
|
||||
public Collection<DInstancePlayer> getByInstance(DInstanceWorld instance) {
|
||||
Collection<DInstancePlayer> players = new ArrayList<>();
|
||||
plugin.getDWorldCache().getInstances().forEach(i -> i.getPlayers().forEach(p -> players.add(p)));
|
||||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dGlobalPlayers
|
||||
*/
|
||||
public List<DGlobalPlayer> getDGlobalPlayers() {
|
||||
return dGlobalPlayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dGlobalPlayers that are an instance of DInstancePlayer
|
||||
*/
|
||||
public List<DInstancePlayer> getDInstancePlayers() {
|
||||
List<DInstancePlayer> dInstancePlayers = new ArrayList<>();
|
||||
for (DGlobalPlayer player : dGlobalPlayers) {
|
||||
if (player instanceof DInstancePlayer) {
|
||||
dInstancePlayers.add((DInstancePlayer) player);
|
||||
}
|
||||
}
|
||||
return dInstancePlayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dGlobalPlayers that are an instance of DGamePlayer
|
||||
*/
|
||||
public List<DGamePlayer> getDGamePlayers() {
|
||||
List<DGamePlayer> dPlayers = new ArrayList<>();
|
||||
for (DGlobalPlayer player : dGlobalPlayers) {
|
||||
if (player instanceof DGamePlayer) {
|
||||
dPlayers.add((DGamePlayer) player);
|
||||
}
|
||||
}
|
||||
return dPlayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dGlobalPlayers that are an instance of DEditPlayer
|
||||
*/
|
||||
public List<DEditPlayer> getDEditPlayers() {
|
||||
List<DEditPlayer> dEditPlayers = new ArrayList<>();
|
||||
for (DGlobalPlayer player : dGlobalPlayers) {
|
||||
if (player instanceof DEditPlayer) {
|
||||
dEditPlayers.add((DEditPlayer) player);
|
||||
}
|
||||
}
|
||||
return dEditPlayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player an instance of DGlobalPlayer to add
|
||||
*/
|
||||
public void addPlayer(DGlobalPlayer player) {
|
||||
removePlayer(player);
|
||||
dGlobalPlayers.add(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player an instance of DGlobalPlayer to remove
|
||||
*/
|
||||
public void removePlayer(DGlobalPlayer player) {
|
||||
for (DGlobalPlayer dGlobalPlayer : dGlobalPlayers) {
|
||||
if (dGlobalPlayer.getPlayer().equals(player.getPlayer())) {
|
||||
dGlobalPlayers.remove(dGlobalPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all players
|
||||
*/
|
||||
public void loadAll() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
new DGlobalPlayer(plugin, player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
dPlayer.setPlayer(player);
|
||||
dPlayer.setOfflineTime(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -21,14 +21,22 @@ import de.erethon.caliburn.item.ExItem;
|
|||
import de.erethon.caliburn.item.VanillaItem;
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Game;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRule;
|
||||
import de.erethon.dungeonsxl.api.player.EditPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.GamePlayer;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.InstancePlayer;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerCache;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.api.world.EditWorld;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.config.MainConfig;
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import de.erethon.dungeonsxl.mob.DMob;
|
||||
import de.erethon.dungeonsxl.dungeon.DGame;
|
||||
import de.erethon.dungeonsxl.util.ParsingUtil;
|
||||
import de.erethon.dungeonsxl.world.DEditWorld;
|
||||
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||
import de.erethon.dungeonsxl.world.DWorldCache;
|
||||
import de.erethon.dungeonsxl.world.block.LockedDoor;
|
||||
import java.util.ArrayList;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -65,22 +73,20 @@ public class DPlayerListener implements Listener {
|
|||
|
||||
private DungeonsXL plugin;
|
||||
private MainConfig config;
|
||||
private DWorldCache worlds;
|
||||
private DPlayerCache dPlayers;
|
||||
private PlayerCache dPlayers;
|
||||
|
||||
public static final String ALL = "@all ";
|
||||
|
||||
public DPlayerListener(DungeonsXL plugin) {
|
||||
this.plugin = plugin;
|
||||
config = plugin.getMainConfig();
|
||||
worlds = plugin.getDWorldCache();
|
||||
dPlayers = plugin.getDPlayerCache();
|
||||
dPlayers = plugin.getPlayerCache();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
World world = event.getEntity().getWorld();
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(world);
|
||||
GameWorld gameWorld = plugin.getGameWorld(world);
|
||||
|
||||
if (gameWorld == null) {
|
||||
return;
|
||||
|
@ -96,7 +102,7 @@ public class DPlayerListener implements Listener {
|
|||
}
|
||||
|
||||
boolean dead = ((LivingEntity) event.getEntity()).getHealth() - event.getFinalDamage() <= 0;
|
||||
if (dead && DMob.getByEntity(event.getEntity()) != null) {
|
||||
if (dead && plugin.getDungeonMob((LivingEntity) event.getEntity()) != null) {
|
||||
String killer = null;
|
||||
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
|
@ -113,14 +119,14 @@ public class DPlayerListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
gameWorld.getGame().addKill(killer);
|
||||
((DGame) gameWorld.getGame()).addKill(killer);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
World world = event.getEntity().getWorld();
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(world);
|
||||
GameWorld gameWorld = plugin.getGameWorld(world);
|
||||
|
||||
if (gameWorld == null) {
|
||||
return;
|
||||
|
@ -136,8 +142,8 @@ public class DPlayerListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
boolean pvp = game.getRules().isPlayerVersusPlayer();
|
||||
boolean friendlyFire = game.getRules().isFriendlyFire();
|
||||
boolean pvp = game.getRules().getState(GameRule.PLAYER_VERSUS_PLAYER);
|
||||
boolean friendlyFire = game.getRules().getState(GameRule.FRIENDLY_FIRE);
|
||||
|
||||
Entity attackerEntity = event.getDamager();
|
||||
Entity attackedEntity = event.getEntity();
|
||||
|
@ -149,8 +155,8 @@ public class DPlayerListener implements Listener {
|
|||
Player attackerPlayer = null;
|
||||
Player attackedPlayer = null;
|
||||
|
||||
DGroup attackerDGroup = null;
|
||||
DGroup attackedDGroup = null;
|
||||
PlayerGroup attackerGroup = null;
|
||||
PlayerGroup attackedGroup = null;
|
||||
|
||||
if (!(attackerEntity instanceof LivingEntity) || !(attackedEntity instanceof LivingEntity)) {
|
||||
return;
|
||||
|
@ -163,16 +169,16 @@ public class DPlayerListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
attackerDGroup = DGroup.getByPlayer(attackerPlayer);
|
||||
attackedDGroup = DGroup.getByPlayer(attackedPlayer);
|
||||
attackerGroup = plugin.getPlayerGroup(attackerPlayer);
|
||||
attackedGroup = plugin.getPlayerGroup(attackedPlayer);
|
||||
|
||||
if (!pvp) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (attackerDGroup != null && attackedDGroup != null) {
|
||||
if (!friendlyFire && attackerDGroup.equals(attackedDGroup)) {
|
||||
if (attackerGroup != null && attackedGroup != null) {
|
||||
if (!friendlyFire && attackerGroup.equals(attackedGroup)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
@ -181,9 +187,9 @@ public class DPlayerListener implements Listener {
|
|||
|
||||
// Check Dogs
|
||||
if (attackerEntity instanceof Player || attackedEntity instanceof Player) {
|
||||
for (DGamePlayer dPlayer : DGamePlayer.getByWorld(gameWorld.getWorld())) {
|
||||
if (dPlayer.getWolf() != null) {
|
||||
if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) {
|
||||
for (GamePlayer player : dPlayers.getAllGamePlayersIf(p -> p.getGameWorld() == gameWorld)) {
|
||||
if (player.getWolf() != null) {
|
||||
if (attackerEntity == player.getWolf() || attackedEntity == player.getWolf()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
@ -191,7 +197,7 @@ public class DPlayerListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
for (DGamePlayer dPlayer : DGamePlayer.getByWorld(gameWorld.getWorld())) {
|
||||
for (GamePlayer dPlayer : dPlayers.getAllGamePlayersIf(p -> p.getGameWorld() == gameWorld)) {
|
||||
if (dPlayer.getWolf() != null) {
|
||||
if (attackerEntity instanceof Player || attackedEntity instanceof Player) {
|
||||
if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) {
|
||||
|
@ -210,8 +216,7 @@ public class DPlayerListener implements Listener {
|
|||
// Players don't need to eat in lobbies
|
||||
@EventHandler
|
||||
public void onFoodLevelChange(FoodLevelChangeEvent event) {
|
||||
World world = event.getEntity().getWorld();
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(world);
|
||||
GameWorld gameWorld = plugin.getGameWorld(event.getEntity().getWorld());
|
||||
if (gameWorld != null) {
|
||||
if (!gameWorld.isPlaying()) {
|
||||
event.setCancelled(true);
|
||||
|
@ -225,7 +230,7 @@ public class DPlayerListener implements Listener {
|
|||
if (isCitizensNPC(player)) {
|
||||
return;
|
||||
}
|
||||
DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
|
||||
GlobalPlayer dPlayer = dPlayers.get(player);
|
||||
if (dPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -239,8 +244,8 @@ public class DPlayerListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
if (dGroup == null) {
|
||||
PlayerGroup group = plugin.getPlayerGroup(player);
|
||||
if (group == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -249,7 +254,7 @@ public class DPlayerListener implements Listener {
|
|||
if (game) {
|
||||
((DInstancePlayer) dPlayer).chat(event.getMessage().substring(ALL.length()));
|
||||
} else {
|
||||
dGroup.sendMessage(ParsingUtil.replaceChatPlaceholders(config.getChatFormatGroup(), dPlayer) + event.getMessage());
|
||||
group.sendMessage(ParsingUtil.replaceChatPlaceholders(config.getChatFormatGroup(), dPlayer) + event.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,16 +269,14 @@ public class DPlayerListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!(dPlayers.getByPlayer(player) instanceof DInstancePlayer)) {
|
||||
if (!(dPlayers.get(player) instanceof DInstancePlayer)) {
|
||||
return;
|
||||
}
|
||||
DInstancePlayer dPlayer = (DInstancePlayer) dPlayers.getByPlayer(player);
|
||||
InstancePlayer dPlayer = dPlayers.getInstancePlayer(player);
|
||||
|
||||
String command = event.getMessage().toLowerCase();
|
||||
ArrayList<String> commandWhitelist = new ArrayList<>();
|
||||
|
||||
Game game = Game.getByWorld(dPlayer.getWorld());
|
||||
|
||||
if (dPlayer instanceof DEditPlayer) {
|
||||
if (DPermission.hasPermission(player, DPermission.CMD_EDIT)) {
|
||||
return;
|
||||
|
@ -282,10 +285,8 @@ public class DPlayerListener implements Listener {
|
|||
commandWhitelist.addAll(config.getEditCommandWhitelist());
|
||||
}
|
||||
|
||||
} else if (game != null) {
|
||||
if (game.getRules() != null) {
|
||||
commandWhitelist.addAll(game.getRules().getGameCommandWhitelist());
|
||||
}
|
||||
} else {
|
||||
commandWhitelist.addAll(dPlayer.getGroup().getDungeon().getRules().getState(GameRule.GAME_COMMAND_WHITELIST));
|
||||
}
|
||||
|
||||
commandWhitelist.add("dungeonsxl");
|
||||
|
@ -311,7 +312,7 @@ public class DPlayerListener implements Listener {
|
|||
if (isCitizensNPC(player)) {
|
||||
return;
|
||||
}
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
DGamePlayer dPlayer = (DGamePlayer) dPlayers.getGamePlayer(player);
|
||||
if (dPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -325,12 +326,12 @@ public class DPlayerListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
|
||||
GlobalPlayer dPlayer = dPlayers.get(player);
|
||||
if (dPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (dPlayer instanceof DEditPlayer && !config.getDropItems() && !DPermission.hasPermission(player, DPermission.INSECURE)) {
|
||||
if (dPlayer instanceof EditPlayer && !config.getDropItems() && !DPermission.hasPermission(player, DPermission.INSECURE)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
@ -340,7 +341,7 @@ public class DPlayerListener implements Listener {
|
|||
|
||||
DGamePlayer gamePlayer = (DGamePlayer) dPlayer;
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
DGroup dGroup = gamePlayer.getGroup();
|
||||
if (dGroup == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -355,9 +356,7 @@ public class DPlayerListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
Game game = Game.getByWorld(gamePlayer.getWorld());
|
||||
|
||||
for (ExItem item : game.getRules().getSecureObjects()) {
|
||||
for (ExItem item : dGroup.getDungeon().getRules().getState(GameRule.SECURE_OBJECTS)) {
|
||||
if (event.getItemDrop().getItemStack().isSimilar(item.toItemStack())) {
|
||||
event.setCancelled(true);
|
||||
MessageUtil.sendMessage(player, DMessage.ERROR_DROP.getMessage());
|
||||
|
@ -369,7 +368,7 @@ public class DPlayerListener implements Listener {
|
|||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (dPlayers.checkPlayer(player)) {
|
||||
if (plugin.checkPlayer(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -379,7 +378,7 @@ public class DPlayerListener implements Listener {
|
|||
}
|
||||
|
||||
if (!dPlayer.getData().hasFinishedTutorial() && config.isTutorialActivated()) {
|
||||
if (worlds.getInstances().size() < config.getMaxInstances()) {
|
||||
if (plugin.getInstanceCache().size() < config.getMaxInstances()) {
|
||||
dPlayer.startTutorial();
|
||||
} else {
|
||||
event.getPlayer().kickPlayer(DMessage.ERROR_TOO_MANY_TUTORIALS.getMessage());
|
||||
|
@ -393,14 +392,14 @@ public class DPlayerListener implements Listener {
|
|||
if (isCitizensNPC(player)) {
|
||||
return;
|
||||
}
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(player.getWorld());
|
||||
DGamePlayer gamePlayer = DGamePlayer.getByPlayer(player);
|
||||
DGameWorld gameWorld = (DGameWorld) plugin.getGameWorld(player.getWorld());
|
||||
DGamePlayer gamePlayer = (DGamePlayer) dPlayers.getGamePlayer(player);
|
||||
if (gameWorld != null && gamePlayer != null) {
|
||||
if (gamePlayer.getDGroupTag() != null) {
|
||||
gamePlayer.getDGroupTag().update();
|
||||
}
|
||||
if (gamePlayer.isStealing()) {
|
||||
DGroup group = gamePlayer.getDGroup();
|
||||
if (gamePlayer.isStealingFlag()) {
|
||||
DGroup group = gamePlayer.getGroup();
|
||||
Location startLocation = gameWorld.getStartLocation(group);
|
||||
|
||||
if (startLocation.distance(player.getLocation()) < 3) {
|
||||
|
@ -413,34 +412,34 @@ public class DPlayerListener implements Listener {
|
|||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
Game game = Game.getByWorld(player.getWorld());
|
||||
GlobalPlayer dPlayer = dPlayers.get(player);
|
||||
PlayerGroup dGroup = dPlayer.getGroup();
|
||||
Dungeon dungeon = dGroup.getDungeon();
|
||||
|
||||
if (!(dPlayer instanceof DInstancePlayer)) {
|
||||
if (!(dPlayer instanceof InstancePlayer)) {
|
||||
if (dGroup != null) {
|
||||
dGroup.removePlayer(player);
|
||||
}
|
||||
|
||||
} else if (game != null) {
|
||||
int timeUntilKickOfflinePlayer = game.getRules().getTimeUntilKickOfflinePlayer();
|
||||
} else if (dPlayer instanceof GamePlayer) {
|
||||
int timeUntilKickOfflinePlayer = dungeon.getRules().getState(GameRule.TIME_UNTIL_KICK_OFFLINE_PLAYER);
|
||||
|
||||
if (timeUntilKickOfflinePlayer == 0) {
|
||||
((DGamePlayer) dPlayer).leave();
|
||||
((InstancePlayer) dPlayer).leave();
|
||||
|
||||
} else if (timeUntilKickOfflinePlayer > 0) {
|
||||
dGroup.sendMessage(DMessage.PLAYER_OFFLINE.getMessage(dPlayer.getName(), String.valueOf(timeUntilKickOfflinePlayer)), player);
|
||||
((DGamePlayer) dPlayer).setOfflineTime(System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000);
|
||||
((GamePlayer) dPlayer).setOfflineTimeMillis(System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000);
|
||||
|
||||
} else {
|
||||
dGroup.sendMessage(DMessage.PLAYER_OFFLINE_NEVER.getMessage(dPlayer.getName()), player);
|
||||
}
|
||||
|
||||
} else if (dPlayer instanceof DEditPlayer) {
|
||||
((DEditPlayer) dPlayer).leave();
|
||||
} else if (dPlayer instanceof InstancePlayer) {
|
||||
((InstancePlayer) dPlayer).leave();
|
||||
}
|
||||
|
||||
dPlayers.removePlayer(dPlayer);
|
||||
dPlayers.remove(dPlayer);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -450,13 +449,13 @@ public class DPlayerListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
DGlobalPlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
GlobalPlayer dPlayer = dPlayers.get(player);
|
||||
if (dPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (dPlayer instanceof DEditPlayer) {
|
||||
DEditWorld editWorld = DEditWorld.getByWorld(((DEditPlayer) dPlayer).getWorld());
|
||||
if (dPlayer instanceof EditPlayer) {
|
||||
EditWorld editWorld = ((EditPlayer) dPlayer).getEditWorld();
|
||||
if (editWorld == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -468,21 +467,20 @@ public class DPlayerListener implements Listener {
|
|||
event.setRespawnLocation(editWorld.getLobbyLocation());
|
||||
}
|
||||
|
||||
} else if (dPlayer instanceof DGamePlayer) {
|
||||
DGamePlayer gamePlayer = (DGamePlayer) dPlayer;
|
||||
|
||||
DGameWorld gameWorld = DGameWorld.getByWorld(gamePlayer.getWorld());
|
||||
} else if (dPlayer instanceof GamePlayer) {
|
||||
GamePlayer gamePlayer = (GamePlayer) dPlayer;
|
||||
|
||||
GameWorld gameWorld = gamePlayer.getGameWorld();
|
||||
if (gameWorld == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer());
|
||||
PlayerGroup group = dPlayer.getGroup();
|
||||
|
||||
Location respawn = gamePlayer.getCheckpoint();
|
||||
Location respawn = gamePlayer.getLastCheckpoint();
|
||||
|
||||
if (respawn == null) {
|
||||
respawn = dGroup.getGameWorld().getStartLocation(dGroup);
|
||||
respawn = group.getGameWorld().getStartLocation(group);
|
||||
}
|
||||
|
||||
// Because some plugins set another respawn point, DXL teleports a few ticks later.
|
||||
|
@ -501,7 +499,7 @@ public class DPlayerListener implements Listener {
|
|||
if (isCitizensNPC(player)) {
|
||||
return;
|
||||
}
|
||||
DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
|
||||
GlobalPlayer dPlayer = dPlayers.get(player);
|
||||
|
||||
World toWorld = event.getTo().getWorld();
|
||||
|
||||
|
@ -509,7 +507,7 @@ public class DPlayerListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
if (worlds.getInstanceByWorld(toWorld) != null) {
|
||||
if (plugin.getInstanceWorld(toWorld) != null) {
|
||||
dPlayer.sendMessage(DMessage.ERROR_JOIN_GROUP.getMessage());
|
||||
dPlayer.sendMessage(ChatColor.GOLD + DMessage.CMD_ENTER_HELP.getMessage());
|
||||
event.setCancelled(true);
|
||||
|
@ -528,10 +526,10 @@ public class DPlayerListener implements Listener {
|
|||
return;
|
||||
}
|
||||
Block clickedBlock = event.getClickedBlock();
|
||||
DGameWorld dGameWorld = DGameWorld.getByWorld(player.getWorld());
|
||||
DGameWorld gameWorld = (DGameWorld) plugin.getGameWorld(player.getWorld());
|
||||
if (clickedBlock != null) {
|
||||
// Block Enderchests
|
||||
if (dGameWorld != null || DEditWorld.getByWorld(player.getWorld()) != null) {
|
||||
if (gameWorld != null || plugin.getEditWorld(player.getWorld()) != null) {
|
||||
if (event.getAction() != Action.LEFT_CLICK_BLOCK) {
|
||||
if (VanillaItem.ENDER_CHEST.is(clickedBlock)) {
|
||||
if (!DPermission.hasPermission(player, DPermission.BYPASS) && !DPermission.hasPermission(player, DPermission.ENDER_CHEST)) {
|
||||
|
@ -549,7 +547,7 @@ public class DPlayerListener implements Listener {
|
|||
}
|
||||
|
||||
// Block Dispensers
|
||||
if (dGameWorld != null) {
|
||||
if (gameWorld != null) {
|
||||
if (event.getAction() != Action.LEFT_CLICK_BLOCK) {
|
||||
if (VanillaItem.DISPENSER.is(clickedBlock)) {
|
||||
if (!DPermission.hasPermission(player, DPermission.BYPASS) && !DPermission.hasPermission(player, DPermission.DISPENSER)) {
|
||||
|
@ -559,7 +557,7 @@ public class DPlayerListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
for (LockedDoor door : dGameWorld.getLockedDoors()) {
|
||||
for (LockedDoor door : gameWorld.getLockedDoors()) {
|
||||
if (clickedBlock.equals(door.getBlock()) || clickedBlock.equals(door.getAttachedBlock())) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
@ -573,12 +571,12 @@ public class DPlayerListener implements Listener {
|
|||
ItemStack item = event.getItem();
|
||||
|
||||
// Copy/Paste a Sign and Block-info
|
||||
if (DEditWorld.getByWorld(player.getWorld()) != null) {
|
||||
if (plugin.getEditWorld(player.getWorld()) != null) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
if (VanillaItem.STICK.is(item)) {
|
||||
DEditPlayer dPlayer = DEditPlayer.getByPlayer(player);
|
||||
if (dPlayer != null) {
|
||||
dPlayer.poke(clickedBlock);
|
||||
DEditPlayer editPlayer = (DEditPlayer) dPlayers.getEditPlayer(player);
|
||||
if (editPlayer != null) {
|
||||
editPlayer.poke(clickedBlock);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
package de.erethon.dungeonsxl.player;
|
||||
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.InstancePlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
@ -35,12 +37,12 @@ public class SecureModeTask extends BukkitRunnable {
|
|||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
DGlobalPlayer dGlobalPlayer = plugin.getDPlayerCache().getByPlayer(player);
|
||||
if (dGlobalPlayer == null) {
|
||||
dGlobalPlayer = new DGlobalPlayer(plugin, player);
|
||||
GlobalPlayer globalPlayer = plugin.getPlayerCache().get(player);
|
||||
if (globalPlayer == null) {
|
||||
globalPlayer = new DGlobalPlayer(plugin, player);
|
||||
}
|
||||
|
||||
if (!(dGlobalPlayer instanceof DInstancePlayer)) {
|
||||
if (!(globalPlayer instanceof InstancePlayer)) {
|
||||
if (player.getWorld().getName().startsWith("DXL_Game_") | player.getWorld().getName().startsWith("DXL_Edit_") && !DPermission.hasPermission(player, DPermission.INSECURE)) {
|
||||
player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation());
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
package de.erethon.dungeonsxl.player;
|
||||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.event.dplayer.DPlayerKickEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -29,12 +31,15 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||
*/
|
||||
public class TimeIsRunningTask extends BukkitRunnable {
|
||||
|
||||
private DGroup dGroup;
|
||||
private DungeonsXL plugin;
|
||||
|
||||
private PlayerGroup group;
|
||||
private int time;
|
||||
private int timeLeft;
|
||||
|
||||
public TimeIsRunningTask(DGroup dGroup, int time) {
|
||||
this.dGroup = dGroup;
|
||||
public TimeIsRunningTask(DungeonsXL plugin, PlayerGroup group, int time) {
|
||||
this.plugin = plugin;
|
||||
this.group = group;
|
||||
this.time = time;
|
||||
this.timeLeft = time;
|
||||
}
|
||||
|
@ -52,10 +57,10 @@ public class TimeIsRunningTask extends BukkitRunnable {
|
|||
color = ChatColor.DARK_RED.toString();
|
||||
|
||||
} finally {
|
||||
for (Player player : dGroup.getPlayers().getOnlinePlayers()) {
|
||||
for (Player player : group.getMembers().getOnlinePlayers()) {
|
||||
MessageUtil.sendActionBarMessage(player, DMessage.PLAYER_TIME_LEFT.getMessage(color, String.valueOf(timeLeft)));
|
||||
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
DGamePlayer dPlayer = (DGamePlayer) plugin.getPlayerCache().getGamePlayer(player);
|
||||
if (timeLeft > 0) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -18,9 +18,11 @@ package de.erethon.dungeonsxl.requirement;
|
|||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.Requirement;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Game;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRule;
|
||||
import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.game.Game;
|
||||
import de.erethon.dungeonsxl.game.GameRuleProvider;
|
||||
import de.erethon.dungeonsxl.player.DGamePlayer;
|
||||
import de.erethon.dungeonsxl.player.DPlayerData;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
@ -29,15 +31,15 @@ import org.bukkit.entity.Player;
|
|||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class FeeLevelRequirement extends Requirement {
|
||||
public class FeeLevelRequirement implements Requirement {
|
||||
|
||||
private RequirementType type = RequirementTypeDefault.FEE_LEVEL;
|
||||
private DungeonsXL plugin;
|
||||
|
||||
private int fee;
|
||||
private Boolean keepInventory;
|
||||
|
||||
public FeeLevelRequirement(DungeonsXL plugin) {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
|
@ -55,11 +57,6 @@ public class FeeLevelRequirement extends Requirement {
|
|||
this.fee = fee;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequirementType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
@Override
|
||||
public void setup(ConfigurationSection config) {
|
||||
|
@ -72,7 +69,7 @@ public class FeeLevelRequirement extends Requirement {
|
|||
return player.getLevel() >= fee;
|
||||
}
|
||||
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
DGamePlayer dPlayer = (DGamePlayer) plugin.getPlayerCache().getGamePlayer(player);
|
||||
return dPlayer != null ? dPlayer.getData().getOldLevel() >= fee : true;
|
||||
}
|
||||
|
||||
|
@ -82,7 +79,7 @@ public class FeeLevelRequirement extends Requirement {
|
|||
player.setLevel(player.getLevel() - fee);
|
||||
|
||||
} else {
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
DGamePlayer dPlayer = (DGamePlayer) plugin.getPlayerCache().getGamePlayer(player);
|
||||
if (dPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -98,17 +95,17 @@ public class FeeLevelRequirement extends Requirement {
|
|||
return keepInventory;
|
||||
}
|
||||
|
||||
Game game = Game.getByPlayer(player);
|
||||
GameRuleProvider rules = null;
|
||||
Game game = plugin.getGame(player);
|
||||
GameRuleContainer rules = null;
|
||||
if (game != null) {
|
||||
rules = game.getRules();
|
||||
}
|
||||
if (rules != null) {
|
||||
keepInventory = rules.getKeepInventoryOnEnter();
|
||||
keepInventory = rules.getState(GameRule.KEEP_INVENTORY_ON_ENTER);
|
||||
return keepInventory;
|
||||
}
|
||||
|
||||
keepInventory = GameRuleProvider.DEFAULT_VALUES.getKeepInventoryOnEnter();
|
||||
keepInventory = GameRuleContainer.DEFAULT_VALUES.getState(GameRule.KEEP_INVENTORY_ON_ENTER);
|
||||
return keepInventory;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.requirement;
|
|||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.Requirement;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
@ -26,16 +27,13 @@ import org.bukkit.entity.Player;
|
|||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class FeeMoneyRequirement extends Requirement {
|
||||
public class FeeMoneyRequirement implements Requirement {
|
||||
|
||||
private Economy econ;
|
||||
|
||||
private RequirementType type = RequirementTypeDefault.FEE_MONEY;
|
||||
|
||||
private double fee;
|
||||
|
||||
public FeeMoneyRequirement(DungeonsXL plugin) {
|
||||
super(plugin);
|
||||
econ = plugin.getEconomyProvider();
|
||||
}
|
||||
|
||||
|
@ -54,11 +52,6 @@ public class FeeMoneyRequirement extends Requirement {
|
|||
this.fee = fee;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequirementType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
@Override
|
||||
public void setup(ConfigurationSection config) {
|
||||
|
|
|
@ -18,7 +18,7 @@ package de.erethon.dungeonsxl.requirement;
|
|||
|
||||
import de.erethon.caliburn.CaliburnAPI;
|
||||
import de.erethon.caliburn.item.ExItem;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.Requirement;
|
||||
import java.util.List;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -27,17 +27,14 @@ import org.bukkit.inventory.ItemStack;
|
|||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class ForbiddenItemsRequirement extends Requirement {
|
||||
public class ForbiddenItemsRequirement implements Requirement {
|
||||
|
||||
private CaliburnAPI caliburn;
|
||||
|
||||
private RequirementType type = RequirementTypeDefault.FORBIDDEN_ITEMS;
|
||||
|
||||
private List<ExItem> forbiddenItems;
|
||||
|
||||
public ForbiddenItemsRequirement(DungeonsXL plugin) {
|
||||
super(plugin);
|
||||
caliburn = plugin.getCaliburn();
|
||||
public ForbiddenItemsRequirement(CaliburnAPI caliburn) {
|
||||
this.caliburn = caliburn;
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
|
@ -48,11 +45,6 @@ public class ForbiddenItemsRequirement extends Requirement {
|
|||
return forbiddenItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequirementType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
@Override
|
||||
public void setup(ConfigurationSection config) {
|
||||
|
|
|
@ -17,22 +17,23 @@
|
|||
package de.erethon.dungeonsxl.requirement;
|
||||
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.api.Requirement;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class GroupSizeRequirement extends Requirement {
|
||||
public class GroupSizeRequirement implements Requirement {
|
||||
|
||||
private RequirementType type = RequirementTypeDefault.GROUP_SIZE;
|
||||
private DungeonsXL plugin;
|
||||
|
||||
private int minimum;
|
||||
private int maximum;
|
||||
|
||||
public GroupSizeRequirement(DungeonsXL plugin) {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,11 +64,6 @@ public class GroupSizeRequirement extends Requirement {
|
|||
this.maximum = maximum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequirementType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
@Override
|
||||
public void setup(ConfigurationSection config) {
|
||||
|
@ -77,8 +73,8 @@ public class GroupSizeRequirement extends Requirement {
|
|||
|
||||
@Override
|
||||
public boolean check(Player player) {
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
int size = dGroup.getPlayers().size();
|
||||
PlayerGroup group = plugin.getPlayerGroup(player);
|
||||
int size = group.getMembers().size();
|
||||
return size >= minimum && size <= maximum;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ package de.erethon.dungeonsxl.requirement;
|
|||
|
||||
import de.erethon.caliburn.CaliburnAPI;
|
||||
import de.erethon.caliburn.item.ExItem;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.Requirement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
@ -28,17 +28,14 @@ import org.bukkit.inventory.ItemStack;
|
|||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class KeyItemsRequirement extends Requirement {
|
||||
public class KeyItemsRequirement implements Requirement {
|
||||
|
||||
private CaliburnAPI caliburn;
|
||||
|
||||
private RequirementType type = RequirementTypeDefault.KEY_ITEMS;
|
||||
|
||||
private List<ExItem> keyItems;
|
||||
|
||||
public KeyItemsRequirement(DungeonsXL plugin) {
|
||||
super(plugin);
|
||||
caliburn = plugin.getCaliburn();
|
||||
public KeyItemsRequirement(CaliburnAPI caliburn) {
|
||||
this.caliburn = caliburn;
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
|
@ -49,11 +46,6 @@ public class KeyItemsRequirement extends Requirement {
|
|||
return keyItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequirementType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
@Override
|
||||
public void setup(ConfigurationSection config) {
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package de.erethon.dungeonsxl.requirement;
|
||||
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.Requirement;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -26,16 +26,10 @@ import org.bukkit.entity.Player;
|
|||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class PermissionRequirement extends Requirement {
|
||||
|
||||
private RequirementType type = RequirementTypeDefault.PERMISSION;
|
||||
public class PermissionRequirement implements Requirement {
|
||||
|
||||
private List<String> permissions = new ArrayList<>();
|
||||
|
||||
public PermissionRequirement(DungeonsXL plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
/**
|
||||
* @return the permission the player must have to play the dungeon
|
||||
|
@ -51,11 +45,6 @@ public class PermissionRequirement extends Requirement {
|
|||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequirementType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
@Override
|
||||
public void setup(ConfigurationSection config) {
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.requirement;
|
||||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.event.requirement.RequirementRegistrationEvent;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Extend this to create a custom Requirement.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public abstract class Requirement {
|
||||
|
||||
protected DungeonsXL plugin;
|
||||
|
||||
protected Requirement(DungeonsXL plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public static Requirement create(DungeonsXL plugin, RequirementType type) {
|
||||
Requirement requirement = null;
|
||||
|
||||
try {
|
||||
Constructor<? extends Requirement> constructor = type.getHandler().getConstructor(DungeonsXL.class);
|
||||
requirement = constructor.newInstance(plugin);
|
||||
|
||||
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) {
|
||||
MessageUtil.log("An error occurred while accessing the handler class of the requirement " + type.getIdentifier() + ": " + exception.getClass().getSimpleName());
|
||||
if (!(type instanceof RequirementTypeDefault)) {
|
||||
MessageUtil.log("Please note that this requirement is an unsupported feature added by an addon!");
|
||||
}
|
||||
}
|
||||
|
||||
RequirementRegistrationEvent event = new RequirementRegistrationEvent(requirement);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return requirement;
|
||||
}
|
||||
|
||||
/* Abstracts */
|
||||
public abstract void setup(ConfigurationSection config);
|
||||
|
||||
public abstract boolean check(Player player);
|
||||
|
||||
public abstract void demand(Player player);
|
||||
|
||||
public abstract RequirementType getType();
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "{type=" + getType() + "}";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2020 Frank Baumann
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.requirement;
|
||||
|
||||
/**
|
||||
* Implement this to create custom requirement types.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public interface RequirementType {
|
||||
|
||||
/**
|
||||
* @return the identifier
|
||||
*/
|
||||
String getIdentifier();
|
||||
|
||||
/**
|
||||
* @return the handler
|
||||
*/
|
||||
Class<? extends Requirement> getHandler();
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user