Overhaul: Maven

This commit is contained in:
Daniel Saukel 2016-03-01 22:08:07 +01:00
parent 72c0fd6152
commit 312844be78
318 changed files with 19576 additions and 18484 deletions

23
.gitignore vendored
View File

@ -1,20 +1,3 @@
# Eclipse stuff
/.classpath
/.project
/.settings
# NetBeans
/nbproject
/build.xml
# vim
.*.sw[a-p]
# various other potential build files
/build
/bin
/dist
/*.jardesc
# Mac filesystem dust
.DS_Store
/nb-configuration.xml
/target
/dependency-reduced-pom.xml

1
build.bat Normal file
View File

@ -0,0 +1 @@
mvn clean install

92
pom.xml Normal file
View File

@ -0,0 +1,92 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId>
<version>0.11-SNAPSHOT</version>
<packaging>jar</packaging>
<name>DungeonsXL</name>
<url>https://dre2n.github.io</url>
<description>Create custom dungeons and adventure maps with ease!</description>
<build>
<finalName>dungeonsxl-${project.version}</finalName>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources/</directory>
<includes>
<include>plugin.yml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>io.github.dre2n:commons</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.9-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.github.dre2n</groupId>
<artifactId>commons</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>io.github.dre2n</groupId>
<artifactId>commandsxl</artifactId>
<version>2.1.2</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.theyeticave.net/content/repositories/pub_releases</url>
</repository>
<repository>
<id>dre2n-repo</id>
<url>http://feuerstern.bplaced.net/repo/</url>
</repository>
</repositories>
</project>

View File

@ -1,590 +0,0 @@
package io.github.dre2n.dungeonsxl;
import io.github.dre2n.dungeonsxl.command.DCommands;
import io.github.dre2n.dungeonsxl.config.MainConfig;
import io.github.dre2n.dungeonsxl.config.MessageConfig;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.DLootInventory;
import io.github.dre2n.dungeonsxl.dungeon.Dungeons;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GameTypes;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.global.DPortal;
import io.github.dre2n.dungeonsxl.global.GameSign;
import io.github.dre2n.dungeonsxl.global.GroupSign;
import io.github.dre2n.dungeonsxl.global.LeaveSign;
import io.github.dre2n.dungeonsxl.listener.BlockListener;
import io.github.dre2n.dungeonsxl.listener.CommandListener;
import io.github.dre2n.dungeonsxl.listener.EntityListener;
import io.github.dre2n.dungeonsxl.listener.HangingListener;
import io.github.dre2n.dungeonsxl.listener.PlayerListener;
import io.github.dre2n.dungeonsxl.listener.WorldListener;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.player.DSavePlayer;
import io.github.dre2n.dungeonsxl.requirement.RequirementTypes;
import io.github.dre2n.dungeonsxl.reward.RewardTypes;
import io.github.dre2n.dungeonsxl.sign.DSigns;
import io.github.dre2n.dungeonsxl.task.LazyUpdateTask;
import io.github.dre2n.dungeonsxl.task.UpdateTask;
import io.github.dre2n.dungeonsxl.task.WorldUnloadTask;
import io.github.dre2n.dungeonsxl.trigger.Triggers;
import io.github.dre2n.dungeonsxl.util.FileUtil;
import io.github.dre2n.dungeonsxl.util.VersionUtil;
import io.github.dre2n.dungeonsxl.util.VersionUtil.Internals;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArrayList;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
public class DungeonsXL extends JavaPlugin {
private static DungeonsXL plugin;
private Economy economyProvider;
private Permission permissionProvider;
private MainConfig mainConfig;
private MessageConfig messageConfig;
private VersionUtil versionUtil;
private DCommands dCommands;
private DSigns dSigns;
private GameTypes gameTypes;
private RequirementTypes requirementTypes;
private RewardTypes rewardTypes;
private Triggers triggers;
private Dungeons dungeons;
private BukkitTask worldUnloadTask;
private BukkitTask lazyUpdateTask;
private BukkitTask updateTask;
private CopyOnWriteArrayList<Player> inBreakMode = new CopyOnWriteArrayList<Player>();
private CopyOnWriteArrayList<Player> chatSpyers = new CopyOnWriteArrayList<Player>();
private CopyOnWriteArrayList<DLootInventory> dLootInventories = new CopyOnWriteArrayList<DLootInventory>();
private CopyOnWriteArrayList<EditWorld> editWorlds = new CopyOnWriteArrayList<EditWorld>();
private CopyOnWriteArrayList<GameWorld> gameWorlds = new CopyOnWriteArrayList<GameWorld>();
private CopyOnWriteArrayList<GameSign> gameSigns = new CopyOnWriteArrayList<GameSign>();
private CopyOnWriteArrayList<GroupSign> groupSigns = new CopyOnWriteArrayList<GroupSign>();
private CopyOnWriteArrayList<LeaveSign> leaveSigns = new CopyOnWriteArrayList<LeaveSign>();
private CopyOnWriteArrayList<DPortal> dPortals = new CopyOnWriteArrayList<DPortal>();
private CopyOnWriteArrayList<Game> games = new CopyOnWriteArrayList<Game>();
private CopyOnWriteArrayList<DGroup> dGroups = new CopyOnWriteArrayList<DGroup>();
private CopyOnWriteArrayList<DPlayer> dPlayers = new CopyOnWriteArrayList<DPlayer>();
@Override
public void onEnable() {
plugin = this;
// InitFolders
initFolders();
// Load Language
loadMessageConfig(new File(plugin.getDataFolder(), "languages/en.yml"));
// Load Config
loadMainConfig(new File(plugin.getDataFolder(), "config.yml"));
// Load Language 2
loadMessageConfig(new File(plugin.getDataFolder(), "languages/" + mainConfig.getLanguage() + ".yml"));
loadVersionUtil();
loadDCommands();
loadGameTypes();
loadRequirementTypes();
loadRewardTypes();
loadTriggers();
loadDSigns();
loadDungeons();
// Setup Permissions
loadPermissionProvider();
// Setup Economy
loadEconomyProvider();
getCommand("dungeonsxl").setExecutor(new CommandListener());
getServer().getPluginManager().registerEvents(new EntityListener(), this);
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
getServer().getPluginManager().registerEvents(new BlockListener(), this);
getServer().getPluginManager().registerEvents(new WorldListener(), this);
getServer().getPluginManager().registerEvents(new HangingListener(), this);
// Load All
loadAll();
// Tasks
startWorldUnloadTask(1200L);
startLazyUpdateTask(20L);
startUpdateTask(20L);
// MSG
getLogger().info("DungeonsXL " + getDescription().getVersion() + " for Spigot 1.8.8 loaded succesfully!");
if (versionUtil.getInternals() == Internals.OUTDATED) {
getLogger().info("Warning: Your CraftBukkit version is deprecated. DungeonsXL does not support it.");
}
}
@Override
public void onDisable() {
// Save
saveData();
messageConfig.save();
// DPlayer leaves World
for (DPlayer dPlayer : dPlayers) {
dPlayer.leave();
}
// Delete all Data
chatSpyers.clear();
dLootInventories.clear();
groupSigns.clear();
leaveSigns.clear();
dPortals.clear();
dGroups.clear();
dPlayers.clear();
// Delete Worlds
GameWorld.deleteAll();
gameWorlds.clear();
EditWorld.deleteAll();
editWorlds.clear();
// Disable listeners
HandlerList.unregisterAll(plugin);
// Stop shedulers
plugin.getServer().getScheduler().cancelTasks(this);
}
// Init.
public void initFolders() {
if ( !getDataFolder().exists()) {
getDataFolder().mkdir();
}
File dungeons = new File(getDataFolder() + "/dungeons");
if ( !dungeons.exists()) {
dungeons.mkdir();
}
File languages = new File(getDataFolder() + "/languages");
if ( !languages.exists()) {
languages.mkdir();
}
File maps = new File(getDataFolder() + "/maps");
if ( !maps.exists()) {
maps.mkdir();
}
}
// Save and Load
public void saveData() {
File file = new File(getDataFolder(), "data.yml");
FileConfiguration configFile = new YamlConfiguration();
DPortal.save(configFile);
GroupSign.save(configFile);
LeaveSign.save(configFile);
try {
configFile.save(file);
} catch (IOException exception) {
exception.printStackTrace();
}
}
public void loadAll() {
// Load world data
File file = new File(getDataFolder(), "data.yml");
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
DPortal.load(configFile);
GroupSign.load(configFile);
LeaveSign.load(configFile);
// Load saved players
DSavePlayer.load();
// Check Worlds
checkWorlds();
}
public void checkWorlds() {
File serverDir = new File(".");
for (File file : serverDir.listFiles()) {
if (file.getName().contains("DXL_Edit_") && file.isDirectory()) {
for (File dungeonFile : file.listFiles()) {
if (dungeonFile.getName().contains(".id_")) {
String dungeonName = dungeonFile.getName().substring(4);
FileUtil.copyDirectory(file, new File(plugin.getDataFolder(), "/maps/" + dungeonName));
FileUtil.deleteUnusedFiles(new File(plugin.getDataFolder(), "/maps/" + dungeonName));
}
}
FileUtil.removeDirectory(file);
} else if (file.getName().contains("DXL_Game_") && file.isDirectory()) {
FileUtil.removeDirectory(file);
}
}
}
// Getters & loaders
/**
* @return the plugin instance
*/
public static DungeonsXL getPlugin() {
return plugin;
}
/**
* @return the loaded instance of Economy
*/
public Economy getEconomyProvider() {
return economyProvider;
}
/**
* load / reload a new instance of Permission
*/
public void loadEconomyProvider() {
try {
if (mainConfig.enableEconomy()) {
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(Economy.class);
if (economyProvider != null) {
this.economyProvider = economyProvider.getProvider();
}
}
} catch (NoClassDefFoundError error) {
getLogger().info("Could not hook into Vault to register an economy provider!");
}
}
/**
* @return the loaded instance of Permission
*/
public Permission getPermissionProvider() {
return permissionProvider;
}
/**
* load / reload a new instance of Permission
*/
public void loadPermissionProvider() {
try {
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(Permission.class);
if (permissionProvider != null) {
this.permissionProvider = permissionProvider.getProvider();
}
} catch (NoClassDefFoundError error) {
getLogger().info("Could not hook into Vault to register a permission provider!");
}
}
/**
* @param group
* the group to be checked
*/
public boolean isGroupEnabled(String group) {
for (String agroup : permissionProvider.getGroups()) {
if (agroup.equalsIgnoreCase(group)) {
return true;
}
}
return false;
}
/**
* @return the loaded instance of MainConfig
*/
public MainConfig getMainConfig() {
return mainConfig;
}
/**
* load / reload a new instance of MainConfig
*/
public void loadMainConfig(File file) {
mainConfig = new MainConfig(file);
}
/**
* @return the loaded instance of VersionUtil
*/
public VersionUtil getVersion() {
return versionUtil;
}
/**
* load / reload a new instance of VersionUtil
*/
public void loadVersionUtil() {
versionUtil = new VersionUtil();
}
/**
* @return the loaded instance of MessageConfig
*/
public MessageConfig getMessageConfig() {
return messageConfig;
}
/**
* load / reload a new instance of MessageConfig
*/
public void loadMessageConfig(File file) {
messageConfig = new MessageConfig(file);
}
/**
* @return the loaded instance of DCommands
*/
public DCommands getDCommands() {
return dCommands;
}
/**
* load / reload a new instance of DCommands
*/
public void loadDCommands() {
dCommands = new DCommands();
}
/**
* @return the dSigns
*/
public DSigns getDSigns() {
return dSigns;
}
/**
* load / reload a new instance of DSigns
*/
public void loadDSigns() {
dSigns = new DSigns();
}
/**
* @return the game types
*/
public GameTypes getGameTypes() {
return gameTypes;
}
/**
* load / reload a new instance of GameTypes
*/
public void loadGameTypes() {
gameTypes = new GameTypes();
}
/**
* @return the requirement types
*/
public RequirementTypes getRequirementTypes() {
return requirementTypes;
}
/**
* load / reload a new instance of RequirementTypes
*/
public void loadRequirementTypes() {
requirementTypes = new RequirementTypes();
}
/**
* @return the reward types
*/
public RewardTypes getRewardTypes() {
return rewardTypes;
}
/**
* load / reload a new instance of RewardTypes
*/
public void loadRewardTypes() {
rewardTypes = new RewardTypes();
}
/**
* @return the triggers
*/
public Triggers getTriggers() {
return triggers;
}
/**
* load / reload a new instance of Triggers
*/
public void loadTriggers() {
triggers = new Triggers();
}
/**
* @return the loaded instance of Dungeons
*/
public Dungeons getDungeons() {
return dungeons;
}
/**
* load / reload a new instance of Dungeons
*/
public void loadDungeons() {
dungeons = new Dungeons();
}
/**
* @return the worldUnloadTask
*/
public BukkitTask getWorldUnloadTask() {
return worldUnloadTask;
}
/**
* start a new WorldUnloadTask
*/
public void startWorldUnloadTask(long period) {
worldUnloadTask = new WorldUnloadTask().runTaskTimer(this, 0L, period);
}
/**
* @return the lazyUpdateTask
*/
public BukkitTask getLazyUpdateTask() {
return lazyUpdateTask;
}
/**
* start a new LazyUpdateTask
*/
public void startLazyUpdateTask(long period) {
lazyUpdateTask = new LazyUpdateTask().runTaskTimer(this, 0L, period);
}
/**
* @return the updateTask
*/
public BukkitTask getUpdateTask() {
return updateTask;
}
/**
* start a new LazyUpdateTask
*/
public void startUpdateTask(long period) {
updateTask = new UpdateTask().runTaskTimer(this, 0L, period);
}
/**
* @return the inBreakMode
*/
public CopyOnWriteArrayList<Player> getInBreakMode() {
return inBreakMode;
}
/**
* @return the chatSpyers
*/
public CopyOnWriteArrayList<Player> getChatSpyers() {
return chatSpyers;
}
/**
* @return the dLootInventories
*/
public CopyOnWriteArrayList<DLootInventory> getDLootInventories() {
return dLootInventories;
}
/**
* @return the editWorlds
*/
public CopyOnWriteArrayList<EditWorld> getEditWorlds() {
return editWorlds;
}
/**
* @return the defaultConfig
*/
public WorldConfig getDefaultConfig() {
return WorldConfig.defaultConfig;// TODO
}
/**
* @return the gameWorlds
*/
public CopyOnWriteArrayList<GameWorld> getGameWorlds() {
return gameWorlds;
}
/**
* @return the gameSigns
*/
public CopyOnWriteArrayList<GameSign> getGameSigns() {
return gameSigns;
}
/**
* @return the groupSigns
*/
public CopyOnWriteArrayList<GroupSign> getGroupSigns() {
return groupSigns;
}
/**
* @return the dPortals
*/
public CopyOnWriteArrayList<DPortal> getDPortals() {
return dPortals;
}
/**
* @return the leaveSigns
*/
public CopyOnWriteArrayList<LeaveSign> getLeaveSigns() {
return leaveSigns;
}
/**
* @return the games
*/
public CopyOnWriteArrayList<Game> getGames() {
return games;
}
/**
* @return the dGroups
*/
public CopyOnWriteArrayList<DGroup> getDGroups() {
return dGroups;
}
/**
* @return the dPlayers
*/
public CopyOnWriteArrayList<DPlayer> getDPlayers() {
return dPlayers;
}
}

View File

@ -1,33 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class BreakCommand extends DCommand {
public BreakCommand() {
setCommand("break");
setMinArgs(0);
setMaxArgs(0);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_BREAK));
setPermission("dxl.break");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
if ( !plugin.getInBreakMode().contains(player)) {
plugin.getInBreakMode().add(player);
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.CMD_BREAK_BREAK_MODE));
} else {
plugin.getInBreakMode().remove(player);
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.CMD_BREAK_PROTECTED_MODE));
}
}
}

View File

@ -1,41 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ChatCommand extends DCommand {
public ChatCommand() {
setCommand("chat");
setMinArgs(0);
setMaxArgs(0);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_CHAT));
setPermission("dxl.chat");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dplayer = DPlayer.getByPlayer(player);
if (dplayer == null) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP));
return;
}
if (dplayer.isInDungeonChat()) {
dplayer.setInDungeonChat(false);
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_CHAT_NORMAL_CHAT));
} else {
dplayer.setInDungeonChat(true);
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_CHAT_DUNGEON_CHAT));
}
}
}

View File

@ -1,34 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ChatSpyCommand extends DCommand {
public ChatSpyCommand() {
setCommand("chatspy");
setMinArgs(0);
setMaxArgs(0);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_CHATSPY));
setPermission("dxl.chatspy");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
if (plugin.getChatSpyers().contains(player)) {
plugin.getChatSpyers().remove(player);
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_CHATSPY_STOPPED));
} else {
plugin.getChatSpyers().add(player);
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_CHATSPY_START));
}
}
}

View File

@ -1,83 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class CreateCommand extends DCommand {
public CreateCommand() {
setMinArgs(1);
setMaxArgs(1);
setCommand("create");
setHelp(messageConfig.getMessage(Messages.HELP_CMD_CREATE));
setPermission("dxl.create");
setPlayerCommand(true);
setConsoleCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
String name = args[1];
if (sender instanceof ConsoleCommandSender) {
if (name.length() <= 15) {
// Msg create
plugin.getLogger().info(messageConfig.getMessage(Messages.LOG_NEW_DUNGEON));
plugin.getLogger().info(messageConfig.getMessage(Messages.LOG_GENERATE_NEW_WORLD));
// Create World
EditWorld editWorld = new EditWorld();
editWorld.generate();
editWorld.setMapName(name);
editWorld.save();
editWorld.delete();
// MSG Done
plugin.getLogger().info(messageConfig.getMessage(Messages.LOG_WORLD_GENERATION_FINISHED));
} else {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NAME_TO_LONG));
}
} else if (sender instanceof Player) {
Player player = (Player) sender;
if (DPlayer.getByPlayer(player) != null) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_DUNGEON));
return;
}
if (name.length() <= 15) {
// Msg create
plugin.getLogger().info(messageConfig.getMessage(Messages.LOG_NEW_DUNGEON));
plugin.getLogger().info(messageConfig.getMessage(Messages.LOG_GENERATE_NEW_WORLD));
// Create World
EditWorld editWorld = new EditWorld();
editWorld.generate();
editWorld.setMapName(name);
// MSG Done
plugin.getLogger().info(messageConfig.getMessage(Messages.LOG_WORLD_GENERATION_FINISHED));
// Tp Player
if (editWorld.getLobby() == null) {
new DPlayer(player, editWorld.getWorld(), editWorld.getWorld().getSpawnLocation(), true);
} else {
new DPlayer(player, editWorld.getWorld(), editWorld.getLobby(), true);
}
} else {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NAME_TO_LONG));
}
}
}
}

View File

@ -1,149 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.MessageConfig;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public abstract class DCommand {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
protected static MessageConfig messageConfig = plugin.getMessageConfig();
public boolean costsMoney;
private String command;
private int minArgs;
private int maxArgs;
private String help;
private String permission;
private boolean isPlayerCommand = false;
private boolean isConsoleCommand = false;
public DCommand() {
costsMoney = false;
}
public void displayHelp(CommandSender sender) {
MessageUtil.sendMessage(sender, ChatColor.RED + help);
}
public boolean playerHasPermissions(Player player) {
if (player.hasPermission(permission) || permission == null) {
return true;
}
return false;
}
/**
* @return the command
*/
public String getCommand() {
return command;
}
/**
* @param command
* the command to set
*/
public void setCommand(String command) {
this.command = command;
}
/**
* @return the minimal amount of arguments
*/
public int getMinArgs() {
return minArgs;
}
/**
* @param minArgs
* the minimal amount of arguments to set
*/
public void setMinArgs(int minArgs) {
this.minArgs = minArgs;
}
/**
* @return the maximum amount of arguments
*/
public int getMaxArgs() {
return maxArgs;
}
/**
* @param maxArgs
* the maximum amount of arguments to set
*/
public void setMaxArgs(int maxArgs) {
this.maxArgs = maxArgs;
}
/**
* @return the help
*/
public String getHelp() {
return help;
}
/**
* @param help
* the help to set
*/
public void setHelp(String help) {
this.help = help;
}
/**
* @return the permission
*/
public String getPermission() {
return permission;
}
/**
* @param permission
* the permission to set
*/
public void setPermission(String permission) {
this.permission = permission;
}
/**
* @return the isPlayerCommand
*/
public boolean isPlayerCommand() {
return isPlayerCommand;
}
/**
* @param isPlayerCommand
* the isPlayerCommand to set
*/
public void setPlayerCommand(boolean isPlayerCommand) {
this.isPlayerCommand = isPlayerCommand;
}
/**
* @return the isConsoleCommand
*/
public boolean isConsoleCommand() {
return isConsoleCommand;
}
/**
* @param isConsoleCommand
* the isConsoleCommand to set
*/
public void setConsoleCommand(boolean isConsoleCommand) {
this.isConsoleCommand = isConsoleCommand;
}
// Abstracts
public abstract void onExecute(String[] args, CommandSender sender);
}

View File

@ -1,58 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class DCommands {
private CopyOnWriteArrayList<DCommand> dCommands = new CopyOnWriteArrayList<DCommand>();
// Methods
public DCommands() {
// Add Commands
dCommands.add(new HelpCommand());
dCommands.add(new BreakCommand());
dCommands.add(new ChatCommand());
dCommands.add(new ChatSpyCommand());
dCommands.add(new CreateCommand());
dCommands.add(new EditCommand());
dCommands.add(new EscapeCommand());
dCommands.add(new GameCommand());
dCommands.add(new GroupCommand());
dCommands.add(new InviteCommand());
dCommands.add(new LeaveCommand());
dCommands.add(new ListCommand());
dCommands.add(new LivesCommand());
dCommands.add(new MainCommand());
dCommands.add(new UninviteCommand());
dCommands.add(new MsgCommand());
dCommands.add(new PlayCommand());
dCommands.add(new PortalCommand());
dCommands.add(new DeletePortalCommand());
dCommands.add(new ReloadCommand());
dCommands.add(new SaveCommand());
dCommands.add(new TestCommand());
}
/**
* @param command
* usually the first command variable
*/
public DCommand getDCommand(String command) {
for (DCommand dCommand : dCommands) {
if (dCommand.getCommand().equals(command)) {
return dCommand;
}
}
return null;
}
/**
* @return the dCommands
*/
public List<DCommand> getDCommands() {
return dCommands;
}
}

View File

@ -1,39 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.global.DPortal;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import java.util.Set;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@Deprecated
public class DeletePortalCommand extends DCommand {
public DeletePortalCommand() {
setCommand("deleteportal");
setMinArgs(0);
setMaxArgs(0);
setHelp("/dxl deleteportal - Deletes the portal you are looking at");
setPermission("dxl.portal");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPortal dPortal = DPortal.getByLocation(player.getTargetBlock((Set<Material>) null, 20).getLocation());
if (dPortal != null) {
dPortal.delete();
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.PLAYER_PROTECTED_BLOCK_DELETED));
} else {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NO_PROTECTED_BLOCK));
}
}
}

View File

@ -1,60 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class EditCommand extends DCommand {
public EditCommand() {
setCommand("edit");
setMinArgs(1);
setMaxArgs(1);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_EDIT));
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
String mapName = args[1];
EditWorld editWorld = EditWorld.load(mapName);
DGroup dGroup = DGroup.getByPlayer(player);
DPlayer dPlayer = DPlayer.getByPlayer(player);
if ( !(EditWorld.isInvitedPlayer(mapName, player.getUniqueId(), player.getName()) || player.hasPermission("dxl.edit"))) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NO_PERMISSIONS));
return;
}
if (dPlayer != null) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_DUNGEON));
return;
}
if (dGroup != null) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP));
return;
}
if (editWorld == null) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, mapName));
return;
}
if (editWorld.getLobby() == null) {
new DPlayer(player, editWorld.getWorld(), editWorld.getWorld().getSpawnLocation(), true);
} else {
new DPlayer(player, editWorld.getWorld(), editWorld.getLobby(), true);
}
}
}

View File

@ -1,56 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class EscapeCommand extends DCommand {
public EscapeCommand() {
setCommand("escape");
setMinArgs(0);
setMaxArgs(0);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_ESCAPE));
setPermission("dxl.escape");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dPlayer = DPlayer.getByPlayer(player);
if (dPlayer != null) {
if ( !dPlayer.isEditing()) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_DUNGEON));
return;
}
dPlayer.escape();
EditWorld editWorld = EditWorld.getByWorld(dPlayer.getWorld());
if (editWorld == null) {
return;
}
if (editWorld.getWorld().getPlayers().isEmpty()) {
editWorld.deleteNoSave();
}
} else {
DGroup dGroup = DGroup.getByPlayer(player);
if (dGroup != null) {
dGroup.removePlayer(player);
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_LEAVE_SUCCESS));
return;
}
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_IN_DUNGEON));
}
}
}

View File

@ -1,55 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class GameCommand extends DCommand {
public GameCommand() {
setCommand("game");
setMinArgs(0);
setMaxArgs(0);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_GAME));
setPermission("dxl.game");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DGroup dGroup = DGroup.getByPlayer(player);
if (dGroup == null) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP));
return;
}
GameWorld gameWorld = dGroup.getGameWorld();
if (gameWorld == null) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_GAME));
return;
}
Game game = gameWorld.getGame();
if (game == null) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_GAME));
return;
}
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();
}
MessageUtil.sendMessage(sender, "&bGroups: &e" + groups);
MessageUtil.sendMessage(sender, "&bGame type: &e" + 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()));
}
}

View File

@ -1,247 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupDisbandEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class GroupCommand extends DCommand {
public GroupCommand() {
setCommand("group");
setMinArgs(0);
setMaxArgs(2);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_GROUP));
setPermission("dxl.group");
setPlayerCommand(true);
}
private CommandSender sender;
private Player player;
private String[] args;
@Override
public void onExecute(String[] args, CommandSender sender) {
this.sender = sender;
this.player = (Player) sender;
this.args = args;
DGroup dGroup = DGroup.getByPlayer(player);
if (args.length == 2) {
if (args[1].equalsIgnoreCase("disband")) {
disbandGroup(dGroup);
return;
} else if (args[1].equalsIgnoreCase("show")) {
showGroup(dGroup);
return;
}
} else if (args.length >= 3) {
if (args[1].equalsIgnoreCase("kick")) {
kickPlayer(dGroup);
return;
} else if (args[1].equalsIgnoreCase("invite")) {
invitePlayer(dGroup);
return;
} else if (args[1].equalsIgnoreCase("uninvite")) {
uninvitePlayer(dGroup);
return;
} else if (args[1].equalsIgnoreCase("help")) {
showHelp(args[2]);
return;
} else if (args[1].equalsIgnoreCase("create")) {
createGroup();
return;
} else if (args[1].equalsIgnoreCase("disband") && sender.hasPermission("dxl.group.admin")) {
disbandGroup(DGroup.getByName(args[2]));
return;
} else if (args[1].equalsIgnoreCase("join")) {
joinGroup(DGroup.getByName(args[2]));
return;
} else if (args[1].equalsIgnoreCase("show") && sender.hasPermission("dxl.group.admin")) {
showGroup(DGroup.getByName(args[2]));
return;
}
}
showHelp("1");
}
public void createGroup() {
if (DGroup.getByPlayer(player) == null && DGroup.getByName(args[2]) == null) {
DGroup dGroup = new DGroup(args[2], player);
DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND);
if (event.isCancelled()) {
plugin.getDGroups().remove(dGroup);
dGroup = null;
} else {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.GROUP_CREATED, sender.getName(), args[2]));
}
} else {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP));
}
}
public void disbandGroup(DGroup dGroup) {
if (dGroup != null) {
DGroupDisbandEvent event = new DGroupDisbandEvent(dGroup, player, DGroupDisbandEvent.Cause.COMMAND);
if ( !event.isCancelled()) {
plugin.getDGroups().remove(dGroup);
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.GROUP_DISBANDED, sender.getName(), dGroup.getName()));
dGroup = null;
}
} else {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_GROUP));
}
}
public void invitePlayer(DGroup dGroup) {
if (dGroup == null) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP));
return;
}
Player toInvite = plugin.getServer().getPlayer(args[2]);
if (toInvite != null) {
dGroup.addInvitedPlayer(toInvite, false);
} else {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_PLAYER, args[2]));
}
}
public void uninvitePlayer(DGroup dGroup) {
if (dGroup == null) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP));
return;
}
dGroup.clearOfflineInvitedPlayers();
Player toUninvite = plugin.getServer().getPlayer(args[2]);
if (toUninvite != null) {
if (dGroup.getInvitedPlayers().contains(toUninvite)) {
dGroup.removeInvitedPlayer(toUninvite, false);
} else {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NOT_IN_GROUP, args[2]));
}
} else {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_PLAYER, args[2]));
}
}
public void joinGroup(DGroup dGroup) {
if (dGroup == null) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_GROUP, args[2]));
return;
}
for (DGroup anyDGroup : plugin.getDGroups()) {
if (anyDGroup.getPlayers().contains(player)) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP));
}
}
if ( !dGroup.getInvitedPlayers().contains(player) && !player.hasPermission("dxl.bypass")) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NOT_INVITED, args[2]));
return;
}
dGroup.addPlayer(player);
dGroup.removeInvitedPlayer(player, true);
}
public void kickPlayer(DGroup dGroup) {
if (dGroup == null) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP));
}
Player toKick = plugin.getServer().getPlayer(args[2]);
if (toKick != null) {
DPlayerKickEvent event = new DPlayerKickEvent(DPlayer.getByPlayer(toKick.getPlayer()), DPlayerKickEvent.Cause.COMMAND);
if ( !event.isCancelled()) {
if (dGroup.getPlayers().contains(toKick)) {
dGroup.removePlayer(toKick);
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.GROUP_KICKED_PLAYER, sender.getName(), args[2], dGroup.getName()));
} else {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NOT_IN_GROUP, args[2], dGroup.getName()));
}
}
} else {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_PLAYER, args[2]));
}
}
public void showGroup(DGroup dGroup) {
if (dGroup == null) {
if (args.length == 3) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_SUCH_GROUP, args[2]));
} else if (args.length == 2) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP));
}
return;
}
MessageUtil.sendCenteredMessage(sender, "&4&l[ &6" + dGroup.getName() + " &4&l]");
MessageUtil.sendMessage(sender, "&bCaptain: &e" + dGroup.getCaptain().getName());
String players = "";
for (Player player : dGroup.getPlayers()) {
players += (player == dGroup.getPlayers().get(0) ? "" : "&b, &e") + player.getName();
}
MessageUtil.sendMessage(sender, "&bPlayers: &e" + players);
MessageUtil.sendMessage(sender, "&bDungeon: &e" + (dGroup.getDungeonName() == null ? "N/A" : dGroup.getDungeonName()));
MessageUtil.sendMessage(sender, "&bMap: &e" + (dGroup.getMapName() == null ? "N/A" : dGroup.getMapName()));
}
public void showHelp(String page) {
MessageUtil.sendPluginTag(sender, plugin);
switch (page) {
default:
MessageUtil.sendCenteredMessage(sender, "&4&l[ &61-5 &4/ &67 &4| &61 &4&l]");
MessageUtil.sendMessage(sender, "&bcreate" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_CREATE));
MessageUtil.sendMessage(sender, "&bdisband" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_DISBAND));
MessageUtil.sendMessage(sender, "&binvite" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_INVITE));
MessageUtil.sendMessage(sender, "&buninvite" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_UNINVITE));
MessageUtil.sendMessage(sender, "&bjoin" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_JOIN));
break;
case "2":
MessageUtil.sendCenteredMessage(sender, "&4&l[ &66-10 &4/ &67 &4| &62 &4&l]");
MessageUtil.sendMessage(sender, "&bkick" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_KICK));
MessageUtil.sendMessage(sender, "&bshow" + "&7 - " + messageConfig.getMessage(Messages.HELP_CMD_GROUP_SHOW));
break;
}
}
}

View File

@ -1,53 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import java.util.ArrayList;
import java.util.List;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.util.NumberUtil;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.command.CommandSender;
public class HelpCommand extends DCommand {
public HelpCommand() {
setCommand("help");
setMinArgs(0);
setMaxArgs(1);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_HELP));
setPermission("dxl.help");
setPlayerCommand(true);
setConsoleCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
List<DCommand> dCommandList = plugin.getDCommands().getDCommands();
ArrayList<DCommand> toSend = new ArrayList<DCommand>();
int page = 1;
if (args.length == 2) {
page = NumberUtil.parseInt(args[1], 1);
}
int send = 0;
int max = 0;
int min = 0;
for (DCommand dCommand : dCommandList) {
send++;
if (send >= page * 5 - 4 && send <= page * 5) {
min = page * 5 - 4;
max = page * 5;
toSend.add(dCommand);
}
}
MessageUtil.sendPluginTag(sender, plugin);
MessageUtil.sendCenteredMessage(sender, "&4&l[ &6" + min + "-" + max + " &4/&6 " + send + " &4|&6 " + page + " &4&l]");
for (DCommand dCommand : toSend) {
MessageUtil.sendMessage(sender, "&b" + dCommand.getCommand() + "&7 - " + dCommand.getHelp());
}
}
}

View File

@ -1,32 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.util.UUIDUtil;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.command.CommandSender;
public class InviteCommand extends DCommand {
public InviteCommand() {
setMinArgs(2);
setMaxArgs(2);
setCommand("invite");
setHelp(messageConfig.getMessage(Messages.HELP_CMD_INVITE));
setPermission("dxl.invite");
setPlayerCommand(true);
setConsoleCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
if (EditWorld.addInvitedPlayer(args[2], UUIDUtil.getUniqueIdFromName(args[1]))) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.CMD_INVITE_SUCCESS, args[1], args[2]));
} else {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, args[2]));
}
}
}

View File

