mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
commit
f72c0f06d1
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
/nb-configuration.xml
|
||||
/target
|
||||
/dependency-reduced-pom.xml
|
||||
licenseheader.txt
|
||||
|
@ -4,6 +4,7 @@
|
||||
[![Wiki](http://feuerstern.bplaced.net/ressourcen/buttons/Wiki.png)](../../wiki/)
|
||||
[![Issues](http://feuerstern.bplaced.net/ressourcen/buttons/Issues.png)](../../issues/)
|
||||
[![JavaDocs](http://feuerstern.bplaced.net/ressourcen/buttons/JavaDocs.png)](http://feuerstern.bplaced.net/javadocs/dxl/)
|
||||
[![MCStats](http://feuerstern.bplaced.net/ressourcen/buttons/MCStats.png)](http://mcstats.org/plugin/DungeonsXL/)
|
||||
|
||||
![Doge](https://i.imgflip.com/vtpyi.jpg)
|
||||
|
||||
@ -30,6 +31,7 @@ DungeonsXL also provides custom game mechanics to make these worlds interesting.
|
||||
* A built-in custom mob system and support for MythicMobs. [Read more...](../../wiki/signs#mob)
|
||||
* A powerful API: [Read more...](../../wiki/api-tutorial)
|
||||
* Different game types allow you to use your maps dynamically for different purposes. [Read more...](../../wiki/game-types)
|
||||
* Announcements sothat users can join the next match easily. [Read more...](../../wiki/announcements)
|
||||
* ...and many more!
|
||||
|
||||
|
||||
@ -67,8 +69,6 @@ Instead of referencing the internals of the implementation directly, DungeonsXL
|
||||
The shaded version of DXL (standard version) contains this library, while the original version needs it as an external plugin.
|
||||
Have a look at the [installation instructions](../../wiki/getting-started#installation) for detailed information.
|
||||
|
||||
DungeonsXL currently uses BRCommons 0.5.2.
|
||||
|
||||
### Java
|
||||
7 and higher
|
||||
|
||||
|
37
pom.xml
37
pom.xml
@ -2,11 +2,15 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>io.github.dre2n</groupId>
|
||||
<artifactId>dungeonsxl</artifactId>
|
||||
<version>0.11.4</version>
|
||||
<version>0.12-SNAPSHOT${buildNo}</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>DungeonsXL</name>
|
||||
<url>https://dre2n.github.io</url>
|
||||
<description>Create custom dungeons and adventure maps with ease!</description>
|
||||
<properties>
|
||||
<buildNo></buildNo>
|
||||
<skipTests>true</skipTests>
|
||||
</properties>
|
||||
<build>
|
||||
<finalName>dungeonsxl-${project.version}</finalName>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
@ -40,9 +44,20 @@
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>io.github.dre2n.commons</pattern>
|
||||
<shadedPattern>io.github.dre2n.util.commons</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>io.github.dre2n.caliburn</pattern>
|
||||
<shadedPattern>io.github.dre2n.dungeonsxl.util.caliburn</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>io.github.dre2n:commons</include>
|
||||
<include>io.github.dre2n:caliburn</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
@ -53,9 +68,9 @@
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.9.2-R0.1-SNAPSHOT</version>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.10-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -67,7 +82,17 @@
|
||||
<dependency>
|
||||
<groupId>io.github.dre2n</groupId>
|
||||
<artifactId>commons</artifactId>
|
||||
<version>0.5.2</version>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.dre2n</groupId>
|
||||
<artifactId>caliburn</artifactId>
|
||||
<version>0.1.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.dre2n</groupId>
|
||||
<artifactId>itemsxl</artifactId>
|
||||
<version>0.1.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.dre2n</groupId>
|
||||
@ -77,7 +102,7 @@
|
||||
<dependency>
|
||||
<groupId>net.citizensnpcs</groupId>
|
||||
<artifactId>citizensapi</artifactId>
|
||||
<version>2.0.17-SNAPSHOT</version>
|
||||
<version>2.0.18-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -16,23 +16,26 @@
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl;
|
||||
|
||||
import io.github.dre2n.caliburn.CaliburnAPI;
|
||||
import io.github.dre2n.commons.command.BRCommands;
|
||||
import io.github.dre2n.commons.compatibility.Internals;
|
||||
import io.github.dre2n.commons.config.MessageConfig;
|
||||
import io.github.dre2n.commons.javaplugin.BRPlugin;
|
||||
import io.github.dre2n.commons.javaplugin.BRPluginSettings;
|
||||
import io.github.dre2n.commons.util.FileUtil;
|
||||
import io.github.dre2n.dungeonsxl.announcer.Announcers;
|
||||
import io.github.dre2n.dungeonsxl.command.*;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.config.DataConfig;
|
||||
import io.github.dre2n.dungeonsxl.config.GlobalData;
|
||||
import io.github.dre2n.dungeonsxl.config.MainConfig;
|
||||
import io.github.dre2n.dungeonsxl.config.WorldConfig;
|
||||
import io.github.dre2n.dungeonsxl.dungeon.Dungeons;
|
||||
import io.github.dre2n.dungeonsxl.game.Game;
|
||||
import io.github.dre2n.dungeonsxl.game.GameTypes;
|
||||
import io.github.dre2n.dungeonsxl.global.GlobalProtections;
|
||||
import io.github.dre2n.dungeonsxl.listener.*;
|
||||
import io.github.dre2n.dungeonsxl.mob.DMobTypes;
|
||||
import io.github.dre2n.dungeonsxl.mob.ExternalMobProviders;
|
||||
import io.github.dre2n.dungeonsxl.player.DClasses;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||
@ -42,6 +45,8 @@ import io.github.dre2n.dungeonsxl.requirement.RequirementTypes;
|
||||
import io.github.dre2n.dungeonsxl.reward.DLootInventory;
|
||||
import io.github.dre2n.dungeonsxl.reward.RewardTypes;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSignTypes;
|
||||
import io.github.dre2n.dungeonsxl.sign.SignScripts;
|
||||
import io.github.dre2n.dungeonsxl.task.AnnouncerTask;
|
||||
import io.github.dre2n.dungeonsxl.task.LazyUpdateTask;
|
||||
import io.github.dre2n.dungeonsxl.task.SecureModeTask;
|
||||
import io.github.dre2n.dungeonsxl.task.UpdateTask;
|
||||
@ -49,6 +54,7 @@ import io.github.dre2n.dungeonsxl.task.WorldUnloadTask;
|
||||
import io.github.dre2n.dungeonsxl.trigger.TriggerTypes;
|
||||
import io.github.dre2n.dungeonsxl.world.EditWorld;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import io.github.dre2n.itemsxl.ItemsXL;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
@ -63,8 +69,19 @@ public class DungeonsXL extends BRPlugin {
|
||||
private static DungeonsXL instance;
|
||||
|
||||
public static final String[] EXCLUDED_FILES = {"config.yml", "uid.dat", "DXLData.data"};
|
||||
public static File DUNGEONS;
|
||||
public static File LANGUAGES;
|
||||
public static File MAPS;
|
||||
public static File PLAYERS;
|
||||
public static File SCRIPTS;
|
||||
public static File ANNOUNCERS;
|
||||
public static File CLASSES;
|
||||
public static File MOBS;
|
||||
public static File SIGNS;
|
||||
|
||||
private DataConfig dataConfig;
|
||||
private CaliburnAPI caliburn;
|
||||
|
||||
private GlobalData globalData;
|
||||
private MainConfig mainConfig;
|
||||
private MessageConfig messageConfig;
|
||||
|
||||
@ -78,7 +95,12 @@ public class DungeonsXL extends BRPlugin {
|
||||
private GlobalProtections protections;
|
||||
private ExternalMobProviders dMobProviders;
|
||||
private DPlayers dPlayers;
|
||||
private Announcers announcers;
|
||||
private DClasses dClasses;
|
||||
private DMobTypes dMobTypes;
|
||||
private SignScripts signScripts;
|
||||
|
||||
private BukkitTask announcerTask;
|
||||
private BukkitTask worldUnloadTask;
|
||||
private BukkitTask lazyUpdateTask;
|
||||
private BukkitTask updateTask;
|
||||
@ -96,15 +118,16 @@ public class DungeonsXL extends BRPlugin {
|
||||
* ####~BRPluginSettings~####
|
||||
* ##########################
|
||||
* #~Internals~##~~v1_7_R3+~#
|
||||
* #~SpigotAPI~##~~~false~~~#
|
||||
* #~SpigotAPI~##~~~~true~~~#
|
||||
* #~~~~UUID~~~##~~~~true~~~#
|
||||
* #~~Economy~~##~~~~true~~~#
|
||||
* #Permissions##~~~~true~~~#
|
||||
* #~~Metrics~~##~~~~true~~~#
|
||||
* #Resource ID##~~~~9488~~~#
|
||||
* ##########################
|
||||
*/
|
||||
|
||||
settings = new BRPluginSettings(false, true, true, true, true, Internals.andHigher(Internals.v1_7_R3));
|
||||
settings = new BRPluginSettings(true, true, true, true, true, 9488, Internals.andHigher(Internals.v1_7_R3));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -112,17 +135,17 @@ public class DungeonsXL extends BRPlugin {
|
||||
super.onEnable();
|
||||
|
||||
instance = this;
|
||||
loadCaliburnAPI();
|
||||
|
||||
// InitFolders
|
||||
initFolders();
|
||||
|
||||
// Load Language
|
||||
loadMessageConfig(new File(getDataFolder(), "languages/en.yml"));
|
||||
loadMessageConfig(new File(LANGUAGES, "english.yml"));
|
||||
// Load Config
|
||||
loadDataConfig(new File(getDataFolder(), "data.yml"));
|
||||
loadGlobalData(new File(getDataFolder(), "data.yml"));
|
||||
loadMainConfig(new File(getDataFolder(), "config.yml"));
|
||||
// Load Language 2
|
||||
loadMessageConfig(new File(getDataFolder(), "languages/" + mainConfig.getLanguage() + ".yml"));
|
||||
loadMessageConfig(new File(LANGUAGES, mainConfig.getLanguage() + ".yml"));
|
||||
loadDCommands();
|
||||
DPermissions.register();
|
||||
loadGameTypes();
|
||||
@ -134,8 +157,13 @@ public class DungeonsXL extends BRPlugin {
|
||||
loadGlobalProtections();
|
||||
loadExternalMobProviders();
|
||||
loadDPlayers();
|
||||
loadAnnouncers(ANNOUNCERS);
|
||||
loadDClasses(CLASSES);
|
||||
loadDMobTypes(MOBS);
|
||||
loadSignScripts(SIGNS);
|
||||
|
||||
manager.registerEvents(new EntityListener(), this);
|
||||
manager.registerEvents(new GUIListener(), this);
|
||||
manager.registerEvents(new PlayerListener(), this);
|
||||
manager.registerEvents(new BlockListener(), this);
|
||||
manager.registerEvents(new WorldListener(), this);
|
||||
@ -148,6 +176,7 @@ public class DungeonsXL extends BRPlugin {
|
||||
loadAll();
|
||||
|
||||
// Tasks
|
||||
startAnnouncerTask(200L);
|
||||
startWorldUnloadTask(1200L);
|
||||
startLazyUpdateTask(20L);
|
||||
startUpdateTask(20L);
|
||||
@ -190,19 +219,49 @@ public class DungeonsXL extends BRPlugin {
|
||||
getDataFolder().mkdir();
|
||||
}
|
||||
|
||||
File dungeons = new File(getDataFolder() + "/dungeons");
|
||||
if (!dungeons.exists()) {
|
||||
dungeons.mkdir();
|
||||
DUNGEONS = new File(getDataFolder(), "dungeons");
|
||||
if (!DUNGEONS.exists()) {
|
||||
DUNGEONS.mkdir();
|
||||
}
|
||||
|
||||
File languages = new File(getDataFolder() + "/languages");
|
||||
if (!languages.exists()) {
|
||||
languages.mkdir();
|
||||
LANGUAGES = new File(getDataFolder(), "languages");
|
||||
if (!LANGUAGES.exists()) {
|
||||
LANGUAGES.mkdir();
|
||||
}
|
||||
|
||||
File maps = new File(getDataFolder() + "/maps");
|
||||
if (!maps.exists()) {
|
||||
maps.mkdir();
|
||||
MAPS = new File(getDataFolder(), "maps");
|
||||
if (!MAPS.exists()) {
|
||||
MAPS.mkdir();
|
||||
}
|
||||
|
||||
PLAYERS = new File(getDataFolder(), "players");
|
||||
if (!PLAYERS.exists()) {
|
||||
PLAYERS.mkdir();
|
||||
}
|
||||
|
||||
SCRIPTS = new File(getDataFolder(), "scripts");
|
||||
if (!SCRIPTS.exists()) {
|
||||
SCRIPTS.mkdir();
|
||||
}
|
||||
|
||||
ANNOUNCERS = new File(SCRIPTS, "announcers");
|
||||
if (!ANNOUNCERS.exists()) {
|
||||
ANNOUNCERS.mkdir();
|
||||
}
|
||||
|
||||
CLASSES = new File(SCRIPTS, "classes");
|
||||
if (!CLASSES.exists()) {
|
||||
CLASSES.mkdir();
|
||||
}
|
||||
|
||||
MOBS = new File(SCRIPTS, "mobs");
|
||||
if (!MOBS.exists()) {
|
||||
MOBS.mkdir();
|
||||
}
|
||||
|
||||
SIGNS = new File(SCRIPTS, "signs");
|
||||
if (!SIGNS.exists()) {
|
||||
SIGNS.mkdir();
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +302,7 @@ public class DungeonsXL extends BRPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
// Getters & loaders
|
||||
/* Getters and loaders */
|
||||
/**
|
||||
* @return the plugin instance
|
||||
*/
|
||||
@ -252,17 +311,35 @@ public class DungeonsXL extends BRPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of DataConfig
|
||||
* @return the loaded instance of CaliburnAPI
|
||||
*/
|
||||
public DataConfig getDataConfig() {
|
||||
return dataConfig;
|
||||
public CaliburnAPI getCaliburnAPI() {
|
||||
return caliburn;
|
||||
}
|
||||
|
||||
/**
|
||||
* load / reload a new instance of MainConfig
|
||||
* load / reload a new instance of CaliburnAPI
|
||||
*/
|
||||
public void loadDataConfig(File file) {
|
||||
dataConfig = new DataConfig(file);
|
||||
public void loadCaliburnAPI() {
|
||||
if (manager.isPluginEnabled("ItemsXL")) {
|
||||
this.caliburn = ItemsXL.getInstance().getAPI();
|
||||
} else {
|
||||
this.caliburn = new CaliburnAPI(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of GlobalData
|
||||
*/
|
||||
public GlobalData getGlobalData() {
|
||||
return globalData;
|
||||
}
|
||||
|
||||
/**
|
||||
* load / reload a new instance of GlobalData
|
||||
*/
|
||||
public void loadGlobalData(File file) {
|
||||
globalData = new GlobalData(file);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -318,6 +395,7 @@ public class DungeonsXL extends BRPlugin {
|
||||
new GameCommand(),
|
||||
new GroupCommand(),
|
||||
new InviteCommand(),
|
||||
new JoinCommand(),
|
||||
new EnterCommand(),
|
||||
new LeaveCommand(),
|
||||
new ListCommand(),
|
||||
@ -462,6 +540,62 @@ public class DungeonsXL extends BRPlugin {
|
||||
dPlayers = new DPlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of Announcers
|
||||
*/
|
||||
public Announcers getAnnouncers() {
|
||||
return announcers;
|
||||
}
|
||||
|
||||
/**
|
||||
* load / reload a new instance of Announcers
|
||||
*/
|
||||
public void loadAnnouncers(File file) {
|
||||
announcers = new Announcers(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of DClasses
|
||||
*/
|
||||
public DClasses getDClasses() {
|
||||
return dClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* load / reload a new instance of DClasses
|
||||
*/
|
||||
public void loadDClasses(File file) {
|
||||
dClasses = new DClasses(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of DMobTypes
|
||||
*/
|
||||
public DMobTypes getDMobTypes() {
|
||||
return dMobTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* load / reload a new instance of DMobTypes
|
||||
*/
|
||||
public void loadDMobTypes(File file) {
|
||||
dMobTypes = new DMobTypes(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of SignScripts
|
||||
*/
|
||||
public SignScripts getSignScripts() {
|
||||
return signScripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* load / reload a new instance of SignScripts
|
||||
*/
|
||||
public void loadSignScripts(File file) {
|
||||
signScripts = new SignScripts(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the worldUnloadTask
|
||||
*/
|
||||
@ -469,6 +603,22 @@ public class DungeonsXL extends BRPlugin {
|
||||
return worldUnloadTask;
|
||||
}
|
||||
|
||||
/**
|
||||
* start a new AnnouncerTask
|
||||
*/
|
||||
public void startAnnouncerTask(long period) {
|
||||
if (!announcers.getAnnouncers().isEmpty()) {
|
||||
announcerTask = new AnnouncerTask(announcers).runTaskTimer(this, 0L, period);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the AnnouncerTask
|
||||
*/
|
||||
public BukkitTask getAnnouncerTask() {
|
||||
return announcerTask;
|
||||
}
|
||||
|
||||
/**
|
||||
* start a new WorldUnloadTask
|
||||
*/
|
||||
@ -532,13 +682,6 @@ public class DungeonsXL extends BRPlugin {
|
||||
return editWorlds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the defaultConfig
|
||||
*/
|
||||
public WorldConfig getDefaultConfig() {
|
||||
return WorldConfig.defaultConfig;// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the gameWorlds
|
||||
*/
|
||||
|
@ -0,0 +1,445 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.announcer;
|
||||
|
||||
import io.github.dre2n.commons.compatibility.CompatibilityHandler;
|
||||
import io.github.dre2n.commons.util.guiutil.GUIUtil;
|
||||
import io.github.dre2n.commons.util.messageutil.DefaultFontInfo;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
|
||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.task.AnnouncerStartGameTask;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class Announcer {
|
||||
|
||||
DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
|
||||
private String name;
|
||||
|
||||
private List<String> description;
|
||||
private List<String> worlds;
|
||||
|
||||
private String dungeonName;
|
||||
private String mapName;
|
||||
|
||||
private int minGroupsPerGame;
|
||||
private int minPlayersPerGroup;
|
||||
|
||||
private short maxGroupsPerGame;
|
||||
private int maxPlayersPerGroup;
|
||||
|
||||
private List<DGroup> dGroups;
|
||||
private List<ItemStack> buttons;
|
||||
|
||||
private AnnouncerStartGameTask startTask;
|
||||
|
||||
/**
|
||||
* @param file
|
||||
* the script file
|
||||
*/
|
||||
public Announcer(File file) {
|
||||
this(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name of the Announcer
|
||||
* @param config
|
||||
* the config that stores the information
|
||||
*/
|
||||
public Announcer(String name, FileConfiguration config) {
|
||||
this.name = name;
|
||||
|
||||
description = config.getStringList("description");
|
||||
worlds = config.getStringList("worlds");
|
||||
|
||||
String identifier = config.getString("identifier");
|
||||
boolean multiFloor = config.getBoolean("multiFloor");
|
||||
if (multiFloor) {
|
||||
dungeonName = identifier;
|
||||
|
||||
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
|
||||
if (dungeon != null) {
|
||||
mapName = dungeon.getConfig().getStartFloor();
|
||||
}
|
||||
|
||||
} else {
|
||||
mapName = identifier;
|
||||
}
|
||||
|
||||
minGroupsPerGame = config.getInt("minGroupsPerGame");
|
||||
minPlayersPerGroup = config.getInt("minPlayersPerGroup");
|
||||
|
||||
maxGroupsPerGame = (short) config.getInt("maxGroupsPerGame");
|
||||
dGroups = new ArrayList<>(Collections.nCopies(maxGroupsPerGame + 1, (DGroup) null));
|
||||
maxPlayersPerGroup = config.getInt("maxPlayersPerGroup");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name of the Announcer
|
||||
* @param description
|
||||
* the description messages
|
||||
* @param worlds
|
||||
* the names of the worlds where the announcement will be seen or null to broadcast it to all worlds
|
||||
* @param identifier
|
||||
* the dungeon identifier
|
||||
* @param multiFloor
|
||||
* if the identifier refers to an MFD (true) or an SFD (false)
|
||||
* @param maxGroupsPerGame
|
||||
* the amount of groups in one game
|
||||
* @param maxPlayersPerGame
|
||||
* the amount of players in one group
|
||||
*/
|
||||
public Announcer(String name, List<String> description, List<String> worlds, String identifier, boolean multiFloor, short maxGroupsPerGame, int maxPlayersPerGroup) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.worlds = worlds;
|
||||
|
||||
if (multiFloor) {
|
||||
dungeonName = identifier;
|
||||
|
||||
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
|
||||
if (dungeon != null) {
|
||||
mapName = dungeon.getConfig().getStartFloor();
|
||||
}
|
||||
|
||||
} else {
|
||||
mapName = identifier;
|
||||
}
|
||||
|
||||
this.maxGroupsPerGame = maxGroupsPerGame;
|
||||
this.dGroups = new ArrayList<>(Collections.nCopies(maxGroupsPerGame + 1, (DGroup) null));
|
||||
this.maxPlayersPerGroup = maxPlayersPerGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the announcer
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the description messages
|
||||
*/
|
||||
public List<String> getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description
|
||||
* the description to set
|
||||
*/
|
||||
public void setDescription(List<String> description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the names of the worlds where the announcement will be seen or null to broadcast it to all worlds
|
||||
*/
|
||||
public List<String> getWorlds() {
|
||||
return worlds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param worlds
|
||||
* the worlds to set
|
||||
*/
|
||||
public void setWorlds(List<String> worlds) {
|
||||
this.worlds = worlds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the dungeon
|
||||
*/
|
||||
public String getDungeonName() {
|
||||
return dungeonName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dungeonName
|
||||
* the name of the dungeon to set
|
||||
*/
|
||||
public void setDungeonName(String dungeonName) {
|
||||
this.dungeonName = dungeonName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the first or only floor
|
||||
*/
|
||||
public String getMapName() {
|
||||
return mapName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mapName
|
||||
* the name of the map to set
|
||||
*/
|
||||
public void setMapName(String mapName) {
|
||||
this.mapName = mapName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the minimum amount of filled groups per game
|
||||
*/
|
||||
public int getMinGroupsPerGame() {
|
||||
return minGroupsPerGame;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param amount
|
||||
* the amount to set
|
||||
*/
|
||||
public void setMinGroupsPerGame(int amount) {
|
||||
minGroupsPerGame = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the minimum amount of filled groups per game
|
||||
*/
|
||||
public int getMinPlayersPerGroup() {
|
||||
return minPlayersPerGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param amount
|
||||
* the amount to set
|
||||
*/
|
||||
public void setMinPlayersPerGroup(int amount) {
|
||||
minPlayersPerGroup = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maximum amount of groups per game
|
||||
*/
|
||||
public short getMaxGroupsPerGame() {
|
||||
return maxGroupsPerGame;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param amount
|
||||
* the amount to set
|
||||
*/
|
||||
public void setMaxGroupsPerGame(short amount) {
|
||||
maxGroupsPerGame = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maximum amount of players per group
|
||||
*/
|
||||
public int getMaxPlayersPerGroup() {
|
||||
return maxPlayersPerGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the DGroups
|
||||
*/
|
||||
public List<DGroup> getDGroups() {
|
||||
return dGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the buttons that represent the DGroups
|
||||
*/
|
||||
public List<ItemStack> getButtons() {
|
||||
return buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param amount
|
||||
* the amount to set
|
||||
*/
|
||||
public void setMaxPlayersPerGroup(int amount) {
|
||||
maxPlayersPerGroup = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the start task
|
||||
*/
|
||||
public AnnouncerStartGameTask getStartTask() {
|
||||
return startTask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the start task and sets it to null.
|
||||
*/
|
||||
public void endStartTask() {
|
||||
startTask.cancel();
|
||||
startTask = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the announcement
|
||||
*/
|
||||
public void send(Player player) {
|
||||
for (String message : description) {
|
||||
MessageUtil.sendCenteredMessage(player, message);
|
||||
}
|
||||
|
||||
if (CompatibilityHandler.getInstance().isSpigot()) {
|
||||
ClickEvent onClick = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/dungeonsxl join " + name);
|
||||
|
||||
BaseComponent[] message = TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', DMessages.ANNOUNCER_CLICK.getMessage()));
|
||||
for (BaseComponent slice : message) {
|
||||
slice.setClickEvent(onClick);
|
||||
}
|
||||
|
||||
TextComponent center = new TextComponent(DefaultFontInfo.center(BaseComponent.toPlainText(message)).replaceAll(BaseComponent.toPlainText(message), ""));
|
||||
|
||||
ArrayList<BaseComponent> toSend = new ArrayList<>(Arrays.asList(message));
|
||||
toSend.add(0, center);
|
||||
player.spigot().sendMessage(toSend.toArray(new BaseComponent[]{}));
|
||||
|
||||
} else {
|
||||
MessageUtil.sendCenteredMessage(player, DMessages.ANNOUNCER_CMD.getMessage(getName().toUpperCase()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the group selection GUI
|
||||
*/
|
||||
public void showGUI(Player player) {
|
||||
updateButtons();
|
||||
Inventory gui = GUIUtil.createGUI(plugin, ChatColor.DARK_RED + name, buttons);
|
||||
plugin.addGUI(gui);
|
||||
player.closeInventory();
|
||||
player.openInventory(gui);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param button
|
||||
* the clicked button
|
||||
*/
|
||||
public void clickGroupButton(Player player, ItemStack button) {
|
||||
DGroup dGroup = getDGroupByButton(button);
|
||||
DGroup pGroup = DGroup.getByPlayer(player);
|
||||
|
||||
for (DGroup group : dGroups) {
|
||||
if (dGroups.contains(pGroup) && pGroup != null && pGroup.isCustom() && pGroup.getCaptain() == player) {
|
||||
dGroups.set(dGroups.indexOf(pGroup), null);
|
||||
}
|
||||
|
||||
if (group != null && group.getPlayers().contains(player)) {
|
||||
group.removePlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (dGroup != null && pGroup == null) {
|
||||
if (dGroup.getPlayers().size() < maxPlayersPerGroup) {
|
||||
dGroup.addPlayer(player);
|
||||
}
|
||||
|
||||
} else if (dGroup == null && pGroup == null) {
|
||||
DGroupCreateEvent event = new DGroupCreateEvent(dGroup, player, DGroupCreateEvent.Cause.ANNOUNCER);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
dGroups.set(buttons.indexOf(button), new DGroup(player));
|
||||
}
|
||||
|
||||
} else if (dGroup == null && pGroup != null) {
|
||||
dGroups.set(buttons.indexOf(button), pGroup);
|
||||
|
||||
} else if (pGroup != null && dGroups.contains(pGroup) && pGroup != dGroup) {
|
||||
dGroups.set(dGroups.indexOf(pGroup), null);
|
||||
dGroups.set(buttons.indexOf(button), pGroup);
|
||||
}
|
||||
|
||||
showGUI(player);
|
||||
|
||||
int i = 0;
|
||||
for (DGroup group : dGroups) {
|
||||
if (group != null && group.getPlayers().size() >= minPlayersPerGroup) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= minGroupsPerGame) {
|
||||
if (startTask == null) {
|
||||
startTask = new AnnouncerStartGameTask(this);
|
||||
startTask.runTaskLater(plugin, 20 * 30L);
|
||||
} else {
|
||||
startTask.getProgressBar().addPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the buttons to group changes.
|
||||
*/
|
||||
public void updateButtons() {
|
||||
int groupCount = 0;
|
||||
|
||||
buttons = new ArrayList<>(dGroups.size());
|
||||
do {
|
||||
String name = ChatColor.DARK_GRAY + "EMPTY GROUP";
|
||||
int playerCount = 0;
|
||||
|
||||
DGroup dGroup = dGroups.get(groupCount);
|
||||
if (!plugin.getDGroups().contains(dGroup)) {
|
||||
dGroups.set(groupCount, null);
|
||||
|
||||
} else if (dGroup != null) {
|
||||
name = ChatColor.AQUA + dGroup.getName();
|
||||
playerCount = dGroup.getPlayers().size();
|
||||
}
|
||||
|
||||
boolean full = playerCount >= maxPlayersPerGroup;
|
||||
|
||||
ItemStack button = new ItemStack(Material.WOOL, playerCount, plugin.getMainConfig().getGroupColorPriority().get(groupCount));
|
||||
ItemMeta meta = button.getItemMeta();
|
||||
meta.setDisplayName(name + (full ? ChatColor.DARK_RED : ChatColor.GREEN) + " [" + playerCount + "/" + maxPlayersPerGroup + "]");
|
||||
button.setItemMeta(meta);
|
||||
buttons.add(button);
|
||||
|
||||
groupCount++;
|
||||
} while (groupCount != maxGroupsPerGame);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param button
|
||||
* the button
|
||||
* @return the matching DGroup
|
||||
*/
|
||||
public DGroup getDGroupByButton(ItemStack button) {
|
||||
int index = buttons.indexOf(button);
|
||||
return dGroups.get(index);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.announcer;
|
||||
|
||||
import io.github.dre2n.commons.util.FileUtil;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class Announcers {
|
||||
|
||||
private List<Announcer> announcers = new ArrayList<>();
|
||||
|
||||
public Announcers(File file) {
|
||||
if (file.isDirectory()) {
|
||||
for (File script : FileUtil.getFilesForFolder(file)) {
|
||||
announcers.add(new Announcer(script));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the announcer that has the name
|
||||
*/
|
||||
public Announcer getByName(String name) {
|
||||
for (Announcer announcer : announcers) {
|
||||
if (announcer.getName().equalsIgnoreCase(name)) {
|
||||
return announcer;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the announcer that has the GUI
|
||||
*/
|
||||
public Announcer getByGUI(Inventory gui) {
|
||||
for (Announcer announcer : announcers) {
|
||||
if ((ChatColor.DARK_RED + announcer.getName()).equals(gui.getTitle())) {
|
||||
return announcer;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the announcers
|
||||
*/
|
||||
public List<Announcer> getAnnouncers() {
|
||||
return announcers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param announcer
|
||||
* the Announcer to add
|
||||
*/
|
||||
public void addAnnouncer(Announcer announcer) {
|
||||
announcers.add(announcer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param announcer
|
||||
* the Announcer to remove
|
||||
*/
|
||||
public void removeAnnouncer(Announcer announcer) {
|
||||
announcers.remove(announcer);
|
||||
}
|
||||
|
||||
}
|
@ -20,6 +20,7 @@ import io.github.dre2n.commons.command.BRCommand;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||
import io.github.dre2n.dungeonsxl.world.EditWorld;
|
||||
@ -95,7 +96,7 @@ public class CreateCommand extends BRCommand {
|
||||
MessageUtil.log(plugin, DMessages.LOG_WORLD_GENERATION_FINISHED.getMessage());
|
||||
|
||||
// Tp Player
|
||||
new DGamePlayer(player, editWorld.getWorld(), true);
|
||||
new DEditPlayer(player, editWorld.getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ import io.github.dre2n.commons.command.BRCommand;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||
@ -71,7 +72,7 @@ public class EditCommand extends BRCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
new DGamePlayer(player, editWorld.getWorld(), true);
|
||||
new DEditPlayer(player, editWorld.getWorld());
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -18,8 +18,8 @@ package io.github.dre2n.dungeonsxl.command;
|
||||
|
||||
import io.github.dre2n.commons.command.BRCommand;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||
@ -32,8 +32,6 @@ import org.bukkit.entity.Player;
|
||||
*/
|
||||
public class EscapeCommand extends BRCommand {
|
||||
|
||||
DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
|
||||
public EscapeCommand() {
|
||||
setCommand("escape");
|
||||
setMinArgs(0);
|
||||
@ -46,14 +44,12 @@ public class EscapeCommand extends BRCommand {
|
||||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
if (dPlayer != null) {
|
||||
DEditPlayer dPlayer = DEditPlayer.getByPlayer(player);
|
||||
|
||||
if (!dPlayer.isEditing()) {
|
||||
if (DGamePlayer.getByPlayer(player) != null) {
|
||||
MessageUtil.sendMessage(player, DMessages.ERROR_LEAVE_DUNGEON.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (dPlayer != null) {
|
||||
dPlayer.escape();
|
||||
|
||||
EditWorld editWorld = EditWorld.getByWorld(dPlayer.getWorld());
|
||||
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.command;
|
||||
|
||||
import io.github.dre2n.commons.command.BRCommand;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.announcer.Announcer;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.player.DGlobalPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DInstancePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class JoinCommand extends BRCommand {
|
||||
|
||||
DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
|
||||
public JoinCommand() {
|
||||
setCommand("join");
|
||||
setMinArgs(1);
|
||||
setMaxArgs(1);
|
||||
setHelp(DMessages.HELP_CMD_JOIN.getMessage());
|
||||
setPermission(DPermissions.JOIN.getNode());
|
||||
setPlayerCommand(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
DGlobalPlayer player = plugin.getDPlayers().getByPlayer((Player) sender);
|
||||
if (player instanceof DInstancePlayer) {
|
||||
MessageUtil.sendMessage(sender, DMessages.ERROR_LEAVE_GAME.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
Announcer announcer = plugin.getAnnouncers().getByName(args[1]);
|
||||
if (announcer != null) {
|
||||
announcer.showGUI((Player) sender);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -22,8 +22,10 @@ import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerEscapeEvent;
|
||||
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerLeaveDGroupEvent;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGlobalPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.player.DInstancePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -48,7 +50,8 @@ public class LeaveCommand extends BRCommand {
|
||||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
Player player = (Player) sender;
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
|
||||
DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(player);
|
||||
|
||||
if (GameWorld.getByWorld(player.getWorld()) != null) {
|
||||
if (GameWorld.getByWorld(player.getWorld()).isTutorial()) {
|
||||
@ -57,9 +60,13 @@ public class LeaveCommand extends BRCommand {
|
||||
}
|
||||
}
|
||||
|
||||
if (dPlayer != null) {
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
|
||||
if (dGroup == null && !(dPlayer instanceof DEditPlayer)) {
|
||||
MessageUtil.sendMessage(player, DMessages.ERROR_JOIN_GROUP.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
DPlayerEscapeEvent dPlayerEscapeEvent = new DPlayerEscapeEvent(dPlayer);
|
||||
plugin.getServer().getPluginManager().callEvent(dPlayerEscapeEvent);
|
||||
DPlayerLeaveDGroupEvent dPlayerLeaveDGroupEvent = new DPlayerLeaveDGroupEvent(dPlayer, dGroup);
|
||||
@ -69,19 +76,13 @@ public class LeaveCommand extends BRCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
dPlayer.leave();
|
||||
MessageUtil.sendMessage(player, DMessages.CMD_LEAVE_SUCCESS.getMessage());
|
||||
|
||||
if (dPlayer instanceof DInstancePlayer) {
|
||||
((DInstancePlayer) dPlayer).leave();
|
||||
} else {
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
if (dGroup != null) {
|
||||
dGroup.removePlayer(player);
|
||||
MessageUtil.sendMessage(player, DMessages.CMD_LEAVE_SUCCESS.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
MessageUtil.sendMessage(player, DMessages.ERROR_NOT_IN_DUNGEON.getMessage());
|
||||
}
|
||||
MessageUtil.sendMessage(player, DMessages.CMD_LEAVE_SUCCESS.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,15 +21,13 @@ import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.config.DungeonConfig;
|
||||
import io.github.dre2n.dungeonsxl.config.WorldConfig;
|
||||
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
|
||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent;
|
||||
import io.github.dre2n.dungeonsxl.game.Game;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||
import io.github.dre2n.dungeonsxl.world.EditWorld;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import java.io.File;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -91,24 +89,6 @@ public class PlayCommand extends BRCommand {
|
||||
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, DMessages.ERROR_COOLDOWN.getMessage(String.valueOf(confReader.getTimeToNextPlay())));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GameWorld.checkRequirements(mapName, player)) {
|
||||
MessageUtil.sendMessage(player, DMessages.ERROR_REQUIREMENTS.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
|
||||
if (dGroup != null) {
|
||||
@ -155,7 +135,7 @@ public class PlayCommand extends BRCommand {
|
||||
}
|
||||
|
||||
if (dGroup.getGameWorld() == null) {
|
||||
dGroup.setGameWorld(GameWorld.load(DGroup.getByPlayer(player).getMapName()));
|
||||
new Game(dGroup, dGroup.getMapName());
|
||||
}
|
||||
|
||||
if (dGroup.getGameWorld() == null) {
|
||||
|
@ -71,7 +71,7 @@ public class ReloadCommand extends BRCommand {
|
||||
// Load Language
|
||||
plugin.loadMessageConfig(new File(plugin.getDataFolder(), "languages/en.yml"));
|
||||
// Load Config
|
||||
plugin.loadDataConfig(new File(plugin.getDataFolder(), "data.yml"));
|
||||
plugin.loadGlobalData(new File(plugin.getDataFolder(), "data.yml"));
|
||||
plugin.loadMainConfig(new File(plugin.getDataFolder(), "config.yml"));
|
||||
// Load Language 2
|
||||
plugin.loadMessageConfig(new File(plugin.getDataFolder(), "languages/" + plugin.getMainConfig().getLanguage() + ".yml"));
|
||||
@ -82,6 +82,10 @@ public class ReloadCommand extends BRCommand {
|
||||
plugin.loadTriggers();
|
||||
plugin.loadDSigns();
|
||||
plugin.loadDungeons();
|
||||
plugin.loadAnnouncers(DungeonsXL.ANNOUNCERS);
|
||||
plugin.loadDClasses(DungeonsXL.CLASSES);
|
||||
plugin.loadDMobTypes(DungeonsXL.MOBS);
|
||||
plugin.loadSignScripts(DungeonsXL.SIGNS);
|
||||
|
||||
MessageUtil.sendPluginTag(sender, plugin);
|
||||
MessageUtil.sendCenteredMessage(sender, DMessages.CMD_RELOAD_DONE.getMessage());
|
||||
|
@ -18,6 +18,7 @@ package io.github.dre2n.dungeonsxl.config;
|
||||
|
||||
import io.github.dre2n.commons.config.Messages;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
@ -26,6 +27,8 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
*/
|
||||
public enum DMessages implements Messages {
|
||||
|
||||
ANNOUNCER_CMD("Announcer_Cmd", "&4&l=> &6USE &4/DXL JOIN &v1 &6TO JOIN &4&l<="),
|
||||
ANNOUNCER_CLICK("Announcer_Click", "&4&l=> &6CLICK HERE TO JOIN &4&l<="),
|
||||
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"),
|
||||
@ -80,10 +83,12 @@ public enum DMessages implements Messages {
|
||||
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_REQUIREMENTS("Error_Requirements", "&4You don't fulfill the requirements for this dungeon!"),
|
||||
ERROR_SIGN_WRONG_FORMAT("Error_SignWrongFormat", "&4The sign is not written correctly!"),
|
||||
ERROR_TOO_MANY_INSTANCES("Error_TooManyInstances", "&4There are currently too many maps instantiated. Try it again in a few minutes!"),
|
||||
ERROR_TOO_MANY_TUTORIALS("Error_TooManyTutorials", "&4There are currently too many tutorials running. Try it again in a few minutes!"),
|
||||
ERROR_TUTORIAL_NOT_EXIST("Error_TutorialNotExist", "&4Tutorial dungeon does not exist!"),
|
||||
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"),
|
||||
@ -101,6 +106,7 @@ public enum DMessages implements Messages {
|
||||
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_JOIN("Help_Cmd_Join", "/dxl join [announcement] - Opens the GUI to join a group in an upcoming game"),
|
||||
HELP_CMD_ENTER("Help_Cmd_Enter", "/dxl enter ([joining group]) [target group] - Let the joining group enter the game of the target group"),
|
||||
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"),
|
||||
@ -111,6 +117,7 @@ public enum DMessages implements Messages {
|
||||
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_SETTINGS("Help_Cmd_Settings", "/dxl settings ([edit|global|player])- Opens the settings menu"),
|
||||
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"),
|
||||
GROUP_CREATED("Group_Created", "&4&v1&6 created the group &4&v2&6!"),
|
||||
@ -126,6 +133,7 @@ public enum DMessages implements Messages {
|
||||
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_NEW_PLAYER_DATA("Log_NewPlayerData", "&6A new player data file has been created and saved as &v1."),
|
||||
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!"),
|
||||
@ -155,7 +163,17 @@ public enum DMessages implements Messages {
|
||||
PLAYER_TREASURES("Player_Treasures", "&1Treasures"),
|
||||
PLAYER_WAIT_FOR_OTHER_PLAYERS("Player_WaitForOtherPlayers", "&6Waiting for teammates..."),
|
||||
REQUIREMENT_FEE("Requirement_Fee", "&6You have been charged &4&v1 &6for entering the dungeon."),
|
||||
REWARD_GENERAL("Reward_General", "&6You received &4&v1 &6for finishing the dungeon.");
|
||||
REWARD_GENERAL("Reward_General", "&6You received &4&v1 &6for finishing the dungeon."),
|
||||
SETTINGS_ANNOUNCEMENTS_1("Settings_Announcements1", "&fToggles personal"),
|
||||
SETTINGS_ANNOUNCEMENTS_2("Settings_Announcements2", "&fgame announcements."),
|
||||
SETTINGS_BREAK_1("Settings_Break1", "&fAllows you to break blocks"),
|
||||
SETTINGS_BREAK_2("Settings_Break2", "&fprotected by DungeonsXL."),
|
||||
SETTINGS_CHAT_SPY1("Settings_ChatSpy1", "&fAllows you to receive"),
|
||||
SETTINGS_CHAT_SPY2("Settings_ChatSpy2", "&fall dungeon chat messages."),
|
||||
SETTINGS_TITLE("Settings_Title", "&4Settings: &o"),
|
||||
SETTINGS_TITLE_EDIT("Settings_Title_Edit", "Dungeon Setup"),
|
||||
SETTINGS_TITLE_GLOBAL("Settings_Title_Global", "Global Configuration"),
|
||||
SETTINGS_TITLE_PLAYER("Settings_Title_Player", "Player");
|
||||
|
||||
private String identifier;
|
||||
private String message;
|
||||
@ -172,7 +190,7 @@ public enum DMessages implements Messages {
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
return ChatColor.translateAlternateColorCodes('&', message);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,57 +16,33 @@
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.config;
|
||||
|
||||
import io.github.dre2n.commons.config.BRConfig;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class DungeonConfig extends WorldConfig {
|
||||
public class DungeonConfig extends BRConfig {
|
||||
|
||||
public static final int CONFIG_VERSION = 1;
|
||||
|
||||
private String startFloor;
|
||||
private String endFloor;
|
||||
private List<String> floors = new ArrayList<>();
|
||||
private int floorCount;
|
||||
private boolean removeWhenPlayed;
|
||||
private WorldConfig overrideValues;
|
||||
private WorldConfig defaultValues;
|
||||
|
||||
public DungeonConfig(File file) {
|
||||
super(file);
|
||||
load(YamlConfiguration.loadConfiguration(file));
|
||||
}
|
||||
super(file, CONFIG_VERSION);
|
||||
|
||||
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");
|
||||
if (initialize) {
|
||||
initialize();
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,4 +128,105 @@ public class DungeonConfig extends WorldConfig {
|
||||
this.removeWhenPlayed = removeWhenPlayed;
|
||||
}
|
||||
|
||||
/**
|
||||
* The values from this WorldConfig will override all values of the
|
||||
* WorldConfigs of inherited maps.
|
||||
*
|
||||
* @return the override values
|
||||
*/
|
||||
public WorldConfig getOverrideValues() {
|
||||
return overrideValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param worldConfig
|
||||
* the WorldConfig to set
|
||||
*/
|
||||
public void setOverrideValues(WorldConfig worldConfig) {
|
||||
overrideValues = worldConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* The values from this WorldConfig will get overriden by values of the
|
||||
* WorldConfigs of inherited maps.
|
||||
* They will still override the values from the main config, though.
|
||||
*
|
||||
* @return the default values
|
||||
*/
|
||||
public WorldConfig getDefaultValues() {
|
||||
return defaultValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param worldConfig
|
||||
* the WorldConfig to set
|
||||
*/
|
||||
public void setDefaultValues(WorldConfig worldConfig) {
|
||||
defaultValues = worldConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
if (!config.contains("floors")) {
|
||||
config.set("floors", floors);
|
||||
}
|
||||
|
||||
if (!config.contains("startFloor")) {
|
||||
config.set("startFloor", startFloor);
|
||||
}
|
||||
|
||||
if (!config.contains("endFloor")) {
|
||||
config.set("endFloor", endFloor);
|
||||
}
|
||||
|
||||
if (!config.contains("floorCount")) {
|
||||
config.set("floorCount", floorCount);
|
||||
}
|
||||
|
||||
if (!config.contains("removeWhenPlayed")) {
|
||||
config.set("removeWhenPlayed", removeWhenPlayed);
|
||||
}
|
||||
|
||||
if (!config.contains("overrideValues")) {
|
||||
config.createSection("overrideValues");
|
||||
}
|
||||
|
||||
if (!config.contains("defaultValues")) {
|
||||
config.createSection("defaultValues");
|
||||
}
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
if (config.contains("floors")) {
|
||||
floors = config.getStringList("floors");
|
||||
}
|
||||
|
||||
if (config.contains("startFloor")) {
|
||||
startFloor = config.getString("startFloor");
|
||||
}
|
||||
|
||||
if (config.contains("endFloor")) {
|
||||
endFloor = config.getString("endFloor");
|
||||
}
|
||||
|
||||
if (config.contains("floorCount")) {
|
||||
floorCount = config.getInt("floorCount");
|
||||
}
|
||||
|
||||
if (config.contains("removeWhenPlayed")) {
|
||||
removeWhenPlayed = config.getBoolean("removeWhenPlayed");
|
||||
}
|
||||
|
||||
if (config.contains("overrideValues")) {
|
||||
overrideValues = new WorldConfig(config.getConfigurationSection("overrideValues"));
|
||||
}
|
||||
|
||||
if (config.contains("defaultValues")) {
|
||||
defaultValues = new WorldConfig(config.getConfigurationSection("defaultValues"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,11 +22,11 @@ import java.io.File;
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class DataConfig extends BRConfig {
|
||||
public class GlobalData extends BRConfig {
|
||||
|
||||
public static final int CONFIG_VERSION = 2;
|
||||
|
||||
public DataConfig(File file) {
|
||||
public GlobalData(File file) {
|
||||
super(file, CONFIG_VERSION);
|
||||
|
||||
if (initialize) {
|
@ -19,6 +19,7 @@ package io.github.dre2n.dungeonsxl.config;
|
||||
import io.github.dre2n.commons.config.BRConfig;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -29,9 +30,9 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
*/
|
||||
public class MainConfig extends BRConfig {
|
||||
|
||||
public static final int CONFIG_VERSION = 5;
|
||||
public static final int CONFIG_VERSION = 8;
|
||||
|
||||
private String language = "en";
|
||||
private String language = "english";
|
||||
private boolean enableEconomy = false;
|
||||
|
||||
/* Tutorial */
|
||||
@ -43,14 +44,19 @@ public class MainConfig extends BRConfig {
|
||||
/* Misc */
|
||||
private boolean sendFloorTitle = true;
|
||||
private Map<String, Object> externalMobProviders = new HashMap<>();
|
||||
private List<Short> groupColorPriority = new ArrayList<>(Arrays.asList((short) 11, (short) 14, (short) 4, (short) 5, (short) 10, (short) 1, (short) 0, (short) 15));
|
||||
private int maxInstances = 10;
|
||||
|
||||
/* Secure Mode*/
|
||||
/* Secure Mode */
|
||||
private boolean secureModeEnabled = false;
|
||||
private double secureModeCheckInterval = 5;
|
||||
private boolean openInventories = false;
|
||||
private boolean dropItems = false;
|
||||
private List<String> editCommandWhitelist = new ArrayList<>();
|
||||
|
||||
/* Permissions bridge */
|
||||
private List<String> editPermissions = new ArrayList<>();
|
||||
|
||||
/* Default Dungeon Settings */
|
||||
private WorldConfig defaultWorldConfig;
|
||||
|
||||
@ -71,26 +77,58 @@ public class MainConfig extends BRConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the enableEconomy
|
||||
* @param language
|
||||
* the language to set
|
||||
*/
|
||||
public boolean enableEconomy() {
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if DungeonsXL should use economy features provided by Vault
|
||||
*/
|
||||
public boolean isEconomyEnabled() {
|
||||
return enableEconomy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tutorialActivated
|
||||
* @param enabled
|
||||
* if DungeonsXL should use economy features provided by Vault
|
||||
*/
|
||||
public void setEconomyEnabled(boolean enabled) {
|
||||
enableEconomy = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the tutorial is activated
|
||||
*/
|
||||
public boolean isTutorialActivated() {
|
||||
return tutorialActivated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tutorialDungeon
|
||||
* @param activated
|
||||
* if new players start in a tutorial
|
||||
*/
|
||||
public void setTutorialActivated(boolean activated) {
|
||||
tutorialActivated = activated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tutorial dungeon
|
||||
*/
|
||||
public String getTutorialDungeon() {
|
||||
return tutorialDungeon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dungeon
|
||||
* the tutorial dungeon to set
|
||||
*/
|
||||
public void setTutorialDungeon(String dungeon) {
|
||||
tutorialDungeon = dungeon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tutorialStartGroup
|
||||
*/
|
||||
@ -99,17 +137,13 @@ public class MainConfig extends BRConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the floor title shall be sent
|
||||
* <<<<<<< HEAD
|
||||
*
|
||||
* @param group
|
||||
* the group the player gets when he plays the tutorial
|
||||
*/
|
||||
public boolean getSendFloorTitle() {
|
||||
return sendFloorTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the custom external mob providers
|
||||
*/
|
||||
public Map<String, Object> getExternalMobProviders() {
|
||||
return externalMobProviders;
|
||||
public void setTutorialStartGroup(String group) {
|
||||
tutorialStartGroup = group;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -119,6 +153,66 @@ public class MainConfig extends BRConfig {
|
||||
return tutorialEndGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param group
|
||||
* the group the player gets when he finshs the tutorial
|
||||
*/
|
||||
public void setTutorialEndGroup(String group) {
|
||||
tutorialEndGroup = group;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the floor title shall be sent
|
||||
*/
|
||||
public boolean isSendFloorTitleEnabled() {
|
||||
return sendFloorTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param enabled
|
||||
* if the floor title shall be sent
|
||||
*/
|
||||
public void setSendFloorTitleEnabled(boolean enabled) {
|
||||
sendFloorTitle = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the custom external mob providers
|
||||
*/
|
||||
public Map<String, Object> getExternalMobProviders() {
|
||||
return externalMobProviders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the group colors
|
||||
*/
|
||||
public List<Short> getGroupColorPriority() {
|
||||
return groupColorPriority;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataValues
|
||||
* wool data values
|
||||
*/
|
||||
public void setGroupColorPriority(List<Short> dataValues) {
|
||||
groupColorPriority = dataValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maximum amount of worlds to instantiate at once
|
||||
*/
|
||||
public int getMaxInstances() {
|
||||
return maxInstances;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxInstances
|
||||
* the maximum amount of worlds to instantiate at once
|
||||
*/
|
||||
public void setMaxInstances(int maxInstances) {
|
||||
this.maxInstances = maxInstances;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the secure mode is enabled
|
||||
*/
|
||||
@ -126,6 +220,14 @@ public class MainConfig extends BRConfig {
|
||||
return secureModeEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param enabled
|
||||
* if the secure mode is enabled
|
||||
*/
|
||||
public void setSecureModeEnabled(boolean enabled) {
|
||||
secureModeEnabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if players may open inventories while editing; false if secure mode disabled
|
||||
*/
|
||||
@ -133,6 +235,14 @@ public class MainConfig extends BRConfig {
|
||||
return openInventories && secureModeEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param openInventories
|
||||
* if inventories can be opened in edit mode
|
||||
*/
|
||||
public void setOpenInventories(boolean openInventories) {
|
||||
this.openInventories = openInventories;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if players may drop items while editing; false if secure mode disabled
|
||||
*/
|
||||
@ -140,6 +250,14 @@ public class MainConfig extends BRConfig {
|
||||
return dropItems && secureModeEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dropItems
|
||||
* if items may be dropped in edit mode
|
||||
*/
|
||||
public void setDropItems(boolean dropItems) {
|
||||
this.dropItems = dropItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the interval for the check task
|
||||
*/
|
||||
@ -147,6 +265,14 @@ public class MainConfig extends BRConfig {
|
||||
return (long) (secureModeCheckInterval * 20);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param interval
|
||||
* the interval for the check task
|
||||
*/
|
||||
public void setSecureModeCheckInterval(double interval) {
|
||||
secureModeCheckInterval = interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the editCommandWhitelist
|
||||
*/
|
||||
@ -154,6 +280,13 @@ public class MainConfig extends BRConfig {
|
||||
return editCommandWhitelist;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the edit mode permissions
|
||||
*/
|
||||
public List<String> getEditPermissions() {
|
||||
return editPermissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the defaultWorldConfig
|
||||
*/
|
||||
@ -196,6 +329,14 @@ public class MainConfig extends BRConfig {
|
||||
config.createSection("externalMobProviders");
|
||||
}
|
||||
|
||||
if (!config.contains("groupColorPriority")) {
|
||||
config.set("groupColorPriority", groupColorPriority);
|
||||
}
|
||||
|
||||
if (!config.contains("maxInstances")) {
|
||||
config.set("maxInstances", maxInstances);
|
||||
}
|
||||
|
||||
if (!config.contains("secureMode.enabled")) {
|
||||
config.set("secureMode.enabled", secureModeEnabled);
|
||||
}
|
||||
@ -216,6 +357,10 @@ public class MainConfig extends BRConfig {
|
||||
config.set("secureMode.editCommandWhitelist", editCommandWhitelist);
|
||||
}
|
||||
|
||||
if (!config.contains("editPermissions")) {
|
||||
config.set("editPermissions", editPermissions);
|
||||
}
|
||||
|
||||
/* Default Dungeon Config */
|
||||
if (!config.contains("default")) {
|
||||
config.createSection("default");
|
||||
@ -259,6 +404,14 @@ public class MainConfig extends BRConfig {
|
||||
externalMobProviders = config.getConfigurationSection("externalMobProviders").getValues(false);
|
||||
}
|
||||
|
||||
if (config.contains("groupColorPriority")) {
|
||||
groupColorPriority = config.getShortList("groupColorPriority");
|
||||
}
|
||||
|
||||
if (config.contains("maxInstances")) {
|
||||
maxInstances = config.getInt("maxInstances");
|
||||
}
|
||||
|
||||
if (config.contains("secureMode.enabled")) {
|
||||
secureModeEnabled = config.getBoolean("secureMode.enabled");
|
||||
}
|
||||
@ -279,11 +432,14 @@ public class MainConfig extends BRConfig {
|
||||
editCommandWhitelist = config.getStringList("secureMode.editCommandWhitelist");
|
||||
}
|
||||
|
||||
if (config.contains("editPermissions")) {
|
||||
editPermissions = config.getStringList("editPermissions");
|
||||
}
|
||||
|
||||
/* Default Dungeon Config */
|
||||
ConfigurationSection configSection = config.getConfigurationSection("default");
|
||||
if (configSection != null) {
|
||||
defaultWorldConfig = new WorldConfig(configSection);
|
||||
WorldConfig.defaultConfig = defaultWorldConfig;// TODO
|
||||
}
|
||||
}
|
||||
|
||||
|
120
src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java
Normal file
120
src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.config;
|
||||
|
||||
import io.github.dre2n.commons.config.BRConfig;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class PlayerData extends BRConfig {
|
||||
|
||||
DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
|
||||
public static final int CONFIG_VERSION = 1;
|
||||
|
||||
private Map<String, Long> timeLastPlayed = new HashMap<>();
|
||||
|
||||
public PlayerData(File file) {
|
||||
super(file, CONFIG_VERSION);
|
||||
|
||||
if (initialize) {
|
||||
initialize();
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a map of the player's finished dungeons with dates.
|
||||
*/
|
||||
public Map<String, Long> getTimeLastPlayed() {
|
||||
return timeLastPlayed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dungeon
|
||||
* the dungeon to check
|
||||
* @return the time when the player finished the dungeon for the last time
|
||||
*/
|
||||
public long getTimeLastPlayed(String dungeon) {
|
||||
Long time = timeLastPlayed.get(dungeon.toLowerCase());
|
||||
if (time == null) {
|
||||
return -1;
|
||||
} else {
|
||||
return time;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dungeon
|
||||
* the finished dungeon
|
||||
* @param time
|
||||
* the time when the dungeon was finished
|
||||
*/
|
||||
public void setTimeLastPlayed(String dungeon, long time) {
|
||||
timeLastPlayed.put(dungeon.toLowerCase(), time);
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dungeon
|
||||
* the finished dungeon
|
||||
*/
|
||||
public void logTimeLastPlayed(String dungeon) {
|
||||
timeLastPlayed.put(dungeon.toLowerCase(), System.currentTimeMillis());
|
||||
save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
if (!config.contains("timeLastPlayed")) {
|
||||
config.createSection("timeLastPlayed");
|
||||
}
|
||||
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
MessageUtil.log(plugin, DMessages.LOG_NEW_PLAYER_DATA.getMessage(file.getName()));
|
||||
} catch (IOException exception) {
|
||||
}
|
||||
}
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
if (config.isConfigurationSection("timeLastPlayed")) {
|
||||
for (String key : config.getConfigurationSection("timeLastPlayed").getKeys(false)) {
|
||||
timeLastPlayed.put(key, config.getLong("timeLastPlayed." + key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
config.set("timeLastPlayed", timeLastPlayed);
|
||||
super.save();
|
||||
}
|
||||
|
||||
}
|
@ -16,87 +16,43 @@
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.config;
|
||||
|
||||
import io.github.dre2n.commons.compatibility.CompatibilityHandler;
|
||||
import io.github.dre2n.commons.compatibility.Version;
|
||||
import io.github.dre2n.commons.util.EnumUtil;
|
||||
import io.github.dre2n.commons.util.NumberUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.game.GameRules;
|
||||
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.FeeLevelRequirement;
|
||||
import io.github.dre2n.dungeonsxl.requirement.FeeMoneyRequirement;
|
||||
import io.github.dre2n.dungeonsxl.requirement.GroupSizeRequirement;
|
||||
import io.github.dre2n.dungeonsxl.requirement.Requirement;
|
||||
import io.github.dre2n.dungeonsxl.reward.Reward;
|
||||
import io.github.dre2n.dungeonsxl.util.DeserialisazionUtil;
|
||||
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.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;
|
||||
|
||||
/**
|
||||
* @author Frank Baumann, Milan Albrecht, Daniel Saukel
|
||||
*/
|
||||
public class WorldConfig {
|
||||
public class WorldConfig extends GameRules {
|
||||
|
||||
DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
|
||||
@Deprecated
|
||||
public static WorldConfig defaultConfig = new WorldConfig();
|
||||
CompatibilityHandler compat = CompatibilityHandler.getInstance();
|
||||
|
||||
private File file;
|
||||
|
||||
private List<String> invitedPlayers = new ArrayList<>();
|
||||
|
||||
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<>();
|
||||
private Map<Integer, String> msgs = new HashMap<>();
|
||||
|
||||
private List<Material> secureObjects = new ArrayList<>();
|
||||
|
||||
private int initialLives = 3;
|
||||
|
||||
private boolean isLobbyDisabled = false;
|
||||
private int timeToNextPlay = 0;
|
||||
private int timeToNextLoot = 0;
|
||||
private int timeToNextWave = 10;
|
||||
|
||||
private int timeUntilKickOfflinePlayer = -1;
|
||||
private int timeToFinish = -1;
|
||||
|
||||
private List<Requirement> requirements = new ArrayList<>();
|
||||
private List<Reward> rewards = new ArrayList<>();
|
||||
|
||||
private List<String> finishedOne;
|
||||
private List<String> finishedAll;
|
||||
private int timeLastPlayed = 0;
|
||||
|
||||
private GameType forcedGameType;
|
||||
|
||||
private Set<DMobType> mobTypes = new HashSet<>();
|
||||
|
||||
private List<String> gameCommandWhitelist = new ArrayList<>();
|
||||
|
||||
public WorldConfig() {
|
||||
}
|
||||
|
||||
@ -114,59 +70,6 @@ public class WorldConfig {
|
||||
|
||||
// Load & Save
|
||||
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<>();
|
||||
|
||||
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) {
|
||||
@ -180,13 +83,10 @@ public class WorldConfig {
|
||||
/* 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));
|
||||
}
|
||||
if (Version.andHigher(Version.MC1_9).contains(compat.getVersion())) {
|
||||
secureObjects = plugin.getCaliburnAPI().getItems().deserializeStackList(secureObjectList);
|
||||
} else {
|
||||
secureObjects = DeserialisazionUtil.deserializeStackList(secureObjectList);
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,41 +107,27 @@ public class WorldConfig {
|
||||
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 */
|
||||
@ -251,71 +137,55 @@ public class WorldConfig {
|
||||
} 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;
|
||||
lobbyDisabled = configFile.getBoolean("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("timeToNextWave")) {
|
||||
timeToNextWave = configFile.getInt("timeToNextWave");
|
||||
} else {
|
||||
timeToNextWave = plugin.getDefaultConfig().timeToNextWave;
|
||||
}
|
||||
|
||||
if (configFile.contains("timeUntilKickOfflinePlayer")) {
|
||||
timeUntilKickOfflinePlayer = configFile.getInt("timeUntilKickOfflinePlayer");
|
||||
} else {
|
||||
timeUntilKickOfflinePlayer = plugin.getDefaultConfig().timeUntilKickOfflinePlayer;
|
||||
}
|
||||
|
||||
if (configFile.contains("timeToFinish")) {
|
||||
timeToFinish = configFile.getInt("timeToFinish");
|
||||
} else {
|
||||
timeToFinish = plugin.getDefaultConfig().timeToFinish;
|
||||
}
|
||||
|
||||
/* Dungeon Requirements */
|
||||
if (configFile.contains("requirements")) {
|
||||
if (requirements == null) {
|
||||
requirements = new ArrayList<>();
|
||||
}
|
||||
|
||||
for (String identifier : configFile.getConfigurationSection("requirements").getKeys(false)) {
|
||||
Requirement requirement = Requirement.create(plugin.getRequirementTypes().getByIdentifier(identifier));
|
||||
|
||||
@ -325,12 +195,14 @@ public class WorldConfig {
|
||||
|
||||
} else if (requirement instanceof FeeLevelRequirement) {
|
||||
((FeeLevelRequirement) requirement).setFee(configFile.getInt("requirements.feeLevel"));
|
||||
|
||||
} else if (requirement instanceof GroupSizeRequirement) {
|
||||
((GroupSizeRequirement) requirement).setMinimum(configFile.getInt("requirements.groupSize.minimum"));
|
||||
((GroupSizeRequirement) requirement).setMaximum(configFile.getInt("requirements.groupSize.maximum"));
|
||||
}
|
||||
|
||||
requirements.add(requirement);
|
||||
}
|
||||
} else {
|
||||
requirements = plugin.getDefaultConfig().requirements;
|
||||
}
|
||||
|
||||
if (configFile.contains("mustFinishOne")) {
|
||||
@ -349,24 +221,16 @@ public class WorldConfig {
|
||||
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("gamePermissions")) {
|
||||
gamePermissions = configFile.getStringList("gamePermissions");
|
||||
}
|
||||
|
||||
if (configFile.contains("forcedGameType")) {
|
||||
GameType gameType = plugin.getGameTypes().getByName(configFile.getString("forcedGameType"));
|
||||
if (gameType != null) {
|
||||
forcedGameType = gameType;
|
||||
|
||||
} else {
|
||||
forcedGameType = null;
|
||||
}
|
||||
forcedGameType = plugin.getGameTypes().getByName(configFile.getString("forcedGameType"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -381,14 +245,13 @@ public class WorldConfig {
|
||||
configFile.set("message." + msgs, this.msgs.get(msgs));
|
||||
}
|
||||
|
||||
// Secure Objects
|
||||
CopyOnWriteArrayList<Integer> secureObjectsids = new CopyOnWriteArrayList<>();
|
||||
List<String> secureObjectIds = new ArrayList<>();
|
||||
|
||||
for (Material mat : secureObjects) {
|
||||
secureObjectsids.add(mat.getId());
|
||||
for (ItemStack item : secureObjects) {
|
||||
secureObjectIds.add(plugin.getCaliburnAPI().getItems().getCustomItemId(item));
|
||||
}
|
||||
|
||||
configFile.set("secureObjects", secureObjectsids);
|
||||
configFile.set("secureObjects", secureObjectIds);
|
||||
|
||||
// Invited Players
|
||||
configFile.set("invitedPlayers", invitedPlayers);
|
||||
@ -401,14 +264,12 @@ public class WorldConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// 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<>();
|
||||
tmpInvitedPlayers.addAll(invitedPlayers);
|
||||
tmpInvitedPlayers.addAll(plugin.getDefaultConfig().invitedPlayers);
|
||||
return tmpInvitedPlayers;
|
||||
}
|
||||
|
||||
@ -432,241 +293,6 @@ public class WorldConfig {
|
||||
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<>();
|
||||
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 break between two waves
|
||||
*/
|
||||
public int getTimeToNextWave() {
|
||||
return timeToNextWave;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the time until a player gets kicked from his group if he is offline
|
||||
*/
|
||||
public int getTimeUntilKickOfflinePlayer() {
|
||||
return timeUntilKickOfflinePlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the game is "time is running"
|
||||
*/
|
||||
public boolean isTimeIsRunning() {
|
||||
return timeToFinish != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the time until a player gets kicked from his group
|
||||
*/
|
||||
public int getTimeToFinish() {
|
||||
return timeToFinish;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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<>();
|
||||
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
|
||||
*/
|
||||
|
@ -35,7 +35,11 @@ public class Dungeon {
|
||||
|
||||
public Dungeon(String name) {
|
||||
this.name = name;
|
||||
this.config = new DungeonConfig(new File(DungeonsXL.getInstance().getDataFolder() + "/dungeons", name + ".yml"));
|
||||
|
||||
File file = new File(DungeonsXL.getInstance().getDataFolder() + "/dungeons", name + ".yml");
|
||||
if (file.exists()) {
|
||||
this.config = new DungeonConfig(file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,4 +56,11 @@ public class Dungeon {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if this dungeon has multiple floors
|
||||
*/
|
||||
public boolean isMultiFloor() {
|
||||
return config != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ public class DGroupCreateEvent extends DGroupEvent implements Cancellable {
|
||||
|
||||
public enum Cause {
|
||||
|
||||
ANNOUNCER,
|
||||
COMMAND,
|
||||
GROUP_SIGN,
|
||||
CUSTOM
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.event.dplayer;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DInstancePlayer;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@ -35,7 +35,7 @@ public class DPlayerUpdateEvent extends DPlayerEvent implements Cancellable {
|
||||
private boolean kick;
|
||||
private boolean triggerAllInDistance;
|
||||
|
||||
public DPlayerUpdateEvent(DGamePlayer dPlayer, boolean locationValid, boolean teleportWolf, boolean respawnInventory, boolean offline, boolean kick, boolean triggerAllInDistance) {
|
||||
public DPlayerUpdateEvent(DInstancePlayer dPlayer, boolean locationValid, boolean teleportWolf, boolean respawnInventory, boolean offline, boolean kick, boolean triggerAllInDistance) {
|
||||
super(dPlayer);
|
||||
this.locationValid = locationValid;
|
||||
this.teleportWolf = teleportWolf;
|
||||
|
@ -19,6 +19,8 @@ package io.github.dre2n.dungeonsxl.game;
|
||||
import io.github.dre2n.commons.util.playerutil.PlayerUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.config.DungeonConfig;
|
||||
import io.github.dre2n.dungeonsxl.config.WorldConfig;
|
||||
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
|
||||
import io.github.dre2n.dungeonsxl.global.GameSign;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
@ -33,6 +35,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@ -47,6 +50,7 @@ public class Game {
|
||||
private boolean started;
|
||||
private GameType type;
|
||||
private GameWorld world;
|
||||
private GameRules rules;
|
||||
private int waveCount;
|
||||
private Map<String, Integer> gameKills = new HashMap<>();
|
||||
private Map<String, Integer> waveKills = new HashMap<>();
|
||||
@ -54,10 +58,31 @@ public class Game {
|
||||
public Game(DGroup dGroup) {
|
||||
dGroups.add(dGroup);
|
||||
started = false;
|
||||
fetchRules();
|
||||
|
||||
plugin.getGames().add(this);
|
||||
}
|
||||
|
||||
public Game(DGroup dGroup, GameWorld world) {
|
||||
dGroups.add(dGroup);
|
||||
started = false;
|
||||
this.world = world;
|
||||
fetchRules();
|
||||
|
||||
plugin.getGames().add(this);
|
||||
}
|
||||
|
||||
public Game(DGroup dGroup, String worldName) {
|
||||
plugin.getGames().add(this);
|
||||
|
||||
dGroups.add(dGroup);
|
||||
started = false;
|
||||
world = new GameWorld();
|
||||
dGroup.setGameWorld(world);
|
||||
world.load(worldName);
|
||||
fetchRules();
|
||||
}
|
||||
|
||||
public Game(DGroup dGroup, GameType type, GameWorld world) {
|
||||
this(new ArrayList<>(Arrays.asList(dGroup)), type, world);
|
||||
}
|
||||
@ -67,6 +92,7 @@ public class Game {
|
||||
this.type = type;
|
||||
this.world = world;
|
||||
this.started = true;
|
||||
fetchRules();
|
||||
|
||||
plugin.getGames().add(this);
|
||||
}
|
||||
@ -136,13 +162,73 @@ public class Game {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param gameWorld
|
||||
* @param world
|
||||
* the GameWorld to connect to the Game
|
||||
*/
|
||||
public void setWorld(GameWorld world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the GameRules
|
||||
*/
|
||||
public GameRules getRules() {
|
||||
return rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rules
|
||||
* the GameRules to set
|
||||
*/
|
||||
public void setRules(GameRules rules) {
|
||||
this.rules = rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetchs the rules with the following priority:
|
||||
* 1. Game type
|
||||
* 2. Dungeon config: Override values
|
||||
* 3. Floor config
|
||||
* 4. Dungeon config: Default values
|
||||
* 5. Main config: Default values
|
||||
* 6. The default values
|
||||
*/
|
||||
public void fetchRules() {
|
||||
DungeonConfig dungeonConfig = null;
|
||||
if (getDungeon() != null) {
|
||||
dungeonConfig = getDungeon().getConfig();
|
||||
}
|
||||
|
||||
WorldConfig floorConfig = null;
|
||||
if (world != null) {
|
||||
floorConfig = world.getConfig();
|
||||
}
|
||||
|
||||
GameRules finalRules = new GameRules();
|
||||
|
||||
if (type != null) {
|
||||
finalRules.apply(type);
|
||||
}
|
||||
|
||||
if (dungeonConfig != null && dungeonConfig.getOverrideValues() != null) {
|
||||
finalRules.apply(dungeonConfig.getOverrideValues());
|
||||
}
|
||||
|
||||
if (floorConfig != null) {
|
||||
finalRules.apply(floorConfig);
|
||||
}
|
||||
|
||||
if (dungeonConfig != null && dungeonConfig.getDefaultValues() != null) {
|
||||
finalRules.apply(dungeonConfig.getDefaultValues());
|
||||
}
|
||||
|
||||
finalRules.apply(plugin.getMainConfig().getDefaultWorldConfig());
|
||||
|
||||
finalRules.apply(GameRules.DEFAULT_VALUES);
|
||||
|
||||
rules = finalRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refers to the DGroup with the best progress.
|
||||
*
|
||||
@ -287,7 +373,7 @@ public class Game {
|
||||
}
|
||||
}
|
||||
|
||||
int delay = world.getConfig().getTimeToNextWave();
|
||||
int delay = rules.getTimeToNextWave();
|
||||
sendMessage(plugin.getMessageConfig().getMessage(DMessages.GROUP_WAVE_FINISHED, String.valueOf(waveCount), String.valueOf(delay)));
|
||||
|
||||
new BukkitRunnable() {
|
||||
@ -349,4 +435,13 @@ public class Game {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Game getByWorld(World world) {
|
||||
GameWorld gameWorld = GameWorld.getByWorld(world);
|
||||
if (gameWorld != null) {
|
||||
return getByGameWorld(gameWorld);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
458
src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java
Normal file
458
src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java
Normal file
@ -0,0 +1,458 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.game;
|
||||
|
||||
import io.github.dre2n.caliburn.item.UniversalItem;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.requirement.Requirement;
|
||||
import io.github.dre2n.dungeonsxl.reward.Reward;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class GameRules {
|
||||
|
||||
public static final GameRules DEFAULT_VALUES = new GameRules();
|
||||
|
||||
static {
|
||||
/* keepInventory */
|
||||
DEFAULT_VALUES.keepInventoryOnEnter = false;
|
||||
DEFAULT_VALUES.keepInventoryOnEscape = false;
|
||||
DEFAULT_VALUES.keepInventoryOnFinish = false;
|
||||
DEFAULT_VALUES.keepInventoryOnDeath = true;
|
||||
DEFAULT_VALUES.lobbyDisabled = false;
|
||||
|
||||
/* World interaction */
|
||||
DEFAULT_VALUES.gameMode = GameMode.SURVIVAL;
|
||||
DEFAULT_VALUES.build = false;
|
||||
|
||||
/* Fighting */
|
||||
DEFAULT_VALUES.playerVersusPlayer = false;
|
||||
DEFAULT_VALUES.friendlyFire = false;
|
||||
DEFAULT_VALUES.initialLives = 3;
|
||||
|
||||
/* Timer */
|
||||
DEFAULT_VALUES.timeLastPlayed = 0;
|
||||
DEFAULT_VALUES.timeToNextPlay = 0;
|
||||
DEFAULT_VALUES.timeToNextLoot = 0;
|
||||
DEFAULT_VALUES.timeToNextWave = 10;
|
||||
DEFAULT_VALUES.timeToFinish = -1;
|
||||
DEFAULT_VALUES.timeUntilKickOfflinePlayer = -1;
|
||||
|
||||
/* Requirements and rewards */
|
||||
DEFAULT_VALUES.requirements = new ArrayList<>();
|
||||
DEFAULT_VALUES.finishedOne = null;
|
||||
DEFAULT_VALUES.finishedAll = null;
|
||||
DEFAULT_VALUES.rewards = new ArrayList<>();
|
||||
|
||||
/* Commands and permissions */
|
||||
DEFAULT_VALUES.gameCommandWhitelist = new ArrayList<>();
|
||||
DEFAULT_VALUES.gamePermissions = new ArrayList<>();
|
||||
|
||||
/* Misc */
|
||||
DEFAULT_VALUES.msgs = new HashMap<>();
|
||||
DEFAULT_VALUES.secureObjects = new ArrayList<>();
|
||||
}
|
||||
|
||||
/* keepInventory */
|
||||
protected Boolean keepInventoryOnEnter;
|
||||
protected Boolean keepInventoryOnEscape;
|
||||
protected Boolean keepInventoryOnFinish;
|
||||
protected Boolean keepInventoryOnDeath;
|
||||
protected Boolean lobbyDisabled;
|
||||
|
||||
/* World interaction */
|
||||
protected GameMode gameMode;
|
||||
protected Boolean build;
|
||||
|
||||
/* Fighting */
|
||||
protected Boolean playerVersusPlayer;
|
||||
protected Boolean friendlyFire;
|
||||
protected Integer initialLives;
|
||||
|
||||
/* Timer */
|
||||
protected Integer timeLastPlayed;
|
||||
protected Integer timeToNextPlay;
|
||||
protected Integer timeToNextLoot;
|
||||
protected Integer timeToNextWave;
|
||||
protected Integer timeToFinish;
|
||||
protected Integer timeUntilKickOfflinePlayer;
|
||||
|
||||
/* Requirements and rewards */
|
||||
protected List<Requirement> requirements;
|
||||
protected List<String> finishedOne;
|
||||
protected List<String> finishedAll;
|
||||
protected List<Reward> rewards;
|
||||
|
||||
/* Commands and permissions */
|
||||
protected List<String> gameCommandWhitelist;
|
||||
protected List<String> gamePermissions;
|
||||
|
||||
/* Misc */
|
||||
protected Map<Integer, String> msgs;
|
||||
protected List<ItemStack> secureObjects;
|
||||
|
||||
/* Getters and setters */
|
||||
// keepInventory
|
||||
/**
|
||||
* @return if the inventory shall be kept when the player enters the dungeon
|
||||
*/
|
||||
public boolean getKeepInventoryOnEnter() {
|
||||
return keepInventoryOnEnter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the inventory shall be kept when the player leaves the dungeon successlessly
|
||||
*/
|
||||
public boolean getKeepInventoryOnEscape() {
|
||||
return keepInventoryOnEscape;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the inventory shall be kept when the player finishs the dungeon
|
||||
*/
|
||||
public boolean getKeepInventoryOnFinish() {
|
||||
return keepInventoryOnFinish;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the inventory shall be kept on death
|
||||
*/
|
||||
public boolean getKeepInventoryOnDeath() {
|
||||
return keepInventoryOnDeath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the lobby is disabled
|
||||
*/
|
||||
public boolean isLobbyDisabled() {
|
||||
return lobbyDisabled;
|
||||
}
|
||||
|
||||
// World interaction
|
||||
/**
|
||||
* @return the gameMode
|
||||
*/
|
||||
public GameMode getGameMode() {
|
||||
return gameMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if players may build
|
||||
*/
|
||||
public boolean canBuild() {
|
||||
return build;
|
||||
}
|
||||
|
||||
// Fight
|
||||
/**
|
||||
* @return if players may attack each other
|
||||
*/
|
||||
public boolean isPlayerVersusPlayer() {
|
||||
return playerVersusPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if players may attack group members
|
||||
*/
|
||||
public boolean isFriendlyFire() {
|
||||
return friendlyFire;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the initial amount of lives
|
||||
*/
|
||||
public int getInitialLives() {
|
||||
return initialLives;
|
||||
}
|
||||
|
||||
// Timer
|
||||
/**
|
||||
* @return the timeLastPlayed
|
||||
*/
|
||||
public int getTimeLastPlayed() {
|
||||
return timeLastPlayed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 break between two waves
|
||||
*/
|
||||
public int getTimeToNextWave() {
|
||||
return timeToNextWave;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the time until a player gets kicked from his group
|
||||
*/
|
||||
public int getTimeToFinish() {
|
||||
return timeToFinish;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the time until a player gets kicked from his group if he is offline
|
||||
*/
|
||||
public int getTimeUntilKickOfflinePlayer() {
|
||||
return timeUntilKickOfflinePlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the game is "time is running"
|
||||
*/
|
||||
public boolean isTimeIsRunning() {
|
||||
return timeToFinish != -1;
|
||||
}
|
||||
|
||||
// Requirements and rewards
|
||||
/**
|
||||
* @return the requirements
|
||||
*/
|
||||
public List<Requirement> getRequirements() {
|
||||
return requirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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<>();
|
||||
merge.addAll(finishedAll);
|
||||
merge.addAll(finishedOne);
|
||||
return merge;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the rewards
|
||||
*/
|
||||
public List<Reward> getRewards() {
|
||||
return rewards;
|
||||
}
|
||||
|
||||
// Commands and permissions
|
||||
/**
|
||||
* @return the gameCommandWhitelist
|
||||
*/
|
||||
public List<String> getGameCommandWhitelist() {
|
||||
return gameCommandWhitelist;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the gamePermissions
|
||||
*/
|
||||
public List<String> getGamePermissions() {
|
||||
return gamePermissions;
|
||||
}
|
||||
|
||||
// Misc
|
||||
/**
|
||||
* @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 DungeonsXL.getInstance().getMainConfig().getDefaultWorldConfig().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 List<ItemStack> getSecureObjects() {
|
||||
return secureObjects;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
/**
|
||||
* @param defaultValues
|
||||
* the GameType that overrides the values that are null.
|
||||
*/
|
||||
public void apply(GameType defaultValues) {
|
||||
if (playerVersusPlayer == null) {
|
||||
playerVersusPlayer = defaultValues.isPlayerVersusPlayer();
|
||||
}
|
||||
|
||||
if (friendlyFire == null) {
|
||||
friendlyFire = defaultValues.isFriendlyFire();
|
||||
}
|
||||
|
||||
if (timeToFinish == null) {
|
||||
timeToFinish = defaultValues.getShowTime() ? null : -1;
|
||||
}
|
||||
|
||||
if (build == null) {
|
||||
build = defaultValues.canBuild();
|
||||
}
|
||||
|
||||
if (gameMode == null) {
|
||||
gameMode = defaultValues.getGameMode();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param defaultValues
|
||||
* the GameRules that override the values that are null.
|
||||
*/
|
||||
public void apply(GameRules defaultValues) {
|
||||
/* keepInventory */
|
||||
if (keepInventoryOnEnter == null) {
|
||||
keepInventoryOnEnter = defaultValues.keepInventoryOnEnter;
|
||||
}
|
||||
|
||||
if (keepInventoryOnEscape == null) {
|
||||
keepInventoryOnEscape = defaultValues.keepInventoryOnEscape;
|
||||
}
|
||||
|
||||
if (keepInventoryOnFinish == null) {
|
||||
keepInventoryOnFinish = defaultValues.keepInventoryOnFinish;
|
||||
}
|
||||
|
||||
if (keepInventoryOnDeath == null) {
|
||||
keepInventoryOnDeath = defaultValues.keepInventoryOnDeath;
|
||||
}
|
||||
|
||||
if (lobbyDisabled == null) {
|
||||
lobbyDisabled = defaultValues.lobbyDisabled;
|
||||
}
|
||||
|
||||
/* World interaction */
|
||||
if (gameMode == null) {
|
||||
gameMode = defaultValues.gameMode;
|
||||
}
|
||||
|
||||
if (build == null) {
|
||||
build = defaultValues.build;
|
||||
}
|
||||
|
||||
/* Fighting */
|
||||
if (playerVersusPlayer == null) {
|
||||
playerVersusPlayer = defaultValues.playerVersusPlayer;
|
||||
}
|
||||
|
||||
if (friendlyFire == null) {
|
||||
friendlyFire = defaultValues.friendlyFire;
|
||||
}
|
||||
|
||||
if (initialLives == null) {
|
||||
initialLives = defaultValues.initialLives;
|
||||
}
|
||||
|
||||
/* Timer */
|
||||
if (timeLastPlayed == null) {
|
||||
timeLastPlayed = defaultValues.timeLastPlayed;
|
||||
}
|
||||
|
||||
if (timeToNextPlay == null) {
|
||||
timeToNextPlay = defaultValues.timeToNextPlay;
|
||||
}
|
||||
|
||||
if (timeToNextLoot == null) {
|
||||
timeToNextLoot = defaultValues.timeToNextLoot;
|
||||
}
|
||||
|
||||
if (timeToNextWave == null) {
|
||||
timeToNextWave = defaultValues.timeToNextWave;
|
||||
}
|
||||
|
||||
if (timeToFinish == null) {
|
||||
timeToFinish = defaultValues.timeToFinish;
|
||||
}
|
||||
|
||||
if (timeUntilKickOfflinePlayer == null) {
|
||||
timeUntilKickOfflinePlayer = defaultValues.timeUntilKickOfflinePlayer;
|
||||
}
|
||||
|
||||
/* Requirements and rewards */
|
||||
if (requirements == null) {
|
||||
requirements = defaultValues.requirements;
|
||||
}
|
||||
|
||||
if (finishedOne == null) {
|
||||
finishedOne = defaultValues.finishedOne;
|
||||
}
|
||||
|
||||
if (finishedAll == null) {
|
||||
finishedAll = defaultValues.finishedAll;
|
||||
}
|
||||
|
||||
if (rewards == null) {
|
||||
rewards = defaultValues.rewards;
|
||||
}
|
||||
|
||||
/* Commands and permissions */
|
||||
if (gameCommandWhitelist == null) {
|
||||
gameCommandWhitelist = defaultValues.gameCommandWhitelist;
|
||||
} else if (defaultValues.gameCommandWhitelist != null) {
|
||||
gameCommandWhitelist.addAll(defaultValues.gameCommandWhitelist);
|
||||
}
|
||||
|
||||
if (gamePermissions == null) {
|
||||
gamePermissions = defaultValues.gamePermissions;
|
||||
} else if (defaultValues.gamePermissions != null) {
|
||||
gamePermissions.addAll(defaultValues.gamePermissions);
|
||||
}
|
||||
|
||||
/* Misc */
|
||||
msgs = defaultValues.msgs;
|
||||
secureObjects = defaultValues.secureObjects;
|
||||
}
|
||||
|
||||
}
|
@ -17,9 +17,9 @@
|
||||
package io.github.dre2n.dungeonsxl.game;
|
||||
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSign;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
@ -60,7 +60,7 @@ public class GameTypes {
|
||||
/**
|
||||
* @return the game type which has the enum value sign text in the second line of the sign
|
||||
*/
|
||||
public GameType getBySign(Sign sign) {
|
||||
public GameType getBySign(DSign sign) {
|
||||
String[] lines = sign.getLines();
|
||||
|
||||
for (GameType type : types) {
|
||||
|
@ -186,20 +186,21 @@ public class DPortal extends GlobalProtection {
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
target = GameWorld.load(dGroup.getMapName());
|
||||
target = new GameWorld(dGroup.getMapName());
|
||||
dGroup.setGameWorld(target);
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.ERROR_DUNGEON_NOT_EXIST, DGroup.getByPlayer(player).getMapName()));
|
||||
MessageUtil.sendMessage(player, DMessages.ERROR_DUNGEON_NOT_EXIST.getMessage(DGroup.getByPlayer(player).getMapName()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (game != null) {
|
||||
if (game == null) {
|
||||
game = new Game(dGroup, target);
|
||||
} else {
|
||||
game.setWorld(target);
|
||||
}
|
||||
|
||||
dGroup.setGameWorld(target);
|
||||
}
|
||||
|
||||
new DGamePlayer(player, target);
|
||||
}
|
||||
|
@ -19,12 +19,9 @@ package io.github.dre2n.dungeonsxl.global;
|
||||
import io.github.dre2n.commons.util.BlockUtil;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.config.WorldConfig;
|
||||
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
|
||||
import io.github.dre2n.dungeonsxl.game.Game;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
@ -472,6 +469,11 @@ public class GameSign extends GlobalProtection {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (plugin.getGameWorlds().size() >= plugin.getMainConfig().getMaxInstances()) {
|
||||
MessageUtil.sendMessage(player, DMessages.ERROR_TOO_MANY_INSTANCES.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
|
||||
if (dGroup == null) {
|
||||
@ -489,23 +491,6 @@ public class GameSign extends GlobalProtection {
|
||||
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(DMessages.ERROR_COOLDOWN, String.valueOf(confReader.getTimeToNextPlay())));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!GameWorld.checkRequirements(gameSign.mapName, dGroup)) {
|
||||
dGroup.sendMessage(plugin.getMessageConfig().getMessage(DMessages.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);
|
||||
|
@ -19,7 +19,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
public abstract class GlobalProtection {
|
||||
|
||||
static DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
static FileConfiguration config = plugin.getDataConfig().getConfig();
|
||||
static FileConfiguration config = plugin.getGlobalData().getConfig();
|
||||
static GlobalProtections protections = plugin.getGlobalProtections();
|
||||
|
||||
private World world;
|
||||
|
@ -86,7 +86,7 @@ public class GlobalProtections {
|
||||
* Save all protections to the default file
|
||||
*/
|
||||
public void saveAll() {
|
||||
saveAll(plugin.getDataConfig().getConfig());
|
||||
saveAll(plugin.getGlobalData().getConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,7 +107,7 @@ public class GlobalProtections {
|
||||
protection.save(config);
|
||||
}
|
||||
|
||||
plugin.getDataConfig().save();
|
||||
plugin.getGlobalData().save();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,7 +144,7 @@ public class GlobalProtections {
|
||||
/* SUBJECT TO CHANGE */
|
||||
@Deprecated
|
||||
public void loadAll() {
|
||||
FileConfiguration data = plugin.getDataConfig().getConfig();
|
||||
FileConfiguration data = plugin.getGlobalData().getConfig();
|
||||
|
||||
for (World world : plugin.getServer().getWorlds()) {
|
||||
// GameSigns
|
||||
|
@ -19,11 +19,8 @@ package io.github.dre2n.dungeonsxl.global;
|
||||
import io.github.dre2n.commons.util.BlockUtil;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.config.WorldConfig;
|
||||
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
@ -458,23 +455,6 @@ public class GroupSign extends GlobalProtection {
|
||||
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(DMessages.ERROR_COOLDOWN, String.valueOf(confReader.getTimeToNextPlay())));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!GameWorld.checkRequirements(groupSign.mapName, player)) {
|
||||
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.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);
|
||||
|
@ -20,6 +20,7 @@ import io.github.dre2n.commons.util.NumberUtil;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.game.Game;
|
||||
import io.github.dre2n.dungeonsxl.game.GamePlaceableBlock;
|
||||
import io.github.dre2n.dungeonsxl.game.GameType;
|
||||
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
|
||||
@ -107,10 +108,11 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (gameWorld.getGame() != null) {
|
||||
GameType gameType = gameWorld.getGame().getType();
|
||||
if (gameType == GameTypeDefault.DEFAULT && gameWorld.getConfig() != null) {
|
||||
event.setCancelled(!gameWorld.getConfig().canBuild());
|
||||
Game game = gameWorld.getGame();
|
||||
if (game != null) {
|
||||
GameType gameType = game.getType();
|
||||
if (gameType == GameTypeDefault.DEFAULT) {
|
||||
event.setCancelled(!game.getRules().canBuild());
|
||||
|
||||
} else if (!gameType.canBuild()) {
|
||||
event.setCancelled(true);
|
||||
@ -132,9 +134,12 @@ public class BlockListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (gameWorld.getConfig().canBuild() || GamePlaceableBlock.canBuildHere(block, block.getFace(event.getBlockAgainst()), event.getItemInHand().getType(), gameWorld)) {
|
||||
Game game = gameWorld.getGame();
|
||||
if (game != null) {
|
||||
if (game.getRules().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();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -17,10 +17,7 @@
|
||||
package io.github.dre2n.dungeonsxl.listener;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.WorldConfig;
|
||||
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.mob.DMob;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
@ -91,7 +88,6 @@ public class EntityListener implements Listener {
|
||||
if (gameWorld.isPlaying()) {
|
||||
DMob dMob = DMob.getByEntity(entity);
|
||||
if (dMob != null) {
|
||||
event.getDrops().clear();
|
||||
dMob.onDeath(event);
|
||||
}
|
||||
}
|
||||
@ -158,16 +154,8 @@ public class EntityListener implements Listener {
|
||||
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();
|
||||
}
|
||||
boolean pvp = game.getRules().isPlayerVersusPlayer();
|
||||
boolean friendlyFire = game.getRules().isFriendlyFire();
|
||||
|
||||
Entity attackerEntity = event.getDamager();
|
||||
Entity attackedEntity = event.getEntity();
|
||||
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.listener;
|
||||
|
||||
import io.github.dre2n.commons.util.guiutil.ButtonClickEvent;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.announcer.Announcer;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class GUIListener implements Listener {
|
||||
|
||||
DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
|
||||
@EventHandler
|
||||
public void onButtonClick(ButtonClickEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
Inventory gui = event.getGUI();
|
||||
if (!plugin.getGUIs().contains(gui)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack button = gui.getItem(event.getSlot());
|
||||
Announcer announcer = plugin.getAnnouncers().getByGUI(gui);
|
||||
|
||||
if (announcer != null) {
|
||||
announcer.clickGroupButton(player, button);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -19,18 +19,21 @@ package io.github.dre2n.dungeonsxl.listener;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.config.WorldConfig;
|
||||
import io.github.dre2n.dungeonsxl.config.MainConfig;
|
||||
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.Game;
|
||||
import io.github.dre2n.dungeonsxl.global.DPortal;
|
||||
import io.github.dre2n.dungeonsxl.global.GameSign;
|
||||
import io.github.dre2n.dungeonsxl.global.GlobalProtection;
|
||||
import io.github.dre2n.dungeonsxl.global.GroupSign;
|
||||
import io.github.dre2n.dungeonsxl.global.LeaveSign;
|
||||
import io.github.dre2n.dungeonsxl.player.DEditPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGlobalPlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.player.DInstancePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||
import io.github.dre2n.dungeonsxl.player.DPlayers;
|
||||
import io.github.dre2n.dungeonsxl.player.DSavePlayer;
|
||||
@ -63,6 +66,7 @@ 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.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPortalEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
@ -82,15 +86,18 @@ public class PlayerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getEntity();
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
|
||||
GameWorld gameWorld = GameWorld.getByWorld(player.getLocation().getWorld());
|
||||
if (gameWorld == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
WorldConfig dConfig = gameWorld.getConfig();
|
||||
Game game = Game.getByGameWorld(gameWorld);
|
||||
if (game == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
if (dPlayer == null) {
|
||||
return;
|
||||
}
|
||||
@ -115,8 +122,7 @@ public class PlayerListener implements Listener {
|
||||
if (dPlayer.getLives() != -1) {
|
||||
MessageUtil.sendMessage(player, DMessages.PLAYER_DEATH.getMessage(String.valueOf(dPlayer.getLives())));
|
||||
|
||||
if (dConfig != null) {
|
||||
if (dConfig.getKeepInventoryOnDeath()) {
|
||||
if (game.getRules().getKeepInventoryOnDeath()) {
|
||||
dPlayer.setRespawnInventory(event.getEntity().getInventory().getContents());
|
||||
dPlayer.setRespawnArmor(event.getEntity().getInventory().getArmorContents());
|
||||
// Delete all drops
|
||||
@ -125,7 +131,6 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dPlayer.getLives() == 0 && dPlayer.isReady()) {
|
||||
DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(dPlayer, DPlayerKickEvent.Cause.DEATH);
|
||||
@ -134,7 +139,7 @@ public class PlayerListener implements Listener {
|
||||
if (!dPlayerKickEvent.isCancelled()) {
|
||||
MessageUtil.broadcastMessage(DMessages.PLAYER_DEATH_KICK.getMessage(player.getName()));
|
||||
dPlayer.leave();
|
||||
if (gameWorld.getConfig().getKeepInventoryOnEscape()) {
|
||||
if (game.getRules().getKeepInventoryOnEscape()) {
|
||||
dPlayer.applyRespawnInventory();
|
||||
}
|
||||
}
|
||||
@ -216,7 +221,7 @@ public class PlayerListener implements Listener {
|
||||
if (EditWorld.getByWorld(player.getWorld()) != null) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
if (item.getType() == Material.STICK) {
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
DEditPlayer dPlayer = DEditPlayer.getByPlayer(player);
|
||||
if (dPlayer != null) {
|
||||
dPlayer.poke(clickedBlock);
|
||||
event.setCancelled(true);
|
||||
@ -315,15 +320,21 @@ public class PlayerListener implements Listener {
|
||||
public void onDropItem(PlayerDropItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
DGlobalPlayer dPlayer = dPlayers.getByPlayer(player);
|
||||
if (dPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (dPlayer.isEditing() && !plugin.getMainConfig().getDropItems() && !DPermissions.hasPermission(player, DPermissions.INSECURE)) {
|
||||
if (dPlayer instanceof DEditPlayer && !plugin.getMainConfig().getDropItems() && !DPermissions.hasPermission(player, DPermissions.INSECURE)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (!(dPlayer instanceof DGamePlayer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
DGamePlayer gamePlayer = (DGamePlayer) dPlayer;
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
if (dGroup == null) {
|
||||
return;
|
||||
@ -334,15 +345,15 @@ public class PlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dPlayer.isReady()) {
|
||||
if (!gamePlayer.isReady()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
GameWorld gameWorld = GameWorld.getByWorld(dPlayer.getWorld());
|
||||
Game game = Game.getByWorld(gamePlayer.getWorld());
|
||||
|
||||
for (Material material : gameWorld.getConfig().getSecureObjects()) {
|
||||
if (material == event.getItemDrop().getItemStack().getType()) {
|
||||
for (ItemStack item : game.getRules().getSecureObjects()) {
|
||||
if (event.getItemDrop().getItemStack().isSimilar(item)) {
|
||||
event.setCancelled(true);
|
||||
MessageUtil.sendMessage(player, DMessages.ERROR_DROP.getMessage());
|
||||
return;
|
||||
@ -355,13 +366,13 @@ public class PlayerListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
plugin.getDPlayers().getByPlayer(player).applyRespawnInventory();
|
||||
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
DGlobalPlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
if (dPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (dPlayer.isEditing()) {
|
||||
EditWorld editWorld = EditWorld.getByWorld(dPlayer.getWorld());
|
||||
if (dPlayer instanceof DEditPlayer) {
|
||||
EditWorld editWorld = EditWorld.getByWorld(((DEditPlayer) dPlayer).getWorld());
|
||||
if (editWorld == null) {
|
||||
return;
|
||||
}
|
||||
@ -373,8 +384,10 @@ public class PlayerListener implements Listener {
|
||||
event.setRespawnLocation(editWorld.getLobbyLocation());
|
||||
}
|
||||
|
||||
} else {
|
||||
GameWorld gameWorld = GameWorld.getByWorld(dPlayer.getWorld());
|
||||
} else if (dPlayer instanceof DGamePlayer) {
|
||||
DGamePlayer gamePlayer = (DGamePlayer) dPlayer;
|
||||
|
||||
GameWorld gameWorld = GameWorld.getByWorld(gamePlayer.getWorld());
|
||||
|
||||
if (gameWorld == null) {
|
||||
return;
|
||||
@ -382,7 +395,7 @@ public class PlayerListener implements Listener {
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer());
|
||||
|
||||
Location respawn = dPlayer.getCheckpoint();
|
||||
Location respawn = gamePlayer.getCheckpoint();
|
||||
|
||||
if (respawn == null) {
|
||||
respawn = dGroup.getGameWorld().getStartLocation();
|
||||
@ -400,8 +413,8 @@ public class PlayerListener implements Listener {
|
||||
new RespawnTask(player, respawn).runTaskLater(plugin, 10);
|
||||
|
||||
// Don't forget Doge!
|
||||
if (dPlayer.getWolf() != null) {
|
||||
dPlayer.getWolf().teleport(respawn);
|
||||
if (gamePlayer.getWolf() != null) {
|
||||
gamePlayer.getWolf().teleport(respawn);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -448,7 +461,10 @@ public class PlayerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(player);
|
||||
if (!(dPlayers.getByPlayer(player) instanceof DInstancePlayer)) {
|
||||
return;
|
||||
}
|
||||
DInstancePlayer dPlayer = (DInstancePlayer) dPlayers.getByPlayer(player);
|
||||
|
||||
if (dPlayer == null) {
|
||||
dPlayers.removePlayer(dPlayer);
|
||||
@ -458,22 +474,22 @@ public class PlayerListener implements Listener {
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
|
||||
// Check GameWorld
|
||||
GameWorld gameWorld = GameWorld.getByWorld(player.getWorld());
|
||||
if (gameWorld != null) {
|
||||
int timeUntilKickOfflinePlayer = gameWorld.getConfig().getTimeUntilKickOfflinePlayer();
|
||||
Game game = Game.getByWorld(player.getWorld());
|
||||
if (game != null) {
|
||||
int timeUntilKickOfflinePlayer = game.getRules().getTimeUntilKickOfflinePlayer();
|
||||
|
||||
if (timeUntilKickOfflinePlayer == 0) {
|
||||
dPlayer.leave();
|
||||
|
||||
} else if (timeUntilKickOfflinePlayer > 0) {
|
||||
dGroup.sendMessage(DMessages.PLAYER_OFFLINE.getMessage(dPlayer.getPlayer().getName(), String.valueOf(timeUntilKickOfflinePlayer)), player);
|
||||
dPlayer.setOfflineTime(System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000);
|
||||
((DGamePlayer) dPlayer).setOfflineTime(System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000);
|
||||
|
||||
} else {
|
||||
dGroup.sendMessage(DMessages.PLAYER_OFFLINE_NEVER.getMessage(dPlayer.getPlayer().getName()), player);
|
||||
}
|
||||
|
||||
} else if (dPlayer.isEditing()) {
|
||||
} else if (dPlayer instanceof DEditPlayer) {
|
||||
dPlayer.leave();
|
||||
}
|
||||
}
|
||||
@ -546,7 +562,7 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
if (dGroup.getGameWorld() == null) {
|
||||
dGroup.setGameWorld(GameWorld.load(DGroup.getByPlayer(player).getMapName()));
|
||||
dGroup.setGameWorld(new GameWorld(DGroup.getByPlayer(player).getMapName()));
|
||||
dGroup.getGameWorld().setTutorial(true);
|
||||
}
|
||||
|
||||
@ -556,6 +572,36 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
new DGamePlayer(player, dGroup.getGameWorld());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
MainConfig config = plugin.getMainConfig();
|
||||
if (!config.isTutorialActivated()) {
|
||||
return;
|
||||
}
|
||||
if (DGamePlayer.getByPlayer(player) != null) {
|
||||
return;
|
||||
}
|
||||
if (plugin.getPermissionProvider() == null) {
|
||||
return;
|
||||
}
|
||||
if ((config.getTutorialDungeon() == null || config.getTutorialStartGroup() == null || config.getTutorialEndGroup() == null)) {
|
||||
return;
|
||||
}
|
||||
for (String group : plugin.getPermissionProvider().getPlayerGroups(player)) {
|
||||
if (!config.getTutorialStartGroup().equalsIgnoreCase(group)) {
|
||||
continue;
|
||||
}
|
||||
if (plugin.getGameWorlds().size() >= config.getMaxInstances()) {
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_FULL);
|
||||
event.setKickMessage(DMessages.ERROR_TOO_MANY_TUTORIALS.getMessage());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -566,17 +612,17 @@ public class PlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
DGamePlayer dPlayer = DGamePlayer.getByPlayer(event.getPlayer());
|
||||
if (dPlayer == null) {
|
||||
if (!(dPlayers.getByPlayer(event.getPlayer()) instanceof DInstancePlayer)) {
|
||||
return;
|
||||
}
|
||||
DInstancePlayer dPlayer = (DInstancePlayer) dPlayers.getByPlayer(event.getPlayer());
|
||||
|
||||
String command = event.getMessage().toLowerCase();
|
||||
ArrayList<String> commandWhitelist = new ArrayList<>();
|
||||
|
||||
GameWorld gameWorld = GameWorld.getByWorld(dPlayer.getWorld());
|
||||
Game game = Game.getByWorld(dPlayer.getWorld());
|
||||
|
||||
if (dPlayer.isEditing()) {
|
||||
if (dPlayer instanceof DEditPlayer) {
|
||||
if (DPermissions.hasPermission(event.getPlayer(), DPermissions.CMD_EDIT)) {
|
||||
return;
|
||||
|
||||
@ -584,9 +630,9 @@ public class PlayerListener implements Listener {
|
||||
commandWhitelist.addAll(plugin.getMainConfig().getEditCommandWhitelist());
|
||||
}
|
||||
|
||||
} else if (gameWorld != null) {
|
||||
if (gameWorld.getConfig() != null) {
|
||||
commandWhitelist.addAll(gameWorld.getConfig().getGameCommandWhitelist());
|
||||
} else if (game != null) {
|
||||
if (game.getRules() != null) {
|
||||
commandWhitelist.addAll(game.getRules().getGameCommandWhitelist());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,10 +16,12 @@
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.listener;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.world.EditWorld;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
|
||||
/**
|
||||
@ -37,4 +39,13 @@ public class WorldListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onWeatherChange(WeatherChangeEvent event) {
|
||||
if (EditWorld.getByWorld(event.getWorld()) != null) {
|
||||
if (event.toWeatherState()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -48,13 +48,12 @@ public class DMob {
|
||||
this.type = type;
|
||||
|
||||
/* Remove DropChance of equipment */
|
||||
try {
|
||||
if (!isExternalMob()) {
|
||||
this.entity.getEquipment().setHelmetDropChance(0);
|
||||
this.entity.getEquipment().setChestplateDropChance(0);
|
||||
this.entity.getEquipment().setLeggingsDropChance(0);
|
||||
this.entity.getEquipment().setBootsDropChance(0);
|
||||
this.entity.getEquipment().setItemInHandDropChance(0);
|
||||
} catch (UnsupportedOperationException exception) {
|
||||
}
|
||||
|
||||
DMobSpawnEvent event = new DMobSpawnEvent(this, entity);
|
||||
@ -70,6 +69,36 @@ public class DMob {
|
||||
this.trigger = trigger;
|
||||
}
|
||||
|
||||
/* Getters */
|
||||
/**
|
||||
* @return the represented LivingEntity
|
||||
*/
|
||||
public LivingEntity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the DMobType or null if the mob is an external mob
|
||||
*/
|
||||
public DMobType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the mob is spawned by an external plugin
|
||||
*/
|
||||
public boolean isExternalMob() {
|
||||
return type == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the trigger String
|
||||
*/
|
||||
public String getTrigger() {
|
||||
return trigger;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
public void onDeath(EntityDeathEvent event) {
|
||||
LivingEntity victim = event.getEntity();
|
||||
GameWorld gameWorld = GameWorld.getByWorld(victim.getWorld());
|
||||
@ -87,6 +116,8 @@ public class DMob {
|
||||
}
|
||||
|
||||
if (type != null) {
|
||||
event.getDrops().clear();
|
||||
|
||||
for (ItemStack itemStack : type.getDrops().keySet()) {
|
||||
Random randomGenerator = new Random();
|
||||
int random = randomGenerator.nextInt(100);
|
||||
@ -95,9 +126,10 @@ public class DMob {
|
||||
event.getDrops().add(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
name = type.getName();
|
||||
|
||||
} else if (type == null && trigger != null) {// <=MythicMobs mob
|
||||
} else if (isExternalMob() && trigger != null) {
|
||||
name = trigger;
|
||||
|
||||
} else {
|
||||
|
@ -19,17 +19,18 @@ package io.github.dre2n.dungeonsxl.mob;
|
||||
import io.github.dre2n.commons.util.EnumUtil;
|
||||
import io.github.dre2n.commons.util.NumberUtil;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Location;
|
||||
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.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@ -44,18 +45,16 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
*/
|
||||
public class DMobType {
|
||||
|
||||
static DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
|
||||
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 ItemStack itemHand;
|
||||
private ItemStack itemHelmet;
|
||||
private ItemStack itemChestplate;
|
||||
private ItemStack itemLeggings;
|
||||
private ItemStack itemBoots;
|
||||
|
||||
private Map<ItemStack, Integer> drops = new HashMap<>();
|
||||
|
||||
@ -63,121 +62,63 @@ public class DMobType {
|
||||
private boolean witherSkeleton = false;
|
||||
private String ocelotType = null;
|
||||
|
||||
/* Methods */
|
||||
public DMobType(String name, EntityType type) {
|
||||
/**
|
||||
* @param file
|
||||
* the script file
|
||||
*/
|
||||
public DMobType(File file) {
|
||||
this(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name of the DMobType
|
||||
* @param config
|
||||
* the config that stores the information
|
||||
*/
|
||||
public DMobType(String name, FileConfiguration config) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void spawn(GameWorld gameWorld, Location loc) {
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!type.isAlive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity entity = (LivingEntity) gameWorld.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 (EnumUtil.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, gameWorld, this);
|
||||
}
|
||||
|
||||
// Load Config
|
||||
public static Set<DMobType> load(ConfigurationSection configFile) {
|
||||
Set<DMobType> set = new HashSet<>();
|
||||
|
||||
if (configFile == null) {
|
||||
return set;
|
||||
}
|
||||
|
||||
// Read Mobs
|
||||
for (String mobName : configFile.getKeys(false)) {
|
||||
EntityType type = EntityType.fromName(configFile.getString(mobName + ".Type"));
|
||||
|
||||
if (type == null) {
|
||||
MessageUtil.log(DMessages.LOG_ERROR_MOBTYPE.getMessage(configFile.getString(mobName + ".Type")));
|
||||
continue;
|
||||
}
|
||||
|
||||
DMobType mobType = new DMobType(mobName, type);
|
||||
set.add(mobType);
|
||||
type = EntityType.fromName(config.getString("type"));
|
||||
|
||||
// Load MaxHealth
|
||||
if (configFile.contains(mobName + ".MaxHealth")) {
|
||||
mobType.maxHealth = configFile.getInt(mobName + ".MaxHealth");
|
||||
if (config.contains("maxHealth")) {
|
||||
maxHealth = config.getInt("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 (config.contains("itemHelmet")) {
|
||||
itemHelmet = new ItemStack(config.getInt("itemHelmet"));
|
||||
}
|
||||
|
||||
if (configFile.contains(mobName + ".ItemChestplate")) {
|
||||
mobType.ItemChestplate = new ItemStack(configFile.getInt(mobName + ".ItemChestplate"));// CraftItemStack.asNMSCopy(new
|
||||
// ItemStack(configFile.getInt(mobName+".ItemChestplate"))).getItem();
|
||||
if (config.contains("itemChestplate")) {
|
||||
itemChestplate = new ItemStack(config.getInt("itemChestplate"));
|
||||
}
|
||||
|
||||
if (configFile.contains(mobName + ".ItemBoots")) {
|
||||
mobType.ItemBoots = new ItemStack(configFile.getInt(mobName + ".ItemBoots"));// CraftItemStack.asNMSCopy(new
|
||||
// ItemStack(configFile.getInt(mobName+".ItemBoots"))).getItem();
|
||||
if (config.contains("itemBoots")) {
|
||||
itemBoots = new ItemStack(config.getInt("itemBoots"));
|
||||
}
|
||||
|
||||
if (configFile.contains(mobName + ".ItemLeggings")) {
|
||||
mobType.ItemLeggings = new ItemStack(configFile.getInt(mobName + ".ItemLeggings"));// CraftItemStack.asNMSCopy(new
|
||||
// ItemStack(configFile.getInt(mobName+".ItemLeggings"))).getItem();
|
||||
if (config.contains("itemLeggings")) {
|
||||
itemLeggings = new ItemStack(config.getInt("itemLeggings"));
|
||||
}
|
||||
|
||||
if (configFile.contains(mobName + ".ItemHand")) {
|
||||
mobType.ItemHand = new ItemStack(configFile.getInt(mobName + ".ItemHand"));// CraftItemStack.asNMSCopy(new
|
||||
// ItemStack(configFile.getInt(mobName+".ItemHand"))).getItem();
|
||||
if (config.contains("itemHand")) {
|
||||
itemHand = new ItemStack(config.getInt("itemHand"));
|
||||
}
|
||||
|
||||
// Load different Mob options
|
||||
if (configFile.contains(mobName + ".isWitherSkeleton")) {
|
||||
mobType.witherSkeleton = configFile.getBoolean(mobName + ".isWitherSkeleton");
|
||||
if (config.contains("isWitherSkeleton")) {
|
||||
witherSkeleton = config.getBoolean("isWitherSkeleton");
|
||||
}
|
||||
|
||||
if (configFile.contains(mobName + ".ocelotType")) {
|
||||
mobType.ocelotType = configFile.getString(mobName + ".ocelotType");
|
||||
if (config.contains("ocelotType")) {
|
||||
ocelotType = config.getString("ocelotType");
|
||||
}
|
||||
|
||||
// Drops
|
||||
ConfigurationSection configSetion = configFile.getConfigurationSection(mobName + ".drops");
|
||||
ConfigurationSection configSetion = config.getConfigurationSection("drops");
|
||||
if (configSetion != null) {
|
||||
Set<String> list = configSetion.getKeys(false);
|
||||
for (String dropPath : list) {
|
||||
@ -234,33 +175,23 @@ public class DMobType {
|
||||
|
||||
/* Add Item to the drops map */
|
||||
item.setItemMeta(itemMeta);
|
||||
mobType.getDrops().put(item, chance);
|
||||
drops.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;
|
||||
/**
|
||||
* @param name
|
||||
* the name of the DMobType
|
||||
* @param type
|
||||
* the EntityType of the mob
|
||||
*/
|
||||
public DMobType(String name, EntityType type) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
@ -309,76 +240,76 @@ public class DMobType {
|
||||
/**
|
||||
* @return the itemHand
|
||||
*/
|
||||
public ItemStack getItemHand() {
|
||||
return ItemHand;
|
||||
public ItemStack getitemHand() {
|
||||
return itemHand;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemHand
|
||||
* the itemHand to set
|
||||
*/
|
||||
public void setItemHand(ItemStack itemHand) {
|
||||
ItemHand = itemHand;
|
||||
public void setitemHand(ItemStack itemHand) {
|
||||
this.itemHand = itemHand;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the itemHelmet
|
||||
*/
|
||||
public ItemStack getItemHelmet() {
|
||||
return ItemHelmet;
|
||||
public ItemStack getitemHelmet() {
|
||||
return itemHelmet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemHelmet
|
||||
* the itemHelmet to set
|
||||
*/
|
||||
public void setItemHelmet(ItemStack itemHelmet) {
|
||||
ItemHelmet = itemHelmet;
|
||||
public void setitemHelmet(ItemStack itemHelmet) {
|
||||
this.itemHelmet = itemHelmet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the itemChestplate
|
||||
*/
|
||||
public ItemStack getItemChestplate() {
|
||||
return ItemChestplate;
|
||||
public ItemStack getitemChestplate() {
|
||||
return itemChestplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemChestplate
|
||||
* the itemChestplate to set
|
||||
*/
|
||||
public void setItemChestplate(ItemStack itemChestplate) {
|
||||
ItemChestplate = itemChestplate;
|
||||
public void setitemChestplate(ItemStack itemChestplate) {
|
||||
this.itemChestplate = itemChestplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the itemLeggings
|
||||
*/
|
||||
public ItemStack getItemLeggings() {
|
||||
return ItemLeggings;
|
||||
public ItemStack getitemLeggings() {
|
||||
return itemLeggings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemLeggings
|
||||
* the itemLeggings to set
|
||||
*/
|
||||
public void setItemLeggings(ItemStack itemLeggings) {
|
||||
ItemLeggings = itemLeggings;
|
||||
public void setitemLeggings(ItemStack itemLeggings) {
|
||||
this.itemLeggings = itemLeggings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the itemBoots
|
||||
*/
|
||||
public ItemStack getItemBoots() {
|
||||
return ItemBoots;
|
||||
public ItemStack getitemBoots() {
|
||||
return itemBoots;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemBoots
|
||||
* the itemBoots to set
|
||||
*/
|
||||
public void setItemBoots(ItemStack itemBoots) {
|
||||
ItemBoots = itemBoots;
|
||||
public void setitemBoots(ItemStack itemBoots) {
|
||||
this.itemBoots = itemBoots;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -426,4 +357,52 @@ public class DMobType {
|
||||
this.ocelotType = ocelotType;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
public void spawn(GameWorld gameWorld, Location loc) {
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!type.isAlive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity entity = (LivingEntity) gameWorld.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 (EnumUtil.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, gameWorld, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
75
src/main/java/io/github/dre2n/dungeonsxl/mob/DMobTypes.java
Normal file
75
src/main/java/io/github/dre2n/dungeonsxl/mob/DMobTypes.java
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.mob;
|
||||
|
||||
import io.github.dre2n.commons.util.FileUtil;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class DMobTypes {
|
||||
|
||||
private List<DMobType> dMobTypes = new ArrayList<>();
|
||||
|
||||
public DMobTypes(File file) {
|
||||
if (file.isDirectory()) {
|
||||
for (File script : FileUtil.getFilesForFolder(file)) {
|
||||
dMobTypes.add(new DMobType(script));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dMobType that has the name
|
||||
*/
|
||||
public DMobType getByName(String name) {
|
||||
for (DMobType dMobType : dMobTypes) {
|
||||
if (dMobType.getName().equalsIgnoreCase(name)) {
|
||||
return dMobType;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dMobTypes
|
||||
*/
|
||||
public List<DMobType> getDMobTypes() {
|
||||
return dMobTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dMobType
|
||||
* the DMobType to add
|
||||
*/
|
||||
public void addDMobType(DMobType dMobType) {
|
||||
dMobTypes.add(dMobType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dMobType
|
||||
* the DMobType to remove
|
||||
*/
|
||||
public void removeDMobType(DMobType dMobType) {
|
||||
dMobTypes.remove(dMobType);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -16,7 +16,15 @@
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.player;
|
||||
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import io.github.dre2n.commons.compatibility.CompatibilityHandler;
|
||||
import io.github.dre2n.commons.compatibility.Version;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.util.DeserialisazionUtil;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
@ -24,31 +32,42 @@ import org.bukkit.inventory.ItemStack;
|
||||
*/
|
||||
public class DClass {
|
||||
|
||||
private CopyOnWriteArrayList<ItemStack> items = new CopyOnWriteArrayList<>();
|
||||
DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
CompatibilityHandler compat = CompatibilityHandler.getInstance();
|
||||
|
||||
private String name;
|
||||
|
||||
private List<ItemStack> items = new ArrayList<>();
|
||||
private boolean dog;
|
||||
|
||||
public DClass(String name, CopyOnWriteArrayList<ItemStack> items, boolean dog) {
|
||||
public DClass(File file) {
|
||||
this(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file));
|
||||
}
|
||||
|
||||
public DClass(String name, FileConfiguration config) {
|
||||
this.name = name;
|
||||
|
||||
if (config.contains("items")) {
|
||||
List<String> itemList = config.getStringList("items");
|
||||
|
||||
if (Version.andHigher(Version.MC1_9).contains(compat.getVersion())) {
|
||||
items = plugin.getCaliburnAPI().getItems().deserializeStackList(itemList);
|
||||
} else {
|
||||
items = DeserialisazionUtil.deserializeStackList(itemList);
|
||||
}
|
||||
}
|
||||
|
||||
if (config.contains("dog")) {
|
||||
dog = config.getBoolean("dog");
|
||||
}
|
||||
}
|
||||
|
||||
public DClass(String name, List<ItemStack> items, boolean dog) {
|
||||
this.items = items;
|
||||
this.name = name;
|
||||
this.dog = dog;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the items
|
||||
*/
|
||||
public CopyOnWriteArrayList<ItemStack> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemStack
|
||||
* the ItemStack to add
|
||||
*/
|
||||
public void setItems(ItemStack itemStack) {
|
||||
items.add(itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
@ -57,11 +76,26 @@ public class DClass {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name to set
|
||||
* @return the items
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
public List<ItemStack> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemStack
|
||||
* the ItemStack to add
|
||||
*/
|
||||
public void addItem(ItemStack itemStack) {
|
||||
items.add(itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemStack
|
||||
* the ItemStack to remove
|
||||
*/
|
||||
public void removeItem(ItemStack itemStack) {
|
||||
items.remove(itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.player;
|
||||
|
||||
import io.github.dre2n.commons.util.FileUtil;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class DClasses {
|
||||
|
||||
private List<DClass> dClasses = new ArrayList<>();
|
||||
|
||||
public DClasses(File file) {
|
||||
if (file.isDirectory()) {
|
||||
for (File script : FileUtil.getFilesForFolder(file)) {
|
||||
dClasses.add(new DClass(script));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dClass that has the name
|
||||
*/
|
||||
public DClass getByName(String name) {
|
||||
for (DClass dClass : dClasses) {
|
||||
if (dClass.getName().equalsIgnoreCase(name)) {
|
||||
return dClass;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dClasses
|
||||
*/
|
||||
public List<DClass> getDClasses() {
|
||||
return dClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dClass
|
||||
* the DClass to add
|
||||
*/
|
||||
public void addDClass(DClass dClass) {
|
||||
dClasses.add(dClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dClass
|
||||
* the DClass to remove
|
||||
*/
|
||||
public void removeDClass(DClass dClass) {
|
||||
dClasses.remove(dClass);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -16,15 +16,208 @@
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.player;
|
||||
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.commons.util.playerutil.PlayerUtil;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerUpdateEvent;
|
||||
import static io.github.dre2n.dungeonsxl.player.DGlobalPlayer.plugin;
|
||||
import io.github.dre2n.dungeonsxl.world.EditWorld;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
/**
|
||||
* Represents a player in an EditWorld.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class DEditPlayer extends DGlobalPlayer {
|
||||
public class DEditPlayer extends DInstancePlayer {
|
||||
|
||||
public DEditPlayer(DGlobalPlayer player) {
|
||||
super(player.getPlayer());
|
||||
private String[] linesCopy;
|
||||
|
||||
public DEditPlayer(DGlobalPlayer player, EditWorld world) {
|
||||
this(player.getPlayer(), world.getWorld());
|
||||
}
|
||||
|
||||
public DEditPlayer(Player player, World world) {
|
||||
super(player, world);
|
||||
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
clearPlayerData();
|
||||
|
||||
Location teleport = EditWorld.getByWorld(world).getLobbyLocation();
|
||||
if (teleport == null) {
|
||||
PlayerUtil.secureTeleport(player, world.getSpawnLocation());
|
||||
} else {
|
||||
PlayerUtil.secureTeleport(player, teleport);
|
||||
}
|
||||
|
||||
// Permission bridge
|
||||
if (plugin.getPermissionProvider() != null) {
|
||||
for (String permission : plugin.getMainConfig().getEditPermissions()) {
|
||||
plugin.getPermissionProvider().playerAddTransient(world.getName(), player, permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
/**
|
||||
* @return the linesCopy
|
||||
*/
|
||||
public String[] getLinesCopy() {
|
||||
return linesCopy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param linesCopy
|
||||
* the linesCopy to set
|
||||
*/
|
||||
public void setLinesCopy(String[] linesCopy) {
|
||||
this.linesCopy = linesCopy;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
@Override
|
||||
public void delete() {
|
||||
// Permission bridge
|
||||
if (plugin.getPermissionProvider() != null) {
|
||||
for (String permission : plugin.getMainConfig().getEditPermissions()) {
|
||||
plugin.getPermissionProvider().playerRemoveTransient(getWorld().getName(), player, permission);
|
||||
}
|
||||
}
|
||||
|
||||
super.delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape the EditWorld without saving.
|
||||
*/
|
||||
public void escape() {
|
||||
delete();
|
||||
getSavePlayer().reset(false);
|
||||
}
|
||||
|
||||
public void poke(Block block) {
|
||||
if (block.getState() instanceof Sign) {
|
||||
Sign sign = (Sign) block.getState();
|
||||
String[] lines = sign.getLines();
|
||||
if (lines[0].isEmpty() && lines[1].isEmpty() && lines[2].isEmpty() && lines[3].isEmpty()) {
|
||||
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(), DMessages.PLAYER_SIGN_COPIED.getMessage());
|
||||
}
|
||||
} else {
|
||||
String info = "" + block.getType();
|
||||
if (block.getData() != 0) {
|
||||
info = info + "," + block.getData();
|
||||
}
|
||||
MessageUtil.sendMessage(getPlayer(), DMessages.PLAYER_BLOCK_INFO.getMessage(info));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leave() {
|
||||
delete();
|
||||
|
||||
getSavePlayer().reset(false);
|
||||
|
||||
EditWorld editWorld = EditWorld.getByWorld(getWorld());
|
||||
if (editWorld != null) {
|
||||
editWorld.save();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
EditWorld editWorld = EditWorld.getByWorld(getWorld());
|
||||
editWorld.sendMessage(message);
|
||||
|
||||
for (DGlobalPlayer player : plugin.getDPlayers().getDGlobalPlayers()) {
|
||||
if (player.isInChatSpyMode()) {
|
||||
if (!editWorld.getWorld().getPlayers().contains(player.getPlayer())) {
|
||||
MessageUtil.sendMessage(player.getPlayer(), ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(boolean updateSecond) {
|
||||
boolean locationValid = true;
|
||||
Location teleportLocation = player.getLocation();
|
||||
|
||||
EditWorld editWorld = EditWorld.getByWorld(getWorld());
|
||||
|
||||
if (!getPlayer().getWorld().equals(getWorld())) {
|
||||
locationValid = false;
|
||||
}
|
||||
|
||||
if (editWorld != null) {
|
||||
if (editWorld.getLobbyLocation() == null) {
|
||||
teleportLocation = editWorld.getWorld().getSpawnLocation();
|
||||
} else {
|
||||
teleportLocation = editWorld.getLobbyLocation();
|
||||
}
|
||||
}
|
||||
|
||||
DPlayerUpdateEvent event = new DPlayerUpdateEvent(this, locationValid, false, false, false, false, false);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!locationValid) {
|
||||
PlayerUtil.secureTeleport(getPlayer(), teleportLocation);
|
||||
}
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static DEditPlayer getByPlayer(Player player) {
|
||||
for (DEditPlayer dPlayer : plugin.getDPlayers().getDEditPlayers()) {
|
||||
if (dPlayer.getPlayer().equals(player)) {
|
||||
return dPlayer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DEditPlayer getByName(String name) {
|
||||
for (DEditPlayer dPlayer : plugin.getDPlayers().getDEditPlayers()) {
|
||||
if (dPlayer.getPlayer().getName().equalsIgnoreCase(name)) {
|
||||
return dPlayer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static CopyOnWriteArrayList<DEditPlayer> getByWorld(World world) {
|
||||
CopyOnWriteArrayList<DEditPlayer> dPlayers = new CopyOnWriteArrayList<>();
|
||||
|
||||
for (DEditPlayer dPlayer : plugin.getDPlayers().getDEditPlayers()) {
|
||||
if (dPlayer.getWorld() == world) {
|
||||
dPlayers.add(dPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
return dPlayers;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,46 +16,40 @@
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.player;
|
||||
|
||||
import io.github.dre2n.commons.compatibility.CompatibilityHandler;
|
||||
import io.github.dre2n.commons.compatibility.Version;
|
||||
import io.github.dre2n.commons.util.NumberUtil;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.commons.util.playerutil.PlayerUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.config.DungeonConfig;
|
||||
import io.github.dre2n.dungeonsxl.config.WorldConfig;
|
||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishDungeonEvent;
|
||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupFinishFloorEvent;
|
||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupRewardEvent;
|
||||
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.event.requirement.RequirementCheckEvent;
|
||||
import io.github.dre2n.dungeonsxl.game.Game;
|
||||
import io.github.dre2n.dungeonsxl.game.GameRules;
|
||||
import io.github.dre2n.dungeonsxl.game.GameType;
|
||||
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
|
||||
import io.github.dre2n.dungeonsxl.mob.DMob;
|
||||
import io.github.dre2n.dungeonsxl.requirement.Requirement;
|
||||
import io.github.dre2n.dungeonsxl.reward.DLootInventory;
|
||||
import io.github.dre2n.dungeonsxl.reward.Reward;
|
||||
import io.github.dre2n.dungeonsxl.trigger.DistanceTrigger;
|
||||
import io.github.dre2n.dungeonsxl.world.EditWorld;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
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;
|
||||
@ -65,15 +59,9 @@ import org.bukkit.potion.PotionEffect;
|
||||
*
|
||||
* @author Frank Baumann, Tobias Schmitz, Milan Albrecht, Daniel Saukel
|
||||
*/
|
||||
public class DGamePlayer extends DGlobalPlayer {
|
||||
public class DGamePlayer extends DInstancePlayer {
|
||||
|
||||
// Variables
|
||||
private World world;
|
||||
|
||||
private DSavePlayer savePlayer;
|
||||
|
||||
private boolean editing;
|
||||
private boolean inDungeonChat = false;
|
||||
private boolean ready = false;
|
||||
private boolean finished = false;
|
||||
|
||||
@ -82,7 +70,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
private Wolf wolf;
|
||||
private int wolfRespawnTime = 30;
|
||||
private long offlineTime;
|
||||
private String[] linesCopy;
|
||||
|
||||
private Inventory treasureInv = plugin.getServer().createInventory(getPlayer(), 45, DMessages.PLAYER_TREASURES.getMessage());
|
||||
|
||||
@ -90,65 +77,39 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
private int lives;
|
||||
|
||||
public DGamePlayer(Player player, GameWorld gameWorld) {
|
||||
this(player, gameWorld.getWorld(), false);
|
||||
this(player, gameWorld.getWorld());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public DGamePlayer(Player player, World world, boolean editing) {
|
||||
super(player);
|
||||
public DGamePlayer(Player player, World world) {
|
||||
super(player, world);
|
||||
|
||||
this.world = world;
|
||||
|
||||
if (!Version.andHigher(Version.MC1_9).contains(CompatibilityHandler.getInstance().getVersion())) {
|
||||
savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), null, player.getLevel(),
|
||||
player.getTotalExperience(), player.getHealth(), player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects());
|
||||
|
||||
} else {
|
||||
savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), player.getInventory().getItemInOffHand(), player.getLevel(),
|
||||
player.getTotalExperience(), player.getHealth(), player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects());
|
||||
Game game = Game.getByWorld(world);
|
||||
if (game == null) {
|
||||
game = new Game(DGroup.getByPlayer(player));
|
||||
}
|
||||
this.editing = editing;
|
||||
|
||||
Location teleport;
|
||||
if (this.editing) {
|
||||
this.getPlayer().setGameMode(GameMode.CREATIVE);
|
||||
clearPlayerData();
|
||||
teleport = EditWorld.getByWorld(world).getLobbyLocation();
|
||||
GameRules rules = game.getRules();
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
|
||||
} else {
|
||||
WorldConfig worldConfig = GameWorld.getByWorld(world).getConfig();
|
||||
this.getPlayer().setGameMode(GameMode.SURVIVAL);
|
||||
if (!worldConfig.getKeepInventoryOnEnter()) {
|
||||
if (!rules.getKeepInventoryOnEnter()) {
|
||||
clearPlayerData();
|
||||
}
|
||||
if (worldConfig.isLobbyDisabled()) {
|
||||
|
||||
if (rules.isLobbyDisabled()) {
|
||||
ready();
|
||||
}
|
||||
initialLives = worldConfig.getInitialLives();
|
||||
lives = initialLives;
|
||||
teleport = GameWorld.getByWorld(world).getLobbyLocation();
|
||||
}
|
||||
|
||||
initialLives = rules.getInitialLives();
|
||||
lives = initialLives;
|
||||
|
||||
Location teleport = GameWorld.getByWorld(world).getLobbyLocation();
|
||||
if (teleport == null) {
|
||||
PlayerUtil.secureTeleport(player, world.getSpawnLocation());
|
||||
|
||||
} else {
|
||||
PlayerUtil.secureTeleport(player, 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 */
|
||||
/**
|
||||
* @param player
|
||||
@ -158,36 +119,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
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
|
||||
*/
|
||||
@ -215,31 +146,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isEditing() {
|
||||
return editing;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
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
|
||||
*/
|
||||
@ -282,12 +188,12 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
* the dClass to set
|
||||
*/
|
||||
public void setDClass(String className) {
|
||||
GameWorld gameWorld = GameWorld.getByWorld(getPlayer().getWorld());
|
||||
if (gameWorld == null) {
|
||||
Game game = Game.getByWorld(getPlayer().getWorld());
|
||||
if (game == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DClass dClass = gameWorld.getConfig().getClass(className);
|
||||
DClass dClass = plugin.getDClasses().getByName(className);
|
||||
if (dClass != null) {
|
||||
if (this.dClass != dClass) {
|
||||
this.dClass = dClass;
|
||||
@ -299,7 +205,7 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
|
||||
if (dClass.hasDog()) {
|
||||
wolf = (Wolf) world.spawnEntity(getPlayer().getLocation(), EntityType.WOLF);
|
||||
wolf = (Wolf) getWorld().spawnEntity(getPlayer().getLocation(), EntityType.WOLF);
|
||||
wolf.setTamed(true);
|
||||
wolf.setOwner(getPlayer());
|
||||
|
||||
@ -408,21 +314,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
this.offlineTime = offlineTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
@ -469,36 +360,27 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
public void escape() {
|
||||
delete();
|
||||
savePlayer.reset(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leave() {
|
||||
GameRules rules = Game.getByWorld(getWorld()).getRules();
|
||||
delete();
|
||||
|
||||
if (!editing) {
|
||||
WorldConfig dConfig = GameWorld.getByWorld(world).getConfig();
|
||||
if (finished) {
|
||||
savePlayer.reset(dConfig.getKeepInventoryOnFinish());
|
||||
getSavePlayer().reset(rules.getKeepInventoryOnFinish());
|
||||
} else {
|
||||
savePlayer.reset(dConfig.getKeepInventoryOnEscape());
|
||||
getSavePlayer().reset(rules.getKeepInventoryOnEscape());
|
||||
}
|
||||
|
||||
} else {
|
||||
savePlayer.reset(false);
|
||||
}
|
||||
|
||||
GameWorld gameWorld = GameWorld.getByWorld(world);
|
||||
GameWorld gameWorld = GameWorld.getByWorld(getWorld());
|
||||
DGroup dGroup = DGroup.getByPlayer(getPlayer());
|
||||
|
||||
if (editing) {
|
||||
EditWorld editWorld = EditWorld.getByWorld(world);
|
||||
if (editWorld != null) {
|
||||
editWorld.save();
|
||||
// Permission bridge
|
||||
if (plugin.getPermissionProvider() != null) {
|
||||
for (String permission : rules.getGamePermissions()) {
|
||||
plugin.getPermissionProvider().playerRemoveTransient(getWorld().getName(), player, permission);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
Game game = Game.getByGameWorld(gameWorld);
|
||||
if (dGroup != null) {
|
||||
dGroup.removePlayer(getPlayer());
|
||||
@ -508,33 +390,13 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
if (game != null) {
|
||||
if (finished) {
|
||||
if (game.getType().hasRewards()) {
|
||||
for (Reward reward : gameWorld.getConfig().getRewards()) {
|
||||
for (Reward reward : rules.getRewards()) {
|
||||
reward.giveTo(getPlayer());
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
getData().logTimeLastPlayed(dGroup.getDungeon().getName());
|
||||
|
||||
// Tutorial Permissions
|
||||
if (gameWorld.isTutorial()) {
|
||||
@ -581,6 +443,102 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkRequirements(Game game) {
|
||||
if (DPermissions.hasPermission(player, DPermissions.IGNORE_REQUIREMENTS)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
GameRules rules = game.getRules();
|
||||
|
||||
if (!checkTime(game)) {
|
||||
MessageUtil.sendMessage(player, DMessages.ERROR_COOLDOWN.getMessage(String.valueOf(rules.getTimeToNextPlay())));
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Requirement requirement : rules.getRequirements()) {
|
||||
RequirementCheckEvent event = new RequirementCheckEvent(requirement, player);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!requirement.check(player)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (rules.getFinished() != null && rules.getFinishedAll() != null) {
|
||||
if (!rules.getFinished().isEmpty()) {
|
||||
|
||||
long bestTime = 0;
|
||||
int numOfNeeded = 0;
|
||||
boolean doneTheOne = false;
|
||||
|
||||
if (rules.getFinished().size() == rules.getFinishedAll().size()) {
|
||||
doneTheOne = true;
|
||||
}
|
||||
|
||||
for (String played : rules.getFinished()) {
|
||||
for (String dungeonName : DungeonsXL.MAPS.list()) {
|
||||
if (new File(DungeonsXL.MAPS, dungeonName).isDirectory()) {
|
||||
if (played.equalsIgnoreCase(dungeonName) || played.equalsIgnoreCase("any")) {
|
||||
|
||||
Long time = getData().getTimeLastPlayed(dungeonName);
|
||||
if (time != -1) {
|
||||
if (rules.getFinishedAll().contains(played)) {
|
||||
numOfNeeded++;
|
||||
} else {
|
||||
doneTheOne = true;
|
||||
}
|
||||
if (bestTime < time) {
|
||||
bestTime = time;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bestTime == 0) {
|
||||
return false;
|
||||
|
||||
} else if (rules.getTimeLastPlayed() != 0) {
|
||||
if (System.currentTimeMillis() - bestTime > rules.getTimeLastPlayed() * (long) 3600000) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (numOfNeeded < rules.getFinishedAll().size() || !doneTheOne) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean checkTime(Game game) {
|
||||
if (DPermissions.hasPermission(player, DPermissions.IGNORE_TIME_LIMIT)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
GameRules rules = game.getRules();
|
||||
|
||||
if (rules.getTimeToNextPlay() != 0) {
|
||||
// read PlayerConfig
|
||||
long time = getData().getTimeLastPlayed(game.getDungeon().getName());
|
||||
if (time != -1) {
|
||||
if (time + rules.getTimeToNextPlay() * 1000 * 60 * 60 > System.currentTimeMillis()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void ready() {
|
||||
@ -588,8 +546,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
|
||||
public void ready(GameType gameType) {
|
||||
ready = true;
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(getPlayer());
|
||||
|
||||
if (dGroup == null) {
|
||||
@ -603,6 +559,14 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
} else {
|
||||
game.setType(gameType);
|
||||
}
|
||||
game.fetchRules();
|
||||
|
||||
if (!checkRequirements(game)) {
|
||||
MessageUtil.sendMessage(player, DMessages.ERROR_REQUIREMENTS.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
ready = true;
|
||||
|
||||
for (DGroup gameGroup : game.getDGroups()) {
|
||||
if (!gameGroup.isPlaying()) {
|
||||
@ -628,7 +592,7 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
|
||||
if (respawn == null) {
|
||||
respawn = world.getSpawnLocation();
|
||||
respawn = getWorld().getSpawnLocation();
|
||||
}
|
||||
|
||||
PlayerUtil.secureTeleport(getPlayer(), respawn);
|
||||
@ -639,7 +603,9 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
|
||||
// Respawn Items
|
||||
if (GameWorld.getByWorld(world).getConfig().getKeepInventoryOnDeath()) {
|
||||
Game game = Game.getByWorld(getWorld());
|
||||
|
||||
if (game != null && game.getRules().getKeepInventoryOnDeath()) {
|
||||
applyRespawnInventory();
|
||||
}
|
||||
}
|
||||
@ -665,11 +631,7 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
boolean invalid = false;
|
||||
|
||||
if (dGroup.getDungeon() == null) {
|
||||
invalid = true;
|
||||
}
|
||||
boolean invalid = !dGroup.getDungeon().isMultiFloor();
|
||||
|
||||
for (Player player : dGroup.getPlayers()) {
|
||||
DGamePlayer dPlayer = getByPlayer(player);
|
||||
@ -697,7 +659,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
|
||||
DGroupFinishFloorEvent event = new DGroupFinishFloorEvent(dGroup, dGroup.getGameWorld(), newFloor);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
@ -707,7 +668,7 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
|
||||
dGroup.removeUnplayedFloor(dGroup.getMapName());
|
||||
dGroup.setMapName(newFloor);
|
||||
GameWorld gameWorld = GameWorld.load(newFloor);
|
||||
GameWorld gameWorld = new GameWorld(newFloor);
|
||||
dGroup.setGameWorld(gameWorld);
|
||||
for (Player player : dGroup.getPlayers()) {
|
||||
DGamePlayer dPlayer = getByPlayer(player);
|
||||
@ -756,7 +717,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
|
||||
DPlayerFinishEvent dPlayerFinishEvent = new DPlayerFinishEvent(this, first, hasToWait);
|
||||
plugin.getServer().getPluginManager().callEvent(dPlayerFinishEvent);
|
||||
|
||||
if (dPlayerFinishEvent.isCancelled()) {
|
||||
finished = false;
|
||||
@ -768,7 +728,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
|
||||
DGroupFinishDungeonEvent dGroupFinishDungeonEvent = new DGroupFinishDungeonEvent(dGroup);
|
||||
plugin.getServer().getPluginManager().callEvent(dGroupFinishDungeonEvent);
|
||||
|
||||
if (dGroupFinishDungeonEvent.isCancelled()) {
|
||||
return;
|
||||
@ -790,21 +749,11 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
if (editing) {
|
||||
EditWorld editWorld = EditWorld.getByWorld(world);
|
||||
editWorld.sendMessage(message);
|
||||
for (DGlobalPlayer player : plugin.getDPlayers().getDGlobalPlayers()) {
|
||||
if (player.isInChatSpyMode()) {
|
||||
if (!editWorld.getWorld().getPlayers().contains(player.getPlayer())) {
|
||||
MessageUtil.sendMessage(player.getPlayer(), ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
GameWorld gameWorld = GameWorld.getByWorld(world);
|
||||
GameWorld gameWorld = GameWorld.getByWorld(getWorld());
|
||||
gameWorld.sendMessage(message);
|
||||
|
||||
for (DGlobalPlayer player : plugin.getDPlayers().getDGlobalPlayers()) {
|
||||
if (player.isInChatSpyMode()) {
|
||||
if (!gameWorld.getWorld().getPlayers().contains(player.getPlayer())) {
|
||||
@ -813,41 +762,12 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void poke(Block block) {
|
||||
if (block.getState() instanceof Sign) {
|
||||
Sign sign = (Sign) block.getState();
|
||||
String[] lines = sign.getLines();
|
||||
if (lines[0].isEmpty() && lines[1].isEmpty() && lines[2].isEmpty() && lines[3].isEmpty()) {
|
||||
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(), DMessages.PLAYER_SIGN_COPIED.getMessage());
|
||||
}
|
||||
} else {
|
||||
String info = "" + block.getType();
|
||||
if (block.getData() != 0) {
|
||||
info = info + "," + block.getData();
|
||||
}
|
||||
MessageUtil.sendMessage(getPlayer(), DMessages.PLAYER_BLOCK_INFO.getMessage(info));
|
||||
}
|
||||
}
|
||||
|
||||
public void addTreasure() {
|
||||
new DLootInventory(getPlayer(), treasureInv.getContents());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(boolean updateSecond) {
|
||||
boolean locationValid = true;
|
||||
Location teleportLocation = player.getLocation();
|
||||
@ -858,22 +778,12 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
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.getLobbyLocation() == null) {
|
||||
teleportLocation = editWorld.getWorld().getSpawnLocation();
|
||||
} else {
|
||||
teleportLocation = editWorld.getLobbyLocation();
|
||||
}
|
||||
}
|
||||
|
||||
} else if (gameWorld != null) {
|
||||
if (gameWorld != null) {
|
||||
DGroup dGroup = DGroup.getByPlayer(getPlayer());
|
||||
|
||||
teleportLocation = getCheckpoint();
|
||||
@ -954,7 +864,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
|
||||
if (kick) {
|
||||
DPlayerKickEvent dPlayerKickEvent = new DPlayerKickEvent(this, DPlayerKickEvent.Cause.OFFLINE);
|
||||
plugin.getServer().getPluginManager().callEvent(dPlayerKickEvent);
|
||||
|
||||
if (!dPlayerKickEvent.isCancelled()) {
|
||||
leave();
|
||||
@ -966,19 +875,6 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete this DGamePlayer. Creates a DGlobalPlayer to replace it!
|
||||
*/
|
||||
public void delete() {
|
||||
if (player.isOnline()) {
|
||||
// Create a new DGlobalPlayer (outside a dungeon)
|
||||
new DGlobalPlayer(this);
|
||||
|
||||
} else {
|
||||
plugin.getDPlayers().removePlayer(this);
|
||||
}
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static DGamePlayer getByPlayer(Player player) {
|
||||
for (DGamePlayer dPlayer : plugin.getDPlayers().getDGamePlayers()) {
|
||||
@ -1002,7 +898,7 @@ public class DGamePlayer extends DGlobalPlayer {
|
||||
CopyOnWriteArrayList<DGamePlayer> dPlayers = new CopyOnWriteArrayList<>();
|
||||
|
||||
for (DGamePlayer dPlayer : plugin.getDPlayers().getDGamePlayers()) {
|
||||
if (dPlayer.world == world) {
|
||||
if (dPlayer.getWorld() == world) {
|
||||
dPlayers.add(dPlayer);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -17,7 +17,9 @@
|
||||
package io.github.dre2n.dungeonsxl.player;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.PlayerData;
|
||||
import io.github.dre2n.dungeonsxl.global.DPortal;
|
||||
import java.io.File;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -32,15 +34,19 @@ public class DGlobalPlayer {
|
||||
|
||||
protected Player player;
|
||||
|
||||
private PlayerData data;
|
||||
|
||||
private boolean breakMode;
|
||||
private boolean chatSpyMode;
|
||||
private DPortal creatingPortal;
|
||||
private boolean announcerEnabled = true;
|
||||
|
||||
private ItemStack[] respawnInventory;
|
||||
private ItemStack[] respawnArmor;
|
||||
|
||||
public DGlobalPlayer(Player player) {
|
||||
this.player = player;
|
||||
loadPlayerData(new File(DungeonsXL.PLAYERS, player.getUniqueId().toString() + ".yml"));
|
||||
|
||||
plugin.getDPlayers().addPlayer(this);
|
||||
}
|
||||
@ -50,6 +56,7 @@ public class DGlobalPlayer {
|
||||
breakMode = dPlayer.isInBreakMode();
|
||||
chatSpyMode = dPlayer.isInChatSpyMode();
|
||||
creatingPortal = dPlayer.getPortal();
|
||||
announcerEnabled = dPlayer.isAnnouncerEnabled();
|
||||
respawnInventory = dPlayer.getRespawnInventory();
|
||||
respawnArmor = dPlayer.getRespawnArmor();
|
||||
|
||||
@ -63,6 +70,20 @@ public class DGlobalPlayer {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the saved data
|
||||
*/
|
||||
public PlayerData getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load / reload a new instance of PlayerData
|
||||
*/
|
||||
public void loadPlayerData(File file) {
|
||||
data = new PlayerData(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the player is in break mode
|
||||
*/
|
||||
@ -115,6 +136,21 @@ public class DGlobalPlayer {
|
||||
creatingPortal = dPortal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the players receives announcer messages
|
||||
*/
|
||||
public boolean isAnnouncerEnabled() {
|
||||
return announcerEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param enabled
|
||||
* set if the players receives announcer messages
|
||||
*/
|
||||
public void setAnnouncerEnabled(boolean enabled) {
|
||||
announcerEnabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the respawnInventory
|
||||
*/
|
||||
|
@ -19,7 +19,6 @@ package io.github.dre2n.dungeonsxl.player;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.config.WorldConfig;
|
||||
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
|
||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupDisbandEvent;
|
||||
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupStartFloorEvent;
|
||||
@ -27,6 +26,7 @@ import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerJoinDGroupEvent;
|
||||
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.GameRules;
|
||||
import io.github.dre2n.dungeonsxl.game.GameType;
|
||||
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
|
||||
import io.github.dre2n.dungeonsxl.global.GroupSign;
|
||||
@ -54,6 +54,7 @@ public class DGroup {
|
||||
private Player captain;
|
||||
private CopyOnWriteArrayList<Player> players = new CopyOnWriteArrayList<>();
|
||||
private List<UUID> invitedPlayers = new ArrayList<>();
|
||||
private Dungeon dungeon;
|
||||
private String dungeonName;
|
||||
private String mapName;
|
||||
private List<String> unplayedFloors = new ArrayList<>();
|
||||
@ -63,6 +64,10 @@ public class DGroup {
|
||||
private List<Reward> rewards = new ArrayList<>();
|
||||
private BukkitTask timeIsRunningTask;
|
||||
|
||||
public DGroup(Player player) {
|
||||
this("Group_" + plugin.getDGroups().size(), player);
|
||||
}
|
||||
|
||||
public DGroup(String name, Player player) {
|
||||
plugin.getDGroups().add(this);
|
||||
this.name = name;
|
||||
@ -98,15 +103,17 @@ public class DGroup {
|
||||
addPlayer(player);
|
||||
}
|
||||
|
||||
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
|
||||
dungeon = plugin.getDungeons().getDungeon(identifier);
|
||||
if (multiFloor && dungeon != null) {
|
||||
dungeonName = identifier;
|
||||
dungeonName = dungeon.getName();
|
||||
mapName = dungeon.getConfig().getStartFloor();
|
||||
unplayedFloors = dungeon.getConfig().getFloors();
|
||||
|
||||
} else {
|
||||
mapName = identifier;
|
||||
dungeon = new Dungeon(identifier);
|
||||
}
|
||||
|
||||
playing = false;
|
||||
floorCount = 0;
|
||||
}
|
||||
@ -288,6 +295,21 @@ public class DGroup {
|
||||
this.gameWorld = gameWorld;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dungeon
|
||||
*/
|
||||
public Dungeon getDungeon() {
|
||||
return dungeon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dungeon
|
||||
* the dungeon to set
|
||||
*/
|
||||
public void setDungeon(Dungeon dungeon) {
|
||||
this.dungeon = dungeon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dungeonName
|
||||
*/
|
||||
@ -303,21 +325,6 @@ public class DGroup {
|
||||
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
|
||||
*/
|
||||
@ -440,6 +447,13 @@ public class DGroup {
|
||||
return players.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the group has been customized with a command
|
||||
*/
|
||||
public boolean isCustom() {
|
||||
return !name.matches("Group_[0-9]{1,}");
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
/**
|
||||
* Remove the group from the List
|
||||
@ -464,6 +478,7 @@ public class DGroup {
|
||||
if (game == null) {
|
||||
return;
|
||||
}
|
||||
game.fetchRules();
|
||||
|
||||
for (DGroup dGroup : game.getDGroups()) {
|
||||
if (dGroup == null) {
|
||||
@ -512,7 +527,7 @@ public class DGroup {
|
||||
|
||||
dPlayer.respawn();
|
||||
|
||||
if (plugin.getMainConfig().getSendFloorTitle()) {
|
||||
if (plugin.getMainConfig().isSendFloorTitleEnabled()) {
|
||||
if (dungeonName != null) {
|
||||
MessageUtil.sendTitleMessage(player, "&b&l" + dungeonName.replaceAll("_", " "), "&4&l" + mapName.replaceAll("_", " "));
|
||||
|
||||
@ -521,9 +536,9 @@ public class DGroup {
|
||||
}
|
||||
}
|
||||
|
||||
WorldConfig config = gameWorld.getConfig();
|
||||
if (config != null) {
|
||||
for (Requirement requirement : config.getRequirements()) {
|
||||
GameRules rules = game.getRules();
|
||||
|
||||
for (Requirement requirement : rules.getRequirements()) {
|
||||
RequirementDemandEvent requirementDemandEvent = new RequirementDemandEvent(requirement, player);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
@ -536,23 +551,57 @@ public class DGroup {
|
||||
|
||||
GameType gameType = game.getType();
|
||||
if (gameType == GameTypeDefault.DEFAULT) {
|
||||
player.setGameMode(config.getGameMode());
|
||||
if (config.isTimeIsRunning()) {
|
||||
timeIsRunningTask = new TimeIsRunningTask(this, config.getTimeToFinish()).runTaskTimer(plugin, 20, 20);
|
||||
player.setGameMode(rules.getGameMode());
|
||||
if (rules.isTimeIsRunning()) {
|
||||
timeIsRunningTask = new TimeIsRunningTask(this, rules.getTimeToFinish()).runTaskTimer(plugin, 20, 20);
|
||||
}
|
||||
|
||||
} else {
|
||||
player.setGameMode(gameType.getGameMode());
|
||||
if (gameType.getShowTime()) {
|
||||
timeIsRunningTask = new TimeIsRunningTask(this, config.getTimeToFinish()).runTaskTimer(plugin, 20, 20);
|
||||
timeIsRunningTask = new TimeIsRunningTask(this, rules.getTimeToFinish()).runTaskTimer(plugin, 20, 20);
|
||||
}
|
||||
}
|
||||
|
||||
// Permission bridge
|
||||
if (plugin.getPermissionProvider() != null) {
|
||||
for (String permission : rules.getGamePermissions()) {
|
||||
plugin.getPermissionProvider().playerRemoveTransient(gameWorld.getWorld().getName(), player, permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GroupSign.updatePerGroup(this);
|
||||
}
|
||||
|
||||
public boolean checkTime(Game game) {
|
||||
if (DPermissions.hasPermission(captain, DPermissions.IGNORE_TIME_LIMIT)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Player player : players) {
|
||||
if (!DGamePlayer.getByPlayer(player).checkTime(game)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean checkRequirements(Game game) {
|
||||
if (DPermissions.hasPermission(captain, DPermissions.IGNORE_REQUIREMENTS)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Player player : players) {
|
||||
if (!DGamePlayer.getByPlayer(player).checkRequirements(game)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to all players in the group
|
||||
*/
|
||||
|
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.player;
|
||||
|
||||
import io.github.dre2n.commons.compatibility.CompatibilityHandler;
|
||||
import io.github.dre2n.commons.compatibility.Version;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public abstract class DInstancePlayer extends DGlobalPlayer {
|
||||
|
||||
private DSavePlayer savePlayer;
|
||||
private World world;
|
||||
private boolean inDungeonChat = false;
|
||||
|
||||
public DInstancePlayer(Player player, World world) {
|
||||
super(player);
|
||||
|
||||
double health = player.getHealth();
|
||||
if (!Version.andHigher(Version.MC1_9).contains(CompatibilityHandler.getInstance().getVersion())) {
|
||||
savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), null, player.getLevel(),
|
||||
player.getTotalExperience(), (int) health, player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects());
|
||||
} else {
|
||||
savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), player.getInventory().getItemInOffHand(), player.getLevel(),
|
||||
player.getTotalExperience(), (int) health, player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects());
|
||||
}
|
||||
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
/**
|
||||
* @return the savePlayer
|
||||
*/
|
||||
public DSavePlayer getSavePlayer() {
|
||||
return savePlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param savePlayer
|
||||
* the savePlayer to set
|
||||
*/
|
||||
public void setSavePlayer(DSavePlayer savePlayer) {
|
||||
this.savePlayer = savePlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* the instance
|
||||
*/
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* the instance to set
|
||||
*/
|
||||
public void setWorld(World instance) {
|
||||
world = instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the inDungeonChat
|
||||
*/
|
||||
public boolean isInDungeonChat() {
|
||||
return inDungeonChat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param inDungeonChat
|
||||
* the inDungeonChat to set
|
||||
*/
|
||||
public void setInDungeonChat(boolean inDungeonChat) {
|
||||
this.inDungeonChat = inDungeonChat;
|
||||
}
|
||||
|
||||
// Players in dungeons never get announcer messages
|
||||
@Override
|
||||
public boolean isAnnouncerEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
/**
|
||||
* Clear the player's inventory, potion effects etc.
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete this DInstancePlayer. Creates a DGlobalPlayer to replace it!
|
||||
*/
|
||||
public void delete() {
|
||||
if (player.isOnline()) {
|
||||
// Create a new DGlobalPlayer (outside a dungeon)
|
||||
new DGlobalPlayer(this);
|
||||
|
||||
} else {
|
||||
plugin.getDPlayers().removePlayer(this);
|
||||
}
|
||||
}
|
||||
|
||||
/* Abstracts */
|
||||
/**
|
||||
* The player leaves the dungeon and / or his group.
|
||||
*/
|
||||
public abstract void leave();
|
||||
|
||||
/**
|
||||
* Sends a message to the player and the world.
|
||||
*/
|
||||
public abstract void sendMessage(String message);
|
||||
|
||||
/**
|
||||
* Repeating checks for the player.
|
||||
*
|
||||
* @param updateSecond
|
||||
* Not all checks have to be done as often as others;
|
||||
* some are just done in "update seconds".
|
||||
*/
|
||||
public abstract void update(boolean updateSecond);
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -49,6 +49,7 @@ public enum DPermissions {
|
||||
IGNORE_TIME_LIMIT("ignoretimelimit", OP),
|
||||
INVITE("invite", OP),
|
||||
INSECURE("insecure", OP),
|
||||
JOIN("join", TRUE),
|
||||
LEAVE("leave", TRUE),
|
||||
LIST("list", OP),
|
||||
LIVES("lives", TRUE),
|
||||
@ -58,6 +59,22 @@ public enum DPermissions {
|
||||
PORTAL("portal", OP),
|
||||
RELOAD("reload", OP),
|
||||
SAVE("save", OP),
|
||||
/**
|
||||
* Allows to open the settings menu.
|
||||
*/
|
||||
SETTINGS("settings", TRUE),
|
||||
/**
|
||||
* Allows to modify dungeon settings unless they have an own node.
|
||||
*/
|
||||
SETTINGS_EDIT("settings.edit", OP),
|
||||
/**
|
||||
* Allows to modify global settings.
|
||||
*/
|
||||
SETTINGS_GLOBAL("settings.global", OP),
|
||||
/**
|
||||
* Allows to modify player settings unless they have an own node.
|
||||
*/
|
||||
SETTINGS_PLAYER("settings.player", TRUE),
|
||||
SIGN("sign", OP),
|
||||
TEST("test", OP),
|
||||
UNINVITE("uninvite", OP),
|
||||
@ -65,7 +82,7 @@ public enum DPermissions {
|
||||
ADMINISTRATOR("*", OP),
|
||||
HALF_EDITOR("halfeditor", OP, ESCAPE, LIST, MESSAGE, SAVE),
|
||||
FULL_EDITOR("fulleditor", OP, HALF_EDITOR, EDIT, PLAY, SIGN, TEST),
|
||||
HALF_PLAYER("halfplayer", TRUE, CHAT, ESCAPE, GAME, HELP, LEAVE, LIVES, MAIN),
|
||||
HALF_PLAYER("halfplayer", TRUE, CHAT, ESCAPE, GAME, HELP, JOIN, LEAVE, LIVES, MAIN, SETTINGS, SETTINGS_PLAYER),
|
||||
FULL_PLAYER("fullplayer", OP, HALF_PLAYER, GROUP);
|
||||
|
||||
public static final String PREFIX = "dxl.";
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -49,11 +50,24 @@ public class DPlayers {
|
||||
return dGlobalPlayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dGlobalPlayers that are an instance of DInstancePlayer
|
||||
*/
|
||||
public List<DInstancePlayer> getDInstancePlayers() {
|
||||
List<DInstancePlayer> dInstancePlayers = new ArrayList<>();
|
||||
for (DGlobalPlayer player : dGlobalPlayers) {
|
||||
if (player instanceof DInstancePlayer) {
|
||||
dInstancePlayers.add((DInstancePlayer) player);
|
||||
}
|
||||
}
|
||||
return dInstancePlayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dGlobalPlayers that are an instance of DGamePlayer
|
||||
*/
|
||||
public List<DGamePlayer> getDGamePlayers() {
|
||||
List<DGamePlayer> dPlayers = new CopyOnWriteArrayList<>();
|
||||
List<DGamePlayer> dPlayers = new ArrayList<>();
|
||||
for (DGlobalPlayer player : dGlobalPlayers) {
|
||||
if (player instanceof DGamePlayer) {
|
||||
dPlayers.add((DGamePlayer) player);
|
||||
@ -66,7 +80,7 @@ public class DPlayers {
|
||||
* @return the dGlobalPlayers that are an instance of DEditPlayer
|
||||
*/
|
||||
public List<DEditPlayer> getDEditPlayers() {
|
||||
List<DEditPlayer> dEditPlayers = new CopyOnWriteArrayList<>();
|
||||
List<DEditPlayer> dEditPlayers = new ArrayList<>();
|
||||
for (DGlobalPlayer player : dGlobalPlayers) {
|
||||
if (player instanceof DEditPlayer) {
|
||||
dEditPlayers.add((DEditPlayer) player);
|
||||
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.requirement;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class GroupSizeRequirement extends Requirement {
|
||||
|
||||
private RequirementType type = RequirementTypeDefault.GROUP_SIZE;
|
||||
|
||||
private int minimum;
|
||||
private int maximum;
|
||||
|
||||
/**
|
||||
* @return the group minimum
|
||||
*/
|
||||
public int getMinimum() {
|
||||
return minimum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param minimum
|
||||
* the minimal group size to set
|
||||
*/
|
||||
public void setMinimum(int minimum) {
|
||||
this.minimum = minimum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the group size maximum
|
||||
*/
|
||||
public int getMaximum() {
|
||||
return maximum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maximum
|
||||
* the maximal group size to set
|
||||
*/
|
||||
public void setMaximum(int maximum) {
|
||||
this.maximum = maximum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(Player player) {
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
int size = dGroup.getPlayers().size();
|
||||
return size >= minimum && size <= maximum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void demand(Player player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequirementType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
@ -22,7 +22,8 @@ package io.github.dre2n.dungeonsxl.requirement;
|
||||
public enum RequirementTypeDefault implements RequirementType {
|
||||
|
||||
FEE_LEVEL("feeLevel", FeeLevelRequirement.class),
|
||||
FEE_MONEY("feeMoney", FeeMoneyRequirement.class);
|
||||
FEE_MONEY("feeMoney", FeeMoneyRequirement.class),
|
||||
GROUP_SIZE("groupSize", GroupSizeRequirement.class);
|
||||
|
||||
private String identifier;
|
||||
private Class<? extends Requirement> handler;
|
||||
|
@ -36,8 +36,8 @@ public class BlockSign extends DSign {
|
||||
private byte offBlockData = 0x0;
|
||||
private byte onBlockData = 0x0;
|
||||
|
||||
public BlockSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public BlockSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -47,7 +47,6 @@ public class BlockSign extends DSign {
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
String lines[] = getSign().getLines();
|
||||
if (!lines[1].isEmpty()) {
|
||||
String line1[] = lines[1].split(",");
|
||||
Material offBlock = Material.matchMaterial(line1[0]);
|
||||
|
@ -36,8 +36,8 @@ public class CheckpointSign extends DSign {
|
||||
private boolean initialized;
|
||||
private CopyOnWriteArrayList<DGamePlayer> done = new CopyOnWriteArrayList<>();
|
||||
|
||||
public CheckpointSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public CheckpointSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,8 +33,8 @@ public class ChestSign extends DSign {
|
||||
private double moneyReward;
|
||||
private int levelReward;
|
||||
|
||||
public ChestSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public ChestSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -44,7 +44,6 @@ public class ChestSign extends DSign {
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
String[] lines = getSign().getLines();
|
||||
if (!lines[1].isEmpty()) {
|
||||
String[] attributes = lines[1].split(",");
|
||||
if (attributes.length >= 1) {
|
||||
|
@ -29,8 +29,8 @@ public class ChunkUpdaterSign extends DSign {
|
||||
|
||||
private DSignType type = DSignTypeDefault.CHUNK_UPDATER;
|
||||
|
||||
public ChunkUpdaterSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public ChunkUpdaterSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -40,7 +40,6 @@ public class ChunkUpdaterSign extends DSign {
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
String lines[] = getSign().getLines();
|
||||
Chunk chunk = getGameWorld().getWorld().getChunkAt(getSign().getBlock());
|
||||
|
||||
if (!lines[1].isEmpty()) {
|
||||
|
@ -16,12 +16,9 @@
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.sign;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.global.GroupSign;
|
||||
import io.github.dre2n.dungeonsxl.player.DClass;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
/**
|
||||
@ -31,61 +28,44 @@ public class ClassesSign extends DSign {
|
||||
|
||||
private DSignType type = DSignTypeDefault.CLASSES;
|
||||
|
||||
public ClassesSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
private DClass dClass;
|
||||
|
||||
public ClassesSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
dClass = plugin.getDClasses().getByName(sign.getLine(1));
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
/**
|
||||
* @return the DClass of the sign
|
||||
*/
|
||||
public DClass getDClass() {
|
||||
return dClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dClass
|
||||
* the DClass to set
|
||||
*/
|
||||
public void setDClass(DClass dClass) {
|
||||
this.dClass = dClass;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
@Override
|
||||
public boolean check() {
|
||||
return true;
|
||||
return plugin.getDClasses().getByName(lines[1]) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
if (getGameWorld().getConfig().isLobbyDisabled()) {
|
||||
getSign().getBlock().setType(Material.AIR);
|
||||
return;
|
||||
}
|
||||
getSign().setLine(0, ChatColor.DARK_BLUE + "############");
|
||||
getSign().setLine(1, ChatColor.DARK_GREEN + dClass.getName());
|
||||
getSign().setLine(2, "");
|
||||
getSign().setLine(3, ChatColor.DARK_BLUE + "############");
|
||||
getSign().update();
|
||||
|
||||
int[] direction = GroupSign.getDirection(getSign().getBlock().getData());
|
||||
int directionX = direction[0];
|
||||
int directionZ = direction[1];
|
||||
|
||||
int xx = 0, zz = 0;
|
||||
for (DClass dclass : getGameWorld().getConfig().getClasses()) {
|
||||
|
||||
// Check existing signs
|
||||
boolean isContinued = true;
|
||||
for (Sign isusedsign : getGameWorld().getSignClass()) {
|
||||
if (dclass.getName().equalsIgnoreCase(ChatColor.stripColor(isusedsign.getLine(1)))) {
|
||||
isContinued = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isContinued) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Block classBlock = getSign().getBlock().getRelative(xx, 0, zz);
|
||||
|
||||
if (classBlock.getData() == getSign().getData().getData() && classBlock.getType() == Material.WALL_SIGN && classBlock.getState() instanceof Sign) {
|
||||
Sign classSign = (Sign) classBlock.getState();
|
||||
|
||||
classSign.setLine(0, ChatColor.DARK_BLUE + "############");
|
||||
classSign.setLine(1, ChatColor.DARK_GREEN + dclass.getName());
|
||||
classSign.setLine(2, "");
|
||||
classSign.setLine(3, ChatColor.DARK_BLUE + "############");
|
||||
classSign.update();
|
||||
|
||||
getGameWorld().getSignClass().add(classSign);
|
||||
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
xx = xx + directionX;
|
||||
zz = zz + directionZ;
|
||||
}
|
||||
getGameWorld().getSignClass().add(getSign());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,13 +44,12 @@ public class CommandSign extends DSign {
|
||||
private String executor;
|
||||
private boolean initialized;
|
||||
|
||||
public CommandSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public CommandSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check() {
|
||||
String lines[] = getSign().getLines();
|
||||
if (lines[1].isEmpty() || lines[2].isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@ -70,7 +69,6 @@ public class CommandSign extends DSign {
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
String[] lines = getSign().getLines();
|
||||
String[] attributes = lines[2].split(",");
|
||||
|
||||
command = lines[1];
|
||||
|
@ -40,8 +40,8 @@ public class DMobSign extends DSign implements MobSign {
|
||||
private boolean active;
|
||||
private BukkitTask task;
|
||||
|
||||
public DMobSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public DMobSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -131,7 +131,6 @@ public class DMobSign extends DSign implements MobSign {
|
||||
|
||||
@Override
|
||||
public boolean check() {
|
||||
String lines[] = getSign().getLines();
|
||||
if (lines[1].isEmpty() || lines[2].isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@ -151,7 +150,6 @@ public class DMobSign extends DSign implements MobSign {
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
String lines[] = getSign().getLines();
|
||||
if (!lines[1].isEmpty() && !lines[2].isEmpty()) {
|
||||
String mob = lines[1];
|
||||
if (mob != null) {
|
||||
|
@ -37,13 +37,15 @@ public abstract class DSign {
|
||||
static DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
|
||||
private Sign sign;
|
||||
protected String[] lines;
|
||||
private GameWorld gameWorld;
|
||||
|
||||
// List of Triggers
|
||||
private Set<Trigger> triggers = new HashSet<>();
|
||||
|
||||
public DSign(Sign sign, GameWorld gameWorld) {
|
||||
this.setSign(sign);
|
||||
public DSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
this.sign = sign;
|
||||
this.lines = lines;
|
||||
this.gameWorld = gameWorld;
|
||||
|
||||
// Check Trigger
|
||||
@ -51,7 +53,7 @@ public abstract class DSign {
|
||||
return;
|
||||
}
|
||||
|
||||
String line3 = sign.getLine(3).replaceAll("\\s", "");
|
||||
String line3 = lines[3].replaceAll("\\s", "");
|
||||
String[] triggerTypes = line3.split(",");
|
||||
|
||||
for (String triggerString : triggerTypes) {
|
||||
@ -88,6 +90,21 @@ public abstract class DSign {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the sign lines
|
||||
*/
|
||||
public String[] getLines() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lines
|
||||
* the sign lines to set
|
||||
*/
|
||||
public void setLines(String[] lines) {
|
||||
this.lines = lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the gameWorld
|
||||
*/
|
||||
@ -169,7 +186,10 @@ public abstract class DSign {
|
||||
}
|
||||
|
||||
public static DSign create(Sign sign, GameWorld gameWorld) {
|
||||
String[] lines = sign.getLines();
|
||||
return create(sign, sign.getLines(), gameWorld);
|
||||
}
|
||||
|
||||
public static DSign create(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
DSign dSign = null;
|
||||
|
||||
for (DSignType type : plugin.getDSigns().getDSigns()) {
|
||||
@ -178,8 +198,8 @@ public abstract class DSign {
|
||||
}
|
||||
|
||||
try {
|
||||
Constructor<? extends DSign> constructor = type.getHandler().getConstructor(Sign.class, GameWorld.class);
|
||||
dSign = constructor.newInstance(sign, gameWorld);
|
||||
Constructor<? extends DSign> constructor = type.getHandler().getConstructor(Sign.class, String[].class, GameWorld.class);
|
||||
dSign = constructor.newInstance(sign, lines, gameWorld);
|
||||
|
||||
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) {
|
||||
MessageUtil.log("An error occurred while accessing the handler class of the sign " + type.getName() + ": " + exception.getClass().getSimpleName());
|
||||
|
@ -42,8 +42,10 @@ public enum DSignTypeDefault implements DSignType {
|
||||
PLACE("Place", "place", false, PlaceSign.class),
|
||||
READY("Ready", "ready", true, ReadySign.class),
|
||||
REDSTONE("Redstone", "redstone", false, RedstoneSign.class),
|
||||
SCRIPT("Script", "script", false, ScriptSign.class),
|
||||
SOUND_MESSAGE("SoundMSG", "soundmsg", false, SoundMessageSign.class),
|
||||
START("Start", "start", true, StartSign.class),
|
||||
TELEPORT("Teleport", "teleport", false, TeleportSign.class),
|
||||
TRIGGER("Trigger", "trigger", true, TriggerSign.class),
|
||||
WAVE("Wave", "wave", false, WaveSign.class);
|
||||
|
||||
|
@ -31,8 +31,8 @@ public class EndSign extends DSign {
|
||||
|
||||
private DSignType type = DSignTypeDefault.END;
|
||||
|
||||
public EndSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public EndSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,8 +52,8 @@ public class ExternalMobSign extends DSign implements MobSign {
|
||||
private LivingEntity externalMob;
|
||||
private List<Entity> externalMobs = new ArrayList<>();
|
||||
|
||||
public ExternalMobSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public ExternalMobSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -196,7 +196,6 @@ public class ExternalMobSign extends DSign implements MobSign {
|
||||
|
||||
@Override
|
||||
public boolean check() {
|
||||
String lines[] = getSign().getLines();
|
||||
if (lines[1].isEmpty() || lines[2].isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@ -216,8 +215,6 @@ public class ExternalMobSign extends DSign implements MobSign {
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
String lines[] = getSign().getLines();
|
||||
|
||||
String mob = lines[1];
|
||||
if (mob != null) {
|
||||
String[] attributes = lines[2].split(",");
|
||||
|
@ -33,8 +33,8 @@ public class FloorSign extends DSign {
|
||||
|
||||
private String floor;
|
||||
|
||||
public FloorSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public FloorSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -44,7 +44,6 @@ public class FloorSign extends DSign {
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
String[] lines = getSign().getLines();
|
||||
if (!lines[1].isEmpty()) {
|
||||
floor = lines[1];
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ public class InteractSign extends DSign {
|
||||
|
||||
private DSignType type = DSignTypeDefault.INTERACT;
|
||||
|
||||
public InteractSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public InteractSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,8 +32,8 @@ public class LeaveSign extends DSign {
|
||||
|
||||
private DSignType type = DSignTypeDefault.LEAVE;
|
||||
|
||||
public LeaveSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public LeaveSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,8 +27,8 @@ public class LobbySign extends DSign {
|
||||
|
||||
private DSignType type = DSignTypeDefault.LOBBY;
|
||||
|
||||
public LobbySign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public LobbySign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,8 +36,8 @@ public class MessageSign extends DSign {
|
||||
private boolean initialized;
|
||||
private CopyOnWriteArrayList<Player> done = new CopyOnWriteArrayList<>();
|
||||
|
||||
public MessageSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public MessageSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,10 +51,8 @@ public class MessageSign extends DSign {
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
String lines[] = getSign().getLines();
|
||||
|
||||
if (!lines[1].isEmpty()) {
|
||||
String msg = getGameWorld().getConfig().getMsg(NumberUtil.parseInt(lines[1]), true);
|
||||
String msg = getGame().getRules().getMsg(NumberUtil.parseInt(lines[1]), true);
|
||||
if (msg != null) {
|
||||
this.msg = msg;
|
||||
getSign().getBlock().setType(Material.AIR);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -28,8 +28,8 @@ public class PlaceSign extends DSign {
|
||||
|
||||
private DSignType type = DSignTypeDefault.PLACE;
|
||||
|
||||
public PlaceSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public PlaceSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -39,7 +39,6 @@ public class PlaceSign extends DSign {
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
String lines[] = getSign().getLines();
|
||||
getGameWorld().getPlaceableBlocks().add(new GamePlaceableBlock(getSign().getBlock(), lines[1], lines[2]));
|
||||
getSign().getBlock().setType(Material.AIR);
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ public class ReadySign extends DSign {
|
||||
|
||||
private GameType gameType;
|
||||
|
||||
public ReadySign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public ReadySign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,8 +65,8 @@ public class ReadySign extends DSign {
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
if (plugin.getGameTypes().getBySign(getSign()) != null) {
|
||||
gameType = plugin.getGameTypes().getBySign(getSign());
|
||||
if (plugin.getGameTypes().getBySign(this) != null) {
|
||||
gameType = plugin.getGameTypes().getBySign(this);
|
||||
|
||||
} else {
|
||||
gameType = GameTypeDefault.DEFAULT;
|
||||
@ -117,10 +117,10 @@ public class ReadySign extends DSign {
|
||||
if (getGameWorld().getSignClass().isEmpty() || dPlayer.getDClass() != null) {
|
||||
GameType forced = getGameWorld().getConfig().getForcedGameType();
|
||||
dPlayer.ready(forced == null ? gameType : forced);
|
||||
MessageUtil.sendMessage(dPlayer.getPlayer(), plugin.getMessageConfig().getMessage(DMessages.PLAYER_READY));
|
||||
}
|
||||
|
||||
} else {
|
||||
MessageUtil.sendMessage(dPlayer.getPlayer(), plugin.getMessageConfig().getMessage(DMessages.ERROR_READY));
|
||||
if (dPlayer.isReady()) {
|
||||
MessageUtil.sendMessage(dPlayer.getPlayer(), plugin.getMessageConfig().getMessage(dPlayer.isReady() ? DMessages.PLAYER_READY : DMessages.ERROR_READY));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,8 @@ public class RedstoneSign extends DSign {
|
||||
private int repeat = 1;
|
||||
private int repeatsToDo = 1;
|
||||
|
||||
public RedstoneSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public RedstoneSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.sign;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class ScriptSign extends DSign {
|
||||
|
||||
private DSignType type = DSignTypeDefault.SCRIPT;
|
||||
|
||||
private String name;
|
||||
|
||||
public ScriptSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
name = lines[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the script
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check() {
|
||||
return plugin.getSignScripts().getByName(lines[1]) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
SignScript script = plugin.getSignScripts().getByName(name);
|
||||
for (String[] lines : script.getSigns()) {
|
||||
DSign dSign = DSign.create(getSign(), lines, getGameWorld());
|
||||
getGameWorld().getDSigns().add(dSign);
|
||||
|
||||
dSign.onInit();
|
||||
if (!dSign.hasTriggers()) {
|
||||
dSign.onTrigger();
|
||||
}
|
||||
}
|
||||
|
||||
getSign().getBlock().setType(Material.AIR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DSignType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.sign;
|
||||
|
||||
import io.github.dre2n.commons.util.NumberUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class SignScript {
|
||||
|
||||
DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
|
||||
private String name;
|
||||
|
||||
private List<String[]> signs;
|
||||
|
||||
/**
|
||||
* @param file
|
||||
* the script file
|
||||
*/
|
||||
public SignScript(File file) {
|
||||
this(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name of the Announcer
|
||||
* @param config
|
||||
* the config that stores the information
|
||||
*/
|
||||
public SignScript(String name, FileConfiguration config) {
|
||||
this.name = name;
|
||||
signs = new ArrayList<>(config.getKeys(false).size());
|
||||
|
||||
for (String key : config.getKeys(false)) {
|
||||
int index = NumberUtil.parseInt(key);
|
||||
String[] lines = new String[]{};
|
||||
lines = config.getStringList(key).toArray(lines);
|
||||
signs.add(index, lines);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the announcer
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the signs
|
||||
*/
|
||||
public List<String[]> getSigns() {
|
||||
return signs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* the index number
|
||||
* @return the lines of the sign
|
||||
*/
|
||||
public String[] getLines(int index) {
|
||||
return signs.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* the index number
|
||||
* @param lines
|
||||
* the lines to set
|
||||
*/
|
||||
public void setLines(int index, String[] lines) {
|
||||
signs.set(index, lines);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.sign;
|
||||
|
||||
import io.github.dre2n.commons.util.FileUtil;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class SignScripts {
|
||||
|
||||
private List<SignScript> scripts = new ArrayList<>();
|
||||
|
||||
public SignScripts(File file) {
|
||||
if (file.isDirectory()) {
|
||||
for (File script : FileUtil.getFilesForFolder(file)) {
|
||||
scripts.add(new SignScript(script));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the script that has the name
|
||||
*/
|
||||
public SignScript getByName(String name) {
|
||||
for (SignScript script : scripts) {
|
||||
if (script.getName().equalsIgnoreCase(name)) {
|
||||
return script;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the scripts
|
||||
*/
|
||||
public List<SignScript> getScripts() {
|
||||
return scripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param script
|
||||
* the SignScript to add
|
||||
*/
|
||||
public void addScript(SignScript script) {
|
||||
scripts.add(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param script
|
||||
* the SignScript to remove
|
||||
*/
|
||||
public void removeScript(SignScript script) {
|
||||
scripts.remove(script);
|
||||
}
|
||||
|
||||
}
|
@ -35,8 +35,8 @@ public class SoundMessageSign extends DSign {
|
||||
private String msg;
|
||||
private CopyOnWriteArrayList<Player> done = new CopyOnWriteArrayList<>();
|
||||
|
||||
public SoundMessageSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public SoundMessageSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,10 +50,8 @@ public class SoundMessageSign extends DSign {
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
String lines[] = getSign().getLines();
|
||||
|
||||
if (!lines[1].isEmpty()) {
|
||||
String msg = getGameWorld().getConfig().getMsg(NumberUtil.parseInt(lines[1]), true);
|
||||
String msg = getGame().getRules().getMsg(NumberUtil.parseInt(lines[1]), true);
|
||||
if (msg != null) {
|
||||
this.msg = msg;
|
||||
getSign().getBlock().setType(Material.AIR);
|
||||
|
@ -27,8 +27,8 @@ public class StartSign extends DSign {
|
||||
|
||||
private DSignType type = DSignTypeDefault.START;
|
||||
|
||||
public StartSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public StartSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
130
src/main/java/io/github/dre2n/dungeonsxl/sign/TeleportSign.java
Normal file
130
src/main/java/io/github/dre2n/dungeonsxl/sign/TeleportSign.java
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.sign;
|
||||
|
||||
import io.github.dre2n.commons.util.NumberUtil;
|
||||
import io.github.dre2n.dungeonsxl.world.GameWorld;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Milan Albrecht
|
||||
*/
|
||||
public class TeleportSign extends DSign {
|
||||
|
||||
private DSignType type = DSignTypeDefault.TELEPORT;
|
||||
|
||||
private Location location;
|
||||
|
||||
public TeleportSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check() {
|
||||
String lines[] = getSign().getLines();
|
||||
for (int i = 1; i <= 2; i++) {
|
||||
if (!lines[i].isEmpty()) {
|
||||
if (letterToYaw(lines[i].charAt(0)) == -1) {
|
||||
String[] loc = lines[i].split(",");
|
||||
if (loc.length != 3) {
|
||||
return false;
|
||||
}
|
||||
NumberUtil.parseDouble(loc[0]);
|
||||
NumberUtil.parseDouble(loc[1]);
|
||||
NumberUtil.parseDouble(loc[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
location = getSign().getLocation().add(0.5, 0, 0.5);
|
||||
location.setYaw(letterToYaw(((org.bukkit.material.Sign) getSign().getData()).getFacing().getOppositeFace().name().charAt(0)));
|
||||
String lines[] = getSign().getLines();
|
||||
for (int i = 1; i <= 2; i++) {
|
||||
if (!lines[i].isEmpty()) {
|
||||
int yaw = letterToYaw(lines[i].charAt(0));
|
||||
if (yaw != -1) {
|
||||
location.setYaw(yaw);
|
||||
} else {
|
||||
String[] loc = lines[i].split(",");
|
||||
if (loc.length == 3) {
|
||||
double x = NumberUtil.parseDouble(loc[0]);
|
||||
double y = NumberUtil.parseDouble(loc[1]);
|
||||
double z = NumberUtil.parseDouble(loc[2]);
|
||||
|
||||
// If round number, add 0.5 to tp to middle of block
|
||||
x = NumberUtil.parseInt(loc[0]) + 0.5;
|
||||
z = NumberUtil.parseInt(loc[2]) + 0.5;
|
||||
|
||||
location.setX(x);
|
||||
location.setY(y);
|
||||
location.setZ(z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
getSign().getBlock().setType(Material.AIR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrigger() {
|
||||
if (location != null) {
|
||||
for (Player player : getGameWorld().getWorld().getPlayers()) {
|
||||
player.teleport(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPlayerTrigger(Player player) {
|
||||
if (location != null) {
|
||||
player.teleport(location);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DSignType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public static int letterToYaw(char c) {
|
||||
switch (c) {
|
||||
case 'S':
|
||||
case 's':
|
||||
return 0;
|
||||
case 'W':
|
||||
case 'w':
|
||||
return 90;
|
||||
case 'N':
|
||||
case 'n':
|
||||
return 180;
|
||||
case 'E':
|
||||
case 'e':
|
||||
return -90;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -38,8 +38,8 @@ public class TriggerSign extends DSign {
|
||||
private int triggerId;
|
||||
private boolean initialized;
|
||||
|
||||
public TriggerSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public TriggerSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,8 +34,8 @@ public class WaveSign extends DSign {
|
||||
private double mobCountIncreaseRate;
|
||||
private boolean teleport;
|
||||
|
||||
public WaveSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public WaveSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,7 +75,6 @@ public class WaveSign extends DSign {
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
String[] lines = getSign().getLines();
|
||||
if (!lines[1].isEmpty()) {
|
||||
mobCountIncreaseRate = NumberUtil.parseDouble(lines[1], 2);
|
||||
}
|
||||
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.task;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.announcer.Announcer;
|
||||
import io.github.dre2n.dungeonsxl.game.Game;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.util.ProgressBar;
|
||||
import java.util.HashSet;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class AnnouncerStartGameTask extends BukkitRunnable {
|
||||
|
||||
private Announcer announcer;
|
||||
private ProgressBar bar;
|
||||
|
||||
public AnnouncerStartGameTask(Announcer announcer) {
|
||||
this.announcer = announcer;
|
||||
|
||||
HashSet<Player> players = new HashSet<>();
|
||||
for (DGroup dGroup : announcer.getDGroups()) {
|
||||
for (Player player : dGroup.getPlayers()) {
|
||||
players.add(player);
|
||||
}
|
||||
}
|
||||
bar = new ProgressBar(players, 30);
|
||||
bar.runTaskTimer(DungeonsXL.getInstance(), 0L, 20L);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the progress bar the players see until they get teleported
|
||||
*/
|
||||
public ProgressBar getProgressBar() {
|
||||
return bar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Game game = new Game(announcer.getDGroups().get(0), announcer.getMapName());
|
||||
|
||||
for (DGroup dGroup : announcer.getDGroups()) {
|
||||
game.getDGroups().set(announcer.getDGroups().indexOf(dGroup), dGroup);
|
||||
}
|
||||
|
||||
for (Player player : game.getPlayers()) {
|
||||
new DGamePlayer(player, game.getWorld());
|
||||
}
|
||||
|
||||
announcer.endStartTask();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.task;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.announcer.Announcer;
|
||||
import io.github.dre2n.dungeonsxl.announcer.Announcers;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class AnnouncerTask extends BukkitRunnable {
|
||||
|
||||
DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
|
||||
private List<Announcer> announcers;
|
||||
private int index;
|
||||
|
||||
public AnnouncerTask(Announcers announcers) {
|
||||
this.announcers = announcers.getAnnouncers();
|
||||
index = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Announcer announcer = announcers.get(index);
|
||||
List<String> worlds = announcer.getWorlds();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (plugin.getDPlayers().getByPlayer(player).isAnnouncerEnabled()) {
|
||||
if (worlds.isEmpty() || worlds.contains(player.getWorld().getName())) {
|
||||
announcer.send(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
index++;
|
||||
if (index == announcers.size()) {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.task;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.mob.DMob;
|
||||
import io.github.dre2n.dungeonsxl.mob.DMobType;
|
||||
import io.github.dre2n.dungeonsxl.sign.DMobSign;
|
||||
@ -71,10 +72,10 @@ public class MobSpawnTask extends BukkitRunnable {
|
||||
}
|
||||
|
||||
// Check custom mobs
|
||||
DMobType mobType = DMobType.getByName(sign.getMob(), gameWorld.getConfig().getMobTypes());
|
||||
DMobType mobType = DungeonsXL.getInstance().getDMobTypes().getByName(sign.getMob());
|
||||
|
||||
if (mobType != null) {
|
||||
mobType.spawn(GameWorld.getByWorld(world), spawnLoc);
|
||||
mobType.spawn(gameWorld, spawnLoc);
|
||||
}
|
||||
|
||||
// Set the amount
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Daniel Saukel
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -21,6 +21,7 @@ import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent;
|
||||
import io.github.dre2n.dungeonsxl.game.Game;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -72,7 +73,7 @@ public class TimeIsRunningTask extends BukkitRunnable {
|
||||
if (!dPlayerKickEvent.isCancelled()) {
|
||||
MessageUtil.broadcastMessage(DMessages.PLAYER_TIME_KICK.getMessage(player.getName()));
|
||||
dPlayer.leave();
|
||||
if (dGroup.getGameWorld().getConfig().getKeepInventoryOnEscape()) {
|
||||
if (Game.getByDGroup(dGroup).getRules().getKeepInventoryOnEscape()) {
|
||||
dPlayer.applyRespawnInventory();
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
package io.github.dre2n.dungeonsxl.task;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DInstancePlayer;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
@ -27,7 +27,7 @@ public class UpdateTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (DGamePlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDGamePlayers()) {
|
||||
for (DInstancePlayer dPlayer : DungeonsXL.getInstance().getDPlayers().getDInstancePlayers()) {
|
||||
dPlayer.update(false);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.util;
|
||||
|
||||
import io.github.dre2n.commons.util.NumberUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Deprecated deserialization methods for compatibility with 1.7.8-1.8.x
|
||||
*
|
||||
* @author Frank Baumann, Daniel Saukel
|
||||
*/
|
||||
@Deprecated
|
||||
public class DeserialisazionUtil {
|
||||
|
||||
public static List<ItemStack> deserializeStackList(List<String> items) {
|
||||
List<ItemStack> itemStacks = new ArrayList<>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return itemStacks;
|
||||
}
|
||||
|
||||
}
|
104
src/main/java/io/github/dre2n/dungeonsxl/util/ProgressBar.java
Normal file
104
src/main/java/io/github/dre2n/dungeonsxl/util/ProgressBar.java
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2016 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.github.dre2n.dungeonsxl.util;
|
||||
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class ProgressBar extends BukkitRunnable {
|
||||
|
||||
public static final String BAR = "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588";
|
||||
|
||||
private Set<UUID> players = new HashSet<>();
|
||||
private int seconds;
|
||||
private int secondsLeft;
|
||||
|
||||
public ProgressBar(Set<Player> players, int seconds) {
|
||||
for (Player player : players) {
|
||||
this.players.add(player.getUniqueId());
|
||||
}
|
||||
this.seconds = seconds;
|
||||
this.secondsLeft = seconds;
|
||||
}
|
||||
|
||||
public ProgressBar(Player player, int seconds) {
|
||||
this.players.add(player.getUniqueId());
|
||||
this.seconds = seconds;
|
||||
this.secondsLeft = seconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* the player to add
|
||||
*/
|
||||
public void addPlayer(Player player) {
|
||||
players.add(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* the player to remove
|
||||
*/
|
||||
public void removePlayer(Player player) {
|
||||
players.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int i = (int) Math.round(((double) secondsLeft / (double) seconds) * 10);
|
||||
StringBuilder bar = new StringBuilder(BAR);
|
||||
bar.insert(10 - i, ChatColor.DARK_RED.toString());
|
||||
for (UUID uuid : players) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player != null && player.isOnline()) {
|
||||
MessageUtil.sendActionBarMessage(player, ChatColor.GREEN.toString() + bar.toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (secondsLeft == 0) {
|
||||
cancel();
|
||||
} else {
|
||||
secondsLeft--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the progress bar to a player
|
||||
*/
|
||||
public static BukkitTask sendProgressBar(Player player, int seconds) {
|
||||
return new ProgressBar(player, seconds).runTaskTimer(DungeonsXL.getInstance(), 0L, 20L);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the progress bar to multiple players
|
||||
*/
|
||||
public static BukkitTask sendProgressBar(Set<Player> players, int seconds) {
|
||||
return new ProgressBar(players, seconds).runTaskTimer(DungeonsXL.getInstance(), 0L, 20L);
|
||||
}
|
||||
|
||||
}
|
@ -25,14 +25,10 @@ import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
|
||||
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.game.Game;
|
||||
import io.github.dre2n.dungeonsxl.game.GamePlaceableBlock;
|
||||
import io.github.dre2n.dungeonsxl.mob.DMob;
|
||||
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||
import io.github.dre2n.dungeonsxl.requirement.Requirement;
|
||||
import io.github.dre2n.dungeonsxl.reward.RewardChest;
|
||||
import io.github.dre2n.dungeonsxl.sign.DSign;
|
||||
import io.github.dre2n.dungeonsxl.sign.MobSign;
|
||||
@ -42,22 +38,21 @@ import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.bukkit.Bukkit;
|
||||
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;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* @author Frank Baumann, Milan Albrecht, Daniel Saukel
|
||||
@ -76,7 +71,7 @@ public class GameWorld {
|
||||
private Location locStart;
|
||||
private boolean isPlaying = false;
|
||||
private int id;
|
||||
private CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<>();
|
||||
private List<ItemStack> secureObjects = new ArrayList<>();
|
||||
private CopyOnWriteArrayList<Chunk> loadedChunks = new CopyOnWriteArrayList<>();
|
||||
|
||||
private CopyOnWriteArrayList<Sign> signClass = new CopyOnWriteArrayList<>();
|
||||
@ -107,6 +102,11 @@ public class GameWorld {
|
||||
}
|
||||
}
|
||||
|
||||
public GameWorld(String name) {
|
||||
this();
|
||||
load(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* the Game connected to the GameWorld
|
||||
@ -244,7 +244,7 @@ public class GameWorld {
|
||||
/**
|
||||
* @return the secureObjects
|
||||
*/
|
||||
public CopyOnWriteArrayList<Material> getSecureObjects() {
|
||||
public List<ItemStack> getSecureObjects() {
|
||||
return secureObjects;
|
||||
}
|
||||
|
||||
@ -252,7 +252,7 @@ public class GameWorld {
|
||||
* @param secureObjects
|
||||
* the secureObjects to set
|
||||
*/
|
||||
public void setSecureObjects(CopyOnWriteArrayList<Material> secureObjects) {
|
||||
public void setSecureObjects(List<ItemStack> secureObjects) {
|
||||
this.secureObjects = secureObjects;
|
||||
}
|
||||
|
||||
@ -361,7 +361,7 @@ public class GameWorld {
|
||||
*/
|
||||
public WorldConfig getConfig() {
|
||||
if (worldConfig == null) {
|
||||
return plugin.getDefaultConfig();
|
||||
return plugin.getMainConfig().getDefaultWorldConfig();
|
||||
}
|
||||
|
||||
return worldConfig;
|
||||
@ -470,20 +470,18 @@ public class GameWorld {
|
||||
}
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static GameWorld load(String name) {
|
||||
public void load(String name) {
|
||||
GameWorldLoadEvent event = new GameWorldLoadEvent(name);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
File file = new File(plugin.getDataFolder(), "/maps/" + name);
|
||||
|
||||
if (file.exists()) {
|
||||
GameWorld gameWorld = new GameWorld();
|
||||
gameWorld.mapName = name;
|
||||
mapName = name;
|
||||
|
||||
// Unload empty editWorlds
|
||||
for (EditWorld editWorld : plugin.getEditWorlds()) {
|
||||
@ -493,61 +491,55 @@ public class GameWorld {
|
||||
}
|
||||
|
||||
// Config einlesen
|
||||
gameWorld.worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + gameWorld.mapName, "config.yml"));
|
||||
worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + mapName, "config.yml"));
|
||||
|
||||
// Secure Objects
|
||||
gameWorld.secureObjects = gameWorld.worldConfig.getSecureObjects();
|
||||
secureObjects = worldConfig.getSecureObjects();
|
||||
|
||||
if (Bukkit.getWorld("DXL_Game_" + gameWorld.id) == null) {
|
||||
if (Bukkit.getWorld("DXL_Game_" + id) == null) {
|
||||
|
||||
// World
|
||||
FileUtil.copyDirectory(file, new File("DXL_Game_" + gameWorld.id), DungeonsXL.EXCLUDED_FILES);
|
||||
FileUtil.copyDirectory(file, new File("DXL_Game_" + id), DungeonsXL.EXCLUDED_FILES);
|
||||
|
||||
// Id File
|
||||
File idFile = new File("DXL_Game_" + gameWorld.id + "/.id_" + name);
|
||||
File idFile = new File("DXL_Game_" + id + "/.id_" + name);
|
||||
try {
|
||||
idFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
gameWorld.world = plugin.getServer().createWorld(WorldCreator.name("DXL_Game_" + gameWorld.id));
|
||||
world = plugin.getServer().createWorld(WorldCreator.name("DXL_Game_" + id));
|
||||
|
||||
ObjectInputStream os;
|
||||
try {
|
||||
os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder() + "/maps/" + gameWorld.mapName + "/DXLData.data")));
|
||||
os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder() + "/maps/" + 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);
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
checkSign(block);
|
||||
}
|
||||
|
||||
os.close();
|
||||
|
||||
} catch (FileNotFoundException exception) {
|
||||
plugin.getLogger().info("Could not find any sign data for the world \"" + name + "\"!");
|
||||
MessageUtil.log(plugin, "Could not find any sign data for the world \"" + name + "\"!");
|
||||
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return gameWorld;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
public static GameWorld getByWorld(World world) {
|
||||
for (GameWorld gameWorld : plugin.getGameWorlds()) {
|
||||
if (gameWorld.getWorld() == null) {
|
||||
continue;
|
||||
|
||||
} else if (gameWorld.getWorld().equals(world)) {
|
||||
if (gameWorld.getWorld() != null && gameWorld.getWorld().equals(world)) {
|
||||
return gameWorld;
|
||||
}
|
||||
}
|
||||
@ -561,155 +553,4 @@ public class GameWorld {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canPlayDungeon(String map, Player player) {
|
||||
if (DPermissions.hasPermission(player, DPermissions.IGNORE_TIME_LIMIT)) {
|
||||
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 (DPermissions.hasPermission(dGroup.getCaptain(), DPermissions.IGNORE_TIME_LIMIT)) {
|
||||
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 (DPermissions.hasPermission(player, DPermissions.IGNORE_REQUIREMENTS)) {
|
||||
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);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
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 (DPermissions.hasPermission(dGroup.getCaptain(), DPermissions.IGNORE_REQUIREMENTS)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Player player : dGroup.getPlayers()) {
|
||||
if (!checkRequirements(map, player)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ version: ${project.version}
|
||||
authors: [Frank Baumann, Milan Albrecht, Tobias Schmitz, Daniel Saukel]
|
||||
description: ${project.description}
|
||||
website: ${project.url}
|
||||
softdepend: [BlueRoseCommons, CommandsXL, Vault, CustomMobs, InsaneMobs, MythicMobs]
|
||||
softdepend: [BlueRoseCommons, CommandsXL, ItemsXL, Vault, CustomMobs, InsaneMobs, MythicMobs]
|
||||
commands:
|
||||
dungeonsxl:
|
||||
description: Reference command for DungeonsXL.
|
||||
|
@ -27,8 +27,8 @@ public class CustomSign extends DSign {
|
||||
|
||||
private DSignType type = DSignTypeCustom.CUSTOM;
|
||||
|
||||
public CustomSign(Sign sign, GameWorld gameWorld) {
|
||||
super(sign, gameWorld);
|
||||
public CustomSign(Sign sign, String[] lines, GameWorld gameWorld) {
|
||||
super(sign, lines, gameWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user