mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
Basic player API
This commit is contained in:
parent
72a941d386
commit
b11ff2d4a3
98
api/src/main/java/de/erethon/dungeonsxl/api/DungeonsAPI.java
Normal file
98
api/src/main/java/de/erethon/dungeonsxl/api/DungeonsAPI.java
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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.api;
|
||||
|
||||
import de.erethon.commons.misc.Registry;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerClass;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup;
|
||||
import de.erethon.dungeonsxl.api.sign.DungeonSignType;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public interface DungeonsAPI {
|
||||
|
||||
static final File PLUGIN_ROOT = new File("plugins/DungeonsXL");
|
||||
static final File BACKUPS = new File(PLUGIN_ROOT, "backups");
|
||||
static final File LANGUAGES = new File(PLUGIN_ROOT, "languages");
|
||||
static final File MAPS = new File(PLUGIN_ROOT, "maps");
|
||||
static final File PLAYERS = new File(PLUGIN_ROOT, "players");
|
||||
static final File SCRIPTS = new File(PLUGIN_ROOT, "scripts");
|
||||
static final File ANNOUNCERS = new File(SCRIPTS, "announcers");
|
||||
static final File CLASSES = new File(SCRIPTS, "classes");
|
||||
static final File DUNGEONS = new File(SCRIPTS, "dungeons");
|
||||
static final File SIGNS = new File(SCRIPTS, "signs");
|
||||
|
||||
/**
|
||||
* Returns a {@link Registry} of the loaded classes.
|
||||
*
|
||||
* @return a {@link Registry} of the loaded classes
|
||||
*/
|
||||
Registry<String, PlayerClass> getClassRegistry();
|
||||
|
||||
/* Object initialization */
|
||||
/**
|
||||
* Creates a new group.
|
||||
*
|
||||
* @param leader the leader
|
||||
* @return a new group
|
||||
*/
|
||||
PlayerGroup createGroup(Player leader);
|
||||
|
||||
/**
|
||||
* Creates a new group.
|
||||
*
|
||||
* @param leader the leader
|
||||
* @param color the color that represents the group and sets the name
|
||||
* @return a new group or null if values are invalid
|
||||
*/
|
||||
PlayerGroup createGroup(Player leader, PlayerGroup.Color color);
|
||||
|
||||
/**
|
||||
* Creates a new group.
|
||||
*
|
||||
* @param leader the leader
|
||||
* @param name the group's name - must be unique
|
||||
* @return a new group or null if values are invalid
|
||||
*/
|
||||
PlayerGroup createGroup(Player leader, String name);
|
||||
|
||||
/**
|
||||
* Creates a new group.
|
||||
*
|
||||
* @param leader the leader
|
||||
* @param dungeon the dungeon to play
|
||||
* @return a new group or null if values are invalid
|
||||
*/
|
||||
PlayerGroup createGroup(Player leader, Dungeon dungeon);
|
||||
|
||||
/**
|
||||
* Creates a new group.
|
||||
*
|
||||
* @param leader the leader
|
||||
* @param members the group members with or without the leader
|
||||
* @param name the name of the group
|
||||
* @param dungeon the dungeon to play
|
||||
* @return a new group or null if values are invalid
|
||||
*/
|
||||
PlayerGroup createGroup(Player leader, Collection<Player> members, String name, Dungeon dungeon);
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.api.player;
|
||||
|
||||
import de.erethon.dungeonsxl.api.world.EditWorld;
|
||||
|
||||
/**
|
||||
* Represents a player in an edit instance.
|
||||
* <p>
|
||||
* All players in an edit world have one wrapper object that is an instance of EditPlayer.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public interface EditPlayer extends InstancePlayer {
|
||||
|
||||
/**
|
||||
* Returns the {@link de.erethon.dungeonsxl.api.world.EditWorld} the player is editing.
|
||||
*
|
||||
* @return the {@link de.erethon.dungeonsxl.api.world.EditWorld} the player is editing
|
||||
*/
|
||||
EditWorld getEditWorld();
|
||||
|
||||
/**
|
||||
* Returns the lines of a sign the player has copied with a stick tool in an array with the length of four.
|
||||
*
|
||||
* @return the lines of a sign the player has copied with a stick tool in an array with the length of four
|
||||
*/
|
||||
String[] getCopiedLines();
|
||||
|
||||
/**
|
||||
* Sets the memorized sign lines.
|
||||
*
|
||||
* @param copiedLines the lines
|
||||
*/
|
||||
void setCopiedLines(String[] copiedLines);
|
||||
|
||||
/**
|
||||
* Makes the player leave the edit world without saving the progress.
|
||||
*/
|
||||
void escape();
|
||||
|
||||
}
|
@ -0,0 +1,210 @@
|
||||
/*
|
||||
* 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.api.player;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
* Represents a player in a game dungeon instance.
|
||||
* <p>
|
||||
* All players in a game world have one wrapper object that is an instance of GamePlayer.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public interface GamePlayer extends InstancePlayer {
|
||||
|
||||
/**
|
||||
* Returns if the player is ready to start the game.
|
||||
* <p>
|
||||
* This is usually achieved by triggering a ready sign.
|
||||
*
|
||||
* @return if the player is ready to start the game
|
||||
*/
|
||||
boolean isReady();
|
||||
|
||||
/**
|
||||
* Returns if the player finished the game.
|
||||
* <p>
|
||||
* This is usually achieved by triggering an end sign.
|
||||
* <p>
|
||||
* It is used for both the end of a whole dungeon and the end of a floor.
|
||||
*
|
||||
* @return if the player finished the game
|
||||
*/
|
||||
boolean isFinished();
|
||||
|
||||
/**
|
||||
* Sets if the player finished their game.
|
||||
*
|
||||
* @param finished if the player finished the game
|
||||
*/
|
||||
void setFinished(boolean finished);
|
||||
|
||||
/**
|
||||
* Returns the player's class or null if they have none.
|
||||
*
|
||||
* @return the player's class
|
||||
*/
|
||||
PlayerClass getPlayerClass();
|
||||
|
||||
/**
|
||||
* Sets and applies the given class.
|
||||
*
|
||||
* @param playerClass the class
|
||||
*/
|
||||
void setPlayerClass(PlayerClass playerClass);
|
||||
|
||||
/**
|
||||
* Returns the location of the last checkpoint the player reached.
|
||||
*
|
||||
* @return the location of the last checkpoint the player reached
|
||||
*/
|
||||
Location getLastCheckpoint();
|
||||
|
||||
/**
|
||||
* Sets the location of the last checkpoint the player reached.
|
||||
* <p>
|
||||
* This is where the player respawns if they die and have -1 or >0 {@link #getLives() lives} left.
|
||||
*
|
||||
* @param checkpoint the checkpoint location
|
||||
*/
|
||||
void setLastCheckpoint(Location checkpoint);
|
||||
|
||||
/**
|
||||
* Returns the saved time millis from when the player went offline.
|
||||
*
|
||||
* @return the saved time millis from when the player went offline
|
||||
*/
|
||||
long getOfflineTimeMillis();
|
||||
|
||||
/**
|
||||
* Sets the saved time millis from when the player went offline.
|
||||
*
|
||||
* @param time the time millis
|
||||
*/
|
||||
void setOfflineTimeMillis(long time);
|
||||
|
||||
/**
|
||||
* Returns the original amount of lives the player had in the current game or -1 if lives aren't used.
|
||||
*
|
||||
* @return the original amount of lives the player had in the current game or -1 if lives aren't used
|
||||
*/
|
||||
int getInitialLives();
|
||||
|
||||
/**
|
||||
* Sets the original amount of lives the player had in the current game; -1 means lives aren't used.
|
||||
*
|
||||
* @param lives the amount of lives
|
||||
*/
|
||||
void setInitialLives(int lives);
|
||||
|
||||
/**
|
||||
* Returns the lives the player has left or -1 if per player lives aren't used.
|
||||
*
|
||||
* @return the lives the player has left or -1 if per player lives aren't used
|
||||
*/
|
||||
int getLives();
|
||||
|
||||
/**
|
||||
* Sets the lives the player has left.
|
||||
* <p>
|
||||
* This is not to be used if the dungeon uses group lives.
|
||||
*
|
||||
* @param lives the lives
|
||||
*/
|
||||
void setLives(int lives);
|
||||
|
||||
/**
|
||||
* Returns if the player is stealing another group's flag.
|
||||
*
|
||||
* @return if the player is stealing another group's flag
|
||||
*/
|
||||
boolean isStealingFlag();
|
||||
|
||||
/**
|
||||
* Returns the group whose flag the player robbed; null if the player isn't stealing any.
|
||||
*
|
||||
* @return the group whose flag the player robbed; null if the player isn't stealing any
|
||||
*/
|
||||
PlayerGroup getRobbedGroup();
|
||||
|
||||
/**
|
||||
* Sets the player to be stealing the team flag of the given group.
|
||||
*
|
||||
* @param group the group
|
||||
*/
|
||||
void setRobbedGroup(PlayerGroup group);
|
||||
|
||||
/* Actions */
|
||||
/**
|
||||
* Scores a point.
|
||||
*/
|
||||
void captureFlag();
|
||||
|
||||
/**
|
||||
* Makes the player leave his group and dungeon.
|
||||
* <p>
|
||||
* This sends default messages to the player.
|
||||
*/
|
||||
@Override
|
||||
default void leave() {
|
||||
leave(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the player leave his group and dungeon.
|
||||
*
|
||||
* @param sendMessages if default messages shall be sent to the player
|
||||
*/
|
||||
void leave(boolean sendMessages);
|
||||
|
||||
/**
|
||||
* Treats the player as if they lost their last life and kicks them from the dungeon.
|
||||
*/
|
||||
void kill();
|
||||
|
||||
/**
|
||||
* Sets the player to be ready to start the dungeon game, like when a ready sign is triggered.
|
||||
* <p>
|
||||
* If all other players in the group are already {@link #isReady() ready}, the game is started.
|
||||
*
|
||||
* @return if the game has been started.
|
||||
*/
|
||||
boolean ready();
|
||||
|
||||
/**
|
||||
* Respawns the player. Also teleports DXL pets if there are any.
|
||||
*/
|
||||
void respawn();
|
||||
|
||||
/**
|
||||
* The player finishs the current game.
|
||||
* <p>
|
||||
* This sends default messages to the player.
|
||||
*/
|
||||
default void finish() {
|
||||
finish(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The player finishs the current game.
|
||||
*
|
||||
* @param sendMessages if default messages shall be sent to the player
|
||||
*/
|
||||
void finish(boolean sendMessages);
|
||||
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* 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.api.player;
|
||||
|
||||
import de.erethon.commons.chat.MessageUtil;
|
||||
import de.erethon.commons.player.PlayerWrapper;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Represents a player anywhere on the server.
|
||||
* <p>
|
||||
* All players on the server, including the ones in dungeons, have one wrapper object that is an instance of GlobalPlayer.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public interface GlobalPlayer extends PlayerWrapper {
|
||||
|
||||
/**
|
||||
* Returns the player's group.
|
||||
*
|
||||
* @return the player's group.
|
||||
*/
|
||||
PlayerGroup getGroup();
|
||||
|
||||
/**
|
||||
* Returns if the player uses the built-in group chat.
|
||||
*
|
||||
* @return if the player uses the built-in group chat
|
||||
*/
|
||||
boolean isInGroupChat();
|
||||
|
||||
/**
|
||||
* Sets if the player uses the built-in group chat.
|
||||
*
|
||||
* @param groupChat if the player shall use the built-in group chat
|
||||
*/
|
||||
void setInGroupChat(boolean groupChat);
|
||||
|
||||
/**
|
||||
* Returns if the player may read messages from the built-in group chat.
|
||||
*
|
||||
* @return if the player may read messages from the built-in group chat
|
||||
*/
|
||||
boolean isInChatSpyMode();
|
||||
|
||||
/**
|
||||
* Sets if the player may read messages from the built-in group chat.
|
||||
*
|
||||
* @param chatSpyMode if the player may read messages from the built-in group chat
|
||||
*/
|
||||
void setInChatSpyMode(boolean chatSpyMode);
|
||||
|
||||
/**
|
||||
* Checks if the player has the given permission.
|
||||
*
|
||||
* @param permission the permission
|
||||
* @return if the player has the given permission
|
||||
*/
|
||||
default boolean hasPermission(String permission) {
|
||||
return getPlayer().hasPermission(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reward items a player collected in a dungeon game.
|
||||
*
|
||||
* @return the reward items a player collected in a dungeon game
|
||||
*/
|
||||
public List<ItemStack> getRewardItems();
|
||||
|
||||
/**
|
||||
* Returns if the player has any reward items left.
|
||||
*
|
||||
* @return if the player has any reward items left
|
||||
*/
|
||||
public boolean hasRewardItemsLeft();
|
||||
|
||||
/**
|
||||
* Returns if the player is currently breaking a global protection (=using /dxl break).
|
||||
*
|
||||
* @return if the player is currently breaking a global protection (=using /dxl break)
|
||||
*/
|
||||
boolean isInBreakMode();
|
||||
|
||||
/**
|
||||
* Sets the player into or out of break mode; see {@link #isInBreakMode()}.
|
||||
*
|
||||
* @param breakMode if the player may break global protections
|
||||
*/
|
||||
void setInBreakMode(boolean breakMode);
|
||||
|
||||
/**
|
||||
* Sends a message to the player.
|
||||
*
|
||||
* @param message the message to send
|
||||
*/
|
||||
default void sendMessage(String message) {
|
||||
MessageUtil.sendMessage(getPlayer(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Respawns the player at his old position before he was in a dungeon.
|
||||
*
|
||||
* @param keepInventory if the saved status shall be reset
|
||||
*/
|
||||
void reset(boolean keepInventory);
|
||||
|
||||
/**
|
||||
* Respawns the player at his old position before he was in a dungeon.
|
||||
*
|
||||
* @param tpLoc the location where the player shall respawn
|
||||
* @param keepInventory if the saved status shall be reset
|
||||
*/
|
||||
void reset(Location tpLoc, boolean keepInventory);
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.api.player;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
/**
|
||||
* Represents a player in an instance.
|
||||
* <p>
|
||||
* All players in a world instantiated by DungeonsXL, have one wrapper object that is an instance of InstancePlayer.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public interface InstancePlayer extends GlobalPlayer {
|
||||
|
||||
/**
|
||||
* The world of the instance, where the player is supposed to be.
|
||||
*
|
||||
* @return the world of the instance
|
||||
*/
|
||||
World getWorld();
|
||||
|
||||
/**
|
||||
* Makes the player leave his group and dungeon.
|
||||
*/
|
||||
void leave();
|
||||
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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.api.player;
|
||||
|
||||
import de.erethon.caliburn.CaliburnAPI;
|
||||
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 PlayerClass {
|
||||
|
||||
private String name;
|
||||
|
||||
private List<ItemStack> items = new ArrayList<>();
|
||||
private boolean dog;
|
||||
|
||||
/**
|
||||
* Creates a PlayerClass from a class YAML file. The name is taken from the file name.
|
||||
*
|
||||
* @param caliburn the CaliburnAPI instance
|
||||
* @param file the class config file
|
||||
*/
|
||||
public PlayerClass(CaliburnAPI caliburn, File file) {
|
||||
this(caliburn, file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a PlayerClass from the given class config.
|
||||
*
|
||||
* @param caliburn the CaliburnAPI instance
|
||||
* @param name the class name
|
||||
* @param config the config
|
||||
*/
|
||||
public PlayerClass(CaliburnAPI caliburn, String name, FileConfiguration config) {
|
||||
this.name = name;
|
||||
|
||||
if (config.contains("items")) {
|
||||
items = caliburn.deserializeStackList(config, "items");
|
||||
}
|
||||
|
||||
if (config.contains("dog")) {
|
||||
dog = config.getBoolean("dog");
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerClass(String name, List<ItemStack> items, boolean dog) {
|
||||
this.items = items;
|
||||
this.name = name;
|
||||
this.dog = dog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the class.
|
||||
*
|
||||
* @return the name of the class
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of the items this class gives to a player.
|
||||
*
|
||||
* @return the list of the the items this class gives to a player
|
||||
*/
|
||||
public List<ItemStack> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given item to this class.
|
||||
*
|
||||
* @param itemStack the ItemStack to add
|
||||
*/
|
||||
public void addItem(ItemStack itemStack) {
|
||||
items.add(itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given item from this class.
|
||||
*
|
||||
* @param itemStack the ItemStack to remove
|
||||
*/
|
||||
public void removeItem(ItemStack itemStack) {
|
||||
items.remove(itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the class gives the player a dog.
|
||||
*
|
||||
* @return if the class has a dog
|
||||
* @deprecated More dynamic pet features might make this obsolete in the future.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean hasDog() {
|
||||
return dog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the class gives the player a dog.
|
||||
*
|
||||
* @param dog if the class shall give the player a dog
|
||||
* @deprecated More dynamic pet features might make this obsolete in the future.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setDog(boolean dog) {
|
||||
this.dog = dog;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,327 @@
|
||||
/*
|
||||
* 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.api.player;
|
||||
|
||||
import de.erethon.caliburn.item.ExItem;
|
||||
import de.erethon.caliburn.item.VanillaItem;
|
||||
import de.erethon.commons.compatibility.Version;
|
||||
import de.erethon.commons.player.PlayerCollection;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Represents a group of players provided by DungeonsXL.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public interface PlayerGroup {
|
||||
|
||||
/**
|
||||
* Links different color types together.
|
||||
*/
|
||||
public enum Color {
|
||||
|
||||
BLACK(ChatColor.BLACK, DyeColor.BLACK, VanillaItem.BLACK_WOOL),
|
||||
DARK_GRAY(ChatColor.DARK_GRAY, DyeColor.GRAY, VanillaItem.GRAY_WOOL),
|
||||
LIGHT_GRAY(ChatColor.GRAY, DyeColor.valueOf(Version.isAtLeast(Version.MC1_13) ? "LIGHT_GRAY" : "SILVER"), VanillaItem.LIGHT_GRAY_WOOL),
|
||||
WHITE(ChatColor.WHITE, DyeColor.WHITE, VanillaItem.WHITE_WOOL),
|
||||
DARK_GREEN(ChatColor.DARK_GREEN, DyeColor.GREEN, VanillaItem.GREEN_WOOL),
|
||||
LIGHT_GREEN(ChatColor.GREEN, DyeColor.LIME, VanillaItem.LIME_WOOL),
|
||||
CYAN(ChatColor.DARK_AQUA, DyeColor.CYAN, VanillaItem.CYAN_WOOL),
|
||||
DARK_BLUE(ChatColor.DARK_BLUE, DyeColor.BLUE, VanillaItem.BLUE_WOOL),
|
||||
LIGHT_BLUE(ChatColor.AQUA, DyeColor.LIGHT_BLUE, VanillaItem.LIGHT_BLUE_WOOL),
|
||||
PURPLE(ChatColor.DARK_PURPLE, DyeColor.PURPLE, VanillaItem.PURPLE_WOOL),
|
||||
MAGENTA(ChatColor.LIGHT_PURPLE, DyeColor.MAGENTA, VanillaItem.MAGENTA_WOOL),
|
||||
DARK_RED(ChatColor.DARK_RED, DyeColor.BROWN, VanillaItem.BROWN_WOOL),
|
||||
LIGHT_RED(ChatColor.RED, DyeColor.RED, VanillaItem.RED_WOOL),
|
||||
ORANGE(ChatColor.GOLD, DyeColor.ORANGE, VanillaItem.ORANGE_WOOL),
|
||||
YELLOW(ChatColor.YELLOW, DyeColor.YELLOW, VanillaItem.YELLOW_WOOL),
|
||||
PINK(ChatColor.BLUE, DyeColor.PINK, VanillaItem.PINK_WOOL);
|
||||
|
||||
private ChatColor chat;
|
||||
private DyeColor dye;
|
||||
private VanillaItem woolMaterial;
|
||||
|
||||
Color(ChatColor chat, DyeColor dye, VanillaItem woolMaterial) {
|
||||
this.chat = chat;
|
||||
this.dye = dye;
|
||||
this.woolMaterial = woolMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ChatColor.
|
||||
*
|
||||
* @return the ChatColor
|
||||
*/
|
||||
public ChatColor getChatColor() {
|
||||
return chat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the DyeColor.
|
||||
*
|
||||
* @return the DyeColor
|
||||
*/
|
||||
public DyeColor getDyeColor() {
|
||||
return dye;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the RGB value.
|
||||
*
|
||||
* @return the RGB value
|
||||
*/
|
||||
public int getRGBColor() {
|
||||
return dye.getColor().asRGB();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the wool material.
|
||||
*
|
||||
* @return the wool material
|
||||
*/
|
||||
public VanillaItem getWoolMaterial() {
|
||||
return woolMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the GroupColor matching the ChatColor or null if none exists.
|
||||
*
|
||||
* @param color the ChatColor to check
|
||||
* @return the GroupColor matching the ChatColor or null if none exists
|
||||
*/
|
||||
public static Color getByChatColor(ChatColor color) {
|
||||
for (Color groupColor : values()) {
|
||||
if (groupColor.chat == color) {
|
||||
return groupColor;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the GroupColor matching the DyeColor or null if none exists.
|
||||
*
|
||||
* @param color the DyeColor to check
|
||||
* @return the GroupColor matching the DyeColor or null if none exists.
|
||||
*/
|
||||
public static Color getByDyeColor(DyeColor color) {
|
||||
for (Color groupColor : values()) {
|
||||
if (groupColor.dye == color) {
|
||||
return groupColor;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the GroupColor matching the wool material or null if none exists.
|
||||
*
|
||||
* @param wool the wool material to check
|
||||
* @return the GroupColor matching the wool material or null if none exists
|
||||
*/
|
||||
public static Color getByWoolType(ExItem wool) {
|
||||
for (Color groupColor : values()) {
|
||||
if (groupColor.woolMaterial == wool) {
|
||||
return groupColor;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID.
|
||||
*
|
||||
* @return the ID
|
||||
*/
|
||||
int getId();
|
||||
|
||||
/**
|
||||
* Returns the formatted name.
|
||||
* <p>
|
||||
* This is the name used e.g. in messages.
|
||||
*
|
||||
* @return the formatted name
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Returns the raw, unformatted name.
|
||||
* <p>
|
||||
* This is the name used e.g. in command arguments.
|
||||
*
|
||||
* @return the raw, unformatted name
|
||||
*/
|
||||
String getRawName();
|
||||
|
||||
/**
|
||||
* Sets the name.
|
||||
*
|
||||
* @param name the name
|
||||
*/
|
||||
void setName(String name);
|
||||
|
||||
/**
|
||||
* Sets the name to a default value taken from the color.
|
||||
* <p>
|
||||
* In the default implementation, this is nameOfTheColor#{@link #getId()}
|
||||
*
|
||||
* @param color the color
|
||||
*/
|
||||
default void setName(Color color) {
|
||||
setName(color.toString() + "#" + getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* The player who has permission to manage the group.
|
||||
*
|
||||
* @return the player who has permission to manage the group
|
||||
*/
|
||||
Player getLeader();
|
||||
|
||||
/**
|
||||
* Sets the leader to another group member.
|
||||
*
|
||||
* @param player the new leader
|
||||
*/
|
||||
void setLeader(Player player);
|
||||
|
||||
/**
|
||||
* Returns a PlayerCollection of the group members
|
||||
*
|
||||
* @return a PlayerCollection of the group members
|
||||
*/
|
||||
PlayerCollection getMembers();
|
||||
|
||||
/**
|
||||
* Adds a player to the group.
|
||||
* <p>
|
||||
* The default implemenation calls {@link #addPlayer(Player, boolean)} with messages set to true.
|
||||
*
|
||||
* @param player the player to add
|
||||
*/
|
||||
default void addPlayer(Player player) {
|
||||
addPlayer(player, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a player to the group.
|
||||
*
|
||||
* @param player the player to add
|
||||
* @param message if messages shall be sent
|
||||
*/
|
||||
void addPlayer(Player player, boolean message);
|
||||
|
||||
/**
|
||||
* Removes a player from the group.
|
||||
* <p>
|
||||
* The default implemenation calls {@link #removePlayer(Player, boolean)} with messages set to true.
|
||||
*
|
||||
* @param player the player to add
|
||||
*/
|
||||
default void removePlayer(Player player) {
|
||||
addPlayer(player, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a player from the group.
|
||||
*
|
||||
* @param player the player to add
|
||||
* @param message if messages shall be sent
|
||||
*/
|
||||
void removePlayer(Player player, boolean message);
|
||||
|
||||
/**
|
||||
* Returns a PlayerCollection of the players who are invited to join the group but did not yet do so.
|
||||
*
|
||||
* @return a PlayerCollection of the players who are invited to join the group but did not yet do so
|
||||
*/
|
||||
PlayerCollection getInvitedPlayers();
|
||||
|
||||
/**
|
||||
* Invites a player to join the group.
|
||||
*
|
||||
* @param player the player to invite
|
||||
* @param message if messages shall be sent
|
||||
*/
|
||||
void addInvitedPlayer(Player player, boolean message);
|
||||
|
||||
/**
|
||||
* Removes an invitation priviously made for a player to join the group.
|
||||
*
|
||||
* @param player the player to uninvite
|
||||
* @param message if messages shall be sent
|
||||
*/
|
||||
void removeInvitedPlayer(Player player, boolean message);
|
||||
|
||||
/**
|
||||
* Removes all invitations for players who are not online.
|
||||
*/
|
||||
void clearOfflineInvitedPlayers();
|
||||
|
||||
/**
|
||||
* Returns the game world the group is in.
|
||||
*
|
||||
* @return the game world the group is in
|
||||
*/
|
||||
GameWorld getGameWorld();
|
||||
|
||||
/**
|
||||
* Sets the game world the group is in.
|
||||
*
|
||||
* @param gameWorld the game world to set
|
||||
*/
|
||||
void setGameWorld(GameWorld gameWorld);
|
||||
|
||||
/**
|
||||
* Returns the dungeon the group is playing or has remembered to play next.
|
||||
* <p>
|
||||
* The latter is for example used when a group is created by a group sign sothat a portal or the auto-join function knows where to send the group.
|
||||
*
|
||||
* @return the dungeon the group is playing or has remembered to play next
|
||||
*/
|
||||
Dungeon getDungeon();
|
||||
|
||||
/**
|
||||
* Returns if the group is already playing its remembered {@link #getDungeon() dungeon}.
|
||||
*
|
||||
* @return if the group is already playing its remembered {@link #getDungeon() dungeon}
|
||||
*/
|
||||
boolean isPlaying();
|
||||
|
||||
/**
|
||||
* Returns the amount of lives the group currently has left or -1 if group lives are not used.
|
||||
*
|
||||
* @return the amount of lives the group currently has left or -1 if group lives are not used
|
||||
*/
|
||||
int getLives();
|
||||
|
||||
/**
|
||||
* Sets the amount of lives the group currently has left.
|
||||
* <p>
|
||||
* The value must be >=0 or -1, which means unlimited lives.
|
||||
*
|
||||
* @param lives the amount of lives the group currently has left
|
||||
*/
|
||||
void setLives(int lives);
|
||||
|
||||
}
|
@ -1,126 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2019 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.util;
|
||||
|
||||
import de.erethon.caliburn.item.ExItem;
|
||||
import de.erethon.caliburn.item.VanillaItem;
|
||||
import de.erethon.commons.compatibility.Version;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
|
||||
/**
|
||||
* Links different color types together.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public enum DColor {
|
||||
|
||||
BLACK(ChatColor.BLACK, DyeColor.BLACK, VanillaItem.BLACK_WOOL),
|
||||
DARK_GRAY(ChatColor.DARK_GRAY, DyeColor.GRAY, VanillaItem.GRAY_WOOL),
|
||||
LIGHT_GRAY(ChatColor.GRAY, DyeColor.valueOf(Version.isAtLeast(Version.MC1_13) ? "LIGHT_GRAY" : "SILVER"), VanillaItem.LIGHT_GRAY_WOOL),
|
||||
WHITE(ChatColor.WHITE, DyeColor.WHITE, VanillaItem.WHITE_WOOL),
|
||||
DARK_GREEN(ChatColor.DARK_GREEN, DyeColor.GREEN, VanillaItem.GREEN_WOOL),
|
||||
LIGHT_GREEN(ChatColor.GREEN, DyeColor.LIME, VanillaItem.LIME_WOOL),
|
||||
CYAN(ChatColor.DARK_AQUA, DyeColor.CYAN, VanillaItem.CYAN_WOOL),
|
||||
DARK_BLUE(ChatColor.DARK_BLUE, DyeColor.BLUE, VanillaItem.BLUE_WOOL),
|
||||
LIGHT_BLUE(ChatColor.AQUA, DyeColor.LIGHT_BLUE, VanillaItem.LIGHT_BLUE_WOOL),
|
||||
PURPLE(ChatColor.DARK_PURPLE, DyeColor.PURPLE, VanillaItem.PURPLE_WOOL),
|
||||
MAGENTA(ChatColor.LIGHT_PURPLE, DyeColor.MAGENTA, VanillaItem.MAGENTA_WOOL),
|
||||
DARK_RED(ChatColor.DARK_RED, DyeColor.BROWN, VanillaItem.BROWN_WOOL),
|
||||
LIGHT_RED(ChatColor.RED, DyeColor.RED, VanillaItem.RED_WOOL),
|
||||
ORANGE(ChatColor.GOLD, DyeColor.ORANGE, VanillaItem.ORANGE_WOOL),
|
||||
YELLOW(ChatColor.YELLOW, DyeColor.YELLOW, VanillaItem.YELLOW_WOOL),
|
||||
PINK(ChatColor.BLUE, DyeColor.PINK, VanillaItem.PINK_WOOL);
|
||||
|
||||
private ChatColor chat;
|
||||
private DyeColor dye;
|
||||
private VanillaItem woolMaterial;
|
||||
|
||||
DColor(ChatColor chat, DyeColor dye, VanillaItem woolMaterial) {
|
||||
this.chat = chat;
|
||||
this.dye = dye;
|
||||
this.woolMaterial = woolMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ChatColor
|
||||
*/
|
||||
public ChatColor getChatColor() {
|
||||
return chat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the DyeColor
|
||||
*/
|
||||
public DyeColor getDyeColor() {
|
||||
return dye;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the RGB value
|
||||
*/
|
||||
public int getRGBColor() {
|
||||
return dye.getColor().asRGB();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the wool material
|
||||
*/
|
||||
public VanillaItem getWoolMaterial() {
|
||||
return woolMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param color the ChatColor to check
|
||||
* @return the matching DColor or null
|
||||
*/
|
||||
public static DColor getByChatColor(ChatColor color) {
|
||||
for (DColor dColor : values()) {
|
||||
if (dColor.chat == color) {
|
||||
return dColor;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param color the DyeColor to check
|
||||
* @return the matching DColor or null
|
||||
*/
|
||||
public static DColor getByDyeColor(DyeColor color) {
|
||||
for (DColor dColor : values()) {
|
||||
if (dColor.dye == color) {
|
||||
return dColor;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param wool the wool item to check
|
||||
* @return the matching DColor or null
|
||||
*/
|
||||
public static DColor getByWoolType(ExItem wool) {
|
||||
for (DColor dColor : values()) {
|
||||
if (dColor.woolMaterial == wool) {
|
||||
return dColor;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user