@ -1,58 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerEscapeEvent;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class LeaveCommand extends DCommand {
public LeaveCommand() {
setCommand("leave");
setMinArgs(0);
setMaxArgs(0);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_LEAVE));
setPermission("dxl.leave");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dPlayer = DPlayer.getByPlayer(player);
if (GameWorld.getByWorld(player.getWorld()) != null) {
if (GameWorld.getByWorld(player.getWorld()).isTutorial()) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NO_LEAVE_IN_TUTORIAL));
return;
}
}
if (dPlayer != null) {
DPlayerEscapeEvent event = new DPlayerEscapeEvent(dPlayer);
if (event.isCancelled()) {
return;
}
dPlayer.leave();
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_LEAVE_SUCCESS));
} else {
DGroup dGroup = DGroup.getByPlayer(player);
if (dGroup != null) {
dGroup.removePlayer(player);
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_LEAVE_SUCCESS));
return;
}
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_IN_DUNGEON));
}
}
}

View File

@ -1,134 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.DungeonConfig;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.util.NumberUtil;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import java.io.File;
import java.util.ArrayList;
import org.bukkit.command.CommandSender;
public class ListCommand extends DCommand {
public ListCommand() {
setCommand("list");
setMinArgs(0);
setMaxArgs(3);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_LIST));
setPermission("dxl.list");
setPlayerCommand(true);
setConsoleCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
File dungeonFolder = new File(plugin.getDataFolder() + "/dungeons");
File mapFolder = new File(plugin.getDataFolder() + "/maps");
ArrayList<String> dungeonList = new ArrayList<String>();
for (Dungeon dungeon : plugin.getDungeons().getDungeons()) {
dungeonList.add(dungeon.getName());
}
ArrayList<String> mapList = new ArrayList<String>();
for (File file : mapFolder.listFiles()) {
mapList.add(file.getName());
}
ArrayList<String> loadedList = new ArrayList<String>();
for (EditWorld editWorld : plugin.getEditWorlds()) {
loadedList.add(editWorld.getWorld().getWorldFolder().getName());
}
for (GameWorld gameWorld : plugin.getGameWorlds()) {
loadedList.add(gameWorld.getWorld().getWorldFolder().getName());
}
ArrayList<String> toSend = new ArrayList<String>();
ArrayList<String> stringList = mapList;
boolean specified = false;
byte listType = 0;
if (args.length >= 2) {
if (args[1].equalsIgnoreCase("dungeons") || args[1].equalsIgnoreCase("d")) {
if (args.length >= 3) {
Dungeon dungeon = plugin.getDungeons().getDungeon(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() + "]");
return;
}
}
specified = true;
stringList = dungeonList;
listType = 1;
} else if (args[1].equalsIgnoreCase("maps") || args[1].equalsIgnoreCase("m")) {
specified = true;
} else if (args[1].equalsIgnoreCase("loaded") || args[1].equalsIgnoreCase("l")) {
specified = true;
stringList = loadedList;
listType = 2;
}
}
int page = 1;
if (args.length == 3) {
page = NumberUtil.parseInt(args[2], 1);
} else if (args.length == 2 & !specified) {
page = NumberUtil.parseInt(args[1], 1);
}
int send = 0;
int max = 0;
int min = 0;
for (String string : stringList) {
send++;
if (send >= page * 5 - 4 && send <= page * 5) {
min = page * 5 - 4;
max = page * 5;
toSend.add(string);
}
}
MessageUtil.sendPluginTag(sender, plugin);
MessageUtil.sendCenteredMessage(sender, "&4&l[ &6" + min + "-" + max + " &4/&6 " + send + " &4|&6 " + page + " &4&l]");
if (listType == 0) {
MessageUtil.sendMessage(sender, "&4Map&7 | &eInvited");
for (String map : toSend) {
WorldConfig worldConfig = new WorldConfig(new File(mapFolder + "/" + map, "config.yml"));
boolean invited = false;
if (worldConfig != null) {
invited = worldConfig.getInvitedPlayers().contains(sender);
}
MessageUtil.sendMessage(sender, "&b" + map + "&7 | &e" + invited);
}
} else if (listType == 1) {
MessageUtil.sendMessage(sender, "&4Dungeon&7 | &eMap count");
for (String dungeon : toSend) {
DungeonConfig dungeonConfig = new DungeonConfig(new File(dungeonFolder, dungeon + ".yml"));
int count = dungeonConfig.getFloors().size() + 2;
MessageUtil.sendMessage(sender, "&b" + dungeon + "&7 | &e" + count);
}
} else if (listType == 2) {
MessageUtil.sendMessage(sender, "&4Loaded map");
for (String map : toSend) {
MessageUtil.sendMessage(sender, "&b" + map);
}
}
}
}

View File

@ -1,49 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class LivesCommand extends DCommand {
public LivesCommand() {
setCommand("lives");
setMinArgs(0);
setMaxArgs(1);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_LIVES));
setPermission("dxl.lives");
setPlayerCommand(true);
setConsoleCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = null;
if (args.length == 2) {
if (Bukkit.getServer().getPlayer(args[1]) != null) {
player = Bukkit.getServer().getPlayer(args[1]);
}
} else if (sender instanceof Player) {
player = (Player) sender;
} else {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NO_CONSOLE_COMMAND, getCommand()));
return;
}
DPlayer dPlayer = DPlayer.getByPlayer(player);
if (dPlayer != null) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_LIVES, player.getName(), String.valueOf(dPlayer.getLives())));
} else {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_IN_DUNGEON));
}
}
}

View File

@ -1,54 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import java.io.File;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.util.VersionUtil.Internals;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.PluginManager;
public class MainCommand extends DCommand {
public MainCommand() {
setCommand("main");
setHelp(messageConfig.getMessage(Messages.HELP_CMD_MAIN));
setPermission("dxl.main");
setPlayerCommand(true);
setConsoleCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
PluginManager plugins = Bukkit.getServer().getPluginManager();
int maps = new File(plugin.getDataFolder() + "/maps").listFiles().length;
int dungeons = new File(plugin.getDataFolder() + "/dungeons").listFiles().length;
int loaded = plugin.getEditWorlds().size() + plugin.getGameWorlds().size();
int players = plugin.getDPlayers().size();
Internals internals = DungeonsXL.getPlugin().getVersion().getInternals();
String vault = "";
if (plugins.getPlugin("Vault") != null) {
vault = plugins.getPlugin("Vault").getDescription().getVersion();
}
String mythicMobs = "";
if (plugins.getPlugin("MythicMobs") != null) {
mythicMobs = plugins.getPlugin("MythicMobs").getDescription().getVersion();
}
MessageUtil.sendCenteredMessage(sender, "&4" + MessageUtil.BIG_D[0] + "&f" + MessageUtil.BIG_X[0] + MessageUtil.BIG_L[0]);
MessageUtil.sendCenteredMessage(sender, "&4" + MessageUtil.BIG_D[1] + "&f" + MessageUtil.BIG_X[1] + MessageUtil.BIG_L[1]);
MessageUtil.sendCenteredMessage(sender, "&4" + MessageUtil.BIG_D[2] + "&f" + MessageUtil.BIG_X[2] + MessageUtil.BIG_L[2]);
MessageUtil.sendCenteredMessage(sender, "&4" + MessageUtil.BIG_D[3] + "&f" + MessageUtil.BIG_X[3] + MessageUtil.BIG_L[3]);
MessageUtil.sendCenteredMessage(sender, "&4" + MessageUtil.BIG_D[4] + "&f" + MessageUtil.BIG_X[4] + MessageUtil.BIG_L[4]);
MessageUtil.sendCenteredMessage(sender, "&b&l####### " + messageConfig.getMessage(Messages.CMD_MAIN_WELCOME) + "&7 v" + plugin.getDescription().getVersion() + " &b&l#######");
MessageUtil.sendCenteredMessage(sender, messageConfig.getMessage(Messages.CMD_MAIN_LOADED, String.valueOf(maps), String.valueOf(dungeons), String.valueOf(loaded), String.valueOf(players)));
MessageUtil.sendCenteredMessage(sender, messageConfig.getMessage(Messages.CMD_MAIN_COMPATIBILITY, String.valueOf(internals), vault, mythicMobs));
MessageUtil.sendCenteredMessage(sender, messageConfig.getMessage(Messages.CMD_MAIN_HELP));
MessageUtil.sendCenteredMessage(sender, "&7\u00a92012-2016 Frank Baumann & contributors; lcsd. under GPLv3.");
}
}

View File

@ -1,92 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.util.NumberUtil;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import java.io.File;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class MsgCommand extends DCommand {
public MsgCommand() {
setMinArgs( -1);
setMaxArgs( -1);
setCommand("msg");
setHelp(messageConfig.getMessage(Messages.HELP_CMD_MSG));
setPermission("dxl.msg");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
EditWorld editWorld = EditWorld.getByWorld(player.getWorld());
if (editWorld == null) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_IN_DUNGEON));
return;
}
if (args.length <= 1) {
displayHelp(player);
return;
}
try {
int id = NumberUtil.parseInt(args[1]);
WorldConfig confreader = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + editWorld.getMapName(), "config.yml"));
if (args.length == 2) {
String msg = confreader.getMsg(id, true);
if (msg != null) {
MessageUtil.sendMessage(player, ChatColor.WHITE + msg);
} else {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_MSG_ID_NOT_EXIST, "" + id));
}
} else {
String msg = "";
int i = 0;
for (String arg : args) {
i++;
if (i > 2) {
msg = msg + " " + arg;
}
}
String[] splitMsg = msg.split("\"");
if (splitMsg.length > 1) {
msg = splitMsg[1];
String old = confreader.getMsg(id, false);
if (old == null) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_MSG_ADDED, "" + id));
} else {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_MSG_UPDATED, "" + id));
}
confreader.setMsg(msg, id);
confreader.save();
} else {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_MSG_FORMAT));
}
}
} catch (NumberFormatException e) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_MSG_NO_INT));
}
}
}

View File

@ -1,156 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.DungeonConfig;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import java.io.File;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class PlayCommand extends DCommand {
public PlayCommand() {
setCommand("play");
setMinArgs(1);
setMaxArgs(2);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_PLAY));
setPermission("dxl.play");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dPlayer = DPlayer.getByPlayer(player);
if (dPlayer != null) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_DUNGEON));
return;
}
if ( !(args.length >= 2 && args.length <= 3)) {
displayHelp(player);
return;
}
String identifier = args[1];
String mapName = identifier;
boolean multiFloor = false;
if (args.length == 3) {
identifier = args[2];
mapName = identifier;
if (args[1].equalsIgnoreCase("dungeon") || args[1].equalsIgnoreCase("d")) {
Dungeon dungeon = plugin.getDungeons().getDungeon(args[2]);
if (dungeon != null) {
multiFloor = true;
mapName = dungeon.getConfig().getStartFloor();
} else {
displayHelp(player);
return;
}
} else if (args[1].equalsIgnoreCase("map") || args[1].equalsIgnoreCase("m")) {
identifier = args[2];
}
}
if ( !multiFloor && !EditWorld.exists(identifier)) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, identifier));
return;
}
if ( !GameWorld.canPlayDungeon(identifier, player)) {
File file = new File(plugin.getDataFolder() + "/maps/" + identifier + "/config.yml");
if (file.exists()) {
WorldConfig confReader = new WorldConfig(file);
if (confReader != null) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_COOLDOWN, "" + confReader.getTimeToNextPlay()));
}
}
return;
}
if ( !GameWorld.checkRequirements(mapName, player)) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_REQUIREMENTS));
return;
}
DGroup dGroup = DGroup.getByPlayer(player);
if (dGroup != null) {
if ( !dGroup.getCaptain().equals(player) && !player.hasPermission("dxl.bypass")) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_CAPTAIN));
}
if (dGroup.getMapName() == null) {
if ( !multiFloor) {
dGroup.setMapName(identifier);
} else {
dGroup.setDungeonName(identifier);
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
if (dungeon != null) {
DungeonConfig config = dungeon.getConfig();
if (config != null) {
dGroup.setMapName(config.getStartFloor());
}
}
}
} else {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_GROUP));
return;
}
} else {
dGroup = new DGroup(player, identifier, multiFloor);
}
DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.COMMAND);
if (event.isCancelled()) {
plugin.getDGroups().remove(dGroup);
dGroup = null;
}
if (dGroup == null) {
return;
}
if (dGroup.getGameWorld() == null) {
dGroup.setGameWorld(GameWorld.load(DGroup.getByPlayer(player).getMapName()));
}
if (dGroup.getGameWorld() == null) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_SAVED, DGroup.getByPlayer(player).getMapName()));
dGroup.remove();
return;
}
if (dGroup.getGameWorld().getLocLobby() == null) {
for (Player groupPlayer : dGroup.getPlayers()) {
new DPlayer(groupPlayer, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getWorld().getSpawnLocation(), false);
}
} else {
for (Player groupPlayer : dGroup.getPlayers()) {
new DPlayer(groupPlayer, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getLocLobby(), false);
}
}
}
}

View File

@ -1,48 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.global.DPortal;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class PortalCommand extends DCommand {
public PortalCommand() {
setCommand("portal");
setMinArgs(0);
setMaxArgs(0);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_PORTAL));
setPermission("dxl.portal");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dPlayer = DPlayer.getByPlayer(player);
if (dPlayer != null) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEAVE_DUNGEON));
}
DPortal dPortal = DPortal.getByPlayer(player);
if (dPortal == null) {
dPortal = new DPortal(false);
dPortal.setPlayer(player);
dPortal.setWorld(player.getWorld());
player.getInventory().setItemInHand(new ItemStack(Material.WOOD_SWORD));
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.PLAYER_PORTAL_INTRODUCTION));
} else {
plugin.getDPortals().remove(dPortal);
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.PLAYER_PORTAL_ABORT));
}
}
}

View File

@ -1,61 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.util.VersionUtil.Internals;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.PluginManager;
public class ReloadCommand extends DCommand {
public ReloadCommand() {
setCommand("reload");
setMinArgs(0);
setMaxArgs(0);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_RELOAD));
setPermission("dxl.reload");
setPlayerCommand(true);
setConsoleCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
PluginManager plugins = Bukkit.getServer().getPluginManager();
int maps = new File(plugin.getDataFolder() + "/maps").listFiles().length;
int dungeons = new File(plugin.getDataFolder() + "/dungeons").listFiles().length;
int loaded = plugin.getEditWorlds().size() + plugin.getGameWorlds().size();
int players = plugin.getDPlayers().size();
Internals internals = DungeonsXL.getPlugin().getVersion().getInternals();
String vault = "";
if (plugins.getPlugin("Vault") != null) {
vault = plugins.getPlugin("Vault").getDescription().getVersion();
}
String mythicMobs = "";
if (plugins.getPlugin("MythicMobs") != null) {
mythicMobs = plugins.getPlugin("MythicMobs").getDescription().getVersion();
}
// Save
plugin.saveData();
plugin.getMessageConfig().save();
// Load Config
plugin.loadMainConfig(new File(plugin.getDataFolder(), "config.yml"));
plugin.loadMessageConfig(new File(plugin.getDataFolder(), "languages/" + plugin.getMainConfig().getLanguage() + ".yml"));
plugin.loadVersionUtil();
plugin.loadDCommands();
plugin.loadDungeons();
MessageUtil.sendPluginTag(sender, plugin);
MessageUtil.sendCenteredMessage(sender, messageConfig.getMessage(Messages.CMD_RELOAD_DONE));
MessageUtil.sendCenteredMessage(sender, messageConfig.getMessage(Messages.CMD_MAIN_LOADED, String.valueOf(maps), String.valueOf(dungeons), String.valueOf(loaded), String.valueOf(players)));
MessageUtil.sendCenteredMessage(sender, messageConfig.getMessage(Messages.CMD_MAIN_COMPATIBILITY, String.valueOf(internals), vault, mythicMobs));
}
}

View File

@ -1,34 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SaveCommand extends DCommand {
public SaveCommand() {
setCommand("save");
setMinArgs(0);
setMaxArgs(0);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_SAVE));
setPermission("dxl.save");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
EditWorld editWorld = EditWorld.getByWorld(player.getWorld());
if (editWorld != null) {
editWorld.save();
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.CMD_SAVE_SUCCESS));
} else {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NOT_IN_DUNGEON));
}
}
}

View File

@ -1,57 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class TestCommand extends DCommand {
public TestCommand() {
setCommand("test");
setMinArgs(0);
setMaxArgs(0);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_TEST));
setPermission("dxl.test");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DGroup dGroup = DGroup.getByPlayer(player);
if (dGroup == null) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_JOIN_GROUP));
return;
}
if ( !dGroup.getCaptain().equals(player)) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NOT_CAPTAIN));
return;
}
GameWorld gameWorld = dGroup.getGameWorld();
if (gameWorld == null) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_NOT_IN_DUNGEON));
return;
}
Game game = gameWorld.getGame();
if (game != null) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_LEAVE_DUNGEON));
return;
}
for (Player groupPlayer : dGroup.getPlayers()) {
DPlayer.getByPlayer(groupPlayer).ready(GameTypeDefault.TEST);
}
}
}

View File

@ -1,32 +0,0 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.util.UUIDUtil;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.command.CommandSender;
public class UninviteCommand extends DCommand {
public UninviteCommand() {
setCommand("uninvite");
setMinArgs(2);
setMaxArgs(2);
setHelp(messageConfig.getMessage(Messages.HELP_CMD_UNINVITE));
setPermission("dxl.uninvite");
setPlayerCommand(true);
setConsoleCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
if (EditWorld.removeInvitedPlayer(args[2], UUIDUtil.getUniqueIdFromName(args[1]), args[1])) {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.CMD_UNINVITE_SUCCESS, args[1], args[2]));
} else {
MessageUtil.sendMessage(sender, messageConfig.getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, args[2]));
}
}
}

View File

@ -1,137 +0,0 @@
package io.github.dre2n.dungeonsxl.config;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
public class DungeonConfig extends WorldConfig {
private String startFloor;
private String endFloor;
private List<String> floors = new ArrayList<String>();
private int floorCount;
private boolean removeWhenPlayed;
public DungeonConfig(File file) {
super(file);
load(YamlConfiguration.loadConfiguration(file));
}
public DungeonConfig(ConfigurationSection configFile) {
super(configFile);
load(configFile);
}
@Override
public void load(ConfigurationSection configFile) {
super.load(configFile);
/* Floors */
if (configFile.contains("floors")) {
floors = configFile.getStringList("floors");
}
if (configFile.contains("startFloor")) {
startFloor = configFile.getString("startFloor");
}
if (configFile.contains("endFloor")) {
endFloor = configFile.getString("endFloor");
}
if (configFile.contains("floorCount")) {
floorCount = configFile.getInt("floorCount");
}
if (configFile.contains("removeWhenPlayed")) {
removeWhenPlayed = configFile.getBoolean("removeWhenPlayed");
}
}
/**
* @return the startFloor
*/
public String getStartFloor() {
return startFloor;
}
/**
* @param startFloor
* the startFloor to set
*/
public void setStartFloor(String startFloor) {
this.startFloor = startFloor;
}
/**
* @return the endFloor
*/
public String getEndFloor() {
return endFloor;
}
/**
* @param endFloor
* the endFloor to set
*/
public void setEndFloor(String endFloor) {
this.endFloor = endFloor;
}
/**
* @return the floors
*/
public List<String> getFloors() {
return floors;
}
/**
* @param gameWorld
* the gameWorld to add
*/
public void addFloor(String gameWorld) {
floors.add(gameWorld);
}
/**
* @param gameWorld
* the gameWorld to remove
*/
public void removeFloor(String gameWorld) {
floors.remove(gameWorld);
}
/**
* @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;
}
}

View File

@ -1,171 +0,0 @@
package io.github.dre2n.dungeonsxl.config;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
public class MainConfig {
private String language = "en";
private boolean enableEconomy = false;
/* Tutorial */
private boolean tutorialActivated = false;
private String tutorialDungeon = "tutorial";
private String tutorialStartGroup = "default";
private String tutorialEndGroup = "player";
/* Default Dungeon Settings */
private WorldConfig defaultWorldConfig;
private List<String> editCommandWhitelist = new ArrayList<String>();
public MainConfig(File file) {
if ( !file.exists()) {
try {
file.createNewFile();
FileConfiguration configFile = new YamlConfiguration();
configFile.set("language", "en");
configFile.set("enableEconomy", true);
configFile.set("tutorialActivated", false);
configFile.set("tutorialDungeon", "tutorial");
configFile.set("tutorialStartGroup", "default");
configFile.set("tutorialEndGroup", "player");
configFile.set("tutorialEndGroup", "player");
configFile.createSection("editCommandWhitelist");
ConfigurationSection defaultDungeon = configFile.createSection("default");
defaultDungeon.set("initialLives", 3);
defaultDungeon.set("timeUntilKickOfflinePlayer", 10000);
defaultDungeon.set("keepInventoryOnEnter", false);
defaultDungeon.set("keepInventoryOnDeath", true);
defaultDungeon.set("keepInventoryOnFinish", false);
defaultDungeon.set("keepInventoryOnEscape", false);
configFile.save(file);
} catch (IOException exception) {
exception.printStackTrace();
}
} else {
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
/* Main Config */
if (configFile.contains("language")) {
language = configFile.getString("language");
}
if (configFile.contains("enableEconomy")) {
enableEconomy = configFile.getBoolean("enableEconomy");
}
if (configFile.contains("tutorial.activated")) {
tutorialActivated = configFile.getBoolean("tutorial.activated");
}
if (configFile.contains("tutorial.dungeon")) {
tutorialDungeon = configFile.getString("tutorial.dungeon");
}
if (configFile.contains("tutorial.startgroup")) {
tutorialStartGroup = configFile.getString("tutorial.startgroup");
}
if (configFile.contains("tutorial.endgroup")) {
tutorialEndGroup = configFile.getString("tutorial.endgroup");
}
if (configFile.contains("editCommandWhitelist")) {
editCommandWhitelist = configFile.getStringList("editCommandWhitelist");
}
/* Default Dungeon Config */
ConfigurationSection configSection = configFile.getConfigurationSection("default");
if (configSection != null) {
setDefaultWorldConfig(new WorldConfig(configSection));
WorldConfig.defaultConfig = defaultWorldConfig;// TODO
}
}
}
/**
* @return the language
*/
public String getLanguage() {
return language;
}
/**
* @param language
* the language to set
*/
public void setLanguage(String language) {
this.language = language;
}
/**
* @return the enableEconomy
*/
public boolean enableEconomy() {
return enableEconomy;
}
/**
* @return the tutorialActivated
*/
public boolean isTutorialActivated() {
return tutorialActivated;
}
/**
* @return the tutorialDungeon
*/
public String getTutorialDungeon() {
return tutorialDungeon;
}
/**
* @return the tutorialStartGroup
*/
public String getTutorialStartGroup() {
return tutorialStartGroup;
}
/**
* @return the tutorialEndGroup
*/
public String getTutorialEndGroup() {
return tutorialEndGroup;
}
/**
* @return the editCommandWhitelist
*/
public List<String> getEditCommandWhitelist() {
return editCommandWhitelist;
}
/**
* @return the defaultWorldConfig
*/
public WorldConfig getDefaultWorldConfig() {
return defaultWorldConfig;
}
/**
* @param defaultWorldConfig
* the defaultWorldConfig to set
*/
public void setDefaultWorldConfig(WorldConfig defaultWorldConfig) {
this.defaultWorldConfig = defaultWorldConfig;
}
}

View File

@ -1,283 +0,0 @@
package io.github.dre2n.dungeonsxl.config;
import java.io.File;
import java.io.IOException;
import java.util.Set;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
public class MessageConfig {
public enum Messages {
GROUP_CREATED("Group_Created", "&4&v1&6 created the group &4&v2&6!"),
GROUP_DISBANDED("Group_Disbanded", "&4&v1&6 disbanded the group &4&v2&6."),
GROUP_INVITED_PLAYER("Group_InvitedPlayer", "&4&v1&6 invited the player &4&v2&6 to the group &4&v3&6."),
GROUP_UNINVITED_PLAYER("Group_UninvitedPlayer", "&4&v1&6 took back the invitation for &4&v2&6 to the group &4&v3&6."),
GROUP_KICKED_PLAYER("Group_KickedPlayer", "&4&v1&6 kicked the player &4&v2&6 from the group &4&v3&6."),
GROUP_PLAYER_JOINED("Group_PlayerJoined", "&6Player &4&v1&6 has joined the group!"),
GROUP_WAVE_FINISHED("Group_WaveFinished", "&6Your group finished wave no. &4&v1&6. The next one is going to start in &4&v2&6 seconds."),
LOG_ERROR_MOB_ENCHANTMENT("Log_Error_MobEnchantment", "&4Error at loading mob.yml: Enchantment &6&v1&4 doesn't exist!"),
LOG_ERROR_MOBTYPE("Log_Error_MobType", "&4Error at loading mob.yml: Mob &6&v1&4 doesn't exist!"),
LOG_ERROR_NO_CONSOLE_COMMAND("Log_Error_NoConsoleCommand", "&6/dxl &v1&4 can not be executed as Console!"),
LOG_GENERATE_NEW_WORLD("Log_GenerateNewWorld", "&6Generate new world..."),
LOG_NEW_DUNGEON("Log_NewDungeon", "&6New Dungeon"),
LOG_WORLD_GENERATION_FINISHED("Log_WorldGenerationFinished", "&6World generation finished!"),
PLAYER_BLOCK_INFO("Player_BlockInfo", "&6Block-ID: &2&v1"),
PLAYER_CHECKPOINT_REACHED("Player_CheckpointReached", "&6Checkpoint reached!"),
PLAYER_DEATH("Player_Death", "&6You died, lives left: &2&v1"),
PLAYER_DEATH_KICK("Player_DeathKick", "&2&v1&6 died and lost his last life."),
PLAYER_FINISHED_DUNGEON("Player_FinishedDungeon", "&6You successfully finished the Dungeon!"),
PLAYER_INVITED("Player_Invited", "&4&v1&6 invited you to the group &4&v2&6."),
PLAYER_UNINVITED("Player_Uninvited", "&4&v1&6 took back your invitation to the group &4&v2&6."),
PLAYER_JOIN_GROUP("Player_JoinGroup", "&6You successfully joined the group!"),
PLAYER_KICKED("Player_Kicked", "&4You have been kicked out of the group &6&v1&4."),
PLAYER_LEAVE_GROUP("Player_LeaveGroup", "&6You have successfully left your group!"),
PLAYER_LEFT_GROUP("Player_LeftGroup", "&6Player &4&v1&6 has left the Group!"),
PLAYER_LOOT_ADDED("Player_LootAdded", "&4&v1&6 have been added to your reward inventory!"),
PLAYER_NEW_CAPTAIN("Player_NewCaptain", "&6You are now the new captain of your group."),
PLAYER_OFFLINE("Player_Offline", "&Player &4&v1&6 went offline. In &4&v2&6 seconds he will autmatically be kicked from the Dungeon!"),
PLAYER_OFFLINE_NEVER("Player_OfflineNever", "&Player &4&v1&6 went offline. He will &4not&6 be kicked from the Dungeon automatically!"),
PLAYER_PORTAL_ABORT("Player_PortalAbort", "&6Portal creation cancelled!"),
PLAYER_PORTAL_INTRODUCTION("Player_PortalIntroduction", "&6Click the two edges of the Portal with the wooden sword!"),
PLAYER_PORTAL_CREATED("Player_PortalCreated", "&6Portal created!"),
PLAYER_PORTAL_PROGRESS("Player_PortalProgress", "&6First Block, now the second one!"),
PLAYER_PROTECTED_BLOCK_DELETED("Player_ProtectedBlockDeleted", "&6Protected block deleted!"),
PLAYER_READY("Player_Ready", "&6You are now ready for the Dungeon!"),
PLAYER_SIGN_CREATED("Player_SignCreated", "&6Sign created!"),
PLAYER_SIGN_COPIED("Player_SignCopied", "&6Copied!"),
PLAYER_TREASURES("Player_Treasures", "&1Treasures"),
PLAYER_WAIT_FOR_OTHER_PLAYERS("Player_WaitForOtherPlayers", "&6Waiting for teammates..."),
CMD_BREAK_PROTECTED_MODE("Cmd_Break_ProtectedMode", "&6You may not break blocks protected by DungeonsXL anymore."),
CMD_BREAK_BREAK_MODE("Cmd_Break_BreakMode", "&6You may break a block protected by DungeonsXL."),
CMD_CHAT_DUNGEON_CHAT("Cmd_Chat_DungeonChat", "&6You have entered the Dungeon-chat"),
CMD_CHAT_NORMAL_CHAT("Cmd_Chat_NormalChat", "&6You are now in the public chat"),
CMD_CHATSPY_STOPPED("Cmd_Chatspy_Stopped", "&6You stopped spying the DXL-chat!"),
CMD_CHATSPY_START("Cmd_Chatspy_Start", "&You started spying the DXL-chat!"),
CMD_INVITE_SUCCESS("Cmd_Invite_Success", "&6Player &4&v1&6 was successfully invited to edit the Dungeon &4&v2&6!"),
CMD_LEAVE_SUCCESS("Cmd_Leave_Success", "&6You have successfully left your group!"),
CMD_LIVES("Cmd_Lives", "&4v1&6 has &4v2 &6lives left."),
CMD_MAIN_WELCOME("Cmd_Main_Welcome", "&7Welcome to &4Dungeons&fXL"),
CMD_MAIN_LOADED("Cmd_Main_Loaded", "&eMaps: &o[&v1] &eDungeons: &o[&v2] &eLoaded: &o[&v3] &ePlayers: &o[&v4]"),
CMD_MAIN_COMPATIBILITY("Cmd_Main_Compatibility", "&eInternals: &o[&v1] &eVault: &o[&v2] &eMythicMobs: &o[&v3]"),
CMD_MAIN_HELP("Cmd_Main_Help", "&7Type in &o/dxl help&r&7 for further information."),
CMD_MSG_ADDED("Cmd_Msg_Added", "&6New Messages (&4&v1&6) added!"),
CMD_MSG_UPDATED("Cmd_Msg_Updated", "&6Messages (&4&v1&6) updated!"),
CMD_RELOAD_DONE("Cmd_Reload_Done", "&7Successfully reloaded DungeonsXL."),
CMD_SAVE_SUCCESS("Cmd_Save_Success", "&6Dungeon saved!"),
CMD_UNINVITE_SUCCESS("Cmd_Uninvite_Success", "&4&v1&6 was successfully uninvited to edit the Dungeon &4&v1&6!"),
ERROR_BED("Error_Bed", "&4You cannot use a bed while in a Dungeon!"),
ERROR_CHEST_IS_OPENED("Error_ChestIsOpened", "&4This chest has already been opened."),
ERROR_CMD("Error_Cmd", "&4Commands are not allowed while in a dungeon!"),
ERROR_CMD_NOT_EXIST_1("Error_CmdNotExist1", "&4Command &6&v1&4 does not exist!"),
ERROR_CMD_NOT_EXIST_2("Error_CmdNotExist2", "&4Please enter &6/dxl help&4 for help!"),
ERROR_COOLDOWN("Error_Cooldown", "&4You can only enter this Dungeon every &6&v1&4 hours!"),
ERROR_DISPENSER("Error_Dispenser", "&4You cannot access this dispenser!"),
ERROR_DROP("Error_Drop", "&4You cannot drop safe items"),
ERROR_DUNGEON_NOT_EXIST("Error_DungeonNotExist", "&4Dungeon &6&v1&4 does not exist!"),
ERROR_ENDERCHEST("Error_Enderchest", "&4You cannot use an enderchest while in a Dungeon!"),
ERROR_IN_GROUP("Error_InGroup", "&4The player &6&v1&4 is already member of a group."),
ERROR_JOIN_GROUP("Error_JoinGroup", "&4You have to join a group first!"),
ERROR_LEAVE_DUNGEON("Error_LeaveDungeon", "&4You have to leave your current dungeon first!"),
ERROR_LEAVE_GAME("Error_LeaveGame", "&4You have to leave your game first!"),
ERROR_LEAVE_GROUP("Error_LeaveGroup", "&4You have to leave your group first!"),
ERROR_LEFT_CLICK("Error_Leftklick", "&4You have to use Left-Click on this sign!"),
ERROR_MSG_ID_NOT_EXIST("Error_MsgIdNotExist", "&4Messages with Id &6&v1&4 does not exist!"),
ERROR_MSG_FORMAT("Error_MsgFormat", "&4The Messages has to be between \"!"),
ERROR_MSG_NO_INT("Error_MsgNoInt", "&4Argument <id> has to include a number!"),
ERROR_NAME_TO_LONG("Error_NameToLong", "&4The name may not be longer than 15 characters!"),
ERROR_NO_CONSOLE_COMMAND("Error_NoConsoleCommand", "&6/dxl &v1&4 cannot be executed as console!"),
ERROR_NO_GAME("Error_NoGame", "&4You currently do not take part in a game."),
ERROR_NO_LEAVE_IN_TUTORIAL("Error_NoLeaveInTutorial", "&4You cannot use this command in the tutorial!"),
ERROR_NO_PERMISSIONS("Error_NoPermissions", "&4You have no permission to do this!"),
ERROR_NO_PLAYER_COMMAND("Error_NoPlayerCommand", "&6/dxl &v1&4 cannot be executed as player!"),
ERROR_NO_PROTECTED_BLOCK("Error_NoDXLBlock", "&4This is not a block protected by DungeonsXL!"),
ERROR_NO_SUCH_GROUP("Error_NoSuchGroup", "&4The group &6&v1&4 does not exist!"),
ERROR_NO_SUCH_PLAYER("Error_NoSuchPlayer", "&4The player &6&v1&4 does not exist!"),
ERROR_NOT_CAPTAIN("Error_NotCaptain", "&4You are not the captain of your group!"),
ERROR_NOT_IN_DUNGEON("Error_NotInDungeon", "&4You are not in a dungeon!"),
ERROR_NOT_IN_GROUP("Error_NotInGroup", "&4The player &6&v1&4 is not member of the group &6&v2&v4."),
ERROR_NOT_INVITED("Error_NotInvited", "&4You are not invited to the group &6&v1&4."),
ERROR_NOT_SAVED("Error_NotSaved", "&4The map &6&v1&4 has not been saved to the &6DungeonsXL/maps/ &4folder yet!"),
ERROR_TUTORIAL_NOT_EXIST("Error_TutorialNotExist", "&4Tutorial dungeon does not exist!"),
ERROR_READY("Error_Ready", "&4Choose your class first!"),
ERROR_REQUIREMENTS("Error_Requirements", "&4You don't fulfill the requirements for this Dungeon!"),
ERROR_SIGN_WRONG_FORMAT("Error_SignWrongFormat", "&4The sign is not written correctly!"),
HELP_CMD_BREAK("Help_Cmd_Break", "/dxl break - Break a block protected by DungeonsXL"),
HELP_CMD_CHAT("Help_Cmd_Chat", "/dxl chat - Change the chat mode"),
HELP_CMD_CHATSPY("Help_Cmd_Chatspy", "/dxl chatspy - Dis/enables the spymode"),
HELP_CMD_CREATE("Help_Cmd_Create", "/dxl create <name> - Creates a new dungeon"),
HELP_CMD_EDIT("Help_Cmd_Edit", "/dxl edit <name> - Edit an existing dungeon"),
HELP_CMD_ESCAPE("Help_Cmd_Escape", "/dxl escape - Leaves the current dungeon, without saving!"),
HELP_CMD_GAME("Help_Cmd_Game", "/dxl game - Shows information about the current game session"),
HELP_CMD_GROUP("Help_Cmd_Group", "/dxl group - Shows group command help"),
HELP_CMD_GROUP_CREATE("Help_Cmd_GroupCreate", "/dxl group create [group] - Creates a new group"),
HELP_CMD_GROUP_DISBAND("Help_Cmd_GroupDisband", "/dxl group disband ([group]) - Disbands a group"),
HELP_CMD_GROUP_INVITE("Help_Cmd_GroupInvite", "/dxl group invite [player]- Invites someone to your group"),
HELP_CMD_GROUP_UNINVITE("Help_Cmd_GroupUninvite", "/dxl group uninvite [player] - Takes back an invitation to your group"),
HELP_CMD_GROUP_JOIN("Help_Cmd_GroupJoin", "/dxl group join [group]- Join a group"),
HELP_CMD_GROUP_KICK("Help_Cmd_GroupKick", "/dxl group kick [player] - Kicks a player"),
HELP_CMD_GROUP_SHOW("Help_Cmd_GroupShow", "/dxl group show [group] - Shows a group"),
HELP_CMD_HELP("Help_Cmd_Help", "/dxl help <page> - Shows the help page"),
HELP_CMD_INVITE("Help_Cmd_Invite", "/dxl invite <player> <dungeon> - Invite a player to edit a dungeon"),
HELP_CMD_LEAVE("Help_Cmd_Leave", "/dxl leave - Leaves the current dungeon"),
HELP_CMD_LIST("Help_Cmd_List", "/dxl list ([dungeon|map|loaded]) ([dungeon]) - Lists all dungeons"),
HELP_CMD_LIVES("Help_Cmd_Lives", "/dxl lives <player> - Shows the lives a player has left"),
HELP_CMD_MAIN("Help_Cmd_Main", "/dxl - General status information"),
HELP_CMD_MSG("Help_Cmd_Msg", "/dxl msg <id> '[msg]' - Show or edit a message"),
HELP_CMD_PLAY("Help_Cmd_Play", "/dxl play ([dungeon|map]) [name] - Allows the player to join a game without a portal"),
HELP_CMD_PORTAL("Help_Cmd_Portal", "/dxl portal - Creates a portal that leads into a dungeon"),
HELP_CMD_RELOAD("Help_Cmd_Reload", "/dxl reload - Reloads the plugin"),
HELP_CMD_SAVE("Help_Cmd_Save", "/dxl save - Saves the current dungeon"),
HELP_CMD_TEST("Help_Cmd_Test", "/dxl test - Starts the game in test mode"),
HELP_CMD_UNINVITE("Help_Cmd_Uninvite", "/dxl uninvite <player> <dungeon> - Uninvite a player to edit a dungeon"),
REQUIREMENT_FEE("Requirement_Fee", "&6You have been charged &4&v1 &6for entering the dungeon."),
REWARD_MONEY("Reward_Money", "&6You received &4&v1 &6for finishing the dungeon.");
private String identifier;
private String message;
Messages(String identifier, String message) {
this.identifier = identifier;
this.message = message;
}
/**
* @return the identifier
*/
public String getIdentifier() {
return identifier;
}
/**
* @return the message
*/
public String getMessage() {
return message;
}
/**
* @param message
* the message to set
*/
public void setMessage(String message) {
this.message = message;
}
// Static
/**
* @param identifer
* the identifer to set
*/
public static Messages getByIdentifier(String identifier) {
for (Messages message : Messages.values()) {
if (message.getIdentifier().equals(identifier)) {
return message;
}
}
return null;
}
/**
* @return a FileConfiguration containing all messages
*/
public static FileConfiguration toConfig() {
FileConfiguration config = new YamlConfiguration();
for (Messages message : Messages.values()) {
config.set(message.getIdentifier(), message.getMessage());
}
return config;
}
}
private File file;
private FileConfiguration config;
public MessageConfig(File file) {
this.file = file;
if ( !file.exists()) {
try {
file.createNewFile();
config = Messages.toConfig();
config.save(file);
} catch (IOException exception) {
exception.printStackTrace();
}
} else {
config = YamlConfiguration.loadConfiguration(file);
load();
}
}
public void load() {
if (config != null) {
Set<String> keySet = config.getKeys(false);
for (String key : keySet) {
Messages message = Messages.getByIdentifier(key);
if (message != null) {
message.setMessage(config.getString(key));
}
}
}
}
public boolean changed() {
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
if ( !Messages.toConfig().getValues(false).equals(config.getValues(false))) {
return true;
} else {
return false;
}
}
public void save() {
if ( !changed()) {
return;
}
String filePath = file.getPath();
File oldMessages = new File(filePath.substring(0, filePath.length() - 4) + "_old.yml");
try {
Messages.toConfig().save(oldMessages);
} catch (IOException exception) {
exception.printStackTrace();
}
}
public String getMessage(Messages message, String... args) {
String output = message.getMessage();
int i = 0;
for (String arg : args) {
i++;
if (arg != null) {
output = output.replace("&v" + i, arg);
} else {
output = output.replace("&v" + i, "null");
}
}
return output;
}
}

View File

@ -1,634 +0,0 @@
package io.github.dre2n.dungeonsxl.config;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.game.GameType;
import io.github.dre2n.dungeonsxl.mob.DMobType;
import io.github.dre2n.dungeonsxl.player.DClass;
import io.github.dre2n.dungeonsxl.requirement.FeeRequirement;
import io.github.dre2n.dungeonsxl.requirement.Requirement;
import io.github.dre2n.dungeonsxl.reward.Reward;
import io.github.dre2n.dungeonsxl.util.NumberUtil;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import org.apache.commons.lang3.EnumUtils;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
public class WorldConfig {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
@Deprecated
public static WorldConfig defaultConfig = new WorldConfig();
private File file;
private List<String> invitedPlayers = new ArrayList<String>();
private boolean keepInventory = false;
private boolean keepInventoryOnEnter = false;
private boolean keepInventoryOnEscape = false;
private boolean keepInventoryOnFinish = false;
private boolean keepInventoryOnDeath = true;
private GameMode gameMode = GameMode.SURVIVAL;
private boolean build = false;
private boolean playerVersusPlayer = false;
private boolean friendlyFire = false;
private List<DClass> dClasses = new ArrayList<DClass>();
private Map<Integer, String> msgs = new HashMap<Integer, String>();
private List<Material> secureObjects = new ArrayList<Material>();
private int initialLives = 3;
private boolean isLobbyDisabled = false;
private int timeToNextPlay = 0;
private int timeToNextLoot = 0;
private int timeUntilKickOfflinePlayer = -1;
private List<Requirement> requirements = new ArrayList<Requirement>();
private List<Reward> rewards = new ArrayList<Reward>();
private List<String> finishedOne;
private List<String> finishedAll;
private int timeLastPlayed = 0;
private GameType forcedGameType;
// MobTypes
private Set<DMobType> mobTypes = new HashSet<DMobType>();
private List<String> gameCommandWhitelist = new ArrayList<String>();
public WorldConfig() {
}
public WorldConfig(File file) {
this.file = file;
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
load(configFile);
}
public WorldConfig(ConfigurationSection configFile) {
load(configFile);
}
// Load & Save
@SuppressWarnings("deprecation")
public void load(ConfigurationSection configFile) {
/* Classes */
ConfigurationSection configSectionClasses = configFile.getConfigurationSection("classes");
if (configSectionClasses != null) {
Set<String> list = configSectionClasses.getKeys(false);
for (String className : list) {
String name = className;
boolean hasDog = configSectionClasses.getBoolean(className + ".dog");
/* Items */
List<String> items = configSectionClasses.getStringList(className + ".items");
CopyOnWriteArrayList<ItemStack> itemStacks = new CopyOnWriteArrayList<ItemStack>();
for (String item : items) {
String[] itemSplit = item.split(",");
if (itemSplit.length > 0) {
int itemId = 0, itemData = 0, itemSize = 1, itemLvlEnchantment = 1;
Enchantment itemEnchantment = null;
// Check Id & Data
String[] idAndData = itemSplit[0].split("/");
itemId = NumberUtil.parseInt(idAndData[0]);
if (idAndData.length > 1) {
itemData = NumberUtil.parseInt(idAndData[1]);
}
// Size
if (itemSplit.length > 1) {
itemSize = NumberUtil.parseInt(itemSplit[1]);
}
// Enchantment
if (itemSplit.length > 2) {
String[] enchantmentSplit = itemSplit[2].split("/");
itemEnchantment = Enchantment.getByName(enchantmentSplit[0]);
if (enchantmentSplit.length > 1) {
itemLvlEnchantment = NumberUtil.parseInt(enchantmentSplit[1]);
}
}
// Add Item to Stacks
ItemStack itemStack = new ItemStack(itemId, itemSize, (short) itemData);
if (itemEnchantment != null) {
itemStack.addEnchantment(itemEnchantment, itemLvlEnchantment);
}
itemStacks.add(itemStack);
}
}
/* Create Class */
dClasses.add(new DClass(name, itemStacks, hasDog));
}
}
/* Messages */
ConfigurationSection configSectionMessages = configFile.getConfigurationSection("message");
if (configSectionMessages != null) {
Set<String> list = configSectionMessages.getKeys(false);
for (String messagePath : list) {
int messageId = NumberUtil.parseInt(messagePath);
msgs.put(messageId, configSectionMessages.getString(messagePath));
}
}
/* Secure Objects */
if (configFile.contains("secureObjects")) {
List<String> secureObjectList = configFile.getStringList("secureObjects");
for (String id : secureObjectList) {
if (Material.getMaterial(NumberUtil.parseInt(id)) != null) {
secureObjects.add(Material.getMaterial(NumberUtil.parseInt(id)));
} else if (Material.getMaterial(id) != null) {
secureObjects.add(Material.getMaterial(id));
}
}
}
/* Invited Players */
if (configFile.contains("invitedPlayers")) {
invitedPlayers = configFile.getStringList("invitedPlayers");
}
/* Keep Inventory */
if (configFile.contains("keepInventory")) {
if ( !configFile.contains("keepInventoryOnEnter")) {
keepInventoryOnEnter = configFile.getBoolean("keepInventory");
}
if ( !configFile.contains("keepInventoryOnEscape")) {
keepInventoryOnEscape = configFile.getBoolean("keepInventory");
}
if ( !configFile.contains("keepInventoryOnFinish")) {
keepInventoryOnFinish = configFile.getBoolean("keepInventory");
}
} else {
if (plugin.getDefaultConfig().keepInventory) {
keepInventoryOnEnter = plugin.getDefaultConfig().keepInventory;
keepInventoryOnEscape = plugin.getDefaultConfig().keepInventory;
keepInventoryOnFinish = plugin.getDefaultConfig().keepInventory;
}
}
if (configFile.contains("keepInventoryOnEnter")) {
keepInventoryOnEnter = configFile.getBoolean("keepInventoryOnEnter");
} else {
keepInventoryOnEnter = plugin.getDefaultConfig().keepInventoryOnEnter;
}
if (configFile.contains("keepInventoryOnEscape")) {
keepInventoryOnEscape = configFile.getBoolean("keepInventoryOnEscape");
} else {
keepInventoryOnEscape = plugin.getDefaultConfig().keepInventoryOnEscape;
}
if (configFile.contains("keepInventoryOnFinish")) {
keepInventoryOnFinish = configFile.getBoolean("keepInventoryOnFinish");
} else {
keepInventoryOnFinish = plugin.getDefaultConfig().keepInventoryOnFinish;
}
if (configFile.contains("keepInventoryOnDeath")) {
keepInventoryOnDeath = configFile.getBoolean("keepInventoryOnDeath");
} else {
keepInventoryOnDeath = plugin.getDefaultConfig().keepInventoryOnDeath;
}
/* Build */
if (configFile.contains("build")) {
build = configFile.getBoolean("build");
} else {
build = plugin.getDefaultConfig().build;
}
/* GameMode */
if (configFile.contains("gameMode")) {
if (EnumUtils.isValidEnum(GameMode.class, configFile.getString("gameMode").toUpperCase())) {
gameMode = GameMode.valueOf(configFile.getString("gameMode"));
} else {
gameMode = GameMode.getByValue(configFile.getInt("gameMode"));
}
} else {
gameMode = plugin.getDefaultConfig().gameMode;
}
/* PvP */
if (configFile.contains("playerVersusPlayer")) {
playerVersusPlayer = configFile.getBoolean("playerVersusPlayer");
} else {
playerVersusPlayer = plugin.getDefaultConfig().playerVersusPlayer;
}
/* Friendly fire */
if (configFile.contains("friendlyFire")) {
friendlyFire = configFile.getBoolean("friendlyFire");
} else {
friendlyFire = plugin.getDefaultConfig().friendlyFire;
}
/* Lives */
if (configFile.contains("initialLives")) {
initialLives = configFile.getInt("initialLives");
} else {
initialLives = plugin.getDefaultConfig().getInitialLives();
}
/* Lobby */
if (configFile.contains("isLobbyDisabled")) {
isLobbyDisabled = configFile.getBoolean("isLobbyDisabled");
} else {
isLobbyDisabled = plugin.getDefaultConfig().isLobbyDisabled;
}
/* Times */
if (configFile.contains("timeToNextPlay")) {
timeToNextPlay = configFile.getInt("timeToNextPlay");
} else {
timeToNextPlay = plugin.getDefaultConfig().timeToNextPlay;
}
if (configFile.contains("timeToNextLoot")) {
timeToNextLoot = configFile.getInt("timeToNextLoot");
} else {
timeToNextLoot = plugin.getDefaultConfig().timeToNextLoot;
}
if (configFile.contains("timeUntilKickOfflinePlayer")) {
timeUntilKickOfflinePlayer = configFile.getInt("timeUntilKickOfflinePlayer");
} else {
timeUntilKickOfflinePlayer = plugin.getDefaultConfig().timeUntilKickOfflinePlayer;
}
/* Dungeon Requirements */
if (configFile.contains("requirements")) {
for (String identifier : configFile.getConfigurationSection("requirements").getKeys(false)) {
Requirement requirement = Requirement.create(plugin.getRequirementTypes().getByIdentifier(identifier));
// Check for built-in requirements
if (requirement instanceof FeeRequirement) {
((FeeRequirement) requirement).setFee(configFile.getDouble("requirements.fee"));
}
requirements.add(requirement);
}
} else {
requirements = plugin.getDefaultConfig().requirements;
}
if (configFile.contains("mustFinishOne")) {
finishedOne = configFile.getStringList("mustFinishOne");
} else {
finishedOne = new ArrayList<String>();
}
if (configFile.contains("mustFinishAll")) {
finishedAll = configFile.getStringList("mustFinishAll");
} else {
finishedAll = new ArrayList<String>();
}
if (configFile.contains("timeLastPlayed")) {
timeLastPlayed = configFile.getInt("timeLastPlayed");
}
/* Mobtypes */
configSectionMessages = configFile.getConfigurationSection("mobTypes");
mobTypes = DMobType.load(configSectionMessages);
if (configFile.contains("gameCommandWhitelist")) {
gameCommandWhitelist = configFile.getStringList("gameCommandWhitelist");
} else {
gameCommandWhitelist = plugin.getDefaultConfig().gameCommandWhitelist;
}
if (configFile.contains("forcedGameType")) {
GameType gameType = plugin.getGameTypes().getByName(configFile.getString("forcedGameType"));
if (gameType != null) {
forcedGameType = gameType;
} else {
forcedGameType = null;
}
}
}
@SuppressWarnings("deprecation")
public void save() {
if (file == null) {
return;
}
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
// Messages
for (int msgs : this.msgs.keySet()) {
configFile.set("message." + msgs, this.msgs.get(msgs));
}
// Secure Objects
CopyOnWriteArrayList<Integer> secureObjectsids = new CopyOnWriteArrayList<Integer>();
for (Material mat : secureObjects) {
secureObjectsids.add(mat.getId());
}
configFile.set("secureObjects", secureObjectsids);
// Invited Players
configFile.set("invitedPlayers", invitedPlayers);
try {
configFile.save(file);
} catch (IOException exception) {
exception.printStackTrace();
}
}
// Getters and Setters
/**
* @return the UUIDs or names of the players invited to edit the map
*/
public CopyOnWriteArrayList<String> getInvitedPlayers() {
CopyOnWriteArrayList<String> tmpInvitedPlayers = new CopyOnWriteArrayList<String>();
tmpInvitedPlayers.addAll(invitedPlayers);
tmpInvitedPlayers.addAll(plugin.getDefaultConfig().invitedPlayers);
return tmpInvitedPlayers;
}
/**
* @param uuid
* the player's unique ID
*/
public void addInvitedPlayer(String uuid) {
invitedPlayers.add(uuid);
}
/**
* @param uuid
* the player's unique ID
* @param name
* the player's name
*/
public void removeInvitedPlayers(String uuid, String name) {
invitedPlayers.remove(uuid);
// remove player from a 0.9.1 and lower file
invitedPlayers.remove(name);
}
/**
* @return the classes
*/
public List<DClass> getClasses() {
if (dClasses != null) {
if ( !dClasses.isEmpty()) {
return dClasses;
}
}
return plugin.getDefaultConfig().dClasses;
}
/**
* @param name
* the name of the class
*/
public DClass getClass(String name) {
for (DClass dClass : dClasses) {
if (dClass.getName().equals(name)) {
return dClass;
}
}
for (DClass dClass : plugin.getDefaultConfig().dClasses) {
if (dClass.getName().equals(name)) {
return dClass;
}
}
return null;
}
/**
* @param id
* the id of the message
* @param returnMainConfig
* if a default value shall be returned
*/
public String getMsg(int id, boolean returnMainConfig) {
String msg = msgs.get(id);
if (msg != null) {
return msgs.get(id);
}
if (returnMainConfig) {
return plugin.getDefaultConfig().msgs.get(id);
}
return null;
}
/**
* @param msg
* the message to set
* @param id
* the ID of the message
*/
public void setMsg(String msg, int id) {
msgs.put(id, msg);
}
/**
* @return the objects to get passed to another player of the group when this player leaves
*/
public CopyOnWriteArrayList<Material> getSecureObjects() {
CopyOnWriteArrayList<Material> tmpSecureObjects = new CopyOnWriteArrayList<Material>();
tmpSecureObjects.addAll(secureObjects);
tmpSecureObjects.addAll(plugin.getDefaultConfig().secureObjects);
return tmpSecureObjects;
}
/**
* @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 the gameMode
*/
public GameMode getGameMode() {
return gameMode;
}
/**
* @return if players may build
*/
public boolean canBuild() {
return build;
}
/**
* @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 if the lobby is disabled
*/
public boolean isLobbyDisabled() {
return isLobbyDisabled;
}
/**
* @return the time until a player can play again
*/
public int getTimeToNextPlay() {
return timeToNextPlay;
}
/**
* @return the time until a player can get loot again
*/
public int getTimeToNextLoot() {
return timeToNextLoot;
}
/**
* @return the time until a player gets kicked from his group if he is offline
*/
public int getTimeUntilKickOfflinePlayer() {
return timeUntilKickOfflinePlayer;
}
/**
* @return the requirements
*/
public List<Requirement> getRequirements() {
return requirements;
}
/**
* @return the rewards
*/
public List<Reward> getRewards() {
return rewards;
}
/**
* @return the timeLastPlayed
*/
public int getTimeLastPlayed() {
return timeLastPlayed;
}
/**
* @return all maps needed to be finished to play this map
*/
public List<String> getFinishedAll() {
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() {
List<String> merge = new ArrayList<String>();
merge.addAll(finishedAll);
merge.addAll(finishedOne);
return merge;
}
/**
* @return the mobTypes
*/
public Set<DMobType> getMobTypes() {
return mobTypes;
}
/**
* @return the gameCommandWhitelist
*/
public List<String> getGameCommandWhitelist() {
return gameCommandWhitelist;
}
/**
* @return the forcedGameType
*/
public GameType getForcedGameType() {
return forcedGameType;
}
/**
* @param forcedGameType
* the forcedGameType to set
*/
public void setForcedGameType(GameType forcedGameType) {
this.forcedGameType = forcedGameType;
}
}

View File

@ -1,111 +0,0 @@
package io.github.dre2n.dungeonsxl.dungeon;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
public class DLootInventory {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
private Inventory inventory;
private InventoryView inventoryView;
private Player player;
private long time;
public DLootInventory(Player player, ItemStack[] itemStacks) {
plugin.getDLootInventories().add(this);
inventory = Bukkit.createInventory(player, 54, ChatColor.translateAlternateColorCodes('&', plugin.getMessageConfig().getMessage(Messages.PLAYER_TREASURES)));
for (ItemStack itemStack : itemStacks) {
if (itemStack != null) {
inventory.addItem(itemStack);
}
}
this.player = player;
}
/**
* @return the inventory
*/
public Inventory getInventory() {
return inventory;
}
/**
* @param inventory
* the inventory to set
*/
public void setInventory(Inventory inventory) {
this.inventory = inventory;
}
/**
* @return the inventoryView
*/
public InventoryView getInventoryView() {
return inventoryView;
}
/**
* @param inventoryView
* the inventoryView to set
*/
public void setInventoryView(InventoryView inventoryView) {
this.inventoryView = inventoryView;
}
/**
* @return the player
*/
public Player getPlayer() {
return player;
}
/**
* @param player
* the player to set
*/
public void setPlayer(Player player) {
this.player = player;
}
/**
* @return the time
*/
public long getTime() {
return time;
}
/**
* @param time
* the time to set
*/
public void setTime(long time) {
this.time = time;
}
// Static
/**
* @param player
* the player whose DLootIntentory will be returned
*/
public static DLootInventory getByPlayer(Player player) {
for (DLootInventory inventory : plugin.getDLootInventories()) {
if (inventory.player == player) {
return inventory;
}
}
return null;
}
}

View File

@ -1,38 +0,0 @@
package io.github.dre2n.dungeonsxl.dungeon;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DungeonConfig;
import java.io.File;
public class Dungeon {
private String name;
private DungeonConfig config;
public Dungeon(File file) {
this.name = file.getName().replaceAll(".yml", "");
this.config = new DungeonConfig(file);
}
public Dungeon(String name) {
this.name = name;
this.config = new DungeonConfig(new File(DungeonsXL.getPlugin().getDataFolder() + "/dungeons", name + ".yml"));
System.out.println("Dungeon" + config.getFloors());
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the config
*/
public DungeonConfig getConfig() {
return config;
}
}

View File

@ -1,74 +0,0 @@
package io.github.dre2n.dungeonsxl.dungeon;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class Dungeons {
private List<Dungeon> dungeons = new ArrayList<Dungeon>();
public Dungeons() {
File folder = new File(DungeonsXL.getPlugin().getDataFolder() + "/dungeons");
if ( !folder.exists()) {
folder.mkdir();
}
for (File file : folder.listFiles()) {
dungeons.add(new Dungeon(file));
}
}
/**
* @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 getDungeon(String name) {
for (Dungeon dungeon : dungeons) {
if (dungeon.getName().equals(name)) {
return dungeon;
}
}
return null;
}
/**
* @param name
* the name of the Dungeon
* @return the Dungeon that has the name
*/
public Dungeon loadDungeon(String name) {
Dungeon dungeon = new Dungeon(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);
}
}

View File

@ -1,460 +0,0 @@
package io.github.dre2n.dungeonsxl.dungeon;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.event.editworld.EditWorldGenerateEvent;
import io.github.dre2n.dungeonsxl.event.editworld.EditWorldLoadEvent;
import io.github.dre2n.dungeonsxl.event.editworld.EditWorldSaveEvent;
import io.github.dre2n.dungeonsxl.event.editworld.EditWorldUnloadEvent;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.FileUtil;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
public class EditWorld {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
// Variables
private World world;
private String owner;
private String name;
private String mapName;
private int id;
private Location lobby;
private CopyOnWriteArrayList<String> invitedPlayers = new CopyOnWriteArrayList<String>();
private CopyOnWriteArrayList<Block> sign = new CopyOnWriteArrayList<Block>();
public EditWorld() {
plugin.getEditWorlds().add(this);
// ID
id = -1;
int i = -1;
while (id == -1) {
i++;
boolean exist = false;
for (EditWorld editWorld : plugin.getEditWorlds()) {
if (editWorld.id == i) {
exist = true;
break;
}
}
if ( !exist) {
id = i;
}
}
name = "DXL_Edit_" + id;
}
/**
* @return the world
*/
public World getWorld() {
return world;
}
/**
* @param world
* the world to set
*/
public void setWorld(World world) {
this.world = world;
}
/**
* @return the owner
*/
public String getOwner() {
return owner;
}
/**
* @param owner
* the owner to set
*/
public void setOwner(String owner) {
this.owner = owner;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the mapName
*/
public String getMapName() {
return mapName;
}
/**
* @param mapName
* the mapName to set
*/
public void setMapName(String mapName) {
this.mapName = mapName;
}
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id
* the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the lobby
*/
public Location getLobby() {
return lobby;
}
/**
* @param lobby
* the lobby to set
*/
public void setLobby(Location lobby) {
this.lobby = lobby;
}
/**
* @return the invitedPlayers
*/
public CopyOnWriteArrayList<String> getInvitedPlayers() {
return invitedPlayers;
}
/**
* @param invitedPlayers
* the invitedPlayers to set
*/
public void setInvitedPlayers(CopyOnWriteArrayList<String> invitedPlayers) {
this.invitedPlayers = invitedPlayers;
}
/**
* @return the sign
*/
public CopyOnWriteArrayList<Block> getSign() {
return sign;
}
/**
* @param sign
* the sign to set
*/
public void setSign(CopyOnWriteArrayList<Block> sign) {
this.sign = sign;
}
public void generate() {
WorldCreator creator = WorldCreator.name(name);
creator.type(WorldType.FLAT);
creator.generateStructures(false);
EditWorldGenerateEvent event = new EditWorldGenerateEvent(this);
if (event.isCancelled()) {
return;
}
world = plugin.getServer().createWorld(creator);
}
public void save() {
EditWorldSaveEvent event = new EditWorldSaveEvent(this);
if (event.isCancelled()) {
return;
}
world.save();
File dir = new File("DXL_Edit_" + id);
FileUtil.copyDirectory(dir, new File(plugin.getDataFolder(), "/maps/" + mapName));
FileUtil.deleteUnusedFiles(new File(plugin.getDataFolder(), "/maps/" + mapName));
try {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(new File(plugin.getDataFolder(), "/maps/" + mapName + "/DXLData.data")));
out.writeInt(sign.size());
for (Block sign : this.sign) {
out.writeInt(sign.getX());
out.writeInt(sign.getY());
out.writeInt(sign.getZ());
}
out.close();
} catch (IOException exception) {
}
}
public void checkSign(Block block) {
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
String[] lines = sign.getLines();
if (lines[0].equalsIgnoreCase("[lobby]")) {
lobby = block.getLocation();
}
}
}
public void delete() {
EditWorldUnloadEvent event = new EditWorldUnloadEvent(this, true);
if (event.isCancelled()) {
return;
}
plugin.getEditWorlds().remove(this);
for (Player player : world.getPlayers()) {
DPlayer dPlayer = DPlayer.getByPlayer(player);
dPlayer.leave();
}
plugin.getServer().unloadWorld(world, true);
File dir = new File("DXL_Edit_" + id);
FileUtil.copyDirectory(dir, new File(plugin.getDataFolder(), "/maps/" + mapName));
FileUtil.deleteUnusedFiles(new File(plugin.getDataFolder(), "/maps/" + mapName));
FileUtil.removeDirectory(dir);
}
public void deleteNoSave() {
EditWorldUnloadEvent event = new EditWorldUnloadEvent(this, false);
if (event.isCancelled()) {
return;
}
plugin.getEditWorlds().remove(this);
for (Player player : world.getPlayers()) {
DPlayer dPlayer = DPlayer.getByPlayer(player);
dPlayer.leave();
}
File dir = new File("DXL_Edit_" + id);
FileUtil.copyDirectory(dir, new File(plugin.getDataFolder(), "/maps/" + mapName));
FileUtil.deleteUnusedFiles(new File(plugin.getDataFolder(), "/maps/" + mapName));
plugin.getServer().unloadWorld(world, true);
FileUtil.removeDirectory(dir);
}
public void sendMessage(String message) {
for (DPlayer dPlayer : DPlayer.getByWorld(world)) {
MessageUtil.sendMessage(dPlayer.getPlayer(), message);
}
}
// Static
public static EditWorld getByWorld(World world) {
for (EditWorld editWorld : plugin.getEditWorlds()) {
if (editWorld.world.equals(world)) {
return editWorld;
}
}
return null;
}
public static EditWorld getByName(String name) {
for (EditWorld editWorld : plugin.getEditWorlds()) {
if (editWorld.mapName.equalsIgnoreCase(name)) {
return editWorld;
}
}
return null;
}
public static void deleteAll() {
for (EditWorld editWorld : plugin.getEditWorlds()) {
editWorld.delete();
}
}
public static EditWorld load(String name) {
EditWorldLoadEvent event = new EditWorldLoadEvent(name);
if (event.isCancelled()) {
return null;
}
for (EditWorld editWorld : plugin.getEditWorlds()) {
if (editWorld.mapName.equalsIgnoreCase(name)) {
return editWorld;
}
}
File file = new File(plugin.getDataFolder(), "/maps/" + name);
if (file.exists()) {
EditWorld editWorld = new EditWorld();
editWorld.mapName = name;
// World
FileUtil.copyDirectory(file, new File("DXL_Edit_" + editWorld.id));
// Id File
File idFile = new File("DXL_Edit_" + editWorld.id + "/.id_" + name);
try {
idFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
editWorld.world = plugin.getServer().createWorld(WorldCreator.name("DXL_Edit_" + editWorld.id));
try {
ObjectInputStream os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder(), "/maps/" + editWorld.mapName + "/DXLData.data")));
int length = os.readInt();
for (int i = 0; i < length; i++) {
int x = os.readInt();
int y = os.readInt();
int z = os.readInt();
Block block = editWorld.world.getBlockAt(x, y, z);
editWorld.checkSign(block);
editWorld.sign.add(block);
}
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return editWorld;
}
return null;
}
public static boolean exists(String name) {
// Cheack Loaded EditWorlds
for (EditWorld editWorld : plugin.getEditWorlds()) {
if (editWorld.mapName.equalsIgnoreCase(name)) {
return true;
}
}
// Cheack Unloaded Worlds
File file = new File(plugin.getDataFolder(), "/maps/" + name);
if (file.exists()) {
return true;
}
return false;
}
// Invite
public static boolean addInvitedPlayer(String editWorldName, UUID uuid) {
if ( !exists(editWorldName)) {
return false;
}
File file = new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml");
if ( !file.exists()) {
try {
file.createNewFile();
} catch (IOException exception) {
exception.printStackTrace();
return false;
}
}
WorldConfig config = new WorldConfig(file);
config.addInvitedPlayer(uuid.toString());
config.save();
return true;
}
public static boolean removeInvitedPlayer(String editWorldName, UUID uuid, String name) {
if ( !exists(editWorldName)) {
return false;
}
File file = new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml");
if ( !file.exists()) {
return false;
}
WorldConfig config = new WorldConfig(file);
config.removeInvitedPlayers(uuid.toString(), name.toLowerCase());
config.save();
// Kick Player
EditWorld editWorld = EditWorld.getByName(editWorldName);
if (editWorld != null) {
DPlayer player = DPlayer.getByName(name);
if (player != null) {
if (editWorld.world.getPlayers().contains(player.getPlayer())) {
player.leave();
}
}
}
return true;
}
public static boolean isInvitedPlayer(String editWorldName, UUID uuid, String name) {
if ( !exists(editWorldName)) {
return false;
}
File file = new File(plugin.getDataFolder() + "/maps/" + editWorldName, "config.yml");
if ( !file.exists()) {
return false;
}
WorldConfig config = new WorldConfig(file);
// get player from both a 0.9.1 and lower and 0.9.2 and higher file
if (config.getInvitedPlayers().contains(name.toLowerCase()) || config.getInvitedPlayers().contains(uuid.toString())) {
return true;
} else {
return false;
}
}
}

View File

@ -1,81 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dgroup;
import io.github.dre2n.dungeonsxl.player.DGroup;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class DGroupCreateEvent extends DGroupEvent implements Cancellable {
public enum Cause {
COMMAND,
GROUP_SIGN,
CUSTOM
}
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private Player creator;
private Cause cause;
public DGroupCreateEvent(DGroup dGroup, Player creator, Cause cause) {
super(dGroup);
this.creator = creator;
this.cause = cause;
}
/**
* @return the creator
*/
public Player getCreator() {
return creator;
}
/**
* @param creator
* the creator to set
*/
public void setCreator(Player creator) {
this.creator = creator;
}
/**
* @return the cause
*/
public Cause getCause() {
return cause;
}
/**
* @param cause
* the cause to set
*/
public void setCause(Cause cause) {
this.cause = cause;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,86 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dgroup;
import io.github.dre2n.dungeonsxl.player.DGroup;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class DGroupDisbandEvent extends DGroupEvent implements Cancellable {
public enum Cause {
COMMAND,
DUNGEON_FINISHED,
CUSTOM
}
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private Player disbander;
private Cause cause;
public DGroupDisbandEvent(DGroup dGroup, Cause cause) {
super(dGroup);
this.cause = cause;
}
public DGroupDisbandEvent(DGroup dGroup, Player disbander, Cause cause) {
super(dGroup);
this.disbander = disbander;
this.cause = cause;
}
/**
* @return the disbander
*/
public Player getDisbander() {
return disbander;
}
/**
* @param disbander
* the disbander to set
*/
public void setDisbander(Player disbander) {
this.disbander = disbander;
}
/**
* @return the cause
*/
public Cause getCause() {
return cause;
}
/**
* @param cause
* the cause to set
*/
public void setCause(Cause cause) {
this.cause = cause;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,30 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dgroup;
import io.github.dre2n.dungeonsxl.player.DGroup;
import org.bukkit.event.Event;
public abstract class DGroupEvent extends Event {
private DGroup dGroup;
public DGroupEvent(DGroup dGroup) {
this.dGroup = dGroup;
}
/**
* @return the dGroup
*/
public DGroup getDGroup() {
return dGroup;
}
/**
* @param dGroup
* the dGroup to set
*/
public void setDGroup(DGroup dGroup) {
this.dGroup = dGroup;
}
}

View File

@ -1,36 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dgroup;
import io.github.dre2n.dungeonsxl.player.DGroup;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class DGroupFinishDungeonEvent extends DGroupEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
public DGroupFinishDungeonEvent(DGroup dGroup) {
super(dGroup);
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,72 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dgroup;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class DGroupFinishFloorEvent extends DGroupEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private GameWorld finished;
private String next;
public DGroupFinishFloorEvent(DGroup dGroup, GameWorld finished, String next) {
super(dGroup);
this.finished = finished;
this.next = next;
}
/**
* @return the finished
*/
public GameWorld getFinished() {
return finished;
}
/**
* @param finished
* the name of the GameWorld to set
*/
public void setFinished(GameWorld finished) {
this.finished = finished;
}
/**
* @return the next
*/
public String getNext() {
return next;
}
/**
* @param next
* the name of the GameWorld to set
*/
public void setNext(String next) {
this.next = next;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,91 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dgroup;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.reward.Reward;
public class DGroupRewardEvent extends DGroupEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private List<Reward> rewards = new ArrayList<Reward>();
private List<Player> excludedPlayers = new ArrayList<Player>();
public DGroupRewardEvent(DGroup dGroup) {
super(dGroup);
this.rewards = dGroup.getRewards();
}
/**
* @return the rewards
*/
public List<Reward> getRewards() {
return rewards;
}
/**
* @param reward
* the reward to add
*/
public void addRewards(Reward reward) {
rewards.add(reward);
}
/**
* @param reward
* the reward to remove
*/
public void removeRewards(Reward reward) {
rewards.remove(reward);
}
/**
* @return the excludedPlayers
*/
public List<Player> getExcludedPlayers() {
return excludedPlayers;
}
/**
* @param player
* the player to add
*/
public void addExcludedPlayer(Player player) {
excludedPlayers.add(player);
}
/**
* @param player
* the player to remove
*/
public void removeExcludedPlayer(Player player) {
excludedPlayers.remove(player);
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,55 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dgroup;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class DGroupStartFloorEvent extends DGroupEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private GameWorld gameWorld;
public DGroupStartFloorEvent(DGroup dGroup, GameWorld gameWorld) {
super(dGroup);
this.gameWorld = gameWorld;
}
/**
* @return the gameWorld
*/
public GameWorld getGameWorld() {
return gameWorld;
}
/**
* @param gameWorld
* the gameWorld to set
*/
public void setGameWorld(GameWorld gameWorld) {
this.gameWorld = gameWorld;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,55 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dmob;
import io.github.dre2n.dungeonsxl.mob.DMob;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.EntityDeathEvent;
public class DMobDeathEvent extends DMobEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private EntityDeathEvent bukkitEvent;
public DMobDeathEvent(DMob dMob, EntityDeathEvent bukkitEvent) {
super(dMob);
this.bukkitEvent = bukkitEvent;
}
/**
* @return the bukkitEvent
*/
public EntityDeathEvent getBukkitEvent() {
return bukkitEvent;
}
/**
* @param bukkitEvent
* the bukkitEvent to set
*/
public void setBukkitEvent(EntityDeathEvent bukkitEvent) {
this.bukkitEvent = bukkitEvent;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,30 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dmob;
import io.github.dre2n.dungeonsxl.mob.DMob;
import org.bukkit.event.Event;
public abstract class DMobEvent extends Event {
protected DMob dMob;
public DMobEvent(DMob dMob) {
this.dMob = dMob;
}
/**
* @return the dMob
*/
public DMob getDMob() {
return dMob;
}
/**
* @param dMob
* the dMob to set
*/
public void setDMob(DMob dMob) {
this.dMob = dMob;
}
}

View File

@ -1,55 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dmob;
import io.github.dre2n.dungeonsxl.mob.DMob;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.EntitySpawnEvent;
public class DMobSpawnEvent extends DMobEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private EntitySpawnEvent bukkitEvent;
public DMobSpawnEvent(DMob dMob, EntitySpawnEvent bukkitEvent) {
super(dMob);
this.bukkitEvent = bukkitEvent;
}
/**
* @return the bukkitEvent
*/
public EntitySpawnEvent getBukkitEvent() {
return bukkitEvent;
}
/**
* @param bukkitEvent
* the bukkitEvent to set
*/
public void setBukkitEvent(EntitySpawnEvent bukkitEvent) {
this.bukkitEvent = bukkitEvent;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,72 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dplayer;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.PlayerDeathEvent;
public class DPlayerDeathEvent extends DPlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private PlayerDeathEvent bukkitEvent;
private int lostLives;
public DPlayerDeathEvent(DPlayer dPlayer, PlayerDeathEvent bukkitEvent, int lostLives) {
super(dPlayer);
this.bukkitEvent = bukkitEvent;
this.lostLives = lostLives;
}
/**
* @return the bukkitEvent
*/
public PlayerDeathEvent getBukkitEvent() {
return bukkitEvent;
}
/**
* @param bukkitEvent
* the bukkitEvent to set
*/
public void setBukkitEvent(PlayerDeathEvent bukkitEvent) {
this.bukkitEvent = bukkitEvent;
}
/**
* @return the lostLives
*/
public int getLostLives() {
return lostLives;
}
/**
* @param lostLives
* the lostLives to set
*/
public void setLostLives(int lostLives) {
this.lostLives = lostLives;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,36 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dplayer;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class DPlayerEscapeEvent extends DPlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
public DPlayerEscapeEvent(DPlayer dPlayer) {
super(dPlayer);
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,30 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dplayer;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import org.bukkit.event.Event;
public abstract class DPlayerEvent extends Event {
protected DPlayer dPlayer;
public DPlayerEvent(DPlayer dPlayer) {
this.dPlayer = dPlayer;
}
/**
* @return the dPlayer
*/
public DPlayer getDPlayer() {
return dPlayer;
}
/**
* @param dPlayer
* the dPlayer to set
*/
public void setDPlayer(DPlayer dPlayer) {
this.dPlayer = dPlayer;
}
}

View File

@ -1,71 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dplayer;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class DPlayerFinishEvent extends DPlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private boolean first;
private boolean hasToWait;
public DPlayerFinishEvent(DPlayer dPlayer, boolean first, boolean hasToWait) {
super(dPlayer);
this.first = first;
this.hasToWait = hasToWait;
}
/**
* @return the first
*/
public boolean isFirst() {
return first;
}
/**
* @param first
* the first to set
*/
public void setFirst(boolean first) {
this.first = first;
}
/**
* @return the hasToWait
*/
public boolean getHasToWait() {
return hasToWait;
}
/**
* @param hasToWait
* the hasToWait to set
*/
public void setHasToWait(boolean hasToWait) {
this.hasToWait = hasToWait;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,56 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dplayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class DPlayerJoinDGroupEvent extends DPlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private boolean creator;
private DGroup dGroup;
public DPlayerJoinDGroupEvent(DPlayer dPlayer, boolean creator, DGroup dGroup) {
super(dPlayer);
this.creator = creator;
this.dGroup = dGroup;
}
/**
* @return if the player is the creator of the group
*/
public boolean isCreator() {
return creator;
}
/**
* @return the dGroup
*/
public DGroup getDGroup() {
return dGroup;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,63 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dplayer;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class DPlayerKickEvent extends DPlayerEvent implements Cancellable {
public enum Cause {
COMMAND,
DEATH,
OFFLINE,
CUSTOM
}
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private Cause cause;
public DPlayerKickEvent(DPlayer dPlayer, Cause cause) {
super(dPlayer);
this.cause = cause;
}
/**
* @return the cause
*/
public Cause getCause() {
return cause;
}
/**
* @param cause
* the cause to set
*/
public void setCause(Cause cause) {
this.cause = cause;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,131 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dplayer;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class DPlayerUpdateEvent extends DPlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private boolean locationValid;
private boolean teleportWolf;
private boolean respawnInventory;
private boolean offline;
private boolean kick;
private boolean triggerAllInDistance;
public DPlayerUpdateEvent(DPlayer dPlayer, boolean locationValid, boolean teleportWolf, boolean respawnInventory, boolean offline, boolean kick, boolean triggerAllInDistance) {
super(dPlayer);
this.locationValid = locationValid;
this.teleportWolf = teleportWolf;
this.respawnInventory = respawnInventory;
this.offline = offline;
this.kick = kick;
this.triggerAllInDistance = triggerAllInDistance;
}
/**
* @return if the location is inside the correct game world
*/
public boolean isLocationValid() {
return locationValid;
}
/**
* @param locationValid
* set if the location is valid
*/
public void setLocationValid(boolean locationValid) {
this.locationValid = locationValid;
}
/**
* @return if the player's wolf gets teleported
*/
public boolean isTeleportWolf() {
return teleportWolf;
}
/**
* @param teleportWolf
* set if the wolf gets teleported
*/
public void setTeleportWolf(boolean teleportWolf) {
this.teleportWolf = teleportWolf;
}
/**
* @return if the player's inventory gets respawned
*/
public boolean isRespawnInventory() {
return respawnInventory;
}
/**
* @param respawnInventory
* respawn the player's old inventory on this update?
*/
public void setRespawnInventory(boolean respawnInventory) {
this.respawnInventory = respawnInventory;
}
/**
* @return if the player is offline
*/
public boolean isOffline() {
return offline;
}
/**
* @return if the player gets kicked from the dungeon
*/
public boolean getKick() {
return kick;
}
/**
* @param kick
* if the player gets kicked from the dungeon
*/
public void setKick(boolean kick) {
this.kick = kick;
}
/**
* @return the triggerAllInDistance
*/
public boolean getTriggerAllInDistance() {
return triggerAllInDistance;
}
/**
* @param triggerAllInDistance
* the triggerAllInDistance to set
*/
public void setTriggerAllInDistance(boolean triggerAllInDistance) {
this.triggerAllInDistance = triggerAllInDistance;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,30 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dsign;
import org.bukkit.event.Event;
import io.github.dre2n.dungeonsxl.sign.DSign;
public abstract class DSignEvent extends Event {
protected DSign dSign;
public DSignEvent(DSign dSign) {
this.dSign = dSign;
}
/**
* @return the dSign
*/
public DSign getDSign() {
return dSign;
}
/**
* @param dSign
* the dSign to set
*/
public void setDSign(DSign dSign) {
this.dSign = dSign;
}
}

View File

@ -1,73 +0,0 @@
package io.github.dre2n.dungeonsxl.event.dsign;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.sign.DSign;
import org.bukkit.block.Sign;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class DSignRegistrationEvent extends DSignEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private Sign sign;
private GameWorld gameWorld;
public DSignRegistrationEvent(Sign sign, GameWorld gameWorld, DSign dSign) {
super(dSign);
this.sign = sign;
this.gameWorld = gameWorld;
}
/**
* @return the sign
*/
public Sign getSign() {
return sign;
}
/**
* @param sign
* the sign to set
*/
public void setSign(Sign sign) {
this.sign = sign;
}
/**
* @return the gameWorld
*/
public GameWorld getGameWorld() {
return gameWorld;
}
/**
* @param gameWorld
* the gameWorld to set
*/
public void setGameWorld(GameWorld gameWorld) {
this.gameWorld = gameWorld;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,30 +0,0 @@
package io.github.dre2n.dungeonsxl.event.editworld;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import org.bukkit.event.Event;
public abstract class EditWorldEvent extends Event {
protected EditWorld editWorld;
public EditWorldEvent(EditWorld editWorld) {
this.editWorld = editWorld;
}
/**
* @return the editWorld
*/
public EditWorld getEditWorld() {
return editWorld;
}
/**
* @param editWorld
* the editWorld to set
*/
public void setEditWorld(EditWorld editWorld) {
this.editWorld = editWorld;
}
}

View File

@ -1,36 +0,0 @@
package io.github.dre2n.dungeonsxl.event.editworld;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class EditWorldGenerateEvent extends EditWorldEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
public EditWorldGenerateEvent(EditWorld editWorld) {
super(editWorld);
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,52 +0,0 @@
package io.github.dre2n.dungeonsxl.event.editworld;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class EditWorldLoadEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private String name;
public EditWorldLoadEvent(String name) {
this.name = name;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,36 +0,0 @@
package io.github.dre2n.dungeonsxl.event.editworld;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class EditWorldSaveEvent extends EditWorldEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
public EditWorldSaveEvent(EditWorld editWorld) {
super(editWorld);
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,54 +0,0 @@
package io.github.dre2n.dungeonsxl.event.editworld;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class EditWorldUnloadEvent extends EditWorldEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private boolean save;
public EditWorldUnloadEvent(EditWorld editWorld, boolean save) {
super(editWorld);
this.save = save;
}
/**
* @return the save
*/
public boolean getSave() {
return save;
}
/**
* @param save
* the save to set
*/
public void setSave(boolean save) {
this.save = save;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,30 +0,0 @@
package io.github.dre2n.dungeonsxl.event.gameworld;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import org.bukkit.event.Event;
public abstract class GameWorldEvent extends Event {
protected GameWorld gameWorld;
public GameWorldEvent(GameWorld gameWorld) {
this.gameWorld = gameWorld;
}
/**
* @return the gameWorld
*/
public GameWorld getGameWorld() {
return gameWorld;
}
/**
* @param gameWorld
* the gameWorld to set
*/
public void setGameWorld(GameWorld gameWorld) {
this.gameWorld = gameWorld;
}
}

View File

@ -1,52 +0,0 @@
package io.github.dre2n.dungeonsxl.event.gameworld;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class GameWorldLoadEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private String name;
public GameWorldLoadEvent(String name) {
this.name = name;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,55 +0,0 @@
package io.github.dre2n.dungeonsxl.event.gameworld;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class GameWorldStartGameEvent extends GameWorldEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private Game game;
public GameWorldStartGameEvent(GameWorld gameWorld, Game game) {
super(gameWorld);
this.game = game;
}
/**
* @return the game
*/
public Game getGame() {
return game;
}
/**
* @param game
* the game to set
*/
public void setGame(Game game) {
this.game = game;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,37 +0,0 @@
package io.github.dre2n.dungeonsxl.event.gameworld;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class GameWorldUnloadEvent extends GameWorldEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
public GameWorldUnloadEvent(GameWorld gameWorld) {
super(gameWorld);
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,55 +0,0 @@
package io.github.dre2n.dungeonsxl.event.requirement;
import io.github.dre2n.dungeonsxl.requirement.Requirement;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class RequirementCheckEvent extends RequirementEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private Player player;
public RequirementCheckEvent(Requirement requirement, Player player) {
super(requirement);
this.player = player;
}
/**
* @return the player
*/
public Player getPlayer() {
return player;
}
/**
* @param player
* the player to set
*/
public void setPlayer(Player player) {
this.player = player;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,55 +0,0 @@
package io.github.dre2n.dungeonsxl.event.requirement;
import io.github.dre2n.dungeonsxl.requirement.Requirement;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class RequirementDemandEvent extends RequirementEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private Player player;
public RequirementDemandEvent(Requirement requirement, Player player) {
super(requirement);
this.player = player;
}
/**
* @return the player
*/
public Player getPlayer() {
return player;
}
/**
* @param player
* the player to set
*/
public void setPlayer(Player player) {
this.player = player;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,30 +0,0 @@
package io.github.dre2n.dungeonsxl.event.requirement;
import io.github.dre2n.dungeonsxl.requirement.Requirement;
import org.bukkit.event.Event;
public abstract class RequirementEvent extends Event {
protected Requirement requirement;
public RequirementEvent(Requirement requirement) {
this.requirement = requirement;
}
/**
* @return the requirement
*/
public Requirement getRequirement() {
return requirement;
}
/**
* @param requirement
* the requirement to set
*/
public void setRequirement(Requirement requirement) {
this.requirement = requirement;
}
}

View File

@ -1,36 +0,0 @@
package io.github.dre2n.dungeonsxl.event.requirement;
import io.github.dre2n.dungeonsxl.requirement.Requirement;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class RequirementRegistrationEvent extends RequirementEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
public RequirementRegistrationEvent(Requirement requirement) {
super(requirement);
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,55 +0,0 @@
package io.github.dre2n.dungeonsxl.event.reward;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.reward.Reward;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class RewardAdditionEvent extends RewardEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private DGroup dGroup;
public RewardAdditionEvent(Reward reward, DGroup dGroup) {
super(reward);
this.dGroup = dGroup;
}
/**
* @return the dGroup
*/
public DGroup getDGroup() {
return dGroup;
}
/**
* @param dGroup
* the dGroup to set
*/
public void setDGroup(DGroup dGroup) {
this.dGroup = dGroup;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,30 +0,0 @@
package io.github.dre2n.dungeonsxl.event.reward;
import org.bukkit.event.Event;
import io.github.dre2n.dungeonsxl.reward.Reward;
public abstract class RewardEvent extends Event {
protected Reward reward;
public RewardEvent(Reward reward) {
this.reward = reward;
}
/**
* @return the reward
*/
public Reward getReward() {
return reward;
}
/**
* @param reward
* the reward to set
*/
public void setReward(Reward reward) {
this.reward = reward;
}
}

View File

@ -1,36 +0,0 @@
package io.github.dre2n.dungeonsxl.event.reward;
import io.github.dre2n.dungeonsxl.reward.Reward;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class RewardRegistrationEvent extends RewardEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
public RewardRegistrationEvent(Reward reward) {
super(reward);
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,36 +0,0 @@
package io.github.dre2n.dungeonsxl.event.trigger;
import io.github.dre2n.dungeonsxl.trigger.Trigger;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class TriggerActionEvent extends TriggerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
public TriggerActionEvent(Trigger trigger) {
super(trigger);
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,22 +0,0 @@
package io.github.dre2n.dungeonsxl.event.trigger;
import io.github.dre2n.dungeonsxl.trigger.Trigger;
import org.bukkit.event.Event;
public abstract class TriggerEvent extends Event {
protected Trigger trigger;
public TriggerEvent(Trigger trigger) {
this.trigger = trigger;
}
/**
* @return the trigger
*/
public Trigger getTrigger() {
return trigger;
}
}

View File

@ -1,44 +0,0 @@
package io.github.dre2n.dungeonsxl.event.trigger;
import io.github.dre2n.dungeonsxl.trigger.Trigger;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
public class TriggerRegistrationEvent extends TriggerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
public TriggerRegistrationEvent(Trigger trigger) {
super(trigger);
}
/**
* @param trigger
* the trigger to set
*/
public void setTrigger(Trigger trigger) {
this.trigger = trigger;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,99 +0,0 @@
package io.github.dre2n.dungeonsxl.game;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.player.DGroup;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
public class Game {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
private List<DGroup> dGroups = new ArrayList<DGroup>();
private GameType type;
public Game(DGroup dGroup) {
this.dGroups.add(dGroup);
this.type = GameTypeDefault.DEFAULT;
}
public Game(DGroup dGroup, GameType type) {
this.dGroups.add(dGroup);
this.type = type;
}
/**
* @return the dGroups
*/
public List<DGroup> getDGroups() {
return dGroups;
}
/**
* @param dGroup
* the dGroups to add
*/
public void addDGroup(DGroup dGroup) {
dGroups.add(dGroup);
}
/**
* @param dGroup
* the dGroups to remove
*/
public void removeDGroup(DGroup dGroup) {
dGroups.remove(dGroup);
}
/**
* @return the type
*/
public GameType getType() {
return type;
}
/**
* @param type
* the type to set
*/
public void setType(GameType type) {
this.type = type;
}
/**
* @return if the DGroup list is empty
*/
public boolean isEmpty() {
return dGroups.isEmpty();
}
// Static
public static Game getByDGroup(DGroup dGroup) {
for (Game game : plugin.getGames()) {
if (game.getDGroups().contains(dGroup)) {
return game;
}
}
return null;
}
public static Game getByPlayer(Player player) {
return getByDGroup(DGroup.getByPlayer(player));
}
public static Game getByGameWorld(GameWorld gameWorld) {
for (Game game : plugin.getGames()) {
if (game.getDGroups().get(0).getGameWorld().equals(gameWorld)) {
return game;
}
}
return null;
}
}

View File

@ -1,210 +0,0 @@
package io.github.dre2n.dungeonsxl.game;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.reward.Reward;
import io.github.dre2n.dungeonsxl.reward.MoneyReward;
import io.github.dre2n.dungeonsxl.reward.RewardTypeDefault;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import net.milkbowl.vault.item.ItemInfo;
import net.milkbowl.vault.item.Items;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
public class GameChest {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
// Variables
private boolean used = false;
private Chest chest;
private GameWorld gameWorld;
private double moneyReward;
public GameChest(Block chest, GameWorld gameWorld, double moneyReward) {
if ( !(chest.getState() instanceof Chest)) {
return;
}
this.chest = (Chest) chest.getState();
this.gameWorld = gameWorld;
this.moneyReward = moneyReward;
gameWorld.getGameChests().add(this);
}
/**
* @return if the GameChest is used
*/
public boolean isUsed() {
return used;
}
/**
* @param used
* set if the chest is used
*/
public void setUsed(boolean used) {
this.used = used;
}
/**
* @return the chest
*/
public Chest getChest() {
return chest;
}
/**
* @param chest
* the chest to set
*/
public void setChest(Chest chest) {
this.chest = chest;
}
/**
* @return the gameWorld
*/
public GameWorld getGameWorld() {
return gameWorld;
}
/**
* @param gameWorld
* the gameWorld to set
*/
public void setGameWorld(GameWorld gameWorld) {
this.gameWorld = gameWorld;
}
/**
* @return the moneyReward
*/
public double getMoneyReward() {
return moneyReward;
}
/**
* @param moneyReward
* the moneyReward to set
*/
public void setMoneyReward(double moneyReward) {
this.moneyReward = moneyReward;
}
public void addTreasure(DGroup dGroup) {
if (dGroup == null) {
return;
}
boolean hasMoneyReward = false;
for (Reward reward : dGroup.getRewards()) {
if (reward instanceof MoneyReward) {
hasMoneyReward = true;
((MoneyReward) reward).addMoney(moneyReward);
}
}
if ( !hasMoneyReward) {
Reward reward = Reward.create(RewardTypeDefault.MONEY);
((MoneyReward) reward).addMoney(moneyReward);
dGroup.addReward(reward);
}
for (Player player : dGroup.getPlayers()) {
DPlayer dPlayer = DPlayer.getByPlayer(player);
if (dPlayer == null) {
continue;
}
String msg = "";
for (ItemStack itemStack : chest.getInventory().getContents()) {
if (itemStack == null) {
continue;
}
dPlayer.getTreasureInv().addItem(itemStack);
String name = null;
if (itemStack.hasItemMeta()) {
if (itemStack.getItemMeta().hasDisplayName()) {
name = itemStack.getItemMeta().getDisplayName();
}
}
if (name == null && Bukkit.getPluginManager().getPlugin("Vault") != null) {
ItemInfo itemInfo = Items.itemByStack(itemStack);
if (itemInfo != null) {
name = itemInfo.getName();
} else {
name = itemStack.getType().name();
}
}
msg += ChatColor.RED + " " + itemStack.getAmount() + " " + name + ChatColor.GOLD + ",";
}
msg = msg.substring(0, msg.length() - 1);
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_LOOT_ADDED, msg));
if (moneyReward != 0) {
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_LOOT_ADDED, plugin.getEconomyProvider().format(moneyReward)));
}
}
}
// Statics
/**
* @param event
* event.getPlayer() has to be a Player
*/
public static void onOpenInventory(InventoryOpenEvent event) {
InventoryView inventory = event.getView();
GameWorld gameWorld = GameWorld.getByWorld(event.getPlayer().getWorld());
if (gameWorld == null) {
return;
}
if ( !(inventory.getTopInventory().getHolder() instanceof Chest)) {
return;
}
Chest chest = (Chest) inventory.getTopInventory().getHolder();
for (GameChest gameChest : gameWorld.getGameChests()) {
if ( !gameChest.chest.equals(chest)) {
continue;
}
if (gameChest.used) {
MessageUtil.sendMessage(plugin.getServer().getPlayer(event.getPlayer().getUniqueId()), plugin.getMessageConfig().getMessage(Messages.ERROR_CHEST_IS_OPENED));
event.setCancelled(true);
continue;
}
if (gameChest.chest.getLocation().distance(chest.getLocation()) < 1) {
gameChest.addTreasure(DGroup.getByPlayer((Player) event.getPlayer()));
gameChest.used = true;
event.setCancelled(true);
}
}
}
}

View File

@ -1,280 +0,0 @@
package io.github.dre2n.dungeonsxl.game;
import io.github.dre2n.dungeonsxl.util.NumberUtil;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
public class GamePlaceableBlock {
// Variables
private Block block;
private Set<Material> materials = new HashSet<Material>();
private boolean onTop = false;
private boolean onBottom = false;
private boolean onNorth = false;
private boolean onSouth = false;
private boolean onEast = false;
private boolean onWest = false;
public GamePlaceableBlock(Block block, String ids, String directions) {
this.block = block;
// Split ids
if ( !ids.equals("")) {
String[] splittedIds = ids.split(",");
for (String id : splittedIds) {
@SuppressWarnings("deprecation")
Material material = Material.getMaterial(NumberUtil.parseInt(id));
if (material != null) {
materials.add(material);
}
}
}
// Read directions
if (directions.length() == 6) {
for (int direction = 0; direction < 6; direction++) {
boolean positive = String.valueOf(directions.charAt(direction)).equals("x");
if ( !positive) {
continue;
}
if (direction == 0) {
onTop = true;
}
if (direction == 1) {
onBottom = true;
}
if (block.getType() == Material.WALL_SIGN) {
@SuppressWarnings("deprecation")
int data = block.getData();
switch (data) {
case 3:
if (direction == 2) {
onNorth = true;
}
if (direction == 3) {
onEast = true;
}
if (direction == 4) {
onSouth = true;
}
if (direction == 5) {
onWest = true;
}
break;
case 4:
if (direction == 5) {
onNorth = true;
}
if (direction == 2) {
onEast = true;
}
if (direction == 3) {
onSouth = true;
}
if (direction == 4) {
onWest = true;
}
break;
case 2:
if (direction == 4) {
onNorth = true;
}
if (direction == 5) {
onEast = true;
}
if (direction == 2) {
onSouth = true;
}
if (direction == 3) {
onWest = true;
}
break;
case 5:
if (direction == 3) {
onNorth = true;
}
if (direction == 4) {
onEast = true;
}
if (direction == 5) {
onSouth = true;
}
if (direction == 2) {
onWest = true;
}
break;
}
} else {
@SuppressWarnings("deprecation")
int data = block.getData();
switch (data) {
case 0:
case 1:
case 2:
case 15:
if (direction == 2) {
onNorth = true;
}
if (direction == 3) {
onEast = true;
}
if (direction == 4) {
onSouth = true;
}
if (direction == 5) {
onWest = true;
}
break;
case 4:
case 3:
case 5:
case 6:
if (direction == 5) {
onNorth = true;
}
if (direction == 2) {
onEast = true;
}
if (direction == 3) {
onSouth = true;
}
if (direction == 4) {
onWest = true;
}
break;
case 8:
case 7:
case 9:
case 10:
if (direction == 4) {
onNorth = true;
}
if (direction == 5) {
onEast = true;
}
if (direction == 2) {
onSouth = true;
}
if (direction == 3) {
onWest = true;
}
break;
case 12:
case 11:
case 13:
case 14:
if (direction == 3) {
onNorth = true;
}
if (direction == 4) {
onEast = true;
}
if (direction == 5) {
onSouth = true;
}
if (direction == 2) {
onWest = true;
}
break;
}
}
}
} else {
onTop = true;
onBottom = true;
onNorth = true;
onEast = true;
onSouth = true;
onWest = true;
}
}
// Can build
public static boolean canBuildHere(Block block, BlockFace blockFace, Material mat, GameWorld gameWorld) {
for (GamePlaceableBlock gamePlacableBlock : gameWorld.getPlaceableBlocks()) {
if (gamePlacableBlock.block.getFace(block) != BlockFace.SELF) {
continue;
}
if ( !(gamePlacableBlock.materials.contains(mat) || gamePlacableBlock.materials.isEmpty())) {
continue;
}
if (blockFace == BlockFace.NORTH && gamePlacableBlock.onNorth) {
return true;
}
if (blockFace == BlockFace.SOUTH && gamePlacableBlock.onSouth) {
return true;
}
if (blockFace == BlockFace.EAST && gamePlacableBlock.onEast) {
return true;
}
if (blockFace == BlockFace.WEST && gamePlacableBlock.onWest) {
return true;
}
if (blockFace == BlockFace.UP && gamePlacableBlock.onTop) {
return true;
}
if (blockFace == BlockFace.DOWN && gamePlacableBlock.onBottom) {
return true;
}
}
return false;
}
}

View File

@ -1,106 +0,0 @@
package io.github.dre2n.dungeonsxl.game;
import org.bukkit.GameMode;
public interface GameType {
/**
* @return the displayName
*/
public String getDisplayName();
/**
* @param displayName
* the displayName to set
*/
public void setDisplayName(String displayName);
/**
* @return the signName
*/
public String getSignName();
/**
* @param signName
* the signName to set
*/
public void setSignName(String signName);
/**
* @return the playerVersusPlayer
*/
public boolean isPlayerVersusPlayer();
/**
* @param playerVersusPlayer
* the playerVersusPlayer to set
*/
public void setPlayerVersusPlayer(boolean playerVersusPlayer);
/**
* @return the friendlyFire
*/
public boolean isFriendlyFire();
/**
* @param friendlyFire
* the friendlyFire to set
*/
public void setFriendlyFire(boolean friendlyFire);
/**
* @return the mobWaves
*/
public boolean hasMobWaves();
/**
* @param mobWaves
* the mobWaves to set
*/
public void setMobWaves(boolean mobWaves);
/**
* @return the rewards
*/
public boolean hasRewards();
/**
* @param rewards
* the rewards to set
*/
public void setRewards(boolean rewards);
/**
* @return the showTime
*/
public boolean getShowTime();
/**
* @param showTime
* the showTime to set
*/
public void setShowTime(boolean showTime);
/**
* @return the build
*/
public boolean canBuild();
/**
* @param build
* the build to set
*/
public void setBuild(boolean build);
/**
* @return the gameMode
*/
public GameMode getGameMode();
/**
* @param gameMode
* the gameMode to set
*/
public void setGameMode(GameMode gameMode);
}

View File

@ -1,135 +0,0 @@
package io.github.dre2n.dungeonsxl.game;
import org.bukkit.GameMode;
public enum GameTypeDefault implements GameType {
ADVENTURE("Adventure", "Adventure", false, false, false, true, false, true, GameMode.ADVENTURE),
ADVENTURE_TIME_IS_RUNNING("Adventure - Time is Running", "Adventure TiR", false, false, false, true, true, true, GameMode.ADVENTURE),
APOCALYPSE_LAST_MAN_STANDING("Apocalypse", "Apocalypse LMS", true, true, true, true, false, false, GameMode.SURVIVAL),
APOCALYPSE_LIMITED_MOBS("Apocalypse - Limited Mobs", "Apc Limited", true, true, true, true, false, false, GameMode.SURVIVAL),
APOCALYPSE_TIME_IS_RUNNING("Apocalypse - Time is Running", "Apocalypse TiR", true, true, true, true, true, false, GameMode.SURVIVAL),
PVE_LAST_MAN_STANDING("Player versus Environment - Last Man Standing", "PvE LMS", false, false, true, true, false, false, GameMode.SURVIVAL),
PVE_LIMITED_MOBS("Player versus Environment - Limited Mobs", "PvE Limited", false, false, true, true, false, false, GameMode.SURVIVAL),
PVE_TIME_IS_RUNNING("Player versus Environment - Time is Running", "PvE TiR", false, false, true, true, true, false, GameMode.SURVIVAL),
PVP_FACTIONS_BATTLEFIELD("Player versus Player - Factions Battlefield", "FactionsPvP", true, false, false, false, false, false, GameMode.SURVIVAL),
PVP_LAST_MAN_STANDING("Player versus Player - Last Man Standing", "PvP LMS", true, false, false, false, false, false, GameMode.SURVIVAL),
QUEST("Quest", "Quest", false, false, false, true, false, false, GameMode.SURVIVAL),
QUEST_TIME_IS_RUNNING("Quest - Time is Running", "Quest TiR", false, false, false, true, true, false, GameMode.SURVIVAL),
TEST("Test", "Test", false, false, false, false, true, true, GameMode.SURVIVAL),
TUTORIAL("Tutorial", "Tutorial", false, false, false, true, false, false, GameMode.SURVIVAL),
DEFAULT("Default", "Default", false, false, false, true, false, false, GameMode.SURVIVAL);
private String displayName;
private String signName;
private boolean playerVersusPlayer;// TODO: Testing
private boolean friendlyFire;// TODO: Testing
private boolean mobWaves;// TODO: Implementing
private boolean rewards;// TODO: Testing
private boolean showTime;// TODO: Implementing
private boolean build;// TODO: Testing
private GameMode gameMode;// TODO: Testing
GameTypeDefault(String displayName, String signName, boolean playerVersusPlayer, boolean friendlyFire, boolean mobWaves, boolean rewards, boolean showTime, boolean build, GameMode gameMode) {
this.displayName = displayName;
this.signName = signName;
this.playerVersusPlayer = playerVersusPlayer;
this.friendlyFire = friendlyFire;
this.mobWaves = mobWaves;
this.rewards = rewards;
this.showTime = showTime;
this.build = build;
this.gameMode = gameMode;
}
@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 hasMobWaves() {
return mobWaves;
}
@Override
public void setMobWaves(boolean mobWaves) {
this.mobWaves = mobWaves;
}
@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 canBuild() {
return build;
}
@Override
public void setBuild(boolean build) {
this.build = build;
}
@Override
public GameMode getGameMode() {
return gameMode;
}
@Override
public void setGameMode(GameMode gameMode) {
this.gameMode = gameMode;
}
}

View File

@ -1,83 +0,0 @@
package io.github.dre2n.dungeonsxl.game;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.game.GameType;
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.block.Sign;
public class GameTypes {
private List<GameType> types = new ArrayList<GameType>();
public GameTypes() {
for (GameType type : GameTypeDefault.values()) {
if (type == GameTypeDefault.PVP_FACTIONS_BATTLEFIELD) {
try {
Class.forName("com.massivecraft.factions.Patch");
} catch (ClassNotFoundException exception) {
DungeonsXL.getPlugin().getLogger().info("Could not find compatible Factions plugin. The game type PVP_FACTIONS_BATTLEFIELD will not get enabled...");
continue;
}
}
types.add(type);
}
}
/**
* @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;
}
/**
* @return the game type which has the enum value sign text in the second line of the sign
*/
public GameType getBySign(Sign 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 game
* the game to remove
*/
public void removeGameType(GameType type) {
types.remove(type);
}
}

View File

@ -1,666 +0,0 @@
package io.github.dre2n.dungeonsxl.game;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DungeonConfig;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldLoadEvent;
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldStartGameEvent;
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldUnloadEvent;
import io.github.dre2n.dungeonsxl.event.requirement.RequirementCheckEvent;
import io.github.dre2n.dungeonsxl.mob.DMob;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.requirement.Requirement;
import io.github.dre2n.dungeonsxl.sign.DSign;
import io.github.dre2n.dungeonsxl.trigger.RedstoneTrigger;
import io.github.dre2n.dungeonsxl.util.FileUtil;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Spider;
public class GameWorld {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
// Variables
private Game game;
private boolean tutorial;
private CopyOnWriteArrayList<GamePlaceableBlock> placeableBlocks = new CopyOnWriteArrayList<GamePlaceableBlock>();
private World world;
private String mapName;
private Location locLobby;
private Location locStart;
private boolean isPlaying = false;
private int id;
private CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<Material>();
private CopyOnWriteArrayList<Chunk> loadedChunks = new CopyOnWriteArrayList<Chunk>();
private CopyOnWriteArrayList<Sign> signClass = new CopyOnWriteArrayList<Sign>();
private CopyOnWriteArrayList<DMob> dMobs = new CopyOnWriteArrayList<DMob>();
// TODO: Killed mobs
private CopyOnWriteArrayList<GameChest> gameChests = new CopyOnWriteArrayList<GameChest>();
private CopyOnWriteArrayList<DSign> dSigns = new CopyOnWriteArrayList<DSign>();
private WorldConfig worldConfig;
public GameWorld() {
plugin.getGameWorlds().add(this);
// ID
id = -1;
int i = -1;
while (id == -1) {
i++;
boolean exist = false;
for (GameWorld gameWorld : plugin.getGameWorlds()) {
if (gameWorld.id == i) {
exist = true;
break;
}
}
if ( !exist) {
id = i;
}
}
}
/**
* @return the game
*/
public Game getGame() {
return game;
}
/**
* @param game
* the game to set
*/
public void setGame(Game game) {
this.game = game;
}
/**
* @return the tutorial
*/
public boolean isTutorial() {
return tutorial;
}
/**
* @param tutorial
* if the GameWorld is the tutorial
*/
public void setTutorial(boolean tutorial) {
this.tutorial = tutorial;
}
/**
* @return the placeableBlocks
*/
public CopyOnWriteArrayList<GamePlaceableBlock> getPlaceableBlocks() {
return placeableBlocks;
}
/**
* @param placeableBlocks
* the placeableBlocks to set
*/
public void setPlaceableBlocks(CopyOnWriteArrayList<GamePlaceableBlock> placeableBlocks) {
this.placeableBlocks = placeableBlocks;
}
/**
* @return the world
*/
public World getWorld() {
return world;
}
/**
* @param world
* the world to set
*/
public void setWorld(World world) {
this.world = world;
}
/**
* @return the mapName
*/
public String getMapName() {
return mapName;
}
/**
* @param mapName
* the mapName to set
*/
public void setMapName(String mapName) {
this.mapName = mapName;
}
/**
* @return the locLobby
*/
public Location getLocLobby() {
return locLobby;
}
/**
* @param locLobby
* the locLobby to set
*/
public void setLocLobby(Location locLobby) {
this.locLobby = locLobby;
}
/**
* @return the locStart
*/
public Location getLocStart() {
return locStart;
}
/**
* @param locStart
* the locStart to set
*/
public void setLocStart(Location locStart) {
this.locStart = locStart;
}
/**
* @return the isPlaying
*/
public boolean isPlaying() {
return isPlaying;
}
/**
* @param isPlaying
* the isPlaying to set
*/
public void setPlaying(boolean isPlaying) {
this.isPlaying = isPlaying;
}
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id
* the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the secureObjects
*/
public CopyOnWriteArrayList<Material> getSecureObjects() {
return secureObjects;
}
/**
* @param secureObjects
* the secureObjects to set
*/
public void setSecureObjects(CopyOnWriteArrayList<Material> secureObjects) {
this.secureObjects = secureObjects;
}
/**
* @return the loadedChunks
*/
public CopyOnWriteArrayList<Chunk> getLoadedChunks() {
return loadedChunks;
}
/**
* @param loadedChunks
* the loadedChunks to set
*/
public void setLoadedChunks(CopyOnWriteArrayList<Chunk> loadedChunks) {
this.loadedChunks = loadedChunks;
}
/**
* @return the signClass
*/
public CopyOnWriteArrayList<Sign> getSignClass() {
return signClass;
}
/**
* @param signClass
* the signClass to set
*/
public void setSignClass(CopyOnWriteArrayList<Sign> signClass) {
this.signClass = signClass;
}
/**
* @return the dMobs
*/
public CopyOnWriteArrayList<DMob> getDMobs() {
return dMobs;
}
/**
* @param dMob
* the dMob to add
*/
public void addDMob(DMob dMob) {
dMobs.add(dMob);
}
/**
* @param dMob
* the dMob to remove
*/
public void removeDMob(DMob dMob) {
dMobs.remove(dMob);
}
/**
* @return the gameChests
*/
public CopyOnWriteArrayList<GameChest> getGameChests() {
return gameChests;
}
/**
* @param gameChests
* the gameChests to set
*/
public void setGameChests(CopyOnWriteArrayList<GameChest> gameChests) {
this.gameChests = gameChests;
}
/**
* @return the dSigns
*/
public CopyOnWriteArrayList<DSign> getDSigns() {
return dSigns;
}
/**
* @param dSigns
* the dSigns to set
*/
public void setDSigns(CopyOnWriteArrayList<DSign> dSigns) {
this.dSigns = dSigns;
}
/**
* @return the worldConfig
*/
public WorldConfig getConfig() {
return worldConfig;
}
/**
* @param worldConfig
* the worldConfig to set
*/
public void setConfig(WorldConfig worldConfig) {
this.worldConfig = worldConfig;
}
/**
* @return the Dungeon that contains the GameWorld
*/
public Dungeon getDungeon() {
for (Dungeon dungeon : plugin.getDungeons().getDungeons()) {
DungeonConfig dungeonConfig = dungeon.getConfig();
if (dungeonConfig.getFloors().contains(this) || dungeonConfig.getStartFloor().equals(this) || dungeonConfig.getEndFloor().equals(this)) {
return dungeon;
}
}
return null;
}
public void checkSign(Block block) {
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
dSigns.add(DSign.create(sign, this));
}
}
public void startGame() {
GameWorldStartGameEvent event = new GameWorldStartGameEvent(this, game);
if (event.isCancelled()) {
return;
}
isPlaying = true;
for (DSign dSign : dSigns) {
if (dSign != null) {
if ( !dSign.getType().isOnDungeonInit()) {
dSign.onInit();
}
}
}
if (RedstoneTrigger.hasTriggers(this)) {
for (RedstoneTrigger trigger : RedstoneTrigger.getTriggersArray(this)) {
trigger.onTrigger();
}
}
for (DSign dSign : dSigns) {
if (dSign != null) {
if ( !dSign.hasTriggers()) {
dSign.onTrigger();
}
}
}
}
public void sendMessage(String message) {
for (DPlayer dPlayer : DPlayer.getByWorld(world)) {
MessageUtil.sendMessage(dPlayer.getPlayer(), message);
}
}
public void delete() {
GameWorldUnloadEvent event = new GameWorldUnloadEvent(this);
if (event.isCancelled()) {
return;
}
plugin.getGameWorlds().remove(this);
plugin.getServer().unloadWorld(world, true);
File dir = new File("DXL_Game_" + id);
FileUtil.removeDirectory(dir);
}
public void update() {
if (getWorld() == null) {
return;
}
// Update Spiders
for (LivingEntity mob : getWorld().getLivingEntities()) {
if (mob.getType() == EntityType.SPIDER || mob.getType() == EntityType.CAVE_SPIDER) {
Spider spider = (Spider) mob;
if (spider.getTarget() != null) {
if (spider.getTarget().getType() == EntityType.PLAYER) {
continue;
}
}
for (Entity player : spider.getNearbyEntities(10, 10, 10)) {
if (player.getType() == EntityType.PLAYER) {
spider.setTarget((LivingEntity) player);
}
}
}
}
}
// Statics
public static GameWorld load(String name) {
GameWorldLoadEvent event = new GameWorldLoadEvent(name);
if (event.isCancelled()) {
return null;
}
File file = new File(plugin.getDataFolder(), "/maps/" + name);
if (file.exists()) {
GameWorld gameWorld = new GameWorld();
gameWorld.mapName = name;
// Unload empty editWorlds
for (EditWorld editWorld : plugin.getEditWorlds()) {
if (editWorld.getWorld().getPlayers().isEmpty()) {
editWorld.delete();
}
}
// Config einlesen
gameWorld.worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + gameWorld.mapName, "config.yml"));
// Secure Objects
gameWorld.secureObjects = gameWorld.worldConfig.getSecureObjects();
// World
FileUtil.copyDirectory(file, new File("DXL_Game_" + gameWorld.id));
// Id File
File idFile = new File("DXL_Game_" + gameWorld.id + "/.id_" + name);
try {
idFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
gameWorld.world = plugin.getServer().createWorld(WorldCreator.name("DXL_Game_" + gameWorld.id));
ObjectInputStream os;
try {
os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder() + "/maps/" + gameWorld.mapName + "/DXLData.data")));
int length = os.readInt();
for (int i = 0; i < length; i++) {
int x = os.readInt();
int y = os.readInt();
int z = os.readInt();
Block block = gameWorld.world.getBlockAt(x, y, z);
gameWorld.checkSign(block);
}
os.close();
} catch (FileNotFoundException exception) {
plugin.getLogger().info("Could not find any sign data for the world \"" + name + "\"!");
} catch (IOException exception) {
exception.printStackTrace();
}
return gameWorld;
}
return null;
}
public static GameWorld getByWorld(World world) {
for (GameWorld gameWorld : plugin.getGameWorlds()) {
if (gameWorld.world.equals(world)) {
return gameWorld;
}
}
return null;
}
public static void deleteAll() {
for (GameWorld gameWorld : plugin.getGameWorlds()) {
gameWorld.delete();
}
}
public static boolean canPlayDungeon(String map, Player player) {
if (player.hasPermission("dxl.ignoretimelimit")) {
return true;
}
if (new File(plugin.getDataFolder() + "/maps/" + map).isDirectory()) {
WorldConfig worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + map, "config.yml"));
if (worldConfig.getTimeToNextPlay() != 0) {
// read PlayerConfig
long time = getPlayerTime(map, player);
if (time != -1) {
if (time + worldConfig.getTimeToNextPlay() * 1000 * 60 * 60 > System.currentTimeMillis()) {
return false;
}
}
}
} else {
return false;
}
return true;
}
public static boolean canPlayDungeon(String dungeon, DGroup dGroup) {
if (dGroup.getCaptain().hasPermission("dxl.ignoretimelimit")) {
return true;
}
for (Player player : dGroup.getPlayers()) {
if ( !canPlayDungeon(dungeon, player)) {
return false;
}
}
return true;
}
public static long getPlayerTime(String dungeon, Player player) {
File file = new File(plugin.getDataFolder() + "/maps/" + dungeon, "players.yml");
if ( !file.exists()) {
try {
file.createNewFile();
} catch (IOException exception) {
exception.printStackTrace();
}
}
FileConfiguration playerConfig = YamlConfiguration.loadConfiguration(file);
if (playerConfig.contains(player.getUniqueId().toString())) {
return playerConfig.getLong(player.getUniqueId().toString());
}
if (playerConfig.contains(player.getName())) {
return playerConfig.getLong(player.getName());
}
return -1;
}
public static boolean checkRequirements(String map, Player player) {
if (player.hasPermission("dxl.ignorerequirements")) {
return true;
}
if (new File(plugin.getDataFolder() + "/maps/" + map).isDirectory() == false) {
return false;
}
WorldConfig worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + map, "config.yml"));
for (Requirement requirement : worldConfig.getRequirements()) {
RequirementCheckEvent event = new RequirementCheckEvent(requirement, player);
if (event.isCancelled()) {
continue;
}
if ( !requirement.check(player)) {
return false;
}
}
if (worldConfig.getFinished() != null && worldConfig.getFinishedAll() != null) {
if ( !worldConfig.getFinished().isEmpty()) {
long bestTime = 0;
int numOfNeeded = 0;
boolean doneTheOne = false;
if (worldConfig.getFinished().size() == worldConfig.getFinishedAll().size()) {
doneTheOne = true;
}
for (String played : worldConfig.getFinished()) {
for (String dungeonName : new File(plugin.getDataFolder() + "/maps").list()) {
if (new File(plugin.getDataFolder() + "/maps/" + dungeonName).isDirectory()) {
if (played.equalsIgnoreCase(dungeonName) || played.equalsIgnoreCase("any")) {
Long time = getPlayerTime(dungeonName, player);
if (time != -1) {
if (worldConfig.getFinishedAll().contains(played)) {
numOfNeeded++;
} else {
doneTheOne = true;
}
if (bestTime < time) {
bestTime = time;
}
}
break;
}
}
}
}
if (bestTime == 0) {
return false;
} else {
if (worldConfig.getTimeLastPlayed() != 0) {
if (System.currentTimeMillis() - bestTime > worldConfig.getTimeLastPlayed() * (long) 3600000) {
return false;
}
}
}
if (numOfNeeded < worldConfig.getFinishedAll().size() || !doneTheOne) {
return false;
}
}
}
return true;
}
public static boolean checkRequirements(String map, DGroup dGroup) {
if (dGroup.getCaptain().hasPermission("dxl.ignorerequirements")) {
return true;
}
for (Player player : dGroup.getPlayers()) {
if ( !checkRequirements(map, player)) {
return false;
}
}
return true;
}
}

View File

@ -1,338 +0,0 @@
package io.github.dre2n.dungeonsxl.global;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
public class DPortal {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
private World world;
private Block block1;
private Block block2;
private boolean active;
private Player player;
public DPortal(boolean active) {
plugin.getDPortals().add(this);
this.active = active;
}
/**
* @return the world
*/
public World getWorld() {
return world;
}
/**
* @param world
* the world to set
*/
public void setWorld(World world) {
this.world = world;
}
/**
* @return the block1
*/
public Block getBlock1() {
return block1;
}
/**
* @param block1
* the block1 to set
*/
public void setBlock1(Block block1) {
this.block1 = block1;
}
/**
* @return the block2
*/
public Block getBlock2() {
return block2;
}
/**
* @param block2
* the block2 to set
*/
public void setBlock2(Block block2) {
this.block2 = block2;
}
/**
* @return if the portal is active
*/
public boolean isActive() {
return active;
}
/**
* @param active
* set the DPortal active
*/
public void setActive(boolean active) {
this.active = active;
}
/**
* @return the player
*/
public Player getPlayer() {
return player;
}
/**
* @param player
* the player to set
*/
public void setPlayer(Player player) {
this.player = player;
}
public void create() {
player = null;
if (block1 == null || block2 == null) {
plugin.getDPortals().remove(this);
return;
}
int x1 = block1.getX(), y1 = block1.getY(), z1 = block1.getZ();
int x2 = block2.getX(), y2 = block2.getY(), z2 = block2.getZ();
int xcount = 0, ycount = 0, zcount = 0;
if (x1 > x2) {
xcount = -1;
} else if (x1 < x2) {
xcount = 1;
}
if (y1 > y2) {
ycount = -1;
} else if (y1 < y2) {
ycount = 1;
}
if (z1 > z2) {
zcount = -1;
} else if (z1 < z2) {
zcount = 1;
}
int xx = x1;
do {
int yy = y1;
do {
int zz = z1;
do {
Material type = world.getBlockAt(xx, yy, zz).getType();
if (type == Material.AIR || type == Material.WATER || type == Material.STATIONARY_WATER || type == Material.LAVA || type == Material.STATIONARY_LAVA || type == Material.SAPLING
|| type == Material.WEB || type == Material.LONG_GRASS || type == Material.DEAD_BUSH || type == Material.PISTON_EXTENSION || type == Material.YELLOW_FLOWER
|| type == Material.RED_ROSE || type == Material.BROWN_MUSHROOM || type == Material.RED_MUSHROOM || type == Material.TORCH || type == Material.FIRE
|| type == Material.CROPS || type == Material.REDSTONE_WIRE || type == Material.REDSTONE_TORCH_OFF || type == Material.SNOW || type == Material.REDSTONE_TORCH_ON) {
world.getBlockAt(xx, yy, zz).setType(Material.PORTAL);
}
zz = zz + zcount;
} while (zz != z2 + zcount);
yy = yy + ycount;
} while (yy != y2 + ycount);
xx = xx + xcount;
} while (xx != x2 + xcount);
}
public void teleport(Player player) {
DGroup dgroup = DGroup.getByPlayer(player);
if (dgroup == null) {
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_JOIN_GROUP));
return;
}
if (dgroup.getGameWorld() == null) {
dgroup.setGameWorld(GameWorld.load(DGroup.getByPlayer(player).getMapName()));
}
if (dgroup.getGameWorld() == null) {
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, DGroup.getByPlayer(player).getMapName()));
return;
}
if (dgroup.getGameWorld().getLocLobby() == null) {
new DPlayer(player, dgroup.getGameWorld().getWorld(), dgroup.getGameWorld().getWorld().getSpawnLocation(), false);
} else {
new DPlayer(player, dgroup.getGameWorld().getWorld(), dgroup.getGameWorld().getLocLobby(), false);
}
}
public void delete() {
plugin.getDPortals().remove(this);
int x1 = block1.getX(), y1 = block1.getY(), z1 = block1.getZ();
int x2 = block2.getX(), y2 = block2.getY(), z2 = block2.getZ();
int xcount = 0, ycount = 0, zcount = 0;
if (x1 > x2) {
xcount = -1;
} else if (x1 < x2) {
xcount = 1;
}
if (y1 > y2) {
ycount = -1;
} else if (y1 < y2) {
ycount = 1;
}
if (z1 > z2) {
zcount = -1;
} else if (z1 < z2) {
zcount = 1;
}
int xx = x1;
do {
int yy = y1;
do {
int zz = z1;
do {
Material type = world.getBlockAt(xx, yy, zz).getType();
if (type == Material.PORTAL) {
world.getBlockAt(xx, yy, zz).setType(Material.AIR);
}
zz = zz + zcount;
} while (zz != z2 + zcount);
yy = yy + ycount;
} while (yy != y2 + ycount);
xx = xx + xcount;
} while (xx != x2 + xcount);
}
// Statics
public static DPortal getByLocation(Location location) {
return getByBlock(location.getBlock());
}
public static DPortal getByBlock(Block block) {
for (DPortal portal : plugin.getDPortals()) {
int x1 = portal.block1.getX(), y1 = portal.block1.getY(), z1 = portal.block1.getZ();
int x2 = portal.block2.getX(), y2 = portal.block2.getY(), z2 = portal.block2.getZ();
int x3 = block.getX(), y3 = block.getY(), z3 = block.getZ();
if (x1 > x2) {
if (x3 < x2 || x3 > x1) {
continue;
}
} else {
if (x3 > x2 || x3 < x1) {
continue;
}
}
if (y1 > y2) {
if (y3 < y2 || y3 > y1) {
continue;
}
} else {
if (y3 > y2 || y3 < y1) {
continue;
}
}
if (z1 > z2) {
if (z3 < z2 || z3 > z1) {
continue;
}
} else {
if (z3 > z2 || z3 < z1) {
continue;
}
}
return portal;
}
return null;
}
public static DPortal getByPlayer(Player player) {
for (DPortal portal : plugin.getDPortals()) {
if (portal.player == player) {
return portal;
}
}
return null;
}
// Save and Load
public static void save(FileConfiguration configFile) {
int id = 0;
for (DPortal dPortal : plugin.getDPortals()) {
id++;
if ( !dPortal.active) {
continue;
}
String preString = "portal." + dPortal.world.getName() + "." + id;
// Location1
configFile.set(preString + ".loc1.x", dPortal.block1.getX());
configFile.set(preString + ".loc1.y", dPortal.block1.getY());
configFile.set(preString + ".loc1.z", dPortal.block1.getZ());
// Location1
configFile.set(preString + ".loc2.x", dPortal.block2.getX());
configFile.set(preString + ".loc2.y", dPortal.block2.getY());
configFile.set(preString + ".loc2.z", dPortal.block2.getZ());
}
}
public static void load(FileConfiguration configFile) {
for (World world : plugin.getServer().getWorlds()) {
if ( !configFile.contains("portal." + world.getName())) {
return;
}
int id = 0;
String preString;
do {
id++;
preString = "portal." + world.getName() + "." + id + ".";
if (configFile.contains(preString)) {
DPortal dPortal = new DPortal(true);
dPortal.world = world;
dPortal.block1 = world.getBlockAt(configFile.getInt(preString + "loc1.x"), configFile.getInt(preString + "loc1.y"), configFile.getInt(preString + "loc1.z"));
dPortal.block2 = world.getBlockAt(configFile.getInt(preString + "loc2.x"), configFile.getInt(preString + "loc2.y"), configFile.getInt(preString + "loc2.z"));
dPortal.create();
}
} while (configFile.contains(preString));
}
}
}

View File

@ -1,542 +0,0 @@
package io.github.dre2n.dungeonsxl.global;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import java.io.File;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
public class GameSign {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
// Sign Labels
public static final String IS_PLAYING = ChatColor.DARK_RED + "Is Playing";
public static final String FULL = ChatColor.DARK_RED + "Full";
public static final String JOIN_GROUP = ChatColor.DARK_GREEN + "Join Game";
public static final String NEW_GROUP = ChatColor.DARK_GREEN + "New Game";
// Variables
private Game[] games;
private boolean multiFloor;
private String dungeonName;
private String mapName;
private int maxGroupsPerGame;
private Block startSign;
private int directionX = 0, directionZ = 0;
private int verticalSigns;
public GameSign(Block startSign, String identifier, int maxGames, int maxGroupsPerGame, boolean multiFloor) {
plugin.getGameSigns().add(this);
this.startSign = startSign;
games = new Game[maxGames];
this.setMultiFloor(multiFloor);
if (multiFloor) {
dungeonName = identifier;
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
if (dungeon != null) {
mapName = dungeon.getConfig().getStartFloor();
} else {
mapName = "invalid";
}
} else {
mapName = identifier;
}
this.maxGroupsPerGame = maxGroupsPerGame;
verticalSigns = (int) Math.ceil((float) (1 + maxGroupsPerGame) / 4);
@SuppressWarnings("deprecation")
int[] direction = getDirection(this.startSign.getData());
directionX = direction[0];
directionZ = direction[1];
update();
}
/**
* @return the dungeonName
*/
public String getDungeonName() {
return dungeonName;
}
/**
* @param dungeonName
* the dungeonName to set
*/
public void setDungeonName(String dungeonName) {
this.dungeonName = dungeonName;
}
/**
* @return the mapName
*/
public String getMapName() {
return mapName;
}
/**
* @param mapName
* the mapName to set
*/
public void setMapName(String mapName) {
this.mapName = mapName;
}
/**
* @return the multiFloor
*/
public boolean isMultiFloor() {
return multiFloor;
}
/**
* @param multiFloor
* the multiFloor to set
*/
public void setMultiFloor(boolean multiFloor) {
this.multiFloor = multiFloor;
}
public void delete() {
plugin.getGameSigns().remove(this);
}
public void update() {
int i = 0;
for (Game game : games) {
if ( !(startSign.getRelative(i * directionX, 0, i * directionZ).getState() instanceof Sign)) {
i++;
continue;
}
Sign sign = (Sign) startSign.getRelative(i * directionX, 0, i * directionZ).getState();
// Reset Signs
sign.setLine(0, "");
sign.setLine(1, "");
sign.setLine(2, "");
sign.setLine(3, "");
int yy = -1;
while (sign.getBlock().getRelative(0, yy, 0).getState() instanceof Sign) {
Sign subsign = (Sign) sign.getBlock().getRelative(0, yy, 0).getState();
subsign.setLine(0, "");
subsign.setLine(1, "");
subsign.setLine(2, "");
subsign.setLine(3, "");
subsign.update();
yy--;
}
// Set Signs
if (game != null) {
if (game.getDGroups().get(0).isPlaying()) {
sign.setLine(0, IS_PLAYING);
} else if (game.getDGroups().size() >= maxGroupsPerGame) {
sign.setLine(0, FULL);
} else {
sign.setLine(0, JOIN_GROUP);
}
int j = 1;
Sign rowSign = sign;
for (DGroup dGroup : game.getDGroups()) {
if (j > 3) {
j = 0;
rowSign = (Sign) sign.getBlock().getRelative(0, -1, 0).getState();
}
if (rowSign != null) {
rowSign.setLine(j, dGroup.getName());
}
j++;
rowSign.update();
}
} else {
sign.setLine(0, NEW_GROUP);
}
sign.update();
i++;
}
}
// Static
@SuppressWarnings("deprecation")
public static GameSign tryToCreate(Block startSign, String mapName, int maxGames, int maxGroupsPerGame, boolean multiFloor) {
World world = startSign.getWorld();
int direction = startSign.getData();
int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ();
int verticalSigns = (int) Math.ceil((float) (1 + maxGroupsPerGame) / 4);
CopyOnWriteArrayList<Block> changeBlocks = new CopyOnWriteArrayList<Block>();
int xx, yy, zz;
switch (direction) {
case 2:
zz = z;
for (yy = y; yy > y - verticalSigns; yy--) {
for (xx = x; xx > x - maxGames; xx--) {
Block block = world.getBlockAt(xx, yy, zz);
if (block.getType() != Material.AIR && block.getType() != Material.WALL_SIGN) {
return null;
}
if (block.getRelative(0, 0, 1).getType() == Material.AIR) {
return null;
}
changeBlocks.add(block);
}
}
break;
case 3:
zz = z;
for (yy = y; yy > y - verticalSigns; yy--) {
for (xx = x; xx < x + maxGames; xx++) {
Block block = world.getBlockAt(xx, yy, zz);
if (block.getType() != Material.AIR && block.getType() != Material.WALL_SIGN) {
return null;
}
if (block.getRelative(0, 0, -1).getType() == Material.AIR) {
return null;
}
changeBlocks.add(block);
}
}
break;
case 4:
xx = x;
for (yy = y; yy > y - verticalSigns; yy--) {
for (zz = z; zz < z + maxGames; zz++) {
Block block = world.getBlockAt(xx, yy, zz);
if (block.getType() != Material.AIR && block.getType() != Material.WALL_SIGN) {
return null;
}
if (block.getRelative(1, 0, 0).getType() == Material.AIR) {
return null;
}
changeBlocks.add(block);
}
}
break;
case 5:
xx = x;
for (yy = y; yy > y - verticalSigns; yy--) {
for (zz = z; zz > z - maxGames; zz--) {
Block block = world.getBlockAt(xx, yy, zz);
if (block.getType() != Material.AIR && block.getType() != Material.WALL_SIGN) {
return null;
}
if (block.getRelative( -1, 0, 0).getType() == Material.AIR) {
return null;
}
changeBlocks.add(block);
}
}
break;
}
for (Block block : changeBlocks) {
block.setTypeIdAndData(68, startSign.getData(), true);
}
GameSign sign = new GameSign(startSign, mapName, maxGames, maxGroupsPerGame, multiFloor);
return sign;
}
@SuppressWarnings("deprecation")
public static boolean isRelativeSign(Block block, int x, int z) {
GameSign gameSign = getSign(block.getRelative(x, 0, z));
if (gameSign == null) {
return false;
}
if (x == -1 && gameSign.startSign.getData() == 4) {
return true;
}
if (x == 1 && gameSign.startSign.getData() == 5) {
return true;
}
if (z == -1 && gameSign.startSign.getData() == 2) {
return true;
}
if (z == 1 && gameSign.startSign.getData() == 3) {
return true;
}
return false;
}
public static GameSign getSign(Block block) {
if ( !(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)) {
return null;
}
int x = block.getX(), y = block.getY(), z = block.getZ();
for (GameSign gameSign : plugin.getGameSigns()) {
int sx1 = gameSign.startSign.getX(), sy1 = gameSign.startSign.getY(), sz1 = gameSign.startSign.getZ();
int sx2 = sx1 + (gameSign.games.length - 1) * gameSign.directionX;
int sy2 = sy1 - gameSign.verticalSigns + 1;
int sz2 = sz1 + (gameSign.games.length - 1) * gameSign.directionZ;
if (sx1 > sx2) {
if (x < sx2 || x > sx1) {
continue;
}
} else if (sx1 < sx2) {
if (x > sx2 || x < sx1) {
continue;
}
} else {
if (x != sx1) {
continue;
}
}
if (sy1 > sy2) {
if (y < sy2 || y > sy1) {
continue;
}
} else {
if (y != sy1) {
continue;
}
}
if (sz1 > sz2) {
if (z < sz2 || z > sz1) {
continue;
}
} else if (sz1 < sz2) {
if (z > sz2 || z < sz1) {
continue;
}
} else {
if (z != sz1) {
continue;
}
}
return gameSign;
}
return null;
}
public static boolean playerInteract(Block block, Player player) {
int x = block.getX(), y = block.getY(), z = block.getZ();
GameSign gameSign = getSign(block);
if (gameSign == null) {
return false;
}
DGroup dGroup = DGroup.getByPlayer(player);
if ( !dGroup.getCaptain().equals(player)) {
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_NOT_CAPTAIN));
return true;
}
if (Game.getByDGroup(dGroup) != null) {
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_LEAVE_GAME));
return true;
}
if ( !GameWorld.canPlayDungeon(gameSign.mapName, dGroup)) {
File file = new File(plugin.getDataFolder() + "/maps/" + gameSign.mapName, "config.yml");
if (file != null) {
WorldConfig confReader = new WorldConfig(file);
if (confReader != null) {
dGroup.sendMessage(plugin.getMessageConfig().getMessage(Messages.ERROR_COOLDOWN, String.valueOf(confReader.getTimeToNextPlay())));
}
}
return true;
}
if ( !GameWorld.checkRequirements(gameSign.mapName, dGroup)) {
dGroup.sendMessage(plugin.getMessageConfig().getMessage(Messages.ERROR_REQUIREMENTS));
return true;
}
int sx1 = gameSign.startSign.getX(), sy1 = gameSign.startSign.getY(), sz1 = gameSign.startSign.getZ();
Block topBlock = block.getRelative(0, sy1 - y, 0);
int column;
if (gameSign.directionX != 0) {
column = Math.abs(x - sx1);
} else {
column = Math.abs(z - sz1);
}
if ( !(topBlock.getState() instanceof Sign)) {
return true;
}
Sign topSign = (Sign) topBlock.getState();
if (topSign.getLine(0).equals(NEW_GROUP)) {
gameSign.games[column] = new Game(dGroup);
gameSign.update();
} else if (topSign.getLine(0).equals(JOIN_GROUP)) {
gameSign.games[column].addDGroup(dGroup);
gameSign.update();
}
return true;
}
public static void updatePerGame(Game gameSearch) {
for (GameSign gameSign : plugin.getGameSigns()) {
int i = 0;
for (Game game : gameSign.games) {
if (game == null) {
continue;
}
if (game == gameSearch) {
if (gameSearch.isEmpty()) {
gameSign.games[i] = null;
}
gameSign.update();
}
i++;
}
}
}
public static int[] getDirection(byte data) {
int[] direction = new int[2];
switch (data) {
case 2:
direction[0] = -1;
break;
case 3:
direction[0] = 1;
break;
case 4:
direction[1] = 1;
break;
case 5:
direction[1] = -1;
break;
}
return direction;
}
// Save and Load
public static void save(FileConfiguration configFile) {
int id = 0;
for (GameSign gameSign : plugin.getGameSigns()) {
id++;
String preString = "gamesign." + gameSign.startSign.getWorld().getName() + "." + id;
// Location
configFile.set(preString + ".x", gameSign.startSign.getX());
configFile.set(preString + ".y", gameSign.startSign.getY());
configFile.set(preString + ".z", gameSign.startSign.getZ());
// Etc.
if (gameSign.isMultiFloor()) {
configFile.set(preString + ".dungeon", gameSign.dungeonName);
} else {
configFile.set(preString + ".dungeon", gameSign.mapName);
}
configFile.set(preString + ".maxGames", gameSign.games.length);
configFile.set(preString + ".maxGroupsPerGame", gameSign.maxGroupsPerGame);
configFile.set(preString + ".multiFloor", gameSign.isMultiFloor());
}
}
public static void load(FileConfiguration configFile) {
for (World world : plugin.getServer().getWorlds()) {
if ( !configFile.contains("gamesign." + world.getName())) {
continue;
}
int id = 0;
String preString;
do {
id++;
preString = "gamesign." + world.getName() + "." + id + ".";
if (configFile.contains(preString)) {
String mapName = configFile.getString(preString + ".dungeon");
int maxGames = configFile.getInt(preString + ".maxGames");
int maxGroupsPerGame = configFile.getInt(preString + ".maxGroupsPerGame");
boolean multiFloor = false;
if (configFile.contains(preString + ".multiFloor")) {
multiFloor = configFile.getBoolean(preString + ".multiFloor");
}
Block startSign = world.getBlockAt(configFile.getInt(preString + ".x"), configFile.getInt(preString + ".y"), configFile.getInt(preString + ".z"));
new GameSign(startSign, mapName, maxGames, maxGroupsPerGame, multiFloor);
}
} while (configFile.contains(preString));
}
}
}

View File

@ -1,539 +0,0 @@
package io.github.dre2n.dungeonsxl.global;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import java.io.File;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
public class GroupSign {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
// Sign Labels
public static final String IS_PLAYING = ChatColor.DARK_RED + "Is Playing";
public static final String FULL = ChatColor.DARK_RED + "Full";
public static final String JOIN_GROUP = ChatColor.DARK_GREEN + "Join Group";
public static final String NEW_GROUP = ChatColor.DARK_GREEN + "New Group";
// Variables
private DGroup[] dGroups;
private boolean multiFloor;
private String dungeonName;
private String mapName;
private int maxPlayersPerGroup;
private Block startSign;
private int directionX = 0, directionZ = 0;
private int verticalSigns;
public GroupSign(Block startSign, String identifier, int maxGroups, int maxPlayersPerGroup, boolean multiFloor) {
plugin.getGroupSigns().add(this);
this.startSign = startSign;
dGroups = new DGroup[maxGroups];
this.setMultiFloor(multiFloor);
if (multiFloor) {
dungeonName = identifier;
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
if (dungeon != null) {
mapName = dungeon.getConfig().getStartFloor();
} else {
mapName = "invalid";
}
} else {
mapName = identifier;
}
this.maxPlayersPerGroup = maxPlayersPerGroup;
verticalSigns = (int) Math.ceil((float) (1 + maxPlayersPerGroup) / 4);
@SuppressWarnings("deprecation")
int[] direction = getDirection(this.startSign.getData());
directionX = direction[0];
directionZ = direction[1];
update();
}
/**
* @return the dungeonName
*/
public String getDungeonName() {
return dungeonName;
}
/**
* @param dungeonName
* the dungeonName to set
*/
public void setDungeonName(String dungeonName) {
this.dungeonName = dungeonName;
}
/**
* @return the mapName
*/
public String getMapName() {
return mapName;
}
/**
* @param mapName
* the mapName to set
*/
public void setMapName(String mapName) {
this.mapName = mapName;
}
/**
* @return the multiFloor
*/
public boolean isMultiFloor() {
return multiFloor;
}
/**
* @param multiFloor
* the multiFloor to set
*/
public void setMultiFloor(boolean multiFloor) {
this.multiFloor = multiFloor;
}
public void delete() {
plugin.getGroupSigns().remove(this);
}
public void update() {
int i = 0;
for (DGroup dGroup : dGroups) {
if ( !(startSign.getRelative(i * directionX, 0, i * directionZ).getState() instanceof Sign)) {
i++;
continue;
}
Sign sign = (Sign) startSign.getRelative(i * directionX, 0, i * directionZ).getState();
// Reset Signs
sign.setLine(0, "");
sign.setLine(1, "");
sign.setLine(2, "");
sign.setLine(3, "");
int yy = -1;
while (sign.getBlock().getRelative(0, yy, 0).getState() instanceof Sign) {
Sign subsign = (Sign) sign.getBlock().getRelative(0, yy, 0).getState();
subsign.setLine(0, "");
subsign.setLine(1, "");
subsign.setLine(2, "");
subsign.setLine(3, "");
subsign.update();
yy--;
}
// Set Signs
if (dGroup != null) {
if (dGroup.isPlaying()) {
sign.setLine(0, IS_PLAYING);
} else if (dGroup.getPlayers().size() >= maxPlayersPerGroup) {
sign.setLine(0, FULL);
} else {
sign.setLine(0, JOIN_GROUP);
}
int j = 1;
Sign rowSign = sign;
for (Player player : dGroup.getPlayers()) {
if (j > 3) {
j = 0;
rowSign = (Sign) sign.getBlock().getRelative(0, -1, 0).getState();
}
if (rowSign != null) {
rowSign.setLine(j, player.getName());
}
j++;
rowSign.update();
}
} else {
sign.setLine(0, NEW_GROUP);
}
sign.update();
i++;
}
}
// Static
@SuppressWarnings("deprecation")
public static GroupSign tryToCreate(Block startSign, String mapName, int maxGroups, int maxPlayersPerGroup, boolean multiFloor) {
World world = startSign.getWorld();
int direction = startSign.getData();
int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ();
int verticalSigns = (int) Math.ceil((float) (1 + maxPlayersPerGroup) / 4);
CopyOnWriteArrayList<Block> changeBlocks = new CopyOnWriteArrayList<Block>();
int xx, yy, zz;
switch (direction) {
case 2:
zz = z;
for (yy = y; yy > y - verticalSigns; yy--) {
for (xx = x; xx > x - maxGroups; xx--) {
Block block = world.getBlockAt(xx, yy, zz);
if (block.getType() != Material.AIR && block.getType() != Material.WALL_SIGN) {
return null;
}
if (block.getRelative(0, 0, 1).getType() == Material.AIR) {
return null;
}
changeBlocks.add(block);
}
}
break;
case 3:
zz = z;
for (yy = y; yy > y - verticalSigns; yy--) {
for (xx = x; xx < x + maxGroups; xx++) {
Block block = world.getBlockAt(xx, yy, zz);
if (block.getType() != Material.AIR && block.getType() != Material.WALL_SIGN) {
return null;
}
if (block.getRelative(0, 0, -1).getType() == Material.AIR) {
return null;
}
changeBlocks.add(block);
}
}
break;
case 4:
xx = x;
for (yy = y; yy > y - verticalSigns; yy--) {
for (zz = z; zz < z + maxGroups; zz++) {
Block block = world.getBlockAt(xx, yy, zz);
if (block.getType() != Material.AIR && block.getType() != Material.WALL_SIGN) {
return null;
}
if (block.getRelative(1, 0, 0).getType() == Material.AIR) {
return null;
}
changeBlocks.add(block);
}
}
break;
case 5:
xx = x;
for (yy = y; yy > y - verticalSigns; yy--) {
for (zz = z; zz > z - maxGroups; zz--) {
Block block = world.getBlockAt(xx, yy, zz);
if (block.getType() != Material.AIR && block.getType() != Material.WALL_SIGN) {
return null;
}
if (block.getRelative( -1, 0, 0).getType() == Material.AIR) {
return null;
}
changeBlocks.add(block);
}
}
break;
}
for (Block block : changeBlocks) {
block.setTypeIdAndData(68, startSign.getData(), true);
}
GroupSign sign = new GroupSign(startSign, mapName, maxGroups, maxPlayersPerGroup, multiFloor);
return sign;
}
@SuppressWarnings("deprecation")
public static boolean isRelativeSign(Block block, int x, int z) {
GroupSign groupSign = getSign(block.getRelative(x, 0, z));
if (groupSign == null) {
return false;
}
if (x == -1 && groupSign.startSign.getData() == 4) {
return true;
}
if (x == 1 && groupSign.startSign.getData() == 5) {
return true;
}
if (z == -1 && groupSign.startSign.getData() == 2) {
return true;
}
if (z == 1 && groupSign.startSign.getData() == 3) {
return true;
}
return false;
}
public static GroupSign getSign(Block block) {
if ( !(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)) {
return null;
}
int x = block.getX(), y = block.getY(), z = block.getZ();
for (GroupSign groupSign : plugin.getGroupSigns()) {
int sx1 = groupSign.startSign.getX(), sy1 = groupSign.startSign.getY(), sz1 = groupSign.startSign.getZ();
int sx2 = sx1 + (groupSign.dGroups.length - 1) * groupSign.directionX;
int sy2 = sy1 - groupSign.verticalSigns + 1;
int sz2 = sz1 + (groupSign.dGroups.length - 1) * groupSign.directionZ;
if (sx1 > sx2) {
if (x < sx2 || x > sx1) {
continue;
}
} else if (sx1 < sx2) {
if (x > sx2 || x < sx1) {
continue;
}
} else {
if (x != sx1) {
continue;
}
}
if (sy1 > sy2) {
if (y < sy2 || y > sy1) {
continue;
}
} else {
if (y != sy1) {
continue;
}
}
if (sz1 > sz2) {
if (z < sz2 || z > sz1) {
continue;
}
} else if (sz1 < sz2) {
if (z > sz2 || z < sz1) {
continue;
}
} else {
if (z != sz1) {
continue;
}
}
return groupSign;
}
return null;
}
public static boolean playerInteract(Block block, Player player) {
int x = block.getX(), y = block.getY(), z = block.getZ();
GroupSign groupSign = getSign(block);
if (groupSign == null) {
return false;
}
if (DGroup.getByPlayer(player) != null) {
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_LEAVE_GROUP));
return true;
}
if ( !GameWorld.canPlayDungeon(groupSign.mapName, player)) {
File file = new File(plugin.getDataFolder() + "/maps/" + groupSign.mapName, "config.yml");
if (file != null) {
WorldConfig confReader = new WorldConfig(file);
if (confReader != null) {
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_COOLDOWN, String.valueOf(confReader.getTimeToNextPlay())));
}
}
return true;
}
if ( !GameWorld.checkRequirements(groupSign.mapName, player)) {
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_REQUIREMENTS));
return true;
}
int sx1 = groupSign.startSign.getX(), sy1 = groupSign.startSign.getY(), sz1 = groupSign.startSign.getZ();
Block topBlock = block.getRelative(0, sy1 - y, 0);
int column;
if (groupSign.directionX != 0) {
column = Math.abs(x - sx1);
} else {
column = Math.abs(z - sz1);
}
if ( !(topBlock.getState() instanceof Sign)) {
return true;
}
Sign topSign = (Sign) topBlock.getState();
if (topSign.getLine(0).equals(NEW_GROUP)) {
if (groupSign.isMultiFloor()) {
groupSign.dGroups[column] = new DGroup(player, groupSign.dungeonName, groupSign.isMultiFloor());
} else {
groupSign.dGroups[column] = new DGroup(player, groupSign.mapName, groupSign.isMultiFloor());
}
groupSign.update();
} else if (topSign.getLine(0).equals(JOIN_GROUP)) {
groupSign.dGroups[column].addPlayer(player);
groupSign.update();
}
return true;
}
public static void updatePerGroup(DGroup dGroupSearch) {
for (GroupSign groupSign : plugin.getGroupSigns()) {
int i = 0;
for (DGroup dGroup : groupSign.dGroups) {
if (dGroup == null) {
continue;
}
if (dGroup == dGroupSearch) {
if (dGroupSearch.isEmpty()) {
groupSign.dGroups[i] = null;
}
groupSign.update();
}
i++;
}
}
}
public static int[] getDirection(byte data) {
int[] direction = new int[2];
switch (data) {
case 2:
direction[0] = -1;
break;
case 3:
direction[0] = 1;
break;
case 4:
direction[1] = 1;
break;
case 5:
direction[1] = -1;
break;
}
return direction;
}
// Save and Load
public static void save(FileConfiguration configFile) {
int id = 0;
for (GroupSign groupSign : plugin.getGroupSigns()) {
id++;
String preString = "groupsign." + groupSign.startSign.getWorld().getName() + "." + id;
// Location
configFile.set(preString + ".x", groupSign.startSign.getX());
configFile.set(preString + ".y", groupSign.startSign.getY());
configFile.set(preString + ".z", groupSign.startSign.getZ());
// Etc.
if (groupSign.isMultiFloor()) {
configFile.set(preString + ".dungeon", groupSign.dungeonName);
} else {
configFile.set(preString + ".dungeon", groupSign.mapName);
}
configFile.set(preString + ".maxGroups", groupSign.dGroups.length);
configFile.set(preString + ".maxPlayersPerGroup", groupSign.maxPlayersPerGroup);
configFile.set(preString + ".multiFloor", groupSign.isMultiFloor());
}
}
public static void load(FileConfiguration configFile) {
for (World world : plugin.getServer().getWorlds()) {
if ( !configFile.contains("groupsign." + world.getName())) {
continue;
}
int id = 0;
String preString;
do {
id++;
preString = "groupsign." + world.getName() + "." + id + ".";
if (configFile.contains(preString)) {
String mapName = configFile.getString(preString + ".dungeon");
int maxGroups = configFile.getInt(preString + ".maxGroups");
int maxPlayersPerGroup = configFile.getInt(preString + ".maxPlayersPerGroup");
boolean multiFloor = false;
if (configFile.contains(preString + ".multiFloor")) {
multiFloor = configFile.getBoolean(preString + ".multiFloor");
}
Block startSign = world.getBlockAt(configFile.getInt(preString + ".x"), configFile.getInt(preString + ".y"), configFile.getInt(preString + ".z"));
new GroupSign(startSign, mapName, maxGroups, maxPlayersPerGroup, multiFloor);
}
} while (configFile.contains(preString));
}
}
}

View File

@ -1,148 +0,0 @@
package io.github.dre2n.dungeonsxl.global;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
public class LeaveSign {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
private Sign sign;
public LeaveSign(Sign sign) {
plugin.getLeaveSigns().add(this);
this.sign = sign;
setText();
}
public void setText() {
sign.setLine(0, ChatColor.BLUE + "############");
sign.setLine(1, ChatColor.DARK_GREEN + "Leave");
sign.setLine(2, "");
sign.setLine(3, ChatColor.BLUE + "############");
sign.update();
}
public void delete() {
plugin.getLeaveSigns().remove(this);
}
public static boolean playerInteract(Block block, Player player) {
LeaveSign leaveSign = getSign(block);
if (leaveSign == null) {
return false;
}
DPlayer dplayer = DPlayer.getByPlayer(player);
if (dplayer != null) {
dplayer.leave();
return true;
} else {
DGroup dgroup = DGroup.getByPlayer(player);
if (dgroup != null) {
dgroup.removePlayer(player);
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_LEAVE_GROUP));// ChatColor.YELLOW+"Du hast deine Gruppe erfolgreich verlassen!");
return true;
}
}
return false;
}
@SuppressWarnings("deprecation")
public static boolean isRelativeSign(Block block, int x, int z) {
LeaveSign leaveSign = getSign(block.getRelative(x, 0, z));
if (leaveSign == null) {
return false;
}
if (x == -1 && leaveSign.sign.getData().getData() == 4) {
return true;
}
if (x == 1 && leaveSign.sign.getData().getData() == 5) {
return true;
}
if (z == -1 && leaveSign.sign.getData().getData() == 2) {
return true;
}
if (z == 1 && leaveSign.sign.getData().getData() == 3) {
return true;
}
return false;
}
public static LeaveSign getSign(Block block) {
if ( !(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)) {
return null;
}
for (LeaveSign leavesign : plugin.getLeaveSigns()) {
if (block.getWorld() != leavesign.sign.getWorld()) {
continue;
}
if (block.getLocation().distance(leavesign.sign.getBlock().getLocation()) < 1) {
return leavesign;
}
}
return null;
}
// Save and Load
public static void save(FileConfiguration configFile) {
int id = 0;
for (LeaveSign leaveSign : plugin.getLeaveSigns()) {
id++;
String preString = "leavesign." + leaveSign.sign.getWorld().getName() + "." + id;
configFile.set(preString + ".x", leaveSign.sign.getX());
configFile.set(preString + ".y", leaveSign.sign.getY());
configFile.set(preString + ".z", leaveSign.sign.getZ());
}
}
public static void load(FileConfiguration configFile) {
for (World world : plugin.getServer().getWorlds()) {
if ( !configFile.contains("leavesign." + world.getName())) {
continue;
}
int id = 0;
String preString;
do {
id++;
preString = "leavesign." + world.getName() + "." + id + ".";
if (configFile.contains(preString)) {
Block block = world.getBlockAt(configFile.getInt(preString + ".x"), configFile.getInt(preString + ".y"), configFile.getInt(preString + ".z"));
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
new LeaveSign(sign);
}
}
} while (configFile.contains(preString));
}
}
}

View File

@ -1,272 +0,0 @@
package io.github.dre2n.dungeonsxl.listener;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.game.GamePlaceableBlock;
import io.github.dre2n.dungeonsxl.game.GameType;
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.global.DPortal;
import io.github.dre2n.dungeonsxl.global.GroupSign;
import io.github.dre2n.dungeonsxl.global.LeaveSign;
import io.github.dre2n.dungeonsxl.sign.DSign;
import io.github.dre2n.dungeonsxl.task.RedstoneEventTask;
import io.github.dre2n.dungeonsxl.util.NumberUtil;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.SignChangeEvent;
public class BlockListener implements Listener {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
@EventHandler(priority = EventPriority.HIGH)
public void onPhysics(BlockPhysicsEvent event) {
if (event.getBlock().getType() != Material.PORTAL) {
return;
}
if (DPortal.getByBlock(event.getBlock()) != null) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onBreak(BlockBreakEvent event) {
Block block = event.getBlock();
Player player = event.getPlayer();
// Deny DPortal destroying
if (block.getType() == Material.PORTAL) {
DPortal dPortal = DPortal.getByBlock(event.getBlock());
if (dPortal != null) {
if (plugin.getInBreakMode().contains(player)) {
dPortal.delete();
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_PROTECTED_BLOCK_DELETED));
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.CMD_BREAK_PROTECTED_MODE));
plugin.getInBreakMode().remove(player);
} else {
event.setCancelled(true);
}
return;
}
}
// Delete GroupSign
GroupSign groupSign = GroupSign.getSign(block);
if (groupSign != null) {
if (plugin.getInBreakMode().contains(player)) {
groupSign.delete();
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_PROTECTED_BLOCK_DELETED));
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.CMD_BREAK_PROTECTED_MODE));
plugin.getInBreakMode().remove(player);
} else {
event.setCancelled(true);
}
return;
}
// Deny DGSignblocks destroying
if (GroupSign.isRelativeSign(block, 1, 0) || GroupSign.isRelativeSign(block, -1, 0) || GroupSign.isRelativeSign(block, 0, 1) || GroupSign.isRelativeSign(block, 0, -1)) {
event.setCancelled(true);
return;
}
// Delete LeaveSign
LeaveSign leaveSign = LeaveSign.getSign(block);
if (leaveSign != null) {
if (plugin.getInBreakMode().contains(player)) {
leaveSign.delete();
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_PROTECTED_BLOCK_DELETED));
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.CMD_BREAK_PROTECTED_MODE));
plugin.getInBreakMode().remove(player);
} else {
event.setCancelled(true);
}
return;
}
// Deny LeaveSignblocks destroying
if (LeaveSign.isRelativeSign(block, 1, 0) || LeaveSign.isRelativeSign(block, -1, 0) || LeaveSign.isRelativeSign(block, 0, 1) || LeaveSign.isRelativeSign(block, 0, -1)) {
event.setCancelled(true);
return;
}
// Editworld Signs
EditWorld editWorld = EditWorld.getByWorld(block.getWorld());
if (editWorld != null) {
editWorld.getSign().remove(event.getBlock());
}
// Deny GameWorld Blocks
GameWorld gameWorld = GameWorld.getByWorld(block.getWorld());
if (gameWorld != null) {
if (gameWorld.getDSigns().contains(block)) {
event.setCancelled(true);
} else if (gameWorld.getGame() != null) {
GameType gameType = gameWorld.getGame().getType();
if (gameType == GameTypeDefault.DEFAULT && gameWorld.getConfig() != null) {
event.setCancelled( !gameWorld.getConfig().canBuild());
} else if ( !gameType.canBuild()) {
event.setCancelled(true);
}
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlace(BlockPlaceEvent event) {
Block block = event.getBlock();
// Deny GameWorld Blocks
GameWorld gameWorld = GameWorld.getByWorld(block.getWorld());
if (gameWorld == null) {
return;
}
if (gameWorld.getConfig().canBuild() || GamePlaceableBlock.canBuildHere(block, block.getFace(event.getBlockAgainst()), event.getItemInHand().getType(), gameWorld)) {
return;
}
// Workaround for a bug that would allow 3-Block-high jumping
Location loc = event.getPlayer().getLocation();
if (loc.getY() > block.getY() + 1.0 && loc.getY() <= block.getY() + 1.5) {
if (loc.getX() >= block.getX() - 0.3 && loc.getX() <= block.getX() + 1.3) {
if (loc.getZ() >= block.getZ() - 0.3 && loc.getZ() <= block.getZ() + 1.3) {
loc.setX(block.getX() + 0.5);
loc.setY(block.getY());
loc.setZ(block.getZ() + 0.5);
event.getPlayer().teleport(loc);
}
}
}
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.NORMAL)
public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
String[] lines = event.getLines();
EditWorld editWorld = EditWorld.getByWorld(player.getWorld());
// Group Signs
if (editWorld == null) {
if ( !player.hasPermission("dxl.sign")) {
return;
}
if ( !lines[0].equalsIgnoreCase("[DXL]")) {
return;
}
if (lines[1].equalsIgnoreCase("Group")) {
String dungeonName = lines[2];
String[] data = lines[3].split("\\,");
if (data.length >= 2 && data.length <= 3) {
int maxGroups = NumberUtil.parseInt(data[0]);
int maxPlayersPerGroup = NumberUtil.parseInt(data[1]);
boolean multiFloor = false;
if (data.length == 3) {
if (data[2].equals("+")) {
multiFloor = true;
}
}
if (maxGroups > 0 && maxPlayersPerGroup > 0) {
if (GroupSign.tryToCreate(event.getBlock(), dungeonName, maxGroups, maxPlayersPerGroup, multiFloor) != null) {
event.setCancelled(true);
}
}
}
} else if (lines[1].equalsIgnoreCase("Leave")) {
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
new LeaveSign(sign);
}
event.setCancelled(true);
}
} else { // Editworld Signs
Sign sign = (Sign) block.getState();
if (sign != null) {
sign.setLine(0, lines[0]);
sign.setLine(1, lines[1]);
sign.setLine(2, lines[2]);
sign.setLine(3, lines[3]);
DSign dsign = DSign.create(sign, null);
if (dsign == null) {
return;
}
if ( !player.hasPermission(dsign.getType().getBuildPermission())) {
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_NO_PERMISSIONS));
}
if (dsign.check()) {
editWorld.checkSign(block);
editWorld.getSign().add(block);
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_SIGN_CREATED));
} else {
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_SIGN_WRONG_FORMAT));
}
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onSpread(BlockSpreadEvent event) {
Block block = event.getBlock();
// Block the Spread off Vines
if (block.getType() != Material.VINE) {
return;
}
// Check GameWorlds
GameWorld gameWorld = GameWorld.getByWorld(event.getBlock().getWorld());
if (gameWorld != null) {
event.setCancelled(true);
}
// Check EditWorlds
EditWorld editWorld = EditWorld.getByWorld(event.getBlock().getWorld());
if (editWorld != null) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onRedstoneEvent(BlockRedstoneEvent event) {
new RedstoneEventTask(event.getBlock()).runTaskLater(plugin, 1);
}
}

View File

@ -1,66 +0,0 @@
package io.github.dre2n.dungeonsxl.listener;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import io.github.dre2n.dungeonsxl.command.DCommand;
import io.github.dre2n.dungeonsxl.config.MessageConfig;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class CommandListener implements CommandExecutor {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
@Override
public boolean onCommand(CommandSender sender, Command cmd_notused, String arg, String[] args) {
if (args.length > 0) {
MessageConfig MessageConfig = plugin.getMessageConfig();
DCommand dCommand = plugin.getDCommands().getDCommand(args[0]);
if (dCommand != null) {
if (sender instanceof ConsoleCommandSender) {
if ( !dCommand.isConsoleCommand()) {
MessageUtil.sendMessage(sender, MessageConfig.getMessage(Messages.LOG_ERROR_NO_CONSOLE_COMMAND, dCommand.getCommand()));
return false;
}
}
if (sender instanceof Player) {
Player player = (Player) sender;
if ( !dCommand.isPlayerCommand()) {
MessageUtil.sendMessage(player, MessageConfig.getMessage(Messages.ERROR_NO_PLAYER_COMMAND, dCommand.getCommand()));
return false;
} else {
if (dCommand.getPermission() != null) {
if ( !dCommand.playerHasPermissions(player)) {
MessageUtil.sendMessage(player, MessageConfig.getMessage(Messages.ERROR_NO_PERMISSIONS));
return false;
}
}
}
}
if (dCommand.getMinArgs() <= args.length - 1 & dCommand.getMaxArgs() >= args.length - 1 || dCommand.getMinArgs() == -1) {
dCommand.onExecute(args, sender);
return true;
} else {
dCommand.displayHelp(sender);
return true;
}
}
}
plugin.getDCommands().getDCommand("main").onExecute(null, sender);
return false;
}
}

View File

@ -1,266 +0,0 @@
package io.github.dre2n.dungeonsxl.listener;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GameType;
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.global.DPortal;
import io.github.dre2n.dungeonsxl.global.GroupSign;
import io.github.dre2n.dungeonsxl.mob.DMob;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityCombustByEntityEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
public class EntityListener implements Listener {
// Remove drops from breaking Signs
@EventHandler(priority = EventPriority.HIGH)
public void onItemSpawn(ItemSpawnEvent event) {
if (GameWorld.getByWorld(event.getLocation().getWorld()) != null) {
if (event.getEntity().getItemStack().getType() == Material.SIGN) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onCreatureSpawn(CreatureSpawnEvent event) {
World world = event.getLocation().getWorld();
EditWorld editWorld = EditWorld.getByWorld(world);
GameWorld gameWorld = GameWorld.getByWorld(world);
if (editWorld != null || gameWorld != null) {
if (event.getSpawnReason() == SpawnReason.CHUNK_GEN || event.getSpawnReason() == SpawnReason.BREEDING || event.getSpawnReason() == SpawnReason.NATURAL
|| event.getSpawnReason() == SpawnReason.DEFAULT) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onDeath(EntityDeathEvent event) {
World world = event.getEntity().getWorld();
if (event.getEntity() instanceof LivingEntity) {
LivingEntity entity = event.getEntity();
GameWorld gameWorld = GameWorld.getByWorld(world);
if (gameWorld != null) {
if (gameWorld.isPlaying()) {
if (entity.getType() != EntityType.PLAYER) {
event.getDrops().clear();
DMob.onDeath(event);
}
}
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onDamage(EntityDamageEvent event) {
World world = event.getEntity().getWorld();
GameWorld gameWorld = GameWorld.getByWorld(world);
if (gameWorld == null) {
return;
}
// Deny all Damage in Lobby
if ( !gameWorld.isPlaying()) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onDamageByEntity(EntityDamageByEntityEvent event) {
World world = event.getEntity().getWorld();
GameWorld gameWorld = GameWorld.getByWorld(world);
if (gameWorld == null) {
return;
}
Game game = gameWorld.getGame();
if (game == null) {
return;
}
WorldConfig config = gameWorld.getConfig();
GameType type = game.getType();
boolean pvp = config.isPlayerVersusPlayer();
boolean friendlyFire = config.isFriendlyFire();
if (type != GameTypeDefault.DEFAULT) {
pvp = type.isPlayerVersusPlayer();
friendlyFire = type.isFriendlyFire();
}
Entity attackerEntity = event.getDamager();
Entity attackedEntity = event.getEntity();
if (attackerEntity instanceof Projectile) {
attackerEntity = (Entity) ((Projectile) attackerEntity).getShooter();
}
Player attackerPlayer = null;
Player attackedPlayer = null;
DGroup attackerDGroup = null;
DGroup attackedDGroup = null;
if (attackerEntity instanceof Player && attackedEntity instanceof Player) {
attackerPlayer = (Player) attackerEntity;
attackedPlayer = (Player) attackedEntity;
attackerDGroup = DGroup.getByPlayer(attackerPlayer);
attackedDGroup = DGroup.getByPlayer(attackedPlayer);
if ( !pvp) {
event.setCancelled(true);
}
if (attackerDGroup != null && attackedDGroup != null) {
if ( !friendlyFire && attackerDGroup.equals(attackedDGroup)) {
Bukkit.broadcastMessage("ff cancel");
event.setCancelled(true);
}
}
}
if (attackerEntity instanceof LivingEntity && attackedEntity instanceof LivingEntity) {
if ( !(attackerEntity instanceof Player) && !(attackedEntity instanceof Player)) {
event.setCancelled(true);
}
// Check Dogs
if (attackerEntity instanceof Player || attackedEntity instanceof Player) {
for (DPlayer dPlayer : DPlayer.getByWorld(gameWorld.getWorld())) {
if (dPlayer.getWolf() != null) {
if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) {
event.setCancelled(true);
return;
}
}
}
}
for (DPlayer dPlayer : DPlayer.getByWorld(gameWorld.getWorld())) {
if (dPlayer.getWolf() != null) {
if (attackerEntity instanceof Player || attackedEntity instanceof Player) {
if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) {
event.setCancelled(true);
return;
}
} else {
if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) {
event.setCancelled(false);
return;
}
}
}
}
}
}
// Deny food in Lobby
@EventHandler(priority = EventPriority.HIGH)
public void onFoodLevelChange(FoodLevelChangeEvent event) {
World world = event.getEntity().getWorld();
GameWorld gameWorld = GameWorld.getByWorld(world);
if (gameWorld != null) {
if ( !gameWorld.isPlaying()) {
event.setCancelled(true);
}
}
}
// Zombie/skeleton combustion from the sun.
@EventHandler(priority = EventPriority.NORMAL)
public void onCombust(EntityCombustEvent event) {
GameWorld gameWorld = GameWorld.getByWorld(event.getEntity().getWorld());
if (gameWorld != null) {
event.setCancelled(true);
}
}
// Allow Other combustion
@EventHandler(priority = EventPriority.HIGH)
public void onCombustByEntity(EntityCombustByEntityEvent event) {
GameWorld gameWorld = GameWorld.getByWorld(event.getEntity().getWorld());
if (gameWorld != null) {
if (event.isCancelled()) {
event.setCancelled(false);
}
}
}
// Explosions
@EventHandler
public void onExplode(EntityExplodeEvent event) {
GameWorld gameWorld = GameWorld.getByWorld(event.getEntity().getWorld());
if (gameWorld != null) {
if (event.getEntity() instanceof LivingEntity) {
// Disable Creeper explosions in gameditWorlds
event.setCancelled(true);
return;
} else {
// Disable drops from TNT
event.setYield(0);
}
}
// Prevent Portal and Sign Destroying
List<Block> blocklist = event.blockList();
for (Block block : blocklist) {
// Portals
if (block.getType() == Material.PORTAL) {
if (DPortal.getByBlock(block) != null) {
event.setCancelled(true);
return;
}
}
// Signs
if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) {
if (GroupSign.getSign(block) != null) {
event.setCancelled(true);
return;
}
}
}
}
}

View File

@ -1,19 +0,0 @@
package io.github.dre2n.dungeonsxl.listener;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
public class HangingListener implements Listener {
@EventHandler
public void onHangingBreakByEntity(HangingBreakByEntityEvent event) {
GameWorld gameWorld = GameWorld.getByWorld(event.getEntity().getWorld());
if (gameWorld != null) {
event.setCancelled(true);
}
}
}

View File

@ -1,611 +0,0 @@
package io.github.dre2n.dungeonsxl.listener;
import java.util.ArrayList;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.MessageConfig;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.dungeon.DLootInventory;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerDeathEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent;
import io.github.dre2n.dungeonsxl.game.GameChest;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.global.DPortal;
import io.github.dre2n.dungeonsxl.global.GroupSign;
import io.github.dre2n.dungeonsxl.global.LeaveSign;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.task.RespawnTask;
import io.github.dre2n.dungeonsxl.trigger.InteractTrigger;
import io.github.dre2n.dungeonsxl.trigger.UseItemTrigger;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
public class PlayerListener implements Listener {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
protected static MessageConfig messageConfig = plugin.getMessageConfig();
@EventHandler(priority = EventPriority.HIGH)
public void onDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
final DPlayer dPlayer = DPlayer.getByPlayer(player);
GameWorld gameWorld = GameWorld.getByWorld(player.getLocation().getWorld());
if (gameWorld == null) {
return;
}
WorldConfig dConfig = gameWorld.getConfig();
if (dPlayer == null) {
return;
}
DPlayerDeathEvent dPlayerDeathEvent = new DPlayerDeathEvent(dPlayer, event, 1);
if (dPlayerDeathEvent.isCancelled()) {
return;
}
dPlayer.setLives(dPlayer.getLives() - dPlayerDeathEvent.getLostLives());
if (dPlayer.getLives() == 0 && dPlayer.isReady()) {
DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(dPlayer, DPlayerKickEvent.Cause.DEATH);
if ( !dPlayerKickEvent.isCancelled()) {
MessageUtil.broadcastMessage(messageConfig.getMessage(Messages.PLAYER_DEATH_KICK, player.getName()));
// TODO: This Runnable is a workaround for a bug I couldn't find, yet...
new org.bukkit.scheduler.BukkitRunnable() {
public void run() {
dPlayer.leave();
}
}.runTaskLater(plugin, 1L);
}
}
if (dPlayer.getLives() != -1) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.PLAYER_DEATH, String.valueOf(dPlayer.getLives())));
if (dConfig != null) {
if (dConfig.getKeepInventoryOnDeath()) {
dPlayer.setRespawnInventory(event.getEntity().getInventory().getContents());
dPlayer.setRespawnArmor(event.getEntity().getInventory().getArmorContents());
// Delete all drops
for (ItemStack istack : event.getDrops()) {
istack.setType(Material.AIR);
}
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
Block clickedBlock = event.getClickedBlock();
if (plugin.getInBreakMode().contains(player)) {
return;
}
if (clickedBlock != null) {
// Block Enderchests
if (GameWorld.getByWorld(player.getWorld()) != null || EditWorld.getByWorld(player.getWorld()) != null) {
if (event.getAction() != Action.LEFT_CLICK_BLOCK) {
if (clickedBlock.getType() == Material.ENDER_CHEST) {
if ( !player.hasPermission("dxl.bypass")) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_ENDERCHEST));
event.setCancelled(true);
}
} else if (clickedBlock.getType() == Material.BED_BLOCK) {
if ( !player.hasPermission("dxl.bypass")) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_BED));
event.setCancelled(true);
}
}
}
}
// Block Dispensers
if (GameWorld.getByWorld(player.getWorld()) != null) {
if (event.getAction() != Action.LEFT_CLICK_BLOCK) {
if (clickedBlock.getType() == Material.DISPENSER) {
if ( !player.hasPermission("dxl.bypass")) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_DISPENSER));
event.setCancelled(true);
}
}
}
}
}
// Check Portals
if (event.getItem() != null) {
ItemStack item = event.getItem();
if (item.getType() == Material.WOOD_SWORD) {
if (clickedBlock != null) {
for (DPortal dportal : plugin.getDPortals()) {
if ( !dportal.isActive()) {
if (dportal.getPlayer() == player) {
if (dportal.getBlock1() == null) {
dportal.setBlock1(event.getClickedBlock());
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.PLAYER_PORTAL_PROGRESS));
} else if (dportal.getBlock2() == null) {
dportal.setBlock2(event.getClickedBlock());
dportal.setActive(true);
dportal.create();
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.PLAYER_PORTAL_CREATED));
}
event.setCancelled(true);
}
}
}
}
}
// Copy/Paste a Sign and Block-info
if (EditWorld.getByWorld(player.getWorld()) != null) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (item.getType() == Material.STICK) {
DPlayer dPlayer = DPlayer.getByPlayer(player);
if (dPlayer != null) {
dPlayer.poke(clickedBlock);
event.setCancelled(true);
}
}
}
}
// Trigger UseItem Signs
GameWorld gameWorld = GameWorld.getByWorld(player.getWorld());
if (gameWorld != null) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) {
if (UseItemTrigger.hasTriggers(gameWorld)) {
String name = null;
if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) {
name = item.getItemMeta().getDisplayName();
} else if (item.getType() == Material.WRITTEN_BOOK || item.getType() == Material.BOOK_AND_QUILL) {
if (item.getItemMeta() instanceof BookMeta) {
BookMeta meta = (BookMeta) item.getItemMeta();
if (meta.hasTitle()) {
name = meta.getTitle();
}
}
}
}
if (name == null) {
name = item.getType().toString();
}
UseItemTrigger trigger = UseItemTrigger.get(name, gameWorld);
if (trigger != null) {
trigger.onTrigger(player);
}
}
}
}
}
// Check Signs
if (clickedBlock != null) {
if (clickedBlock.getType() == Material.WALL_SIGN || clickedBlock.getType() == Material.SIGN_POST) {
// Check Group Signs
if (GroupSign.playerInteract(event.getClickedBlock(), player)) {
event.setCancelled(true);
}
// Leave Sign
if (LeaveSign.playerInteract(event.getClickedBlock(), player)) {
event.setCancelled(true);
}
DPlayer dPlayer = DPlayer.getByPlayer(player);
if (dPlayer != null) {
// Check GameWorld Signs
GameWorld gameWorld = GameWorld.getByWorld(player.getWorld());
if (gameWorld != null) {
// Trigger InteractTrigger
InteractTrigger trigger = InteractTrigger.get(clickedBlock, gameWorld);
if (trigger != null) {
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
trigger.onTrigger(player);
} else {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEFT_CLICK));
}
}
// Class Signs
for (Sign classSign : gameWorld.getSignClass()) {
if (classSign != null) {
if (classSign.getLocation().distance(clickedBlock.getLocation()) < 1) {
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
dPlayer.setDClass(ChatColor.stripColor(classSign.getLine(1)));
} else {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_LEFT_CLICK));
}
return;
}
}
}
}
}
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onDropItem(PlayerDropItemEvent event) {
Player player = event.getPlayer();
// Deny dropping things at the lobby
DGroup dGroup = DGroup.getByPlayer(player);
if (dGroup == null) {
return;
}
if ( !dGroup.isPlaying()) {
event.setCancelled(true);
return;
}
if ( !DPlayer.getByPlayer(player).isReady()) {
event.setCancelled(true);
return;
}
DPlayer dPlayer = DPlayer.getByPlayer(player);
GameWorld gameWorld = GameWorld.getByWorld(dPlayer.getWorld());
if (dPlayer != null) {
for (Material material : gameWorld.getConfig().getSecureObjects()) {
if (material == event.getItemDrop().getItemStack().getType()) {
event.setCancelled(true);
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_DROP));
return;
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
DPlayer dPlayer = DPlayer.getByPlayer(player);
if (dPlayer == null) {
return;
}
if (dPlayer.isEditing()) {
EditWorld editWorld = EditWorld.getByWorld(dPlayer.getWorld());
if (editWorld == null) {
return;
}
if (editWorld.getLobby() == null) {
event.setRespawnLocation(editWorld.getWorld().getSpawnLocation());
} else {
event.setRespawnLocation(editWorld.getLobby());
}
} else {
GameWorld gameWorld = GameWorld.getByWorld(dPlayer.getWorld());
if (gameWorld == null) {
return;
}
DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer());
if (dPlayer.getCheckpoint() == null) {
event.setRespawnLocation(dGroup.getGameWorld().getLocStart());
// Da einige Plugins einen anderen Respawn setzen wird
// ein Scheduler gestartet der den Player nach einer
// Sekunde teleportiert.
new RespawnTask(player, dGroup.getGameWorld().getLocStart()).runTaskLater(plugin, 10L);
if (dPlayer.getWolf() != null) {
dPlayer.getWolf().teleport(dGroup.getGameWorld().getLocStart());
}
} else {
event.setRespawnLocation(dPlayer.getCheckpoint());
// Da einige Plugins einen anderen Respawn setzen wird
// ein Scheduler gestartet der den Player nach einer
// Sekunde teleportiert.
new RespawnTask(player, dPlayer.getCheckpoint()).runTaskLater(plugin, 10L);
if (dPlayer.getWolf() != null) {
dPlayer.getWolf().teleport(dPlayer.getCheckpoint());
}
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onPortal(PlayerPortalEvent event) {
Player player = event.getPlayer();
Location location = event.getFrom();
DPortal dportal = DPortal.getByLocation(location);
if (dportal != null) {
event.setCancelled(true);
dportal.teleport(player);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onTeleport(PlayerTeleportEvent event) {
Player player = event.getPlayer();
DPlayer dPlayer = DPlayer.getByPlayer(player);
if (dPlayer == null) {
return;
}
if (dPlayer.getWorld() == event.getTo().getWorld()) {
return;
}
if ( !player.hasPermission("dxl.bypass")) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
DPlayer dPlayer = DPlayer.getByPlayer(player);
if (dPlayer == null) {
return;
}
if (dPlayer.isInDungeonChat()) {
dPlayer.sendMessage(player.getDisplayName() + ": " + event.getMessage());
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
DPlayer dPlayer = DPlayer.getByPlayer(player);
if (dPlayer == null) {
return;
}
DGroup dGroup = DGroup.getByPlayer(player);
// Check GameWorld
GameWorld gameWorld = GameWorld.getByWorld(player.getWorld());
if (gameWorld != null) {
int timeUntilKickOfflinePlayer = gameWorld.getConfig().getTimeUntilKickOfflinePlayer();
if (timeUntilKickOfflinePlayer == 0) {
dPlayer.leave();
} else if (timeUntilKickOfflinePlayer > 0) {
dGroup.sendMessage(messageConfig.getMessage(Messages.PLAYER_OFFLINE, dPlayer.getPlayer().getName(), "" + timeUntilKickOfflinePlayer), player);
dPlayer.setOfflineTime(System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000);
} else {
dGroup.sendMessage(messageConfig.getMessage(Messages.PLAYER_OFFLINE_NEVER, dPlayer.getPlayer().getName()), player);
}
} else if (dPlayer.isEditing()) {
dPlayer.leave();
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
// Check dPlayers
DPlayer dPlayer = DPlayer.getByName(player.getName());
if (dPlayer != null) {
DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer());
if (dGroup != null) {
dGroup.getPlayers().remove(dPlayer.getPlayer());
dGroup.getPlayers().add(player);
}
dPlayer.setPlayer(player);
// Check offlineTime
dPlayer.setOfflineTime(0);
}
// Tutorial Mode
if ( !plugin.getMainConfig().isTutorialActivated()) {
return;
}
if (DPlayer.getByPlayer(player) != null) {
return;
}
if (plugin.getPermissionProvider() == null) {
return;
}
if ((plugin.getMainConfig().getTutorialDungeon() == null || plugin.getMainConfig().getTutorialStartGroup() == null || plugin.getMainConfig().getTutorialEndGroup() == null)) {
return;
}
for (String group : plugin.getPermissionProvider().getPlayerGroups(player)) {
if ( !plugin.getMainConfig().getTutorialStartGroup().equalsIgnoreCase(group)) {
continue;
}
DGroup dGroup = new DGroup(player, plugin.getMainConfig().getTutorialDungeon(), false);
DGroupCreateEvent createEvent = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.GROUP_SIGN);
if (createEvent.isCancelled()) {
dGroup = null;
}
if (dGroup == null) {
continue;
}
if (dGroup.getGameWorld() == null) {
dGroup.setGameWorld(GameWorld.load(DGroup.getByPlayer(player).getMapName()));
dGroup.getGameWorld().setTutorial(true);
}
if (dGroup.getGameWorld() == null) {
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_TUTORIAL_NOT_EXIST));
continue;
}
if (dGroup.getGameWorld().getLocLobby() != null) {
new DPlayer(player, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getLocLobby(), false);
}
}
}
// Deny Player Cmds
@EventHandler(priority = EventPriority.HIGH)
public void onCommand(PlayerCommandPreprocessEvent event) {
if (event.getPlayer().hasPermission("dxl.bypass")) {
return;
}
DPlayer dPlayer = DPlayer.getByPlayer(event.getPlayer());
if (dPlayer == null) {
return;
}
String command = event.getMessage().toLowerCase();
ArrayList<String> commandWhitelist = new ArrayList<String>();
GameWorld gameWorld = GameWorld.getByWorld(dPlayer.getWorld());
if (dPlayer.isEditing()) {
if (event.getPlayer().hasPermission("dxl.cmdedit")) {
return;
} else {
commandWhitelist.addAll(plugin.getMainConfig().getEditCommandWhitelist());
}
} else if (gameWorld != null) {
if (gameWorld.getConfig() != null) {
commandWhitelist.addAll(gameWorld.getConfig().getGameCommandWhitelist());
}
}
commandWhitelist.add("dungeonsxl");
commandWhitelist.add("dungeon");
commandWhitelist.add("dxl");
event.setCancelled(true);
for (String whitelistEntry : commandWhitelist) {
if (command.equals('/' + whitelistEntry.toLowerCase()) || command.startsWith('/' + whitelistEntry.toLowerCase() + ' ')) {
event.setCancelled(false);
}
}
if (event.isCancelled()) {
MessageUtil.sendMessage(event.getPlayer(), messageConfig.getMessage(Messages.ERROR_CMD));
}
}
// Inventory Events
@EventHandler(priority = EventPriority.HIGH)
public void onInventoryOpen(InventoryOpenEvent event) {
if (event.getPlayer() instanceof Player) {
GameChest.onOpenInventory(event);
}
}
@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
Player player = (Player) event.getPlayer();
for (DLootInventory inventory : plugin.getDLootInventories()) {
if (event.getView() != inventory.getInventoryView()) {
continue;
}
if (System.currentTimeMillis() - inventory.getTime() <= 500) {
continue;
}
for (ItemStack istack : inventory.getInventory().getContents()) {
if (istack != null) {
player.getWorld().dropItem(player.getLocation(), istack);
}
}
plugin.getDLootInventories().remove(inventory);
}
}
// Player move
@EventHandler
public void onMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
DLootInventory inventory = DLootInventory.getByPlayer(player);
if (inventory == null) {
return;
}
if (player.getLocation().getBlock().getType() == Material.PORTAL) {
return;
}
if (player.getLocation().getBlock().getRelative(0, 1, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, -1, 0).getType() != Material.PORTAL
&& player.getLocation().getBlock().getRelative(1, 0, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative( -1, 0, 0).getType() != Material.PORTAL
&& player.getLocation().getBlock().getRelative(0, 0, 1).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, 0, -1).getType() != Material.PORTAL) {
inventory.setInventoryView(inventory.getPlayer().openInventory(inventory.getInventory()));
inventory.setTime(System.currentTimeMillis());
}
}
}

View File

@ -1,22 +0,0 @@
package io.github.dre2n.dungeonsxl.listener;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkUnloadEvent;
public class WorldListener implements Listener {
@EventHandler(priority = EventPriority.HIGH)
public void onChunkUnload(ChunkUnloadEvent event) {
GameWorld gameWorld = GameWorld.getByWorld(event.getWorld());
if (gameWorld != null) {
if (gameWorld.getLoadedChunks().contains(event.getChunk())) {
event.setCancelled(true);
}
}
}
}

View File

@ -1,104 +0,0 @@
package io.github.dre2n.dungeonsxl.mob;
import io.github.dre2n.dungeonsxl.event.dmob.DMobDeathEvent;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.trigger.MobTrigger;
import java.util.Random;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
public class DMob {
// Variables
private LivingEntity entity;
private DMobType type;
private String trigger;
public DMob(LivingEntity entity, GameWorld gameWorld, DMobType type) {
gameWorld.addDMob(this);
this.entity = entity;
this.type = type;
/* Remove DropChance of equipment */
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);
}
public DMob(LivingEntity entity, GameWorld gameWorld, DMobType type, String trigger) {
gameWorld.addDMob(this);
this.entity = entity;
this.type = type;
this.trigger = trigger;
/* Remove DropChance of equipment */
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);
}
// Statics
@SuppressWarnings("deprecation")
public static void onDeath(EntityDeathEvent event) {
if ( !(event.getEntity() instanceof LivingEntity)) {
return;
}
LivingEntity victim = event.getEntity();
GameWorld gameWorld = GameWorld.getByWorld(victim.getWorld());
String name = null;
if (gameWorld == null) {
return;
}
for (DMob dMob : gameWorld.getDMobs()) {
if (dMob.entity != victim) {
continue;
}
DMobDeathEvent dMobDeathEvent = new DMobDeathEvent(dMob, event);
if (dMobDeathEvent.isCancelled()) {
return;
}
if (dMob.type != null) {
for (ItemStack itemStack : dMob.type.getDrops().keySet()) {
Random randomGenerator = new Random();
int random = randomGenerator.nextInt(100);
if (dMob.type.getDrops().get(itemStack) > random) {
event.getDrops().add(itemStack);
}
}
name = dMob.type.getName();
} else if (dMob.type == null && dMob.trigger != null) {// <=MythicMobs mob
name = dMob.trigger;
} else {
name = victim.getType().getName();
}
MobTrigger trigger = MobTrigger.get(name, gameWorld);
if (trigger != null) {
trigger.onTrigger();
}
gameWorld.removeDMob(dMob);
return;
}
}
}

View File

@ -1,412 +0,0 @@
package io.github.dre2n.dungeonsxl.mob;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.util.NumberUtil;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.EnumUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class DMobType {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
private String name;
private EntityType type;
private int maxHealth;
private ItemStack ItemHand;
private ItemStack ItemHelmet;
private ItemStack ItemChestplate;
private ItemStack ItemLeggings;
private ItemStack ItemBoots;
private Map<ItemStack, Integer> drops = new HashMap<ItemStack, Integer>();
/* Extra Values for different Mob Types */
private boolean witherSkeleton = false;
private String ocelotType = null;
/* Methods */
public DMobType(String name, EntityType type) {
this.name = name;
this.type = type;
}
public void spawn(GameWorld gWorld, Location loc) {
if (type == null) {
return;
}
if ( !type.isAlive()) {
return;
}
LivingEntity entity = (LivingEntity) gWorld.getWorld().spawnEntity(loc, type);
/* Set the Items */
entity.getEquipment().setItemInHand(ItemHand);
entity.getEquipment().setHelmet(ItemHelmet);
entity.getEquipment().setChestplate(ItemChestplate);
entity.getEquipment().setLeggings(ItemLeggings);
entity.getEquipment().setBoots(ItemBoots);
/* Check mob specified stuff */
if (type == EntityType.SKELETON) {
if (witherSkeleton) {
((Skeleton) entity).setSkeletonType(SkeletonType.WITHER);
} else {
((Skeleton) entity).setSkeletonType(SkeletonType.NORMAL);
}
}
if (type == EntityType.OCELOT) {
Ocelot ocelot = (Ocelot) entity;
if (EnumUtils.isValidEnum(Ocelot.Type.class, ocelotType.toUpperCase())) {
ocelot.setCatType(Ocelot.Type.valueOf(ocelotType.toUpperCase()));
}
}
/* Set Health */
if (maxHealth > 0) {
entity.setMaxHealth(maxHealth);
entity.setHealth(maxHealth);
}
/* Disable Despawning */
entity.setRemoveWhenFarAway(false);
/* Spawn Mob */
new DMob(entity, gWorld, this);
}
// Load Config
@SuppressWarnings("deprecation")
public static Set<DMobType> load(ConfigurationSection configFile) {
Set<DMobType> set = new HashSet<DMobType>();
if (configFile == null) {
return set;
}
// Read Mobs
for (String mobName : configFile.getKeys(false)) {
EntityType type = EntityType.fromName(configFile.getString(mobName + ".Type"));
if (type == null) {
plugin.getLogger().info(plugin.getMessageConfig().getMessage(Messages.LOG_ERROR_MOBTYPE, configFile.getString(mobName + ".Type")));
continue;
}
DMobType mobType = new DMobType(mobName, type);
set.add(mobType);
// Load MaxHealth
if (configFile.contains(mobName + ".MaxHealth")) {
mobType.maxHealth = configFile.getInt(mobName + ".MaxHealth");
}
// Load Items
if (configFile.contains(mobName + ".ItemHelmet")) {
mobType.ItemHelmet = new ItemStack(configFile.getInt(mobName + ".ItemHelmet"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemHelmet"))).getItem();
}
if (configFile.contains(mobName + ".ItemChestplate")) {
mobType.ItemChestplate = new ItemStack(configFile.getInt(mobName + ".ItemChestplate"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemChestplate"))).getItem();
}
if (configFile.contains(mobName + ".ItemBoots")) {
mobType.ItemBoots = new ItemStack(configFile.getInt(mobName + ".ItemBoots"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemBoots"))).getItem();
}
if (configFile.contains(mobName + ".ItemLeggings")) {
mobType.ItemLeggings = new ItemStack(configFile.getInt(mobName + ".ItemLeggings"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemLeggings"))).getItem();
}
if (configFile.contains(mobName + ".ItemHand")) {
mobType.ItemHand = new ItemStack(configFile.getInt(mobName + ".ItemHand"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemHand"))).getItem();
}
// Load different Mob options
if (configFile.contains(mobName + ".isWitherSkeleton")) {
mobType.witherSkeleton = configFile.getBoolean(mobName + ".isWitherSkeleton");
}
if (configFile.contains(mobName + ".ocelotType")) {
mobType.ocelotType = configFile.getString(mobName + ".ocelotType");
}
// Drops
ConfigurationSection configSetion = configFile.getConfigurationSection(mobName + ".drops");
if (configSetion != null) {
Set<String> list = configSetion.getKeys(false);
for (String dropPath : list) {
ItemStack item = null;
ItemMeta itemMeta = null;
int chance = 100;
/* Item Stack */
Material mat = Material.getMaterial(configSetion.getInt(dropPath + ".id"));
int amount = 1;
short data = 0;
if (configSetion.contains(dropPath + ".amount")) {
amount = configSetion.getInt(dropPath + ".amount");
}
if (configSetion.contains(dropPath + ".data")) {
data = Short.parseShort(configSetion.getString(dropPath + ".data"));
}
item = new ItemStack(mat, amount, data);
itemMeta = item.getItemMeta();
/* Enchantments */
if (configSetion.contains(dropPath + ".enchantments")) {
for (String enchantment : configSetion.getStringList(dropPath + ".enchantments")) {
String[] splittedEnchantment = enchantment.split(" ");
if (Enchantment.getByName(splittedEnchantment[0].toUpperCase()) != null) {
if (splittedEnchantment.length > 1) {
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), NumberUtil.parseInt(splittedEnchantment[1]), true);
} else {
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), 1, true);
}
} else {
plugin.getLogger().info(plugin.getMessageConfig().getMessage(Messages.LOG_ERROR_MOB_ENCHANTMENT, splittedEnchantment[0]));
}
}
}
/* Item Name */
if (configSetion.contains(dropPath + ".name")) {
itemMeta.setDisplayName(configSetion.getString(dropPath + ".name"));
}
/* Item Lore */
if (configSetion.contains(dropPath + ".lore")) {
String[] lore = configSetion.getString(dropPath + ".lore").split("//");
itemMeta.setLore(Arrays.asList(lore));
}
/* Drop chance */
if (configSetion.contains(dropPath + ".chance")) {
chance = configSetion.getInt(dropPath + ".chance");
}
/* Add Item to the drops map */
item.setItemMeta(itemMeta);
mobType.getDrops().put(item, chance);
}
}
}
return set;
}
// Get
public static DMobType getByName(String name, Set<DMobType> mobTypes) {
for (DMobType mobType : mobTypes) {
if (mobType.name.equalsIgnoreCase(name)) {
return mobType;
}
}
if (plugin.getMainConfig().getDefaultWorldConfig() != null) {
for (DMobType mobType : plugin.getMainConfig().getDefaultWorldConfig().getMobTypes()) {
if (mobType.name.equalsIgnoreCase(name)) {
return mobType;
}
}
}
return null;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the type
*/
public EntityType getType() {
return type;
}
/**
* @param type
* the type to set
*/
public void setType(EntityType type) {
this.type = type;
}
/**
* @return the maxHealth
*/
public int getMaxHealth() {
return maxHealth;
}
/**
* @param maxHealth
* the maxHealth to set
*/
public void setMaxHealth(int maxHealth) {
this.maxHealth = maxHealth;
}
/**
* @return the itemHand
*/
public ItemStack getItemHand() {
return ItemHand;
}
/**
* @param itemHand
* the itemHand to set
*/
public void setItemHand(ItemStack itemHand) {
ItemHand = itemHand;
}
/**
* @return the itemHelmet
*/
public ItemStack getItemHelmet() {
return ItemHelmet;
}
/**
* @param itemHelmet
* the itemHelmet to set
*/
public void setItemHelmet(ItemStack itemHelmet) {
ItemHelmet = itemHelmet;
}
/**
* @return the itemChestplate
*/
public ItemStack getItemChestplate() {
return ItemChestplate;
}
/**
* @param itemChestplate
* the itemChestplate to set
*/
public void setItemChestplate(ItemStack itemChestplate) {
ItemChestplate = itemChestplate;
}
/**
* @return the itemLeggings
*/
public ItemStack getItemLeggings() {
return ItemLeggings;
}
/**
* @param itemLeggings
* the itemLeggings to set
*/
public void setItemLeggings(ItemStack itemLeggings) {
ItemLeggings = itemLeggings;
}
/**
* @return the itemBoots
*/
public ItemStack getItemBoots() {
return ItemBoots;
}
/**
* @param itemBoots
* the itemBoots to set
*/
public void setItemBoots(ItemStack itemBoots) {
ItemBoots = itemBoots;
}
/**
* @return the drops
*/
public Map<ItemStack, Integer> getDrops() {
return drops;
}
/**
* @param drops
* the drops to set
*/
public void setDrops(Map<ItemStack, Integer> drops) {
this.drops = drops;
}
/**
* @return if the skeleton is a wither skeleton
*/
public boolean isWitherSkeleton() {
return witherSkeleton;
}
/**
* @param witherSkeleton
* set if the skeleton is a wither skeleton
*/
public void setWitherSkeleton(boolean witherSkeleton) {
this.witherSkeleton = witherSkeleton;
}
/**
* @return the ocelotType
*/
public String getOcelotType() {
return ocelotType;
}
/**
* @param ocelotType
* the ocelotType to set
*/
public void setOcelotType(String ocelotType) {
this.ocelotType = ocelotType;
}
}

View File

@ -1,64 +0,0 @@
package io.github.dre2n.dungeonsxl.player;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.inventory.ItemStack;
public class DClass {
private CopyOnWriteArrayList<ItemStack> items = new CopyOnWriteArrayList<ItemStack>();
private String name;
private boolean dog;
public DClass(String name, CopyOnWriteArrayList<ItemStack> items, boolean dog) {
this.items = items;
this.name = name;
this.dog = dog;
}
/**
* @return the items
*/
public CopyOnWriteArrayList<ItemStack> getItems() {
return items;
}
/**
* @param itemStack
* the ItemStack to add
*/
public void setItems(ItemStack itemStack) {
items.add(itemStack);
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @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;
}
}

View File

@ -1,591 +0,0 @@
package io.github.dre2n.dungeonsxl.player;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.MessageConfig;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupStartFloorEvent;
import io.github.dre2n.dungeonsxl.event.requirement.RequirementDemandEvent;
import io.github.dre2n.dungeonsxl.event.reward.RewardAdditionEvent;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GameType;
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.global.GroupSign;
import io.github.dre2n.dungeonsxl.requirement.Requirement;
import io.github.dre2n.dungeonsxl.reward.Reward;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import io.github.dre2n.dungeonsxl.util.playerutil.PlayerUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.entity.Player;
public class DGroup {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
protected static MessageConfig messageConfig = plugin.getMessageConfig();
private String name;
private Player captain;
private List<Player> players = new CopyOnWriteArrayList<Player>();
private List<UUID> invitedPlayers = new ArrayList<UUID>();
private String dungeonName;
private String mapName;
private List<String> unplayedFloors = new ArrayList<String>();
private GameWorld gameWorld;
private boolean playing;
private int floorCount;
private int waveCount;
private List<Reward> rewards = new ArrayList<Reward>();
public DGroup(String name, Player player) {
plugin.getDGroups().add(this);
this.name = name;
captain = player;
players.add(player);
playing = false;
floorCount = 0;
}
public DGroup(Player player, String identifier, boolean multiFloor) {
plugin.getDGroups().add(this);
name = "Group_" + plugin.getDGroups().size();
captain = player;
players.add(player);
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
if (multiFloor && dungeon != null) {
dungeonName = identifier;
mapName = dungeon.getConfig().getStartFloor();
unplayedFloors = dungeon.getConfig().getFloors();
} else {
mapName = identifier;
}
playing = false;
floorCount = 0;
}
public DGroup(String name, Player player, String identifier, boolean multiFloor) {
plugin.getDGroups().add(this);
this.name = name;
captain = player;
players.add(player);
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
if (multiFloor && dungeon != null) {
dungeonName = identifier;
mapName = dungeon.getConfig().getStartFloor();
unplayedFloors = dungeon.getConfig().getFloors();
} else {
mapName = identifier;
}
playing = false;
floorCount = 0;
}
public DGroup(String name, Player captain, List<Player> players, String identifier, boolean multiFloor) {
plugin.getDGroups().add(this);
this.name = name;
this.captain = captain;
this.players = players;
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
if (multiFloor && dungeon != null) {
dungeonName = identifier;
mapName = dungeon.getConfig().getStartFloor();
unplayedFloors = dungeon.getConfig().getFloors();
} else {
mapName = identifier;
}
playing = false;
floorCount = 0;
}
// Getters and setters
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the captain
*/
public Player getCaptain() {
return captain;
}
/**
* @param captain
* the captain to set
*/
public void setCaptain(Player captain) {
this.captain = captain;
}
/**
* @return the players
*/
public List<Player> getPlayers() {
return players;
}
/**
* @param player
* the player to add
*/
public void addPlayer(Player player) {
sendMessage(plugin.getMessageConfig().getMessage(Messages.GROUP_PLAYER_JOINED, player.getName()));
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_JOIN_GROUP));
players.add(player);
}
/**
* @param player
* the player to remove
*/
public void removePlayer(Player player) {
players.remove(player);
GroupSign.updatePerGroup(this);
// Send message
sendMessage(plugin.getMessageConfig().getMessage(Messages.PLAYER_LEFT_GROUP, player.getName()));
// Check group
if (isEmpty()) {
remove();
}
}
/**
* @return the players
*/
public List<Player> getInvitedPlayers() {
ArrayList<Player> players = new ArrayList<Player>();
for (UUID uuid : invitedPlayers) {
players.add(plugin.getServer().getPlayer(uuid));
}
return players;
}
/**
* @param player
* the player to add
*/
public void addInvitedPlayer(Player player, boolean silent) {
if (player == null) {
return;
}
if (DGroup.getByPlayer(player) != null) {
if ( !silent) {
MessageUtil.sendMessage(captain, plugin.getMessageConfig().getMessage(Messages.ERROR_IN_GROUP, player.getName()));
}
return;
}
if ( !silent) {
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_INVITED, captain.getName(), name));
}
// Send message
if ( !silent) {
sendMessage(plugin.getMessageConfig().getMessage(Messages.GROUP_INVITED_PLAYER, captain.getName(), player.getName(), name));
}
// Add player
invitedPlayers.add(player.getUniqueId());
}
/**
* @param player
* the player to remove
*/
public void removeInvitedPlayer(Player player, boolean silent) {
if (player == null) {
return;
}
if (DGroup.getByPlayer(player) != this) {
if ( !silent) {
MessageUtil.sendMessage(captain, plugin.getMessageConfig().getMessage(Messages.ERROR_NOT_IN_GROUP, player.getName(), name));
}
return;
}
if ( !silent) {
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_UNINVITED, player.getName(), name));
}
// Send message
if ( !silent) {
for (Player groupPlayer : getPlayers()) {
MessageUtil.sendMessage(groupPlayer, plugin.getMessageConfig().getMessage(Messages.GROUP_UNINVITED_PLAYER, captain.getName(), player.getName(), name));
}
}
invitedPlayers.remove(player.getUniqueId());
}
/**
* Remove all invitations for players who are not online
*/
public void clearOfflineInvitedPlayers() {
ArrayList<UUID> toRemove = new ArrayList<UUID>();
for (UUID uuid : invitedPlayers) {
if (plugin.getServer().getPlayer(uuid) == null) {
toRemove.add(uuid);
}
}
invitedPlayers.removeAll(toRemove);
}
/**
* @return the gameWorld
*/
public GameWorld getGameWorld() {
return gameWorld;
}
/**
* @param gameWorld
* the gameWorld to set
*/
public void setGameWorld(GameWorld gameWorld) {
this.gameWorld = gameWorld;
}
/**
* @return the dungeonName
*/
public String getDungeonName() {
return dungeonName;
}
/**
* @param dungeonName
* the dungeonName to set
*/
public void setDungeonName(String dungeonName) {
this.dungeonName = dungeonName;
}
/**
* @return the dungeon (saved by name only)
*/
public Dungeon getDungeon() {
return plugin.getDungeons().getDungeon(dungeonName);
}
/**
* @param dungeon
* the dungeon to set (saved by name only)
*/
public void setDungeon(Dungeon dungeon) {
dungeonName = dungeon.getName();
}
/**
* @return if the group is playing
*/
public String getMapName() {
return mapName;
}
/**
* @param name
* the name to set
*/
public void setMapName(String name) {
mapName = name;
}
/**
* @return the unplayedFloors
*/
public List<String> getUnplayedFloors() {
return unplayedFloors;
}
/**
* @param unplayedFloor
* the unplayedFloor to add
*/
public void addUnplayedFloor(String unplayedFloor) {
unplayedFloors.add(unplayedFloor);
}
/**
* @param unplayedFloor
* the unplayedFloor to add
*/
public void removeUnplayedFloor(String unplayedFloor) {
if (getDungeon().getConfig().getRemoveWhenPlayed()) {
unplayedFloors.remove(unplayedFloor);
}
}
/**
* @return if the group is playing
*/
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 waveCount
*/
public int getWaveCount() {
return waveCount;
}
/**
* @param waveCount
* the waveCount to set
*/
public void setWaveCount(int waveCount) {
this.waveCount = waveCount;
}
/**
* @return the rewards
*/
public List<Reward> getRewards() {
return rewards;
}
/**
* @param reward
* the rewards to add
*/
public void addReward(Reward reward) {
RewardAdditionEvent event = new RewardAdditionEvent(reward, this);
if (event.isCancelled()) {
return;
}
rewards.add(reward);
}
/**
* @param reward
* the rewards to remove
*/
public void removeReward(Reward reward) {
rewards.remove(reward);
}
/**
* @return whether there are players in the group
*/
public boolean isEmpty() {
return players.isEmpty();
}
public void remove() {
plugin.getDGroups().remove(this);
GroupSign.updatePerGroup(this);
}
public void startGame(Game game) {
if (game == null) {
return;
}
for (DGroup dGroup : game.getDGroups()) {
if (dGroup == null) {
continue;
}
for (Player player : dGroup.getPlayers()) {
DPlayer dPlayer = DPlayer.getByPlayer(player);
if (dPlayer == null) {
continue;
}
if ( !dPlayer.isReady()) {
return;
}
}
}
gameWorld.setGame(game);
DGroupStartFloorEvent event = new DGroupStartFloorEvent(this, gameWorld);
if (event.isCancelled()) {
return;
}
playing = true;
gameWorld.startGame();
floorCount++;
for (Player player : getPlayers()) {
DPlayer dPlayer = DPlayer.getByPlayer(player);
dPlayer.respawn();
if (dungeonName != null) {
MessageUtil.sendScreenMessage(player, "&b&l" + dungeonName.replaceAll("_", " "), "&4&l" + mapName.replaceAll("_", " "));
} else {
MessageUtil.sendScreenMessage(player, "&4&l" + mapName.replaceAll("_", " "));
}
WorldConfig config = gameWorld.getConfig();
if (config != null) {
for (Requirement requirement : config.getRequirements()) {
RequirementDemandEvent requirementDemandEvent = new RequirementDemandEvent(requirement, player);
if (requirementDemandEvent.isCancelled()) {
continue;
}
requirement.demand(player);
}
GameType gameType = game.getType();
if (gameType == GameTypeDefault.DEFAULT) {
player.setGameMode(config.getGameMode());
} else {
player.setGameMode(gameType.getGameMode());
}
}
}
GroupSign.updatePerGroup(this);
}
public void finishWave(double mobCountIncreaseRate) {
for (DGroup dGroup : DGroup.getByGameWorld(gameWorld)) {
dGroup.sendMessage(messageConfig.getMessage(Messages.GROUP_WAVE_FINISHED, String.valueOf(dGroup.getWaveCount()) + "TIME"));// TODO
for (Player player : dGroup.getPlayers()) {
PlayerUtil.secureTeleport(player, gameWorld.getLocStart());
}
}
}
/**
* Send a message to all players in the group
*/
public void sendMessage(String message) {
for (Player player : players) {
if (player.isOnline()) {
MessageUtil.sendMessage(player, message);
}
}
}
/**
* Send a message to all players in the group
*
* @param except
* Players who do not receive the message
*/
public void sendMessage(String message, Player... except) {
for (Player player : players) {
if (player.isOnline() && !player.equals(except)) {
MessageUtil.sendMessage(player, message);
}
}
}
// Statics
public static DGroup getByName(String name) {
for (DGroup dGroup : plugin.getDGroups()) {
if (dGroup.getName().equals(name)) {
return dGroup;
}
}
return null;
}
public static DGroup getByPlayer(Player player) {
for (DGroup dGroup : plugin.getDGroups()) {
if (dGroup.getPlayers().contains(player)) {
return dGroup;
}
}
return null;
}
public static void leaveGroup(Player player) {
for (DGroup dGroup : plugin.getDGroups()) {
if (dGroup.getPlayers().contains(player)) {
dGroup.getPlayers().remove(player);
}
}
}
/**
* @param gameWorld
* the GameWorld to check
* @return a List of DGroups in this GameWorld
*/
public static List<DGroup> getByGameWorld(GameWorld gameWorld) {
List<DGroup> dGroups = new ArrayList<DGroup>();
for (DGroup dGroup : plugin.getDGroups()) {
if (dGroup.getGameWorld().equals(gameWorld)) {
dGroups.add(dGroup);
}
}
return dGroups;
}
}

View File

@ -1,988 +0,0 @@
package io.github.dre2n.dungeonsxl.player;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DungeonConfig;
import io.github.dre2n.dungeonsxl.config.MessageConfig;
import io.github.dre2n.dungeonsxl.config.WorldConfig;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.dungeon.DLootInventory;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishDungeonEvent;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishFloorEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerFinishEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerUpdateEvent;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GameType;
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
import io.github.dre2n.dungeonsxl.game.GameWorld;
import io.github.dre2n.dungeonsxl.reward.Reward;
import io.github.dre2n.dungeonsxl.trigger.DistanceTrigger;
import io.github.dre2n.dungeonsxl.util.NumberUtil;
import io.github.dre2n.dungeonsxl.util.playerutil.PlayerUtil;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
public class DPlayer {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
protected static MessageConfig messageConfig = plugin.getMessageConfig();
// Variables
private Player player;
private World world;
private DSavePlayer savePlayer;
private boolean editing;
private boolean inDungeonChat = false;
private boolean ready = false;
private boolean finished = false;
private DClass dClass;
private Location checkpoint;
private Wolf wolf;
private int wolfRespawnTime = 30;
private long offlineTime;
private ItemStack[] respawnInventory;
private ItemStack[] respawnArmor;
private String[] linesCopy;
private Inventory treasureInv = plugin.getServer().createInventory(getPlayer(), 45, messageConfig.getMessage(Messages.PLAYER_TREASURES));
private int initialLives = -1;
private int lives;
public DPlayer(Player player, World world, Location teleport, boolean editing) {
plugin.getDPlayers().add(this);
this.setPlayer(player);
this.world = world;
double health = ((Damageable) player).getHealth();
savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), player.getLevel(),
player.getTotalExperience(), (int) health, player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects());
this.editing = editing;
if (this.editing) {
this.getPlayer().setGameMode(GameMode.CREATIVE);
clearPlayerData();
} else {
WorldConfig worldConfig = GameWorld.getByWorld(world).getConfig();
this.getPlayer().setGameMode(GameMode.SURVIVAL);
if ( !worldConfig.getKeepInventoryOnEnter()) {
clearPlayerData();
}
if (worldConfig.isLobbyDisabled()) {
ready();
}
initialLives = worldConfig.getInitialLives();
lives = initialLives;
}
PlayerUtil.secureTeleport(this.getPlayer(), teleport);
}
public void clearPlayerData() {
getPlayer().getInventory().clear();
getPlayer().getInventory().setArmorContents(null);
getPlayer().setTotalExperience(0);
getPlayer().setLevel(0);
getPlayer().setHealth(20);
getPlayer().setFoodLevel(20);
for (PotionEffect effect : getPlayer().getActivePotionEffects()) {
getPlayer().removePotionEffect(effect.getType());
}
}
// Getters and setters
/**
* @return the player
*/
public Player getPlayer() {
return player;
}
/**
* @param player
* the player to set
*/
public void setPlayer(Player player) {
this.player = player;
}
/**
* @return the world
*/
public World getWorld() {
return world;
}
/**
* @param world
* the world to set
*/
public void setWorld(World world) {
this.world = world;
}
/**
* @return the savePlayer
*/
public DSavePlayer getSavePlayer() {
return savePlayer;
}
/**
* @param savePlayer
* the savePlayer to set
*/
public void setSavePlayer(DSavePlayer savePlayer) {
this.savePlayer = savePlayer;
}
/**
* @return if the player is in test mode
*/
public boolean isInTestMode() {
DGroup dGroup = DGroup.getByPlayer(player);
if (dGroup == null) {
return false;
}
GameWorld gameWorld = dGroup.getGameWorld();
if (gameWorld == 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 the editing
*/
public boolean isEditing() {
return editing;
}
/**
* @param editing
* the editing to set
*/
public void setEditing(boolean editing) {
this.editing = editing;
}
/**
* @return the inDungeonChat
*/
public boolean isInDungeonChat() {
return inDungeonChat;
}
/**
* @param inDungeonChat
* the inDungeonChat to set
*/
public void setInDungeonChat(boolean inDungeonChat) {
this.inDungeonChat = inDungeonChat;
}
/**
* @return the isReady
*/
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
*/
public boolean isFinished() {
return finished;
}
/**
* @param finished
* the finished to set
*/
public void setFinished(boolean finished) {
this.finished = finished;
}
/**
* @return the dClass
*/
public DClass getDClass() {
return dClass;
}
/**
* @param dClass
* the dClass to set
*/
public void setDClass(String className) {
GameWorld gameWorld = GameWorld.getByWorld(getPlayer().getWorld());
if (gameWorld == null) {
return;
}
DClass dClass = gameWorld.getConfig().getClass(className);
if (dClass != null) {
if (this.dClass != dClass) {
this.dClass = dClass;
/* Set Dog */
if (wolf != null) {
wolf.remove();
wolf = null;
}
if (dClass.hasDog()) {
wolf = (Wolf) world.spawnEntity(getPlayer().getLocation(), EntityType.WOLF);
wolf.setTamed(true);
wolf.setOwner(getPlayer());
double maxHealth = ((Damageable) wolf).getMaxHealth();
wolf.setHealth(maxHealth);
}
/* Delete Inventory */
getPlayer().getInventory().clear();
getPlayer().getInventory().setArmorContents(null);
getPlayer().getInventory().setItemInHand(new ItemStack(Material.AIR));
// Remove Potion Effects
for (PotionEffect effect : getPlayer().getActivePotionEffects()) {
getPlayer().removePotionEffect(effect.getType());
}
// Reset lvl
getPlayer().setTotalExperience(0);
getPlayer().setLevel(0);
/* Set Inventory */
for (ItemStack istack : dClass.getItems()) {
// Leggings
if (istack.getType() == Material.LEATHER_LEGGINGS || istack.getType() == Material.CHAINMAIL_LEGGINGS || istack.getType() == Material.IRON_LEGGINGS
|| istack.getType() == Material.DIAMOND_LEGGINGS || istack.getType() == Material.GOLD_LEGGINGS) {
getPlayer().getInventory().setLeggings(istack);
}
// Helmet
else if (istack.getType() == Material.LEATHER_HELMET || istack.getType() == Material.CHAINMAIL_HELMET || istack.getType() == Material.IRON_HELMET
|| istack.getType() == Material.DIAMOND_HELMET || istack.getType() == Material.GOLD_HELMET) {
getPlayer().getInventory().setHelmet(istack);
}
// Chestplate
else if (istack.getType() == Material.LEATHER_CHESTPLATE || istack.getType() == Material.CHAINMAIL_CHESTPLATE || istack.getType() == Material.IRON_CHESTPLATE
|| istack.getType() == Material.DIAMOND_CHESTPLATE || istack.getType() == Material.GOLD_CHESTPLATE) {
getPlayer().getInventory().setChestplate(istack);
}
// Boots
else if (istack.getType() == Material.LEATHER_BOOTS || istack.getType() == Material.CHAINMAIL_BOOTS || istack.getType() == Material.IRON_BOOTS
|| istack.getType() == Material.DIAMOND_BOOTS || istack.getType() == Material.GOLD_BOOTS) {
getPlayer().getInventory().setBoots(istack);
}
else {
getPlayer().getInventory().addItem(istack);
}
}
}
}
}
/**
* @return the checkpoint
*/
public Location getCheckpoint() {
return checkpoint;
}
/**
* @param checkpoint
* the checkpoint to set
*/
public void setCheckpoint(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() {
return offlineTime;
}
/**
* @param offlineTime
* the offlineTime to set
*/
public void setOfflineTime(long offlineTime) {
this.offlineTime = offlineTime;
}
/**
* @return the respawnInventory
*/
public ItemStack[] getRespawnInventory() {
return respawnInventory;
}
/**
* @param respawnInventory
* the respawnInventory to set
*/
public void setRespawnInventory(ItemStack[] respawnInventory) {
this.respawnInventory = respawnInventory;
}
/**
* @return the respawnArmor
*/
public ItemStack[] getRespawnArmor() {
return respawnArmor;
}
/**
* @param respawnArmor
* the respawnArmor to set
*/
public void setRespawnArmor(ItemStack[] respawnArmor) {
this.respawnArmor = respawnArmor;
}
/**
* @return the linesCopy
*/
public String[] getLinesCopy() {
return linesCopy;
}
/**
* @param linesCopy
* the linesCopy to set
*/
public void setLinesCopy(String[] linesCopy) {
this.linesCopy = linesCopy;
}
/**
* @return the treasureInv
*/
public Inventory getTreasureInv() {
return treasureInv;
}
/**
* @param treasureInv
* the treasureInv to set
*/
public void setTreasureInv(Inventory treasureInv) {
this.treasureInv = treasureInv;
}
/**
* @return the initialLives
*/
public int getInitialLives() {
return initialLives;
}
/**
* @param initialLives
* the initialLives to set
*/
public void setInitialLives(int initialLives) {
this.initialLives = initialLives;
}
/**
* @return the lives
*/
public int getLives() {
return lives;
}
/**
* @param lives
* the lives to set
*/
public void setLives(int lives) {
this.lives = lives;
}
// ...
public void escape() {
remove(this);
savePlayer.reset(false);
}
public void leave() {
remove(this);
if ( !editing) {
WorldConfig dConfig = GameWorld.getByWorld(world).getConfig();
if (finished) {
savePlayer.reset(dConfig.getKeepInventoryOnFinish());
} else {
savePlayer.reset(dConfig.getKeepInventoryOnEscape());
}
} else {
savePlayer.reset(false);
}
if (editing) {
EditWorld editWorld = EditWorld.getByWorld(world);
if (editWorld != null) {
editWorld.save();
}
} else {
GameWorld gameWorld = GameWorld.getByWorld(world);
DGroup dGroup = DGroup.getByPlayer(getPlayer());
if (dGroup != null) {
dGroup.removePlayer(getPlayer());
}
// Belohnung
if (gameWorld.getGame().getType().hasRewards()) {
if (finished) {
if (gameWorld.getGame() != null) {
for (Reward reward : gameWorld.getConfig().getRewards()) {
reward.giveTo(player);
}
}
addTreasure();
// Set Time
File file = new File(plugin.getDataFolder() + "/maps/" + gameWorld.getMapName(), "players.yml");
if ( !file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileConfiguration playerConfig = YamlConfiguration.loadConfiguration(file);
playerConfig.set(getPlayer().getUniqueId().toString(), System.currentTimeMillis());
try {
playerConfig.save(file);
} catch (IOException exception) {
exception.printStackTrace();
}
// Tutorial Permissions
if (gameWorld.isTutorial()) {
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);
}
}
}
}
if (dGroup != null) {
// Give Secure Objects other Players
if ( !dGroup.isEmpty()) {
int i = 0;
Player groupPlayer;
do {
groupPlayer = dGroup.getPlayers().get(i);
if (groupPlayer != null) {
for (ItemStack itemStack : getPlayer().getInventory()) {
if (itemStack != null) {
if (gameWorld.getSecureObjects().contains(itemStack.getType())) {
groupPlayer.getInventory().addItem(itemStack);
}
}
}
}
i++;
} while (groupPlayer == null);
}
if (dGroup.getCaptain().equals(player) && dGroup.getPlayers().size() > 0) {
// Captain here!
Player newCaptain = dGroup.getPlayers().get(0);
dGroup.setCaptain(newCaptain);
MessageUtil.sendMessage(newCaptain, messageConfig.getMessage(Messages.PLAYER_NEW_CAPTAIN));
// ...*flies away*
}
}
}
}
public void ready() {
ready = true;
DGroup dGroup = DGroup.getByPlayer(getPlayer());
if (dGroup == null) {
return;
}
if ( !dGroup.isPlaying()) {
dGroup.startGame(new Game(dGroup));
} else {
respawn();
}
}
public void ready(GameType gameType) {
ready = true;
DGroup dGroup = DGroup.getByPlayer(getPlayer());
if (dGroup == null) {
return;
}
if ( !dGroup.isPlaying()) {
dGroup.startGame(new Game(dGroup, gameType));
} else {
respawn();
}
}
public void respawn() {
DGroup dGroup = DGroup.getByPlayer(getPlayer());
if (checkpoint == null) {
PlayerUtil.secureTeleport(getPlayer(), dGroup.getGameWorld().getLocStart());
} else {
PlayerUtil.secureTeleport(getPlayer(), checkpoint);
}
if (wolf != null) {
wolf.teleport(getPlayer());
}
// Respawn Items
if (GameWorld.getByWorld(world).getConfig().getKeepInventoryOnDeath()) {
if (respawnInventory != null || respawnArmor != null) {
getPlayer().getInventory().setContents(respawnInventory);
getPlayer().getInventory().setArmorContents(respawnArmor);
respawnInventory = null;
respawnArmor = null;
}
// P.plugin.updateInventory(this.player);
}
}
public void finishFloor(String specifiedFloor) {
MessageUtil.sendMessage(getPlayer(), messageConfig.getMessage(Messages.PLAYER_FINISHED_DUNGEON));
finished = true;
DGroup dGroup = DGroup.getByPlayer(getPlayer());
if (dGroup == null) {
return;
}
if ( !dGroup.isPlaying()) {
return;
}
for (Player player : dGroup.getPlayers()) {
DPlayer dPlayer = getByPlayer(player);
if ( !dPlayer.finished) {
MessageUtil.sendMessage(this.getPlayer(), messageConfig.getMessage(Messages.PLAYER_WAIT_FOR_OTHER_PLAYERS));
return;
}
}
boolean invalid = false;
if (dGroup.getDungeon() == null) {
invalid = true;
}
for (Player player : dGroup.getPlayers()) {
DPlayer dPlayer = getByPlayer(player);
if (invalid) {
dPlayer.leave();
} else {
dPlayer.finished = false;
}
}
if (invalid) {
return;
}
DungeonConfig dConfig = dGroup.getDungeon().getConfig();
int random = NumberUtil.generateRandomInt(0, dConfig.getFloors().size());
String newFloor = dGroup.getUnplayedFloors().get(random);
if (dConfig.getFloorCount() == dGroup.getFloorCount() - 1) {
newFloor = dConfig.getEndFloor();
} else if (specifiedFloor != null) {
newFloor = specifiedFloor;
}
DGroupFinishFloorEvent event = new DGroupFinishFloorEvent(dGroup, dGroup.getGameWorld(), newFloor);
if (event.isCancelled()) {
return;
}
Game game = dGroup.getGameWorld().getGame();
dGroup.removeUnplayedFloor(dGroup.getMapName());
dGroup.setMapName(newFloor);
GameWorld gameWorld = GameWorld.load(newFloor);
dGroup.setGameWorld(gameWorld);
for (Player player : dGroup.getPlayers()) {
DPlayer dPlayer = getByPlayer(player);
dPlayer.setWorld(gameWorld.getWorld());
dPlayer.setCheckpoint(dGroup.getGameWorld().getLocStart());
if (dPlayer.getWolf() != null) {
dPlayer.getWolf().teleport(dPlayer.getCheckpoint());
}
}
dGroup.startGame(game);
}
public void finish() {
MessageUtil.sendMessage(getPlayer(), messageConfig.getMessage(Messages.PLAYER_FINISHED_DUNGEON));
finished = true;
DGroup dGroup = DGroup.getByPlayer(getPlayer());
if (dGroup == null) {
return;
}
if ( !dGroup.isPlaying()) {
return;
}
boolean first = true;
boolean hasToWait = false;
for (Player player : dGroup.getPlayers()) {
DPlayer dPlayer = getByPlayer(player);
if ( !dPlayer.finished) {
MessageUtil.sendMessage(this.getPlayer(), messageConfig.getMessage(Messages.PLAYER_WAIT_FOR_OTHER_PLAYERS));
hasToWait = true;
} else if (dPlayer != this) {
first = false;
}
}
DPlayerFinishEvent dPlayerFinishEvent = new DPlayerFinishEvent(this, first, hasToWait);
if (dPlayerFinishEvent.isCancelled()) {
finished = false;
return;
}
if (hasToWait) {
return;
}
DGroupFinishDungeonEvent dGroupFinishDungeonEvent = new DGroupFinishDungeonEvent(dGroup);
if (dGroupFinishDungeonEvent.isCancelled()) {
return;
}
for (Player player : dGroup.getPlayers()) {
DPlayer dPlayer = getByPlayer(player);
dPlayer.leave();
for (Reward reward : dGroup.getRewards()) {
reward.giveTo(player);
}
}
}
public void sendMessage(String message) {
if (editing) {
EditWorld editWorld = EditWorld.getByWorld(world);
editWorld.sendMessage(message);
for (Player player : plugin.getChatSpyers()) {
if ( !editWorld.getWorld().getPlayers().contains(player)) {
MessageUtil.sendMessage(player, ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + message);
}
}
} else {
GameWorld gameWorld = GameWorld.getByWorld(world);
gameWorld.sendMessage(message);
for (Player player : plugin.getChatSpyers()) {
if ( !gameWorld.getWorld().getPlayers().contains(player)) {
MessageUtil.sendMessage(player, ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + message);
}
}
}
}
@SuppressWarnings("deprecation")
public void poke(Block block) {
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
String[] lines = sign.getLines();
if (lines[0].equals("") && lines[1].equals("") && lines[2].equals("") && lines[3].equals("")) {
if (linesCopy != null) {
SignChangeEvent event = new SignChangeEvent(block, getPlayer(), linesCopy);
plugin.getServer().getPluginManager().callEvent(event);
if ( !event.isCancelled()) {
sign.setLine(0, event.getLine(0));
sign.setLine(1, event.getLine(1));
sign.setLine(2, event.getLine(2));
sign.setLine(3, event.getLine(3));
sign.update();
}
}
} else {
linesCopy = lines;
MessageUtil.sendMessage(getPlayer(), messageConfig.getMessage(Messages.PLAYER_SIGN_COPIED));
}
} else {
String info = "" + block.getType();
if (block.getData() != 0) {
info = info + "," + block.getData();
}
MessageUtil.sendMessage(getPlayer(), messageConfig.getMessage(Messages.PLAYER_BLOCK_INFO, info));
}
}
public void addTreasure() {
new DLootInventory(getPlayer(), treasureInv.getContents());
}
public void update(boolean updateSecond) {
boolean locationValid = true;
Location teleportLocation = getPlayer().getLocation();
boolean teleportWolf = false;
boolean respawnInventory = false;
boolean offline = false;
boolean kick = false;
boolean triggerAllInDistance = false;
GameWorld gameWorld = GameWorld.getByWorld(getWorld());
EditWorld editWorld = EditWorld.getByWorld(getWorld());
if ( !updateSecond) {
if ( !getPlayer().getWorld().equals(getWorld())) {
locationValid = false;
if (isEditing()) {
if (editWorld != null) {
if (editWorld.getLobby() == null) {
teleportLocation = editWorld.getWorld().getSpawnLocation();
} else {
teleportLocation = editWorld.getLobby();
}
}
} else {
if (gameWorld != null) {
DGroup dGroup = DGroup.getByPlayer(getPlayer());
if (getCheckpoint() == null) {
teleportLocation = dGroup.getGameWorld().getLocStart();
if (getWolf() != null) {
getWolf().teleport(dGroup.getGameWorld().getLocStart());
}
} else {
teleportLocation = getCheckpoint();
if (getWolf() != null) {
teleportWolf = true;
}
}
// Respawn Items
if (getRespawnInventory() != null || getRespawnArmor() != null) {
respawnInventory = true;
}
}
}
}
} else {
if (gameWorld != null) {
// Update Wolf
if (getWolf() != null) {
if (getWolf().isDead()) {
if (getWolfRespawnTime() <= 0) {
setWolf((Wolf) getWorld().spawnEntity(getPlayer().getLocation(), EntityType.WOLF));
getWolf().setTamed(true);
getWolf().setOwner(getPlayer());
setWolfRespawnTime(30);
}
wolfRespawnTime--;
}
}
// Kick offline plugin.getDPlayers()
if (getOfflineTime() > 0) {
offline = true;
if (getOfflineTime() < System.currentTimeMillis()) {
kick = true;
}
}
triggerAllInDistance = true;
}
}
DPlayerUpdateEvent event = new DPlayerUpdateEvent(this, locationValid, teleportWolf, respawnInventory, offline, kick, triggerAllInDistance);
if (event.isCancelled()) {
return;
}
if ( !locationValid) {
PlayerUtil.secureTeleport(getPlayer(), teleportLocation);
}
if (teleportWolf) {
getWolf().teleport(getCheckpoint());
}
if (respawnInventory) {
getPlayer().getInventory().setContents(getRespawnInventory());
getPlayer().getInventory().setArmorContents(getRespawnArmor());
setRespawnInventory(null);
setRespawnArmor(null);
}
if (kick) {
DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(this, DPlayerKickEvent.Cause.OFFLINE);
if ( !dPlayerKickEvent.isCancelled()) {
leave();
}
}
if (triggerAllInDistance) {
DistanceTrigger.triggerAllInDistance(getPlayer(), gameWorld);
}
}
// Static
public static void remove(DPlayer player) {
plugin.getDPlayers().remove(player);
}
public static DPlayer getByPlayer(Player player) {
for (DPlayer dPlayer : plugin.getDPlayers()) {
if (dPlayer.getPlayer().equals(player)) {
return dPlayer;
}
}
return null;
}
public static DPlayer getByName(String name) {
for (DPlayer dPlayer : plugin.getDPlayers()) {
if (dPlayer.getPlayer().getName().equalsIgnoreCase(name)) {
return dPlayer;
}
}
return null;
}
public static CopyOnWriteArrayList<DPlayer> getByWorld(World world) {
CopyOnWriteArrayList<DPlayer> dPlayers = new CopyOnWriteArrayList<DPlayer>();
for (DPlayer dPlayer : plugin.getDPlayers()) {
if (dPlayer.world == world) {
dPlayers.add(dPlayer);
}
}
return dPlayers;
}
}

View File

@ -1,179 +0,0 @@
package io.github.dre2n.dungeonsxl.player;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.util.playerutil.PlayerUtil;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
public class DSavePlayer {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
private static CopyOnWriteArrayList<DSavePlayer> savePlayers = new CopyOnWriteArrayList<DSavePlayer>();
// Variables
private String playerName;
private String uuid;
private Location oldLocation;
private ItemStack[] oldInventory;
private ItemStack[] oldArmor;
private int oldLvl;
private int oldExp;
private int oldHealth;
private int oldFoodLevel;
private int oldFireTicks;
private GameMode oldGamemode;
private Collection<PotionEffect> oldPotionEffects;
public DSavePlayer(String playerName, UUID uuid, Location oldLocation, ItemStack[] oldInventory, ItemStack[] oldArmor, int oldLvl, int oldExp, int oldHealth, int oldFoodLevel, int oldFireTicks,
GameMode oldGamemode, Collection<PotionEffect> oldPotionEffects) {
savePlayers.add(this);
this.playerName = playerName;
this.uuid = uuid.toString();
this.oldLocation = oldLocation;
this.oldInventory = oldInventory;
this.oldArmor = oldArmor;
this.oldExp = oldExp;
this.oldHealth = oldHealth;
this.oldFoodLevel = oldFoodLevel;
this.oldGamemode = oldGamemode;
this.oldLvl = oldLvl;
this.oldFireTicks = oldFireTicks;
this.oldPotionEffects = oldPotionEffects;
save();
}
public void reset(boolean keepInventory) {
Player player = plugin.getServer().getPlayer(playerName);
boolean offline = false;
if (player == null) {
player = PlayerUtil.getOfflinePlayer(playerName, UUID.fromString(uuid), oldLocation);
offline = true;
}
if (player == null) {
return;
}
try {
if ( !keepInventory) {
player.getInventory().setContents(oldInventory);
player.getInventory().setArmorContents(oldArmor);
player.setTotalExperience(oldExp);
player.setLevel(oldLvl);
player.setHealth(oldHealth);
player.setFoodLevel(oldFoodLevel);
player.setGameMode(oldGamemode);
player.setFireTicks(oldFireTicks);
for (PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType());
}
// Causes NPE if offline
if ( !offline) {
player.addPotionEffects(oldPotionEffects);
} else {
player.saveData();
}
}
if ( !offline && oldLocation.getWorld() != null) {
PlayerUtil.secureTeleport(player, oldLocation);
}
} catch (NullPointerException exception) {
plugin.getLogger().info("Corrupted playerdata detected and removed!");
}
savePlayers.remove(this);
save();
}
// Static
@SuppressWarnings("deprecation")
public static void save() {
FileConfiguration configFile = new YamlConfiguration();
for (DSavePlayer savePlayer : savePlayers) {
configFile.set(savePlayer.playerName + ".uuid", savePlayer.uuid);
configFile.set(savePlayer.playerName + ".oldGamemode", savePlayer.oldGamemode.getValue());
configFile.set(savePlayer.playerName + ".oldFireTicks", savePlayer.oldFireTicks);
configFile.set(savePlayer.playerName + ".oldFoodLevel", savePlayer.oldFoodLevel);
configFile.set(savePlayer.playerName + ".oldHealth", savePlayer.oldHealth);
configFile.set(savePlayer.playerName + ".oldExp", savePlayer.oldExp);
configFile.set(savePlayer.playerName + ".oldLvl", savePlayer.oldLvl);
configFile.set(savePlayer.playerName + ".oldArmor", savePlayer.oldArmor);
configFile.set(savePlayer.playerName + ".oldInventory", savePlayer.oldInventory);
configFile.set(savePlayer.playerName + ".oldLocation.x", savePlayer.oldLocation.getX());
configFile.set(savePlayer.playerName + ".oldLocation.y", savePlayer.oldLocation.getY());
configFile.set(savePlayer.playerName + ".oldLocation.z", savePlayer.oldLocation.getZ());
configFile.set(savePlayer.playerName + ".oldLocation.yaw", savePlayer.oldLocation.getYaw());
configFile.set(savePlayer.playerName + ".oldLocation.pitch", savePlayer.oldLocation.getPitch());
configFile.set(savePlayer.playerName + ".oldLocation.world", savePlayer.oldLocation.getWorld().getName());
configFile.set(savePlayer.playerName + ".oldPotionEffects", savePlayer.oldPotionEffects);
}
try {
configFile.save(new File(plugin.getDataFolder(), "savePlayers.yml"));
} catch (IOException e) {
e.printStackTrace();
}
}
@SuppressWarnings({"unchecked", "deprecation"})
public static void load() {
FileConfiguration configFile = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "savePlayers.yml"));
for (String playerName : configFile.getKeys(false)) {
// Load uuid
UUID uuid = UUID.fromString(configFile.getString(playerName + ".uuid"));
// Load inventory data
ArrayList<ItemStack> oldInventoryList = (ArrayList<ItemStack>) configFile.get(playerName + ".oldInventory");
ArrayList<ItemStack> oldArmorList = (ArrayList<ItemStack>) configFile.get(playerName + ".oldArmor");
ItemStack[] oldInventory = oldInventoryList.toArray(new ItemStack[oldInventoryList.size()]);
ItemStack[] oldArmor = oldArmorList.toArray(new ItemStack[oldArmorList.size()]);
// Load other data
int oldLvl = configFile.getInt(playerName + ".oldLvl");
int oldExp = configFile.getInt(playerName + ".oldExp");
int oldHealth = configFile.getInt(playerName + ".oldHealth");
int oldFoodLevel = configFile.getInt(playerName + ".oldFoodLevel");
int oldFireTicks = configFile.getInt(playerName + ".oldFireTicks");
GameMode oldGamemode = GameMode.getByValue(configFile.getInt(playerName + ".oldGamemode"));
Collection<PotionEffect> oldPotionEffects = (Collection<PotionEffect>) configFile.get(playerName + ".oldPotionEffects");
// Location
World world = plugin.getServer().getWorld(configFile.getString(playerName + ".oldLocation.world"));
if (world == null) {
world = plugin.getServer().getWorlds().get(0);
}
Location oldLocation = new Location(world, configFile.getDouble(playerName + ".oldLocation.x"), configFile.getDouble(playerName + ".oldLocation.y"), configFile.getDouble(playerName
+ ".oldLocation.z"), configFile.getInt(playerName + ".oldLocation.yaw"), configFile.getInt(playerName + ".oldLocation.pitch"));
// Create Player
DSavePlayer savePlayer = new DSavePlayer(playerName, uuid, oldLocation, oldInventory, oldArmor, oldLvl, oldExp, oldHealth, oldFoodLevel, oldFireTicks, oldGamemode, oldPotionEffects);
savePlayer.reset(false);
}
}
}

View File

@ -1,58 +0,0 @@
package io.github.dre2n.dungeonsxl.requirement;
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
import io.github.dre2n.dungeonsxl.util.messageutil.MessageUtil;
import org.bukkit.entity.Player;
public class FeeRequirement extends Requirement {
private RequirementType type = RequirementTypeDefault.FEE;
private double fee;
/**
* @return the fee
*/
public double getFee() {
return fee;
}
/**
* @param fee
* the fee to set
*/
public void setFee(double fee) {
this.fee = fee;
}
@Override
public boolean check(Player player) {
if (plugin.getEconomyProvider() == null) {
return true;
}
if (plugin.getEconomyProvider().getBalance(player) >= fee) {
return true;
} else {
return false;
}
}
@Override
public void demand(Player player) {
if (plugin.getEconomyProvider() == null) {
return;
}
plugin.getEconomyProvider().withdrawPlayer(player, fee);
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.REQUIREMENT_FEE, plugin.getEconomyProvider().format(fee)));
}
@Override
public RequirementType getType() {
return type;
}
}

View File

@ -1,46 +0,0 @@
package io.github.dre2n.dungeonsxl.requirement;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.bukkit.entity.Player;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.event.requirement.RequirementRegistrationEvent;
public abstract class Requirement {
protected static DungeonsXL plugin = DungeonsXL.getPlugin();
public static Requirement create(RequirementType type) {
Requirement requirement = null;
try {
Constructor<? extends Requirement> constructor = type.getHandler().getConstructor();
requirement = constructor.newInstance();
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) {
plugin.getLogger().info("An error occurred while accessing the handler class of the requirement " + type.getIdentifier() + ": " + exception.getClass().getSimpleName());
if ( !(type instanceof RequirementTypeDefault)) {
plugin.getLogger().info("Please note that this requirement is an unsupported feature added by an addon!");
}
}
RequirementRegistrationEvent event = new RequirementRegistrationEvent(requirement);
if (event.isCancelled()) {
return null;
}
return requirement;
}
// Abstract methods
public abstract boolean check(Player player);
public abstract void demand(Player player);
public abstract RequirementType getType();
}

View File

@ -1,15 +0,0 @@
package io.github.dre2n.dungeonsxl.requirement;
public interface RequirementType {
/**
* @return the identifier
*/
public String getIdentifier();
/**
* @return the handler
*/
public Class<? extends Requirement> getHandler();
}

Some files were not shown because too many files have changed in this diff Show More