General cleanup

Finished to large extent. Including:
- Replaced many field references with getters and setters
- Replaced many "if (...) { if (...) {" blocks with "if (!...) {return}"
to clean up the code a littlebit
- Changed package naming to "io.github.dre2n"
- Rewrote the command system
- Rewrote the lives system
- Rewrote the permissions system to use SuperPerms instead when possible
- Rewrote the multi version handler and added code to support Minecraft
1.9 (obviously untested)
- Added CommandsXL command signs
- Renamed "dungeons" folder to "maps" and prepared a bit more for the
upcoming multi floor support
- Bugfixes
- ...and a looooot more
This commit is contained in:
Daniel Saukel 2015-12-12 21:31:43 +01:00
parent c98e52a925
commit cf17fcf32c
129 changed files with 9635 additions and 7718 deletions

View File

@ -1,17 +0,0 @@
package com.dre.dungeonsxl;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.inventory.ItemStack;
public class DClass {
public CopyOnWriteArrayList<ItemStack> items = new CopyOnWriteArrayList<ItemStack>();
public String name;
public boolean hasDog;
public DClass(String name, CopyOnWriteArrayList<ItemStack> items, boolean hasDog) {
this.items = items;
this.name = name;
this.hasDog = hasDog;
}
}

View File

@ -1,133 +0,0 @@
package com.dre.dungeonsxl;
import java.io.File;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.game.GameWorld;
public class DGroup {
public static CopyOnWriteArrayList<DGroup> dgroups = new CopyOnWriteArrayList<DGroup>();
private CopyOnWriteArrayList<Player> players = new CopyOnWriteArrayList<Player>();
private String dungeonname;
private GameWorld gworld;
public boolean isPlaying;
public DGroup(Player player, String dungeonname) {
dgroups.add(this);
this.getPlayers().add(player);
this.isPlaying = false;
this.setDungeonname(dungeonname);
}
public void addPlayer(Player player) {
// Send message
for (Player groupPlayer : this.getPlayers()) {
P.p.msg(groupPlayer, P.p.language.get("Player_JoinGroup", player.getName()));
}
// Add player
this.getPlayers().add(player);
}
public void removePlayer(Player player) {
this.getPlayers().remove(player);
DGSign.updatePerGroup(this);
// Send message
for (Player groupPlayer : this.getPlayers()) {
P.p.msg(groupPlayer, P.p.language.get("Player_LeftGroup", player.getName()));
}
// Check group
if (this.isEmpty()) {
this.remove();
}
}
public boolean isEmpty() {
return this.getPlayers().isEmpty();
}
public void remove() {
dgroups.remove(this);
DGSign.updatePerGroup(this);
}
public void startGame() {
this.isPlaying = true;
getGworld().startGame();
for (Player player : getPlayers()) {
DPlayer dplayer = DPlayer.get(player);
dplayer.respawn();
if (P.p.mainConfig.enableEconomy) {
File file = new File(P.p.getDataFolder() + "/dungeons/" + dungeonname + "/config.yml");
if (file != null) {
DConfig confReader = new DConfig(file);
if (confReader != null) {
P.p.economy.withdrawPlayer(player, confReader.getFee());
}
}
}
}
DGSign.updatePerGroup(this);
}
// Statics
public static DGroup get(Player player) {
for (DGroup dgroup : dgroups) {
if (dgroup.getPlayers().contains(player)) {
return dgroup;
}
}
return null;
}
public static DGroup get(GameWorld gworld) {
for (DGroup dgroup : dgroups) {
if (dgroup.getGworld() == gworld) {
return dgroup;
}
}
return null;
}
public static void leaveGroup(Player player) {
for (DGroup dgroup : dgroups) {
if (dgroup.getPlayers().contains(player)) {
dgroup.getPlayers().remove(player);
}
}
}
// Getters and setters
public CopyOnWriteArrayList<Player> getPlayers() {
return players;
}
public void setPlayers(CopyOnWriteArrayList<Player> players) {
this.players = players;
}
public GameWorld getGworld() {
return gworld;
}
public void setGworld(GameWorld gworld) {
this.gworld = gworld;
}
public String getDungeonname() {
return dungeonname;
}
public void setDungeonname(String dungeonname) {
this.dungeonname = dungeonname;
}
}

View File

@ -1,41 +0,0 @@
package com.dre.dungeonsxl;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
public class DLootInventory {
public static CopyOnWriteArrayList<DLootInventory> LootInventorys = new CopyOnWriteArrayList<DLootInventory>();
public Inventory inventory;
public InventoryView inventoryView;
public Player player;
public long time;
public DLootInventory(Player player, ItemStack[] istacks) {
LootInventorys.add(this);
this.inventory = Bukkit.createInventory(player, 54, "Belohnungen");
for (ItemStack istack : istacks) {
if (istack != null) {
this.inventory.addItem(istack);
}
}
this.player = player;
}
public static DLootInventory get(Player player) {
for (DLootInventory inventory : LootInventorys) {
if (inventory.player == player) {
return inventory;
}
}
return null;
}
}

View File

@ -1,59 +0,0 @@
package com.dre.dungeonsxl;
import java.io.File;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
public class MainConfig {
public String language = "en";
public boolean enableEconomy = false;
/* Tutorial */
public boolean tutorialActivated = false;
public String tutorialDungeon = "tutorial";
public String tutorialStartGroup = "default";
public String tutorialEndGroup = "player";
/* Default Dungeon Settings */
public DConfig defaultDungeon;
public MainConfig(File file) {
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
/* Main Config */
if (configFile.contains("language")) {
this.language = configFile.getString("language");
}
if (configFile.contains("enableEconomy")) {
this.enableEconomy = configFile.getBoolean("enableEconomy");
}
if (configFile.contains("tutorial.activated")) {
this.tutorialActivated = configFile.getBoolean("tutorial.activated");
}
if (configFile.contains("tutorial.dungeon")) {
this.tutorialDungeon = configFile.getString("tutorial.dungeon");
}
if (configFile.contains("tutorial.startgroup")) {
this.tutorialStartGroup = configFile.getString("tutorial.startgroup");
}
if (configFile.contains("tutorial.endgroup")) {
this.tutorialEndGroup = configFile.getString("tutorial.endgroup");
}
/* Default Dungeon Config */
ConfigurationSection configSetion = configFile.getConfigurationSection("default");
if (configSetion != null) {
defaultDungeon = new DConfig(configSetion);
DConfig.mainConfig = defaultDungeon;
}
}
}

View File

@ -1,466 +0,0 @@
package com.dre.dungeonsxl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.FileChannel;
import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import com.dre.dungeonsxl.commands.DCommandRoot;
import com.dre.dungeonsxl.game.GameWorld;
import com.dre.dungeonsxl.listener.BlockListener;
import com.dre.dungeonsxl.listener.CommandListener;
import com.dre.dungeonsxl.listener.EntityListener;
import com.dre.dungeonsxl.listener.HangingListener;
import com.dre.dungeonsxl.listener.PlayerListener;
import com.dre.dungeonsxl.listener.WorldListener;
import com.dre.dungeonsxl.listener.player.PlayerDeathListener;
import com.dre.dungeonsxl.multiversionhandler.MultiVersionHandler;
public class P extends JavaPlugin {
public static P p;
// Lives
public HashMap<Player, Integer> lives;
// Listener
private static Listener entityListener;
private static Listener playerListener;
private static Listener blockListener;
private static Listener worldListener;
private static Listener hangingListener;
private static Listener playerDeathListener;
// Main Config Reader
public MainConfig mainConfig;
// Language Reader
public LanguageReader language;
// Chatspyer
public CopyOnWriteArrayList<Player> chatSpyer = new CopyOnWriteArrayList<Player>();
@Override
public void onEnable() {
p = this;
// Lives
lives = new HashMap<Player, Integer>();
// Commands
getCommand("dungeonsxl").setExecutor(new CommandListener());
// Load Language
language = new LanguageReader(new File(p.getDataFolder(), "languages/en.yml"));
// Load Config
mainConfig = new MainConfig(new File(p.getDataFolder(), "config.yml"));
// Load Language 2
language = new LanguageReader(new File(p.getDataFolder(), "languages/" + mainConfig.language + ".yml"));
// Init Commands
new DCommandRoot();
// InitFolders
this.initFolders();
// Setup Permissions
this.setupPermissions();
// Setup Economy
this.setupEconomy();
// Listener
entityListener = new EntityListener();
playerListener = new PlayerListener();
blockListener = new BlockListener();
worldListener = new WorldListener();
hangingListener = new HangingListener();
playerDeathListener = new PlayerDeathListener();
Bukkit.getServer().getPluginManager().registerEvents(entityListener, this);
Bukkit.getServer().getPluginManager().registerEvents(playerListener, this);
Bukkit.getServer().getPluginManager().registerEvents(blockListener, this);
Bukkit.getServer().getPluginManager().registerEvents(worldListener, this);
Bukkit.getServer().getPluginManager().registerEvents(hangingListener, this);
Bukkit.getServer().getPluginManager().registerEvents(playerDeathListener, this);
// Load All
this.loadAll();
// Scheduler
this.initSchedulers();
// MSG
this.log(this.getDescription().getName() + " enabled!");
if (!(MultiVersionHandler.supported.contains(MultiVersionHandler.getInternals()))) {
this.log("Warning: Your CraftBukkit version is deprecated. DungeonsXL does not support it.");
}
}
@Override
public void onDisable() {
// Save
this.saveData();
language.save();
// DPlayer leaves World
for (DPlayer dplayer : DPlayer.players) {
dplayer.leave();
}
// Delete all Data
DGroup.dgroups.clear();
DGSign.dgsigns.clear();
DLootInventory.LootInventorys.clear();
DPlayer.players.clear();
DPortal.portals.clear();
LeaveSign.lsigns.clear();
DCommandRoot.root.commands.clear();
// Delete Worlds
GameWorld.deleteAll();
EditWorld.deleteAll();
// Disable listeners
HandlerList.unregisterAll(p);
// Stop shedulers
p.getServer().getScheduler().cancelTasks(this);
// MSG
this.log(this.getDescription().getName() + " disabled!");
}
// Init.
public void initFolders() {
// Check Folder
File folder = new File(this.getDataFolder() + "");
if (!folder.exists()) {
folder.mkdir();
}
folder = new File(this.getDataFolder() + File.separator + "dungeons");
if (!folder.exists()) {
folder.mkdir();
}
}
public void initSchedulers() {
p.getServer().getScheduler().scheduleSyncRepeatingTask(p, new Runnable() {
public void run() {
for (GameWorld gworld : GameWorld.gworlds) {
if (gworld.world.getPlayers().isEmpty()) {
if (DPlayer.get(gworld.world).isEmpty()) {
gworld.delete();
}
}
}
for (EditWorld eworld : EditWorld.eworlds) {
if (eworld.world.getPlayers().isEmpty()) {
eworld.delete();
}
}
}
}, 0L, 1200L);
p.getServer().getScheduler().scheduleSyncRepeatingTask(p, new Runnable() {
public void run() {
GameWorld.update();
DPlayer.update(true);
}
}, 0L, 20L);
p.getServer().getScheduler().scheduleSyncRepeatingTask(p, new Runnable() {
public void run() {
DPlayer.update(false);
}
}, 0L, 2L);
}
// Permissions
public Permission permission = null;
private Boolean setupPermissions() {
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
if (permissionProvider != null) {
permission = permissionProvider.getProvider();
}
return (permission != null);
}
public Boolean GroupEnabled(String group) {
for (String agroup : permission.getGroups()) {
if (agroup.equalsIgnoreCase(group)) {
return true;
}
}
return false;
}
// Economy
public Economy economy = null;
private Boolean setupEconomy() {
if (mainConfig.enableEconomy) {
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
if (economyProvider != null) {
economy = economyProvider.getProvider();
}
return (economy != null);
} else {
return false;
}
}
// Save and Load
public void saveData() {
File file = new File(this.getDataFolder(), "data.yml");
FileConfiguration configFile = new YamlConfiguration();
DPortal.save(configFile);
DGSign.save(configFile);
LeaveSign.save(configFile);
try {
configFile.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
public void loadAll() {
// Load world data
File file = new File(this.getDataFolder(), "data.yml");
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
DPortal.load(configFile);
DGSign.load(configFile);
LeaveSign.load(configFile);
// Load saved players
DSavePlayer.load();
// Check Worlds
this.checkWorlds();
}
public void checkWorlds() {
File serverDir = new File(".");
for (File file : serverDir.listFiles()) {
if (file.getName().contains("DXL_Edit_") && file.isDirectory()) {
for (File dungeonFile : file.listFiles()) {
if (dungeonFile.getName().contains(".id_")) {
String dungeonName = dungeonFile.getName().substring(4);
this.copyDirectory(file, new File(p.getDataFolder(), "/dungeons/" + dungeonName));
this.deletenotusingfiles(new File(p.getDataFolder(), "/dungeons/" + dungeonName));
}
}
this.removeDirectory(file);
} else if (file.getName().contains("DXL_Game_") && file.isDirectory()) {
this.removeDirectory(file);
}
}
}
// File Control
public boolean removeDirectory(File directory) {
if (directory.isDirectory()) {
for (File f : directory.listFiles()) {
if (!removeDirectory(f))
return false;
}
}
return directory.delete();
}
public void copyFile(File in, File out) throws IOException {
FileChannel inChannel = null;
FileChannel outChannel = null;
try {
inChannel = new FileInputStream(in).getChannel();
outChannel = new FileOutputStream(out).getChannel();
inChannel.transferTo(0, inChannel.size(), outChannel);
} catch (IOException e) {
throw e;
} finally {
if (inChannel != null)
inChannel.close();
if (outChannel != null)
outChannel.close();
}
}
public String[] excludedFiles = { "config.yml", "uid.dat", "DXLData.data" };
public void copyDirectory(File sourceLocation, File targetLocation) {
if (sourceLocation.isDirectory()) {
if (!targetLocation.exists()) {
targetLocation.mkdir();
}
String[] children = sourceLocation.list();
for (int i = 0; i < children.length; i++) {
boolean isOk = true;
for (String excluded : excludedFiles) {
if (children[i].contains(excluded)) {
isOk = false;
break;
}
}
if (isOk) {
copyDirectory(new File(sourceLocation, children[i]), new File(targetLocation, children[i]));
}
}
} else {
try {
if (!targetLocation.getParentFile().exists()) {
createDirectory(targetLocation.getParentFile().getAbsolutePath());
targetLocation.createNewFile();
} else if (!targetLocation.exists()) {
targetLocation.createNewFile();
}
InputStream in = new FileInputStream(sourceLocation);
OutputStream out = new FileOutputStream(targetLocation);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
} catch (Exception e) {
if (e.getMessage().contains("Zugriff") || e.getMessage().contains("Access"))
P.p.log("Error: " + e.getMessage() + " // Access denied");
else
P.p.log("Error: " + e.getMessage());
}
}
}
public void createDirectory(String s) {
if (!new File(s).getParentFile().exists()) {
createDirectory(new File(s).getParent());
}
new File(s).mkdir();
}
public void deletenotusingfiles(File directory) {
File[] files = directory.listFiles();
for (File file : files) {
if (file.getName().equalsIgnoreCase("uid.dat") || file.getName().contains(".id_")) {
file.delete();
}
}
}
// Msg
public void msg(CommandSender sender, String msg) {
msg = replaceColors(msg);
sender.sendMessage(ChatColor.DARK_GREEN + "[DXL] " + ChatColor.WHITE + msg);
}
public void msg(CommandSender sender, String msg, boolean zusatz) {
msg = replaceColors(msg);
if (zusatz) {
sender.sendMessage(ChatColor.DARK_GREEN + "[DXL]" + ChatColor.WHITE + msg);
} else {
sender.sendMessage(ChatColor.WHITE + msg);
}
}
private String replaceColors(String msg) {
if (msg != null) {
msg = msg.replace("&0", ChatColor.getByChar("0").toString());
msg = msg.replace("&1", ChatColor.getByChar("1").toString());
msg = msg.replace("&2", ChatColor.getByChar("2").toString());
msg = msg.replace("&3", ChatColor.getByChar("3").toString());
msg = msg.replace("&4", ChatColor.getByChar("4").toString());
msg = msg.replace("&5", ChatColor.getByChar("5").toString());
msg = msg.replace("&6", ChatColor.getByChar("6").toString());
msg = msg.replace("&7", ChatColor.getByChar("7").toString());
msg = msg.replace("&8", ChatColor.getByChar("8").toString());
msg = msg.replace("&9", ChatColor.getByChar("9").toString());
msg = msg.replace("&a", ChatColor.getByChar("a").toString());
msg = msg.replace("&b", ChatColor.getByChar("b").toString());
msg = msg.replace("&c", ChatColor.getByChar("c").toString());
msg = msg.replace("&d", ChatColor.getByChar("d").toString());
msg = msg.replace("&e", ChatColor.getByChar("e").toString());
msg = msg.replace("&f", ChatColor.getByChar("f").toString());
msg = msg.replace("&k", ChatColor.getByChar("k").toString());
msg = msg.replace("&l", ChatColor.getByChar("l").toString());
msg = msg.replace("&m", ChatColor.getByChar("m").toString());
msg = msg.replace("&n", ChatColor.getByChar("n").toString());
msg = msg.replace("&o", ChatColor.getByChar("o").toString());
msg = msg.replace("&r", ChatColor.getByChar("r").toString());
}
return msg;
}
// Misc.
public EntityType getEntitiyType(String name) {
for (EntityType type : EntityType.values()) {
if (name.equalsIgnoreCase(type.name())) {
return type;
}
}
return null;
}
public int parseInt(String string) {
return NumberUtils.toInt(string, 0);
}
public Player getOfflinePlayer(String player, UUID uuid) {
return MultiVersionHandler.getOfflinePlayer(player, uuid);
}
public Player getOfflinePlayer(String player, UUID uuid, Location location) {
return MultiVersionHandler.getOfflinePlayer(player, uuid, location);
}
// -------------------------------------------- //
// LOGGING
// -------------------------------------------- //
public void log(String msg) {
this.msg(Bukkit.getConsoleSender(), msg);
}
}

View File

@ -1,35 +0,0 @@
package com.dre.dungeonsxl.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.DPlayer;
public class CMDChat extends DCommand {
public CMDChat() {
this.command = "chat";
this.args = 0;
this.help = p.language.get("Help_Cmd_Chat");
this.isPlayerCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
if (dplayer.isInDungeonChat) {
dplayer.isInDungeonChat = false;
p.msg(player, p.language.get("Cmd_Chat_NormalChat"));
} else {
dplayer.isInDungeonChat = true;
p.msg(player, p.language.get("Cmd_Chat_DungeonChat"));
}
} else {
p.msg(player, p.language.get("Error_NotInDungeon"));
}
}
}

View File

@ -1,27 +0,0 @@
package com.dre.dungeonsxl.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CMDChatSpy extends DCommand {
public CMDChatSpy() {
this.command = "chatspy";
this.args = 0;
this.help = p.language.get("Help_Cmd_Chatspy");
this.permissions = "dxl.chatspy";
this.isPlayerCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
if (p.chatSpyer.contains(player)) {
p.chatSpyer.remove(player);
p.msg(player, p.language.get("Cmd_Chatspy_Stopped"));
} else {
p.chatSpyer.add(player);
p.msg(player, p.language.get("Cmd_Chatspy_Start"));
}
}
}

View File

@ -1,75 +0,0 @@
package com.dre.dungeonsxl.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.EditWorld;
public class CMDCreate extends DCommand {
public CMDCreate() {
this.args = 1;
this.command = "create";
this.help = p.language.get("Help_Cmd_Create");
this.permissions = "dxl.create";
this.isPlayerCommand = true;
this.isConsoleCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
String name = args[1];
if (sender instanceof ConsoleCommandSender) {
if (name.length() <= 15) {
// Msg create
p.log(p.language.get("Log_NewDungeon"));
p.log(p.language.get("Log_GenerateNewWorld"));
// Create World
EditWorld eworld = new EditWorld();
eworld.generate();
eworld.dungeonname = name;
eworld.save();
eworld.delete();
// MSG Done
p.log(p.language.get("Log_WorldGenerationFinished"));
} else {
p.msg(sender, p.language.get("Error_NameToLong"));
}
} else if (sender instanceof Player) {
Player player = (Player) sender;
if (DPlayer.get(player) == null) {
if (name.length() <= 15) {
// Msg create
p.log(p.language.get("Log_NewDungeon"));
p.log(p.language.get("Log_GenerateNewWorld"));
// Create World
EditWorld eworld = new EditWorld();
eworld.generate();
eworld.dungeonname = name;
// MSG Done
p.log(p.language.get("Log_WorldGenerationFinished"));
// Tp Player
if (eworld.lobby == null) {
new DPlayer(player, eworld.world, eworld.world.getSpawnLocation(), true);
} else {
new DPlayer(player, eworld.world, eworld.lobby, true);
}
} else {
p.msg(player, p.language.get("Error_NameToLong"));
}
} else {
p.msg(player, p.language.get("Error_LeaveDungeon"));
}
}
}
}

View File

@ -1,33 +0,0 @@
package com.dre.dungeonsxl.commands;
import java.util.Set;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.DPortal;
public class CMDDeletePortal extends DCommand {
public CMDDeletePortal() {
this.command = "deleteportal";
this.args = 0;
this.help = p.language.get("Help_Cmd_DeletePortal");
this.permissions = "dxl.deleteportal";
this.isPlayerCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPortal dPortal = DPortal.get(player.getTargetBlock((Set<Material>) null, 20).getLocation());
if (dPortal != null) {
dPortal.delete();
p.msg(player, p.language.get("Player_PortalDeleted"));
} else {
p.msg(player, p.language.get("Error_NoPortal"));
}
}
}

View File

@ -1,52 +0,0 @@
package com.dre.dungeonsxl.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.DGroup;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.EditWorld;
public class CMDEdit extends DCommand {
public CMDEdit() {
this.command = "edit";
this.args = 1;
this.help = p.language.get("Help_Cmd_Edit");
this.isPlayerCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
String dungeonName = args[1];
EditWorld eworld = EditWorld.load(dungeonName);
DGroup dgroup = DGroup.get(player);
DPlayer dplayer = DPlayer.get(player);
if (EditWorld.isInvitedPlayer(dungeonName, player.getUniqueId(), player.getName()) || p.permission.has(player, "dxl.edit") || player.isOp()) {
if (dplayer == null) {
if (dgroup == null) {
if (eworld != null) {
if (eworld.lobby == null) {
new DPlayer(player, eworld.world, eworld.world.getSpawnLocation(), true);
} else {
new DPlayer(player, eworld.world, eworld.lobby, true);
}
} else {
p.msg(player, p.language.get("Error_DungeonNotExist", dungeonName));
}
} else {
p.msg(player, p.language.get("Error_LeaveGroup"));
}
} else {
p.msg(player, p.language.get("Error_LeaveDungeon"));
}
} else {
p.msg(player, p.language.get("Error_NoPermission"));
}
}
}

View File

@ -1,49 +0,0 @@
package com.dre.dungeonsxl.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.DGroup;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.EditWorld;
public class CMDEscape extends DCommand {
public CMDEscape() {
this.command = "escape";
this.args = 0;
this.help = p.language.get("Help_Cmd_Escape");
this.isPlayerCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
if (dplayer.isEditing) {
dplayer.escape();
EditWorld eworld = EditWorld.get(dplayer.world);
if (eworld != null) {
if (eworld.world.getPlayers().isEmpty()) {
eworld.deleteNoSave();
}
}
} else {
p.msg(player, p.language.get("Error_LeaveDungeon"));
}
return;
} else {
DGroup dgroup = DGroup.get(player);
if (dgroup != null) {
dgroup.removePlayer(player);
p.msg(player, p.language.get("Cmd_Leave_Success"));
return;
}
p.msg(player, p.language.get("Error_NotInDungeon"));
}
}
}

View File

@ -1,63 +0,0 @@
package com.dre.dungeonsxl.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class CMDHelp extends DCommand {
public CMDHelp() {
this.command = "help";
this.args = -1;
this.help = p.language.get("Help_Cmd_Help");
this.isPlayerCommand = true;
this.isConsoleCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
boolean isConsole = false, isPlayer = false;
if (sender instanceof ConsoleCommandSender) {
isConsole = true;
} else if (sender instanceof Player) {
isPlayer = true;
}
int page = 1;
int pages = (int) Math.ceil(DCommandRoot.root.commands.size() / 6.0);
if (args.length > 1) {
try {
page = p.parseInt(args[1]);
} catch (NumberFormatException e) {
page = 1;
}
if (page < 1)
page = 1;
if (page > pages)
page = pages;
}
p.msg(sender, ChatColor.GREEN + "============[ " + ChatColor.GOLD + "Help DungeonsXL - " + page + "/" + pages + ChatColor.GREEN + " ]============", false);
int i = -1;
int ipage = 1;
for (DCommand command : DCommandRoot.root.commands) {
if ((command.isConsoleCommand && isConsole) || (command.isPlayerCommand && isPlayer)) {
i++;
if (i > 5) {
i = 0;
ipage++;
}
if (ipage == page) {
p.msg(sender, ChatColor.YELLOW + command.help, false);
}
}
}
p.msg(sender, ChatColor.GREEN + "==============[ " + ChatColor.GOLD + "By Frank Baumann" + ChatColor.GREEN + " ]==============", false);
}
}

View File

@ -1,27 +0,0 @@
package com.dre.dungeonsxl.commands;
import org.bukkit.command.CommandSender;
import com.dre.dungeonsxl.EditWorld;
import com.dre.dungeonsxl.util.OfflinePlayerUtil;
public class CMDInvite extends DCommand {
public CMDInvite() {
this.args = 2;
this.command = "invite";
this.help = p.language.get("Help_Cmd_Invite");
this.permissions = "dxl.invite";
this.isPlayerCommand = true;
this.isConsoleCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
if (EditWorld.addInvitedPlayer(args[2], OfflinePlayerUtil.getUniqueIdFromName(args[1]))) {
p.msg(sender, p.language.get("Cmd_Invite_Success", args[1], args[2]));
} else {
p.msg(sender, p.language.get("Error_DungeonNotExist", args[2]));
}
}
}

View File

@ -1,44 +0,0 @@
package com.dre.dungeonsxl.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.DGroup;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.game.GameWorld;
public class CMDLeave extends DCommand {
public CMDLeave() {
this.command = "leave";
this.args = 0;
this.help = p.language.get("Help_Cmd_Leave");
this.isPlayerCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dplayer = DPlayer.get(player);
if (GameWorld.get(player.getWorld()) != null) {
if (GameWorld.get(player.getWorld()).isTutorial) {
p.msg(player, p.language.get("Error_NoLeaveInTutorial"));
return;
}
}
if (dplayer != null) {
dplayer.leave();
return;
} else {
DGroup dgroup = DGroup.get(player);
if (dgroup != null) {
dgroup.removePlayer(player);
p.msg(player, p.language.get("Cmd_Leave_Success"));
return;
}
p.msg(player, p.language.get("Error_NotInDungeon"));
}
}
}

View File

@ -1,31 +0,0 @@
package com.dre.dungeonsxl.commands;
import java.io.File;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
public class CMDList extends DCommand {
public CMDList() {
this.command = "list";
this.args = 0;
this.help = p.language.get("Help_Cmd_List");
this.isPlayerCommand = true;
this.isConsoleCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
File dungeonsfolder = new File(p.getDataFolder() + "/dungeons");
if (dungeonsfolder.exists()) {
p.msg(sender, ChatColor.DARK_GREEN + "-----[ " + ChatColor.GOLD + "Dungeons " + ChatColor.RED + dungeonsfolder.list().length + ChatColor.DARK_GREEN + "]-----");
for (String dungeon : dungeonsfolder.list()) {
p.msg(sender, dungeon);
}
}
}
}

View File

@ -1,29 +0,0 @@
package com.dre.dungeonsxl.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.P;
public class CMDLives extends DCommand {
public CMDLives() {
this.command = "lives";
this.args = 1;
this.help = p.language.get("Help_Cmd_Lives");
this.isPlayerCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
String lives = "";
if (P.p.lives.containsKey(player)) {
lives = String.valueOf(P.p.lives.get(player));
p.msg(player, p.language.get("Cmd_Lives").replaceAll("v1", player.getName()).replaceAll("v2", lives));
} else {
p.msg(player, p.language.get("Error_NotInDungeon"));
}
}
}

View File

@ -1,80 +0,0 @@
package com.dre.dungeonsxl.commands;
import java.io.File;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.DConfig;
import com.dre.dungeonsxl.EditWorld;
public class CMDMsg extends DCommand {
public CMDMsg() {
this.args = -1;
this.command = "msg";
this.help = p.language.get("Help_Cmd_Msg");
this.permissions = "dxl.msg";
this.isPlayerCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
EditWorld eworld = EditWorld.get(player.getWorld());
if (eworld != null) {
if (args.length > 1) {
try {
int id = p.parseInt(args[1]);
DConfig confreader = new DConfig(new File(p.getDataFolder() + "/dungeons/" + eworld.dungeonname, "config.yml"));
if (args.length == 2) {
String msg = confreader.getMsg(id, true);
if (msg != null) {
p.msg(player, ChatColor.WHITE + msg);
} else {
p.msg(player, p.language.get("Error_MsgIdNotExist", "" + id));
}
} else {
String msg = "";
int i = 0;
for (String arg : args) {
i++;
if (i > 2) {
msg = msg + " " + arg;
}
}
String[] splitMsg = msg.split("\"");
if (splitMsg.length > 1) {
msg = splitMsg[1];
String old = confreader.getMsg(id, false);
if (old == null) {
p.msg(player, p.language.get("Cmd_Msg_Added", "" + id));
} else {
p.msg(player, p.language.get("Cmd_Msg_Updated", "" + id));
}
confreader.setMsg(msg, id);
confreader.save();
} else {
p.msg(player, p.language.get("Error_MsgFormat"));
}
}
} catch (NumberFormatException e) {
p.msg(player, p.language.get("Error_MsgNoInt"));
}
} else {
this.displayHelp(player);
}
} else {
p.msg(player, p.language.get("Error_NotInDungeon"));
}
}
}

View File

@ -1,77 +0,0 @@
package com.dre.dungeonsxl.commands;
import java.io.File;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.DConfig;
import com.dre.dungeonsxl.DGroup;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.EditWorld;
import com.dre.dungeonsxl.P;
import com.dre.dungeonsxl.game.GameWorld;
public class CMDPlay extends DCommand {
public CMDPlay() {
this.command = "play";
this.args = -1;
this.help = p.language.get("Help_Cmd_Play");
this.permissions = "dxl.play";
this.isPlayerCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dplayer = DPlayer.get(player);
String dungeonname;
if (dplayer == null) {
if (args.length > 1) {
dungeonname = args[1];
if (EditWorld.exist(dungeonname)) {
if (GameWorld.canPlayDungeon(dungeonname, player)) {
if (GameWorld.checkRequirements(dungeonname, player)) {
if (DGroup.get(player) == null) {
DGroup dgroup = new DGroup(player, dungeonname);
if (dgroup != null) {
if (dgroup.getGworld() == null) {
dgroup.setGworld(GameWorld.load(DGroup.get(player).getDungeonname()));
}
if (dgroup.getGworld().locLobby == null) {
new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().world.getSpawnLocation(), false);
} else {
new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().locLobby, false);
}
}
} else {
p.msg(player, p.language.get("Error_LeaveGroup"));
}
} else {
P.p.msg(player, P.p.language.get("Error_Requirements"));
}
} else {
File file = new File(p.getDataFolder() + "/dungeons/" + dungeonname + "/config.yml");
if (file != null) {
DConfig confReader = new DConfig(file);
if (confReader != null) {
P.p.msg(player, P.p.language.get("Error_Cooldown", "" + confReader.getTimeToNextPlay()));
}
}
}
} else {
p.msg(player, p.language.get("Error_DungeonNotExist", dungeonname));
}
} else {
this.displayHelp(player);
}
} else {
p.msg(player, p.language.get("Error_LeaveDungeon"));
}
}
}

View File

@ -1,41 +0,0 @@
package com.dre.dungeonsxl.commands;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.DPortal;
public class CMDPortal extends DCommand {
public CMDPortal() {
this.command = "portal";
this.args = 0;
this.help = p.language.get("Help_Cmd_Portal");
this.permissions = "dxl.portal";
this.isPlayerCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dplayer = DPlayer.get(player);
if (dplayer == null) {
DPortal dportal = DPortal.get(player);
if (dportal == null) {
dportal = new DPortal(false);
dportal.player = player;
dportal.world = player.getWorld();
player.getInventory().setItemInHand(new ItemStack(Material.WOOD_SWORD));
p.msg(player, p.language.get("Player_PortalIntroduction"));
} else {
DPortal.portals.remove(dportal);
p.msg(player, p.language.get("Player_PortalAbort"));
}
} else {
p.msg(player, p.language.get("Error_LeaveDungeon"));
}
}
}

View File

@ -1,36 +0,0 @@
package com.dre.dungeonsxl.commands;
import java.io.File;
import org.bukkit.command.CommandSender;
import com.dre.dungeonsxl.LanguageReader;
import com.dre.dungeonsxl.MainConfig;
public class CMDReload extends DCommand {
public CMDReload() {
this.command = "reload";
this.args = 0;
this.help = p.language.get("Help_Cmd_Reload");
this.permissions = "dxl.reload";
this.isPlayerCommand = true;
this.isConsoleCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
p.msg(sender, p.language.get("Cmd_Reload_Start"));
// Save
p.saveData();
p.language.save();
// Load Config
p.mainConfig = new MainConfig(new File(p.getDataFolder(), "config.yml"));
// Load Language
p.language = new LanguageReader(new File(p.getDataFolder(), "languages/" + p.mainConfig.language + ".yml"));
p.msg(sender, p.language.get("Cmd_Reload_Done"));
}
}

View File

@ -1,29 +0,0 @@
package com.dre.dungeonsxl.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.EditWorld;
public class CMDSave extends DCommand {
public CMDSave() {
this.command = "save";
this.args = 0;
this.help = p.language.get("Help_Cmd_Save");
this.permissions = "dxl.save";
this.isPlayerCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
EditWorld eworld = EditWorld.get(player.getWorld());
if (eworld != null) {
eworld.save();
p.msg(player, p.language.get("Cmd_Save_Success"));
} else {
p.msg(player, p.language.get("Error_NotInDungeon"));
}
}
}

View File

@ -1,63 +0,0 @@
package com.dre.dungeonsxl.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.DGroup;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.EditWorld;
import com.dre.dungeonsxl.game.GameWorld;
public class CMDTest extends DCommand {
public CMDTest() {
this.command = "test";
this.args = -1;
this.help = p.language.get("Help_Cmd_Test");
this.permissions = "dxl.test";
this.isPlayerCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dplayer = DPlayer.get(player);
String dungeonname;
if (dplayer == null) {
if (args.length > 1) {
dungeonname = args[1];
if (EditWorld.exist(dungeonname)) {
if (DGroup.get(player) == null) {
DGroup dgroup = new DGroup(player, dungeonname);
if (dgroup != null) {
if (dgroup.getGworld() == null) {
dgroup.setGworld(GameWorld.load(DGroup.get(player).getDungeonname()));
}
DPlayer newDPlayer;
if (dgroup.getGworld().locLobby == null) {
newDPlayer = new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().world.getSpawnLocation(), false);
} else {
newDPlayer = new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().locLobby, false);
}
newDPlayer.isinTestMode = true;
}
} else {
p.msg(player, p.language.get("Error_LeaveGroup"));
}
} else {
p.msg(player, p.language.get("Error_DungeonNotExist", dungeonname));
}
} else {
this.displayHelp(player);
}
} else {
p.msg(player, p.language.get("Error_LeaveDungeon"));
}
}
}

View File

@ -1,27 +0,0 @@
package com.dre.dungeonsxl.commands;
import org.bukkit.command.CommandSender;
import com.dre.dungeonsxl.EditWorld;
import com.dre.dungeonsxl.util.OfflinePlayerUtil;
public class CMDUninvite extends DCommand {
public CMDUninvite() {
this.args = 2;
this.command = "uninvite";
this.help = p.language.get("Help_Cmd_Uninvite");
this.permissions = "dxl.uninvite";
this.isPlayerCommand = true;
this.isConsoleCommand = true;
}
@Override
public void onExecute(String[] args, CommandSender sender) {
if (EditWorld.removeInvitedPlayer(args[2], OfflinePlayerUtil.getUniqueIdFromName(args[1]), args[1])) {
p.msg(sender, p.language.get("Cmd_Uninvite_Success", args[1], args[2]));
} else {
p.msg(sender, p.language.get("Error_DungeonNotExist", args[2]));
}
}
}

View File

@ -1,44 +0,0 @@
package com.dre.dungeonsxl.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.P;
public abstract class DCommand {
public P p = P.p;
public boolean costsMoney;
public String command;
public int args;
public String help;
public String permissions;
public boolean isPlayerCommand = false;
public boolean isConsoleCommand = false;
// TODO : Add Aliases
public DCommand() {
costsMoney = false;
}
public void displayHelp(CommandSender sender) {
p.msg(sender, ChatColor.RED + this.help);
}
public boolean playerHasPermissions(Player player) {
if (this.permissions == null) {
return true;
}
if (p.permission.has(player, this.permissions) || player.isOp()) {
return true;
}
return false;
}
// Abstracts
public abstract void onExecute(String[] args, CommandSender sender);
}

View File

@ -1,55 +0,0 @@
package com.dre.dungeonsxl.commands;
import java.util.concurrent.CopyOnWriteArrayList;
public class DCommandRoot {
// Variables
public static DCommandRoot root;
public CopyOnWriteArrayList<DCommand> commands = new CopyOnWriteArrayList<DCommand>();
// Commands
public CMDCreate cmdCreate = new CMDCreate();
public CMDSave cmdSave = new CMDSave();
public CMDLeave cmdLeave = new CMDLeave();
public CMDEscape cmdEscape = new CMDEscape();
public CMDEdit cmdEdit = new CMDEdit();
public CMDPortal cmdPortal = new CMDPortal();
public CMDDeletePortal cmdDeletePortal = new CMDDeletePortal();
public CMDChat cmdChat = new CMDChat();
public CMDChatSpy cmdChatSpy = new CMDChatSpy();
public CMDLives cmdLives = new CMDLives();
public CMDList cmdList = new CMDList();
public CMDUninvite cmdUninvite = new CMDUninvite();
public CMDInvite cmdInvite = new CMDInvite();
public CMDMsg cmdMsg = new CMDMsg();
public CMDPlay cmdPlay = new CMDPlay();
public CMDTest cmdTest = new CMDTest();
public CMDHelp cmdHelp = new CMDHelp();
public CMDReload cmdReload = new CMDReload();
// Methods
public DCommandRoot() {
root = this;
// Add Commands
this.commands.add(cmdCreate);
this.commands.add(cmdSave);
this.commands.add(cmdLeave);
this.commands.add(cmdEscape);
this.commands.add(cmdEdit);
this.commands.add(cmdPortal);
this.commands.add(cmdDeletePortal);
this.commands.add(cmdChat);
this.commands.add(cmdChatSpy);
this.commands.add(cmdLives);
this.commands.add(cmdList);
this.commands.add(cmdUninvite);
this.commands.add(cmdInvite);
this.commands.add(cmdMsg);
this.commands.add(cmdPlay);
this.commands.add(cmdTest);
this.commands.add(cmdHelp);
this.commands.add(cmdReload);
}
}

View File

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

View File

@ -1,333 +0,0 @@
package com.dre.dungeonsxl.game;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Spider;
import com.dre.dungeonsxl.DConfig;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.P;
import com.dre.dungeonsxl.signs.DSign;
import com.dre.dungeonsxl.EditWorld;
import com.dre.dungeonsxl.trigger.RedstoneTrigger;
public class GameWorld {
private static P p = P.p;
public static CopyOnWriteArrayList<GameWorld> gworlds = new CopyOnWriteArrayList<GameWorld>();
// Variables placeable
public boolean isTutorial;
public CopyOnWriteArrayList<GamePlaceableBlock> placeableBlocks = new CopyOnWriteArrayList<GamePlaceableBlock>();
public World world;
public String dungeonname;
public Location locLobby;
public Location locStart;
public boolean isPlaying = false;
public int id;
public CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<Material>();
public CopyOnWriteArrayList<Chunk> loadedChunks = new CopyOnWriteArrayList<Chunk>();
public CopyOnWriteArrayList<Sign> signClass = new CopyOnWriteArrayList<Sign>();
public CopyOnWriteArrayList<DMob> dmobs = new CopyOnWriteArrayList<DMob>();
public CopyOnWriteArrayList<GameChest> gchests = new CopyOnWriteArrayList<GameChest>();
public CopyOnWriteArrayList<DSign> dSigns = new CopyOnWriteArrayList<DSign>();
public DConfig config;
public GameWorld() {
gworlds.add(this);
// ID
this.id = -1;
int i = -1;
while (this.id == -1) {
i++;
boolean exist = false;
for (GameWorld gworld : gworlds) {
if (gworld.id == i) {
exist = true;
break;
}
}
if (!exist)
this.id = i;
}
}
public void checkSign(Block block) {
if ((block.getState() instanceof Sign)) {
Sign sign = (Sign) block.getState();
dSigns.add(DSign.create(sign, this));
}
}
public void startGame() {
this.isPlaying = true;
for (DSign dSign : this.dSigns) {
if (dSign != null) {
if (!dSign.isOnDungeonInit()) {
dSign.onInit();
}
}
}
if (RedstoneTrigger.hasTriggers(this)) {
for (RedstoneTrigger trigger : RedstoneTrigger.getTriggersArray(this)) {
trigger.onTrigger();
}
}
for (DSign dSign : this.dSigns) {
if (dSign != null) {
if (!dSign.hasTriggers()) {
dSign.onTrigger();
}
}
}
}
public void msg(String msg) {
for (DPlayer dplayer : DPlayer.get(this.world)) {
p.msg(dplayer.player, msg);
}
}
// Static
public static GameWorld get(World world) {
for (GameWorld gworld : gworlds) {
if (gworld.world.equals(world)) {
return gworld;
}
}
return null;
}
public static void deleteAll() {
for (GameWorld gworld : gworlds) {
gworld.delete();
}
}
public static boolean canPlayDungeon(String dungeon, Player player) {
if (p.permission.has(player, "dungeonsxl.ignoretimelimit") || player.isOp()) {
return true;
}
if (new File(p.getDataFolder() + "/dungeons/" + dungeon).isDirectory()) {
DConfig config = new DConfig(new File(p.getDataFolder() + "/dungeons/" + dungeon, "config.yml"));
if (config.getTimeToNextPlay() != 0) {
// read PlayerConfig
Long time = getPlayerTime(dungeon, player);
if (time != -1) {
if (time + (config.getTimeToNextPlay() * 1000 * 60 * 60) > System.currentTimeMillis()) {
return false;
}
}
}
} else {
return false;
}
return true;
}
public static boolean checkRequirements(String dungeon, Player player) {
/*if (p.permission.has(player, "dungeonsxl.ignoreRequirements") || player.isOp()) {
return true;
}*/
if (new File(p.getDataFolder() + "/dungeons/" + dungeon).isDirectory() == false) {
return false;
}
DConfig config = new DConfig(new File(p.getDataFolder() + "/dungeons/" + dungeon, "config.yml"));
if (p.mainConfig.enableEconomy) {
if (!(P.p.economy.getBalance(player) >= config.getFee())) {
return false;
}
}
if (config.getFinished() != null && config.getFinishedAll() != null) {
if (!config.getFinished().isEmpty()) {
long bestTime = 0;
int numOfNeeded = 0;
boolean doneTheOne = false;
if (config.getFinished().size() == config.getFinishedAll().size()) {
doneTheOne = true;
}
for (String played : config.getFinished()) {
for (String dungeonName : new File(p.getDataFolder() + "/dungeons").list()) {
if (new File(p.getDataFolder() + "/dungeons/" + dungeonName).isDirectory()) {
if (played.equalsIgnoreCase(dungeonName) || played.equalsIgnoreCase("any")) {
Long time = getPlayerTime(dungeonName, player);
if (time != -1) {
if (config.getFinishedAll().contains(played)) {
numOfNeeded++;
} else {
doneTheOne = true;
}
if (bestTime < time) {
bestTime = time;
}
}
break;
}
}
}
}
if (bestTime == 0) {
return false;
} else {
if (config.getTimeLastPlayed() != 0) {
if (System.currentTimeMillis() - bestTime > config.getTimeLastPlayed() * (long) 3600000) {
return false;
}
}
}
if (numOfNeeded < config.getFinishedAll().size() || !doneTheOne) {
return false;
}
}
}
return true;
}
public static long getPlayerTime(String dungeon, Player player) {
File file = new File(p.getDataFolder() + "/dungeons/" + dungeon, "players.yml");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.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 void delete() {
gworlds.remove(this);
p.getServer().unloadWorld(this.world, true);
File dir = new File("DXL_Game_" + this.id);
p.removeDirectory(dir);
}
public static GameWorld load(String name) {
File file = new File(p.getDataFolder(), "/dungeons/" + name);
if (file.exists()) {
GameWorld gworld = new GameWorld();
gworld.dungeonname = name;
// Unload empty eworlds
for (EditWorld eworld : EditWorld.eworlds) {
if (eworld.world.getPlayers().isEmpty()) {
eworld.delete();
}
}
// Config einlesen
gworld.config = new DConfig(new File(p.getDataFolder() + "/dungeons/" + gworld.dungeonname, "config.yml"));
// Secure Objects
gworld.secureObjects = gworld.config.getSecureObjects();
// World
p.copyDirectory(file, new File("DXL_Game_" + gworld.id));
// Id File
File idFile = new File("DXL_Game_" + gworld.id + "/.id_" + name);
try {
idFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
gworld.world = p.getServer().createWorld(WorldCreator.name("DXL_Game_" + gworld.id));
ObjectInputStream os;
try {
os = new ObjectInputStream(new FileInputStream(new File(p.getDataFolder() + "/dungeons/" + gworld.dungeonname + "/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 = gworld.world.getBlockAt(x, y, z);
gworld.checkSign(block);
}
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return gworld;
}
return null;
}
public static void update() {
for (GameWorld gworld : gworlds) {
// Update Spiders
for (LivingEntity mob : gworld.world.getLivingEntities()) {
if (mob.getType() == EntityType.SPIDER || mob.getType() == EntityType.CAVE_SPIDER) {
Spider spider = (Spider) mob;
if (spider.getTarget() != null) {
if (spider.getTarget().getType() == EntityType.PLAYER) {
continue;
}
}
for (Entity player : spider.getNearbyEntities(10, 10, 10)) {
if (player.getType() == EntityType.PLAYER) {
spider.setTarget((LivingEntity) player);
}
}
}
}
}
}
}

View File

@ -1,60 +0,0 @@
package com.dre.dungeonsxl.listener;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.P;
import com.dre.dungeonsxl.commands.DCommand;
import com.dre.dungeonsxl.commands.DCommandRoot;
public class CommandListener implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd_notused, String arg, String[] args) {
if (args.length > 0) {
String cmd = args[0];
for (DCommand command : DCommandRoot.root.commands) {
if (cmd.equals(command.command)) {
if (sender instanceof ConsoleCommandSender) {
if (!command.isConsoleCommand) {
P.p.msg(sender, P.p.language.get("Log_Error_NoConsoleCommand", command.command));
return false;
}
}
if (sender instanceof Player) {
Player player = (Player) sender;
if (!command.isPlayerCommand) {
P.p.msg(player, P.p.language.get("Error_NoPlayerCommand", command.command));
return false;
} else {
if (!command.playerHasPermissions(player)) {
P.p.msg(player, P.p.language.get("Error_NoPermissions"));
return false;
}
}
}
if (command.args == args.length - 1 || command.args == -1) {
command.onExecute(args, sender);
return true;
} else {
command.displayHelp(sender);
}
}
}
P.p.msg(sender, P.p.language.get("Error_CmdNotExist1", cmd));
P.p.msg(sender, P.p.language.get("Error_CmdNotExist2"));
} else {
DCommandRoot.root.cmdHelp.onExecute(args, sender);
}
return false;
}
}

View File

@ -1,60 +0,0 @@
package com.dre.dungeonsxl.listener.player;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.ItemStack;
import com.dre.dungeonsxl.DConfig;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.P;
import com.dre.dungeonsxl.game.GameWorld;
public class PlayerDeathListener implements Listener {
P p = P.p;
int lives = -1;
@EventHandler(priority = EventPriority.HIGH)
public void onDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
DPlayer dPlayer = DPlayer.get(player);
GameWorld gameWorld = GameWorld.get(player.getLocation().getWorld());
if (gameWorld != null) {
DConfig dConfig = gameWorld.config;
if (dPlayer != null) {
if (dConfig != null) {
if (dConfig.getKeepInventoryOnDeath()) {
dPlayer.respawnInventory = event.getEntity().getInventory().getContents();
dPlayer.respawnArmor = event.getEntity().getInventory().getArmorContents();
// Delete all drops
for (ItemStack istack : event.getDrops()) {
istack.setType(Material.AIR);
}
}
}
if (p.lives.containsKey(player)) {
lives = p.lives.get(player) - 1;
p.lives.put(player, lives);
}
if (lives == 0 && dPlayer.isReady) {
Bukkit.broadcastMessage(p.language.get("Player_DeathKick").replaceAll("v1", player.getName()).replaceAll("&", "\u00a7"));
player.performCommand("dxl leave");
} else if ( !(lives == -1)) {
p.msg(player, p.language.get("Player_Death").replaceAll("v1", String.valueOf(lives)));
}
}
}
}
}

View File

@ -1,68 +0,0 @@
package com.dre.dungeonsxl.multiversionhandler;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.P;
public class MultiVersionHandler {
private static String version = P.p.getServer().getVersion();
public static String supported = "v1_8_R1,v1_8_R2,v1_8_R3";
public static String getInternals() {
String internals = "v1_8_R3";
if (version.contains("1.8.4") || version.contains("1.8.5") || version.contains("1.8.6") || version.contains("1.8.7") || version.contains("1.8.8")) {
internals = "v1_8_R3";
} else if (version.contains("1.8.3")) {
internals = "v1_8_R2";
} else if (version.contains("1.8") && !version.contains("1.8.")) {
internals = "v1_8_R1";
} else if (version.contains("1.7.10")) {
internals = "v1_7_R4";
} else if (version.contains("1.7.8") || version.contains("1.7.9")) {
internals = "v1_7_R3";
}
return internals;
}
public static Player getOfflinePlayer(String player, UUID uuid) {
Player pplayer = null;
if (getInternals().equals("v1_8_R3")) {
pplayer = v1_8_R3.getOfflinePlayer(player, uuid);
} else if (getInternals().equals("v1_8_R2")) {
pplayer = v1_8_R2.getOfflinePlayer(player, uuid);
} else if (getInternals().equals("v1_8_R1")) {
pplayer = v1_8_R1.getOfflinePlayer(player, uuid);
} else if (getInternals().equals("v1_8_R2")) {
pplayer = v1_8_R1.getOfflinePlayer(player, uuid);
} else if (getInternals().equals("v1_7_R4")) {
pplayer = v1_7_R4.getOfflinePlayer(player, uuid);
} else if (getInternals().equals("v1_7_R3")) {
pplayer = v1_7_R3.getOfflinePlayer(player, uuid);
}
return pplayer;
}
public static Player getOfflinePlayer(String player, UUID uuid, Location location) {
Player pplayer = null;
if (getInternals().equals("v1_8_R3")) {
pplayer = v1_8_R3.getOfflinePlayer(player, uuid, location);
} else if (getInternals().equals("v1_8_R2")) {
pplayer = v1_8_R2.getOfflinePlayer(player, uuid, location);
} else if (getInternals().equals("v1_8_R1")) {
pplayer = v1_8_R1.getOfflinePlayer(player, uuid, location);
} else if (getInternals().equals("v1_8_R2")) {
pplayer = v1_8_R1.getOfflinePlayer(player, uuid, location);
} else if (getInternals().equals("v1_7_R4")) {
pplayer = v1_7_R4.getOfflinePlayer(player, uuid, location);
} else if (getInternals().equals("v1_7_R3")) {
pplayer = v1_7_R3.getOfflinePlayer(player, uuid, location);
}
return pplayer;
}
}

View File

@ -1,161 +0,0 @@
package com.dre.dungeonsxl.signs;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.P;
import com.dre.dungeonsxl.game.GameWorld;
import com.dre.dungeonsxl.trigger.Trigger;
public abstract class DSign {
protected static P p = P.p;
protected Sign sign;
protected GameWorld gworld;
// List of Triggers
protected Set<Trigger> triggers = new HashSet<Trigger>();
public abstract boolean check();
public abstract String getPermissions();
public abstract boolean isOnDungeonInit();
public DSign(Sign sign, GameWorld gworld) {
this.sign = sign;
this.gworld = gworld;
// Check Trigger
if (gworld != null) {
String line3 = sign.getLine(3).replaceAll("\\s", "");
String[] triggerTypes = line3.split(",");
for (String triggerString : triggerTypes) {
if (!triggerString.equals("")) {
String type = triggerString.substring(0, 1);
String value = null;
if (triggerString.length() > 1) {
value = triggerString.substring(1);
}
Trigger trigger = Trigger.getOrCreate(type, value, this);
if (trigger != null) {
trigger.addListener(this);
this.triggers.add(trigger);
}
}
}
}
}
public void onInit() {
}
public void onTrigger() {
}
public boolean onPlayerTrigger(Player player) {
return false;
}
public void onDisable() {
}
public void onUpdate() {
for (Trigger trigger : triggers) {
if (!trigger.triggered) {
onDisable();
return;
}
if (triggers.size() == 1) {
if (trigger.player != null) {
if (onPlayerTrigger(trigger.player)) {
return;
}
}
}
}
onTrigger();
}
public void remove() {
for (Trigger trigger : triggers) {
trigger.removeListener(this);
}
gworld.dSigns.remove(this);
}
public boolean hasTriggers() {
return !triggers.isEmpty();
}
public static DSign create(Sign sign, GameWorld gworld) {
String[] lines = sign.getLines();
DSign dSign = null;
if (lines[0].equalsIgnoreCase("[" + SIGNCheckpoint.name + "]")) {
dSign = new SIGNCheckpoint(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNChest.name + "]")) {
dSign = new SIGNChest(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNChunkUpdater.name + "]")) {
dSign = new SIGNChunkUpdater(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNClasses.name + "]")) {
dSign = new SIGNClasses(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNEnd.name + "]")) {
dSign = new SIGNEnd(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNLeave.name + "]")) {
dSign = new SIGNLeave(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNLobby.name + "]")) {
dSign = new SIGNLobby(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNMob.name + "]")) {
dSign = new SIGNMob(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNMsg.name + "]")) {
dSign = new SIGNMsg(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNPlace.name + "]")) {
dSign = new SIGNPlace(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNReady.name + "]")) {
dSign = new SIGNReady(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNSoundMsg.name + "]")) {
dSign = new SIGNSoundMsg(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNStart.name + "]")) {
dSign = new SIGNStart(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNTrigger.name + "]")) {
dSign = new SIGNTrigger(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNInteract.name + "]")) {
dSign = new SIGNInteract(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNRedstone.name + "]")) {
dSign = new SIGNRedstone(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNBlock.name + "]")) {
dSign = new SIGNBlock(sign, gworld);
} else if (lines[0].equalsIgnoreCase("[" + SIGNMythicMobs.name + "]")) {
dSign = new SIGNMythicMobs(sign, gworld);
}
if (dSign != null && gworld != null) {
if (dSign.isOnDungeonInit()) {
dSign.onInit();
}
}
return dSign;
}
// Getter and Setter
public GameWorld getGameWorld() {
return gworld;
}
public Sign getSign() {
return sign;
}
}

View File

@ -1,61 +0,0 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GameChest;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNChest extends DSign {
public static String name = "Chest";
public String buildPermissions = "dxl.sign.chest";
public boolean onDungeonInit = false;
// Variables
private double moneyReward;
public SIGNChest(Sign sign, GameWorld gworld) {
super(sign, gworld);
}
@Override
public boolean check() {
String lines[] = sign.getLines();
if (lines[1].equals("")) {
return false;
}
return true;
}
@Override
public void onInit() {
String lines[] = sign.getLines();
if (!lines[1].equals("")) {
moneyReward = Double.parseDouble(lines[1]);
}
for (int i = -1; i <= 1; i++) {
if (sign.getBlock().getRelative(i, 0, 0).getType() == Material.CHEST) {
new GameChest(sign.getBlock().getRelative(i, 0, 0), gworld, moneyReward);
}
if (sign.getBlock().getRelative(0, 0, i).getType() == Material.CHEST) {
new GameChest(sign.getBlock().getRelative(0, 0, i), gworld, moneyReward);
}
if (sign.getBlock().getRelative(0, i, 0).getType() == Material.CHEST) {
new GameChest(sign.getBlock().getRelative(0, i, 0), gworld, moneyReward);
}
}
sign.getBlock().setType(Material.AIR);
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

View File

@ -1,55 +0,0 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNChunkUpdater extends DSign {
public static String name = "ChunkUpdater";
public String buildPermissions = "dxl.sign.chunkupdater";
public boolean onDungeonInit = true;
public SIGNChunkUpdater(Sign sign, GameWorld gworld) {
super(sign, gworld);
}
@Override
public boolean check() {
// TODO Auto-generated method stub
return true;
}
@Override
public void onInit() {
String lines[] = sign.getLines();
Chunk chunk = gworld.world.getChunkAt(sign.getBlock());
if (!lines[1].equals("")) {
Integer radius = p.parseInt(lines[1]);
for (int x = -radius; x < radius; x++) {
for (int z = -radius; z < radius; z++) {
Chunk chunk1 = gworld.world.getChunkAt(chunk.getX() - x, chunk.getZ() - z);
chunk1.load();
gworld.loadedChunks.add(chunk1);
}
}
} else {
chunk.load();
gworld.loadedChunks.add(chunk);
}
sign.getBlock().setType(Material.AIR);
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

View File

@ -1,83 +0,0 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.DClass;
import com.dre.dungeonsxl.DGSign;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNClasses extends DSign {
public static String name = "Classes";
public String buildPermissions = "dxl.sign.classes";
public boolean onDungeonInit = true;
public SIGNClasses(Sign sign, GameWorld gworld) {
super(sign, gworld);
}
@Override
public boolean check() {
// TODO Auto-generated method stub
return true;
}
@Override
public void onInit() {
if (!gworld.config.isLobbyDisabled()) {
int[] direction = DGSign.getDirection(sign.getBlock().getData());
int directionX = direction[0];
int directionZ = direction[1];
int xx = 0, zz = 0;
for (DClass dclass : gworld.config.getClasses()) {
// Check existing signs
boolean isContinued = true;
for (Sign isusedsign : gworld.signClass) {
if (dclass.name.equalsIgnoreCase(ChatColor.stripColor(isusedsign.getLine(1)))) {
isContinued = false;
}
}
if (isContinued) {
Block classBlock = sign.getBlock().getRelative(xx, 0, zz);
if (classBlock.getData() == sign.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.name);
classSign.setLine(2, "");
classSign.setLine(3, ChatColor.DARK_BLUE + "############");
classSign.update();
gworld.signClass.add(classSign);
} else {
break;
}
xx = xx + directionX;
zz = zz + directionZ;
}
}
} else {
sign.getBlock().setType(Material.AIR);
}
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

View File

@ -1,74 +0,0 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.game.GameWorld;
import com.dre.dungeonsxl.trigger.InteractTrigger;
public class SIGNEnd extends DSign {
public static String name = "End";
public String buildPermissions = "dxl.sign.end";
public boolean onDungeonInit = false;
public SIGNEnd(Sign sign, GameWorld gworld) {
super(sign, gworld);
}
@Override
public boolean check() {
// TODO Auto-generated method stub
return true;
}
@Override
public void onInit() {
if (triggers.isEmpty()) {
InteractTrigger trigger = InteractTrigger.getOrCreate(0, sign.getBlock(), gworld);
if (trigger != null) {
trigger.addListener(this);
this.triggers.add(trigger);
}
sign.setLine(0, ChatColor.DARK_BLUE + "############");
sign.setLine(1, ChatColor.DARK_GREEN + "End");
sign.setLine(2, "");
sign.setLine(3, ChatColor.DARK_BLUE + "############");
sign.update();
} else {
sign.getBlock().setType(Material.AIR);
}
}
@Override
public boolean onPlayerTrigger(Player player) {
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
if (!dplayer.isFinished) {
dplayer.finish();
}
}
return true;
}
@Override
public void onTrigger() {
for (DPlayer dplayer : DPlayer.players) {
dplayer.finish();
}
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

View File

@ -1,72 +0,0 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.game.GameWorld;
import com.dre.dungeonsxl.trigger.InteractTrigger;
public class SIGNLeave extends DSign {
public static String name = "Leave";
public String buildPermissions = "dxl.sign.leave";
public boolean onDungeonInit = true;
public SIGNLeave(Sign sign, GameWorld gworld) {
super(sign, gworld);
}
@Override
public boolean check() {
// TODO Auto-generated method stub
return true;
}
@Override
public void onInit() {
if (triggers.isEmpty()) {
InteractTrigger trigger = InteractTrigger.getOrCreate(0, sign.getBlock(), gworld);
if (trigger != null) {
trigger.addListener(this);
this.triggers.add(trigger);
}
sign.setLine(0, ChatColor.DARK_BLUE + "############");
sign.setLine(1, ChatColor.DARK_GREEN + "Leave");
sign.setLine(2, "");
sign.setLine(3, ChatColor.DARK_BLUE + "############");
sign.update();
} else {
sign.getBlock().setType(Material.AIR);
}
}
@Override
public boolean onPlayerTrigger(Player player) {
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
dplayer.leave();
}
return true;
}
@Override
public void onTrigger() {
for (DPlayer dplayer : DPlayer.players) {
dplayer.leave();
}
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

View File

@ -1,40 +0,0 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GamePlaceableBlock;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNPlace extends DSign {
public static String name = "Place";
public String buildPermissions = "dxl.sign.place";
public boolean onDungeonInit = false;
public SIGNPlace(Sign sign, GameWorld gworld) {
super(sign, gworld);
}
@Override
public boolean check() {
return true;
}
@Override
public void onInit() {
String lines[] = sign.getLines();
gworld.placeableBlocks.add(new GamePlaceableBlock(sign.getBlock(), lines[1], lines[2]));
sign.getBlock().setType(Material.AIR);
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

View File

@ -1,84 +0,0 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.game.GameWorld;
import com.dre.dungeonsxl.trigger.InteractTrigger;
import com.dre.dungeonsxl.P;
public class SIGNReady extends DSign {
public static String name = "Ready";
public String buildPermissions = "dxl.sign.ready";
public boolean onDungeonInit = true;
public SIGNReady(Sign sign, GameWorld gworld) {
super(sign, gworld);
}
@Override
public boolean check() {
// TODO Auto-generated method stub
return true;
}
@Override
public void onInit() {
if (triggers.isEmpty()) {
InteractTrigger trigger = InteractTrigger.getOrCreate(0, sign.getBlock(), gworld);
if (trigger != null) {
trigger.addListener(this);
this.triggers.add(trigger);
}
sign.setLine(0, ChatColor.DARK_BLUE + "############");
sign.setLine(1, ChatColor.DARK_GREEN + "Ready");
sign.setLine(2, "");
sign.setLine(3, ChatColor.DARK_BLUE + "############");
sign.update();
} else {
sign.getBlock().setType(Material.AIR);
}
}
@Override
public boolean onPlayerTrigger(Player player) {
ready(DPlayer.get(player));
return true;
}
@Override
public void onTrigger() {
for (DPlayer dplayer : DPlayer.players) {
ready(dplayer);
}
}
private void ready(DPlayer dplayer) {
if (dplayer != null) {
if (!dplayer.isReady) {
if (gworld.signClass.isEmpty() || dplayer.dclass != null) {
dplayer.ready();
P.p.msg(dplayer.player, p.language.get("Player_Ready"));
return;
} else {
P.p.msg(dplayer.player, p.language.get("Error_Ready"));
}
}
}
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

View File

@ -1,20 +0,0 @@
package com.dre.dungeonsxl.util;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
public class OfflinePlayerUtil {
static Server server = Bukkit.getServer();
@SuppressWarnings("deprecation")
public static UUID getUniqueIdFromName(String name) {
OfflinePlayer player = server.getOfflinePlayer(name);
UUID uuid = player.getUniqueId();
return uuid;
}
}

View File

@ -0,0 +1,442 @@
package io.github.dre2n.dungeonsxl;
import io.github.dre2n.dungeonsxl.command.DCommands;
import io.github.dre2n.dungeonsxl.dungeon.DLootInventory;
import io.github.dre2n.dungeonsxl.dungeon.Dungeons;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.dungeon.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.file.DMessages;
import io.github.dre2n.dungeonsxl.file.MainConfig;
import io.github.dre2n.dungeonsxl.global.DPortal;
import io.github.dre2n.dungeonsxl.global.GroupSign;
import io.github.dre2n.dungeonsxl.global.LeaveSign;
import io.github.dre2n.dungeonsxl.listener.BlockListener;
import io.github.dre2n.dungeonsxl.listener.CommandListener;
import io.github.dre2n.dungeonsxl.listener.EntityListener;
import io.github.dre2n.dungeonsxl.listener.HangingListener;
import io.github.dre2n.dungeonsxl.listener.PlayerListener;
import io.github.dre2n.dungeonsxl.listener.WorldListener;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.player.DSavePlayer;
import io.github.dre2n.dungeonsxl.util.FileUtil;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import io.github.dre2n.dungeonsxl.util.VersionUtil;
import io.github.dre2n.dungeonsxl.util.VersionUtil.Internals;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArrayList;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
public class DungeonsXL extends JavaPlugin {
private static DungeonsXL plugin;
private MainConfig mainConfig;
private DMessages dMessages;
private VersionUtil versionUtil;
private DCommands dCommands;
private Dungeons dungeons;
private CopyOnWriteArrayList<Player> chatSpyers = new CopyOnWriteArrayList<Player>();
private CopyOnWriteArrayList<DLootInventory> dLootInventories = new CopyOnWriteArrayList<DLootInventory>();
private CopyOnWriteArrayList<EditWorld> editWorlds = new CopyOnWriteArrayList<EditWorld>();
private CopyOnWriteArrayList<GameWorld> gameWorlds = new CopyOnWriteArrayList<GameWorld>();
private CopyOnWriteArrayList<GroupSign> groupSigns = new CopyOnWriteArrayList<GroupSign>();
private CopyOnWriteArrayList<LeaveSign> leaveSigns = new CopyOnWriteArrayList<LeaveSign>();
private CopyOnWriteArrayList<DPortal> dPortals = new CopyOnWriteArrayList<DPortal>();
private CopyOnWriteArrayList<DGroup> dGroups = new CopyOnWriteArrayList<DGroup>();
private CopyOnWriteArrayList<DPlayer> dPlayers = new CopyOnWriteArrayList<DPlayer>();
@Override
public void onEnable() {
plugin = this;
getDataFolder().mkdir();
// Load Language
dMessages = new DMessages(new File(plugin.getDataFolder(), "languages/en.yml"));
// Load Config
mainConfig = new MainConfig(new File(plugin.getDataFolder(), "config.yml"));
// Load Language 2
loadDMessages(new File(plugin.getDataFolder(), "languages/" + mainConfig.getLanguage() + ".yml"));
loadVersionUtil();
loadDCommands();
loadDungeons();
// InitFolders
initFolders();
// Setup Permissions
setupPermissions();
// Setup Economy
setupEconomy();
getCommand("dungeonsxl").setExecutor(new CommandListener());
Bukkit.getServer().getPluginManager().registerEvents(new EntityListener(), this);
Bukkit.getServer().getPluginManager().registerEvents(new PlayerListener(), this);
Bukkit.getServer().getPluginManager().registerEvents(new BlockListener(), this);
Bukkit.getServer().getPluginManager().registerEvents(new WorldListener(), this);
Bukkit.getServer().getPluginManager().registerEvents(new HangingListener(), this);
// Load All
loadAll();
// Scheduler
initSchedulers();
// MSG
log("ItemsXL " + getDescription().getVersion() + " for Spigot 1.8.9 loaded succesfully!");
if (versionUtil.getInternals() == Internals.OUTDATED) {
log("Warning: Your CraftBukkit version is deprecated. DungeonsXL does not support it.");
}
}
@Override
public void onDisable() {
// Save
saveData();
dMessages.save();
// DPlayer leaves World
for (DPlayer dplayer : dPlayers) {
dplayer.leave();
}
// Delete all Data
dGroups.clear();
groupSigns.clear();
dLootInventories.clear();
dPlayers.clear();
dPortals.clear();
leaveSigns.clear();
dCommands.getDCommands().clear();
// Delete Worlds
GameWorld.deleteAll();
EditWorld.deleteAll();
// Disable listeners
HandlerList.unregisterAll(plugin);
// Stop shedulers
plugin.getServer().getScheduler().cancelTasks(this);
}
// Init.
public void initFolders() {
if ( !getDataFolder().exists()) {
getDataFolder().mkdir();
}
File dungeons = new File(getDataFolder() + "/dungeons");
if ( !dungeons.exists()) {
dungeons.mkdir();
}
File languages = new File(getDataFolder() + "/languages");
if ( !languages.exists()) {
languages.mkdir();
}
File maps = new File(getDataFolder() + "/maps");
if ( !maps.exists()) {
maps.mkdir();
}
}
public void initSchedulers() {
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override
public void run() {
for (GameWorld gworld : gameWorlds) {
if (gworld.world.getPlayers().isEmpty()) {
if (DPlayer.get(gworld.world).isEmpty()) {
gworld.delete();
}
}
}
for (EditWorld eworld : editWorlds) {
if (eworld.world.getPlayers().isEmpty()) {
eworld.delete();
}
}
}
}, 0L, 1200L);
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override
public void run() {
GameWorld.update();
DPlayer.update(true);
}
}, 0L, 20L);
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override
public void run() {
DPlayer.update(false);
}
}, 0L, 2L);
}
// Permissions
public Permission permission = null;
private Boolean setupPermissions() {
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
if (permissionProvider != null) {
permission = permissionProvider.getProvider();
}
return permission != null;
}
public Boolean GroupEnabled(String group) {
for (String agroup : permission.getGroups()) {
if (agroup.equalsIgnoreCase(group)) {
return true;
}
}
return false;
}
// Economy
public Economy economy = null;
private Boolean setupEconomy() {
if (mainConfig.enableEconomy()) {
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
if (economyProvider != null) {
economy = economyProvider.getProvider();
}
return economy != null;
} else {
return false;
}
}
// Save and Load
public void saveData() {
File file = new File(getDataFolder(), "data.yml");
FileConfiguration configFile = new YamlConfiguration();
DPortal.save(configFile);
GroupSign.save(configFile);
LeaveSign.save(configFile);
try {
configFile.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
public void loadAll() {
// Load world data
File file = new File(getDataFolder(), "data.yml");
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
DPortal.load(configFile);
GroupSign.load(configFile);
LeaveSign.load(configFile);
// Load saved players
DSavePlayer.load();
// Check Worlds
checkWorlds();
}
public void checkWorlds() {
File serverDir = new File(".");
for (File file : serverDir.listFiles()) {
if (file.getName().contains("DXL_Edit_") && file.isDirectory()) {
for (File dungeonFile : file.listFiles()) {
if (dungeonFile.getName().contains(".id_")) {
String dungeonName = dungeonFile.getName().substring(4);
FileUtil.copyDirectory(file, new File(plugin.getDataFolder(), "/maps/" + dungeonName));
FileUtil.deletenotusingfiles(new File(plugin.getDataFolder(), "/maps/" + dungeonName));
}
}
FileUtil.removeDirectory(file);
} else if (file.getName().contains("DXL_Game_") && file.isDirectory()) {
FileUtil.removeDirectory(file);
}
}
}
// -------------------------------------------- //
// LOGGING
// -------------------------------------------- //
public void log(String msg) {
MessageUtil.sendMessage(Bukkit.getConsoleSender(), msg);
}
// Getters & loaders
/**
* @return the plugin instance
*/
public static DungeonsXL getPlugin() {
return plugin;
}
/**
* @return the loaded instance of MainConfig
*/
public MainConfig getMainConfig() {
return mainConfig;
}
/**
* load / reload a new instance of MainConfig
*/
public void loadMainConfig(File file) {
mainConfig = new MainConfig(file);
}
/**
* @return the loaded instance of VersionUtil
*/
public VersionUtil getVersion() {
return versionUtil;
}
/**
* load / reload a new instance of VersionUtil
*/
public void loadVersionUtil() {
versionUtil = new VersionUtil();
}
/**
* @return the loaded instance of DMessages
*/
public DMessages getDMessages() {
return dMessages;
}
/**
* load / reload a new instance of DMessages
*/
public void loadDMessages(File file) {
dMessages = new DMessages(file);
}
/**
* @return the loaded instance of DCommands
*/
public DCommands getDCommands() {
return dCommands;
}
/**
* load / reload a new instance of DCommands
*/
public void loadDCommands() {
dCommands = new DCommands();
}
/**
* @return the loaded instance of Dungeons
*/
public Dungeons getDungeons() {
return dungeons;
}
/**
* load / reload a new instance of Dungeons
*/
public void loadDungeons() {
dungeons = new Dungeons();
}
/**
* @return the chatSpyers
*/
public CopyOnWriteArrayList<Player> getChatSpyers() {
return chatSpyers;
}
/**
* @return the dLootInventories
*/
public CopyOnWriteArrayList<DLootInventory> getDLootInventories() {
return dLootInventories;
}
/**
* @return the editWorlds
*/
public CopyOnWriteArrayList<EditWorld> getEditWorlds() {
return editWorlds;
}
/**
* @return the defaultConfig
*/
public WorldConfig getDefaultConfig() {
return WorldConfig.defaultConfig;// TODO
}
/**
* @return the gameWorlds
*/
public CopyOnWriteArrayList<GameWorld> getGameWorlds() {
return gameWorlds;
}
/**
* @return the groupSigns
*/
public CopyOnWriteArrayList<GroupSign> getGroupSigns() {
return groupSigns;
}
/**
* @return the dPortals
*/
public CopyOnWriteArrayList<DPortal> getDPortals() {
return dPortals;
}
/**
* @return the leaveSigns
*/
public CopyOnWriteArrayList<LeaveSign> getLeaveSigns() {
return leaveSigns;
}
/**
* @return the dGroups
*/
public CopyOnWriteArrayList<DGroup> getDGroups() {
return dGroups;
}
/**
* @return the dPlayers
*/
public CopyOnWriteArrayList<DPlayer> getDPlayers() {
return dPlayers;
}
}

View File

@ -0,0 +1,39 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ChatCommand extends DCommand {
public ChatCommand() {
setCommand("chat");
setMinArgs(0);
setMaxArgs(0);
setHelp(plugin.getDMessages().get("Help_Cmd_Chat"));
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
if (dplayer.isInDungeonChat) {
dplayer.isInDungeonChat = false;
MessageUtil.sendMessage(player, plugin.getDMessages().get("Cmd_Chat_NormalChat"));
} else {
dplayer.isInDungeonChat = true;
MessageUtil.sendMessage(player, plugin.getDMessages().get("Cmd_Chat_DungeonChat"));
}
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_NotInDungeon"));
}
}
}

View File

@ -0,0 +1,33 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ChatSpyCommand extends DCommand {
public ChatSpyCommand() {
setCommand("chatspy");
setMinArgs(0);
setMaxArgs(0);
setHelp(plugin.getDMessages().get("Help_Cmd_Chatspy"));
setPermission("dxl.chatspy");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
if (plugin.getChatSpyers().contains(player)) {
plugin.getChatSpyers().remove(player);
MessageUtil.sendMessage(player, plugin.getDMessages().get("Cmd_Chatspy_Stopped"));
} else {
plugin.getChatSpyers().add(player);
MessageUtil.sendMessage(player, plugin.getDMessages().get("Cmd_Chatspy_Start"));
}
}
}

View File

@ -0,0 +1,82 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class CreateCommand extends DCommand {
public CreateCommand() {
setMinArgs(1);
setMaxArgs(1);
setCommand("create");
setHelp(plugin.getDMessages().get("Help_Cmd_Create"));
setPermission("dxl.create");
setPlayerCommand(true);
setConsoleCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
String name = args[1];
if (sender instanceof ConsoleCommandSender) {
if (name.length() <= 15) {
// Msg create
plugin.log(plugin.getDMessages().get("Log_NewDungeon"));
plugin.log(plugin.getDMessages().get("Log_GenerateNewWorld"));
// Create World
EditWorld eworld = new EditWorld();
eworld.generate();
eworld.dungeonname = name;
eworld.save();
eworld.delete();
// MSG Done
plugin.log(plugin.getDMessages().get("Log_WorldGenerationFinished"));
} else {
MessageUtil.sendMessage(sender, plugin.getDMessages().get("Error_NameToLong"));
}
} else if (sender instanceof Player) {
Player player = (Player) sender;
if (DPlayer.get(player) == null) {
if (name.length() <= 15) {
// Msg create
plugin.log(plugin.getDMessages().get("Log_NewDungeon"));
plugin.log(plugin.getDMessages().get("Log_GenerateNewWorld"));
// Create World
EditWorld eworld = new EditWorld();
eworld.generate();
eworld.dungeonname = name;
// MSG Done
plugin.log(plugin.getDMessages().get("Log_WorldGenerationFinished"));
// Tp Player
if (eworld.lobby == null) {
new DPlayer(player, eworld.world, eworld.world.getSpawnLocation(), true);
} else {
new DPlayer(player, eworld.world, eworld.lobby, true);
}
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_NameToLong"));
}
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_LeaveDungeon"));
}
}
}
}

View File

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

View File

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

View File

@ -0,0 +1,36 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.global.DPortal;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import java.util.Set;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class DeletePortalCommand extends DCommand {
public DeletePortalCommand() {
setCommand("deleteportal");
setMinArgs(0);
setMaxArgs(0);
setHelp(plugin.getDMessages().get("Help_Cmd_DeletePortal"));
setPermission("dxl.deleteportal");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPortal dPortal = DPortal.get(player.getTargetBlock((Set<Material>) null, 20).getLocation());
if (dPortal != null) {
dPortal.delete();
MessageUtil.sendMessage(player, plugin.getDMessages().get("Player_PortalDeleted"));
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_NoPortal"));
}
}
}

View File

@ -0,0 +1,54 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class EditCommand extends DCommand {
public EditCommand() {
setCommand("edit");
setMinArgs(1);
setMaxArgs(1);
setHelp(plugin.getDMessages().get("Help_Cmd_Edit"));
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
String dungeonName = args[1];
EditWorld eworld = EditWorld.load(dungeonName);
DGroup dgroup = DGroup.get(player);
DPlayer dplayer = DPlayer.get(player);
if (EditWorld.isInvitedPlayer(dungeonName, player.getUniqueId(), player.getName()) || player.hasPermission("dxl.edit")) {
if (dplayer == null) {
if (dgroup == null) {
if (eworld != null) {
if (eworld.lobby == null) {
new DPlayer(player, eworld.world, eworld.world.getSpawnLocation(), true);
} else {
new DPlayer(player, eworld.world, eworld.lobby, true);
}
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_DungeonNotExist", dungeonName));
}
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_LeaveGroup"));
}
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_LeaveDungeon"));
}
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_NoPermission"));
}
}
}

View File

@ -0,0 +1,54 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class EscapeCommand extends DCommand {
public EscapeCommand() {
setCommand("escape");
setMinArgs(0);
setMaxArgs(0);
setHelp(plugin.getDMessages().get("Help_Cmd_Escape"));
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
if (dplayer.isEditing) {
dplayer.escape();
EditWorld eworld = EditWorld.get(dplayer.world);
if (eworld != null) {
if (eworld.world.getPlayers().isEmpty()) {
eworld.deleteNoSave();
}
}
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_LeaveDungeon"));
}
return;
} else {
DGroup dgroup = DGroup.get(player);
if (dgroup != null) {
dgroup.removePlayer(player);
MessageUtil.sendMessage(player, plugin.getDMessages().get("Cmd_Leave_Success"));
return;
}
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_NotInDungeon"));
}
}
}

View File

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

View File

@ -0,0 +1,30 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import io.github.dre2n.dungeonsxl.util.UUIDUtil;
import org.bukkit.command.CommandSender;
public class InviteCommand extends DCommand {
public InviteCommand() {
setMinArgs(2);
setMaxArgs(2);
setCommand("invite");
setHelp(plugin.getDMessages().get("Help_Cmd_Invite"));
setPermission("dxl.invite");
setPlayerCommand(true);
setConsoleCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
if (EditWorld.addInvitedPlayer(args[2], UUIDUtil.getUniqueIdFromName(args[1]))) {
MessageUtil.sendMessage(sender, plugin.getDMessages().get("Cmd_Invite_Success", args[1], args[2]));
} else {
MessageUtil.sendMessage(sender, plugin.getDMessages().get("Error_DungeonNotExist", args[2]));
}
}
}

View File

@ -0,0 +1,49 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class LeaveCommand extends DCommand {
public LeaveCommand() {
setCommand("leave");
setMinArgs(0);
setMaxArgs(0);
setHelp(plugin.getDMessages().get("Help_Cmd_Leave"));
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dplayer = DPlayer.get(player);
if (GameWorld.get(player.getWorld()) != null) {
if (GameWorld.get(player.getWorld()).isTutorial) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_NoLeaveInTutorial"));
return;
}
}
if (dplayer != null) {
dplayer.leave();
MessageUtil.sendMessage(player, plugin.getDMessages().get("Cmd_Leave_Success"));
} else {
DGroup dgroup = DGroup.get(player);
if (dgroup != null) {
dgroup.removePlayer(player);
MessageUtil.sendMessage(player, plugin.getDMessages().get("Cmd_Leave_Success"));
return;
}
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_NotInDungeon"));
}
}
}

View File

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

View File

@ -0,0 +1,49 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class LivesCommand extends DCommand {
public LivesCommand() {
setCommand("lives");
setMinArgs(0);
setMaxArgs(1);
setHelp(plugin.getDMessages().get("Help_Cmd_Lives"));
setPlayerCommand(true);
setConsoleCommand(true);
}
@SuppressWarnings("deprecation")
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = null;
if (args.length == 2) {
if (Bukkit.getServer().getPlayer(args[1]) != null) {
player = Bukkit.getServer().getPlayer(args[1]);
}
} else if (sender instanceof Player) {
player = (Player) sender;
} else {
MessageUtil.sendMessage(sender, DungeonsXL.getPlugin().getDMessages().get("Error_NoConsoleCommand", getCommand()));
return;
}
DPlayer dPlayer = DPlayer.get(player);
if (dPlayer != null) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Cmd_Lives").replaceAll("v1", player.getName()).replaceAll("v2", String.valueOf(dPlayer.lives)));
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_NotInDungeon"));
}
}
}

View File

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

View File

@ -0,0 +1,91 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.dungeon.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.util.IntegerUtil;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import java.io.File;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class MsgCommand extends DCommand {
public MsgCommand() {
setMinArgs( -1);
setMaxArgs( -1);
setCommand("msg");
setHelp(plugin.getDMessages().get("Help_Cmd_Msg"));
setPermission("dxl.msg");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
EditWorld eworld = EditWorld.get(player.getWorld());
if (eworld != null) {
if (args.length > 1) {
try {
int id = IntegerUtil.parseInt(args[1]);
WorldConfig confreader = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + eworld.dungeonname, "config.yml"));
if (args.length == 2) {
String msg = confreader.getMsg(id, true);
if (msg != null) {
MessageUtil.sendMessage(player, ChatColor.WHITE + msg);
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_MsgIdNotExist", "" + id));
}
} else {
String msg = "";
int i = 0;
for (String arg : args) {
i++;
if (i > 2) {
msg = msg + " " + arg;
}
}
String[] splitMsg = msg.split("\"");
if (splitMsg.length > 1) {
msg = splitMsg[1];
String old = confreader.getMsg(id, false);
if (old == null) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Cmd_Msg_Added", "" + id));
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Cmd_Msg_Updated", "" + id));
}
confreader.setMsg(msg, id);
confreader.save();
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_MsgFormat"));
}
}
} catch (NumberFormatException e) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_MsgNoInt"));
}
} else {
displayHelp(player);
}
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_NotInDungeon"));
}
}
}

View File

@ -0,0 +1,87 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.dungeon.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import java.io.File;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class PlayCommand extends DCommand {
public PlayCommand() {
setCommand("play");
setMinArgs(1);
setMaxArgs(2);
setHelp(plugin.getDMessages().get("Help_Cmd_Play"));
setPermission("dxl.play");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_LeaveDungeon"));
return;
}
if (args.length != 2) {
displayHelp(player);
return;
}
String dungeonname = args[1];
if ( !EditWorld.exist(dungeonname)) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_DungeonNotExist", dungeonname));
return;
}
if ( !GameWorld.canPlayDungeon(dungeonname, player)) {
File file = new File(plugin.getDataFolder() + "/maps/" + dungeonname + "/config.yml");
if (file != null) {
WorldConfig confReader = new WorldConfig(file);
if (confReader != null) {
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Error_Cooldown", "" + confReader.getTimeToNextPlay()));
}
}
return;
}
if ( !GameWorld.checkRequirements(dungeonname, player)) {
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Error_Requirements"));
}
if (DGroup.get(player) != null) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_LeaveGroup"));
return;
}
DGroup dgroup = new DGroup(player, dungeonname);
if (dgroup != null) {
if (dgroup.getGworld() == null) {
dgroup.setGworld(GameWorld.load(DGroup.get(player).getDungeonname()));
}
if (dgroup.getGworld().locLobby == null) {
new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().world.getSpawnLocation(), false);
} else {
new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().locLobby, false);
}
}
}
}

View File

@ -0,0 +1,48 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.global.DPortal;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class PortalCommand extends DCommand {
public PortalCommand() {
setCommand("portal");
setMinArgs(0);
setMaxArgs(0);
setHelp(plugin.getDMessages().get("Help_Cmd_Portal"));
setPermission("dxl.portal");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dplayer = DPlayer.get(player);
if (dplayer == null) {
DPortal dportal = DPortal.get(player);
if (dportal == null) {
dportal = new DPortal(false);
dportal.setPlayer(player);
dportal.setWorld(player.getWorld());
player.getInventory().setItemInHand(new ItemStack(Material.WOOD_SWORD));
MessageUtil.sendMessage(player, plugin.getDMessages().get("Player_PortalIntroduction"));
} else {
plugin.getDPortals().remove(dportal);
MessageUtil.sendMessage(player, plugin.getDMessages().get("Player_PortalAbort"));
}
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_LeaveDungeon"));
}
}
}

View File

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

View File

@ -0,0 +1,33 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SaveCommand extends DCommand {
public SaveCommand() {
setCommand("save");
setMinArgs(0);
setMaxArgs(0);
setHelp(plugin.getDMessages().get("Help_Cmd_Save"));
setPermission("dxl.save");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
EditWorld eworld = EditWorld.get(player.getWorld());
if (eworld != null) {
eworld.save();
MessageUtil.sendMessage(player, plugin.getDMessages().get("Cmd_Save_Success"));
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_NotInDungeon"));
}
}
}

View File

@ -0,0 +1,73 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class TestCommand extends DCommand {
public TestCommand() {
setCommand("test");
setMinArgs(1);
setMaxArgs(2);
setHelp(plugin.getDMessages().get("Help_Cmd_Test"));
setPermission("dxl.test");
setPlayerCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_LeaveDungeon"));
return;
}
if (args.length != 2) {
displayHelp(player);
return;
}
String dungeonname = args[1];
if ( !EditWorld.exist(dungeonname)) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_DungeonNotExist", dungeonname));
return;
}
if (DGroup.get(player) != null) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_LeaveGroup"));
return;
}
if (DGroup.get(player) != null) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_LeaveGroup"));
return;
}
DGroup dgroup = new DGroup(player, dungeonname);
if (dgroup.getGworld() == null) {
dgroup.setGworld(GameWorld.load(DGroup.get(player).getDungeonname()));
}
DPlayer newDPlayer;
if (dgroup.getGworld().locLobby == null) {
newDPlayer = new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().world.getSpawnLocation(), false);
} else {
newDPlayer = new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().locLobby, false);
}
newDPlayer.isinTestMode = true;
}
}

View File

@ -0,0 +1,31 @@
package io.github.dre2n.dungeonsxl.command;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import io.github.dre2n.dungeonsxl.util.UUIDUtil;
import org.bukkit.command.CommandSender;
public class UninviteCommand extends DCommand {
public UninviteCommand() {
setCommand("uninvite");
setMinArgs(2);
setMaxArgs(2);
setHelp(plugin.getDMessages().get("Help_Cmd_Uninvite"));
setPermission("dxl.uninvite");
setPlayerCommand(true);
setConsoleCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
if (EditWorld.removeInvitedPlayer(args[2], UUIDUtil.getUniqueIdFromName(args[1]), args[1])) {
MessageUtil.sendMessage(sender, plugin.getDMessages().get("Cmd_Uninvite_Success", args[1], args[2]));
} else {
MessageUtil.sendMessage(sender, plugin.getDMessages().get("Error_DungeonNotExist", args[2]));
}
}
}

View File

@ -0,0 +1,103 @@
package io.github.dre2n.dungeonsxl.dungeon;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
public class DLootInventory {
static DungeonsXL plugin = DungeonsXL.getPlugin();
private Inventory inventory;
private InventoryView inventoryView;
private Player player;
private long time;
public DLootInventory(Player player, ItemStack[] istacks) {
plugin.getDLootInventories().add(this);
inventory = Bukkit.createInventory(player, 54, DungeonsXL.getPlugin().getDMessages().get("Player_Treasures"));
for (ItemStack istack : istacks) {
if (istack != null) {
inventory.addItem(istack);
}
}
this.player = player;
}
public static DLootInventory get(Player player) {
for (DLootInventory inventory : plugin.getDLootInventories()) {
if (inventory.player == player) {
return inventory;
}
}
return null;
}
/**
* @return the inventory
*/
public Inventory getInventory() {
return inventory;
}
/**
* @param inventory
* the inventory to set
*/
public void setInventory(Inventory inventory) {
this.inventory = inventory;
}
/**
* @return the inventoryView
*/
public InventoryView getInventoryView() {
return inventoryView;
}
/**
* @param inventoryView
* the inventoryView to set
*/
public void setInventoryView(InventoryView inventoryView) {
this.inventoryView = inventoryView;
}
/**
* @return the player
*/
public Player getPlayer() {
return player;
}
/**
* @param player
* the player to set
*/
public void setPlayer(Player player) {
this.player = player;
}
/**
* @return the time
*/
public long getTime() {
return time;
}
/**
* @param time
* the time to set
*/
public void setTime(long time) {
this.time = time;
}
}

View File

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

View File

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

View File

@ -0,0 +1,59 @@
package io.github.dre2n.dungeonsxl.dungeon;
import java.util.ArrayList;
import java.util.List;
public class Dungeons {
private List<Dungeon> dungeons = new ArrayList<Dungeon>();
/**
* @return the dungeons
*/
public List<Dungeon> getDungeons() {
return dungeons;
}
/**
* @param name
* the name of the Dungeon
* @return the Dungeon that has the name
*/
public Dungeon getDungeon(String name) {
for (Dungeon dungeon : dungeons) {
if (dungeon.getName().equals(name)) {
return dungeon;
}
}
return null;
}
/**
* @param name
* the name of the Dungeon
* @return the Dungeon that has the name
*/
public Dungeon loadDungeon(String name) {
Dungeon dungeon = new Dungeon(name);
dungeons.add(dungeon);
return dungeon;
}
/**
* @param dungeon
* the dungeon to add
*/
public void addDungeon(Dungeon dungeon) {
dungeons.add(dungeon);
}
/**
* @param dungeon
* the dungeon to remove
*/
public void removeDungeon(Dungeon dungeon) {
dungeons.remove(dungeon);
}
}

View File

@ -1,4 +1,9 @@
package com.dre.dungeonsxl; package io.github.dre2n.dungeonsxl.dungeon;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.FileUtil;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -19,8 +24,8 @@ import org.bukkit.block.Sign;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class EditWorld { public class EditWorld {
private static P p = P.p;
public static CopyOnWriteArrayList<EditWorld> eworlds = new CopyOnWriteArrayList<EditWorld>(); static DungeonsXL plugin = DungeonsXL.getPlugin();
// Variables // Variables
public World world; public World world;
@ -33,25 +38,26 @@ public class EditWorld {
public CopyOnWriteArrayList<Block> sign = new CopyOnWriteArrayList<Block>(); public CopyOnWriteArrayList<Block> sign = new CopyOnWriteArrayList<Block>();
public EditWorld() { public EditWorld() {
eworlds.add(this); plugin.getEditWorlds().add(this);
// ID // ID
this.id = -1; id = -1;
int i = -1; int i = -1;
while (this.id == -1) { while (id == -1) {
i++; i++;
boolean exist = false; boolean exist = false;
for (EditWorld eworld : eworlds) { for (EditWorld eworld : plugin.getEditWorlds()) {
if (eworld.id == i) { if (eworld.id == i) {
exist = true; exist = true;
break; break;
} }
} }
if (!exist) if ( !exist) {
this.id = i; id = i;
}
} }
name = "DXL_Edit_" + this.id; name = "DXL_Edit_" + id;
} }
public void generate() { public void generate() {
@ -59,70 +65,67 @@ public class EditWorld {
creator.type(WorldType.FLAT); creator.type(WorldType.FLAT);
creator.generateStructures(false); creator.generateStructures(false);
this.world = p.getServer().createWorld(creator); world = plugin.getServer().createWorld(creator);
} }
public void save() { public void save() {
this.world.save(); world.save();
try { try {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(new File(p.getDataFolder(), "/dungeons/" + this.dungeonname + "/DXLData.data"))); ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(new File(plugin.getDataFolder(), "/maps/" + dungeonname + "/DXLData.data")));
out.writeInt(this.sign.size()); out.writeInt(sign.size());
for (Block sign : this.sign) { for (Block sign : this.sign) {
out.writeInt(sign.getX()); out.writeInt(sign.getX());
out.writeInt(sign.getY()); out.writeInt(sign.getY());
out.writeInt(sign.getZ()); out.writeInt(sign.getZ());
} }
out.close(); out.close();
} catch (IOException exception) {
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} }
} }
public void checkSign(Block block) { public void checkSign(Block block) {
if ((block.getState() instanceof Sign)) { if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState(); Sign sign = (Sign) block.getState();
String[] lines = sign.getLines(); String[] lines = sign.getLines();
if (lines[0].equalsIgnoreCase("[lobby]")) { if (lines[0].equalsIgnoreCase("[lobby]")) {
this.lobby = block.getLocation(); lobby = block.getLocation();
} }
} }
} }
public void delete() { public void delete() {
eworlds.remove(this); plugin.getEditWorlds().remove(this);
for (Player player : this.world.getPlayers()) { for (Player player : world.getPlayers()) {
DPlayer dplayer = DPlayer.get(player); DPlayer dplayer = DPlayer.get(player);
dplayer.leave(); dplayer.leave();
} }
p.getServer().unloadWorld(this.world, true); plugin.getServer().unloadWorld(world, true);
File dir = new File("DXL_Edit_" + this.id); File dir = new File("DXL_Edit_" + id);
p.copyDirectory(dir, new File(p.getDataFolder(), "/dungeons/" + this.dungeonname)); FileUtil.copyDirectory(dir, new File(plugin.getDataFolder(), "/maps/" + dungeonname));
p.deletenotusingfiles(new File(p.getDataFolder(), "/dungeons/" + this.dungeonname)); FileUtil.deletenotusingfiles(new File(plugin.getDataFolder(), "/maps/" + dungeonname));
p.removeDirectory(dir); FileUtil.removeDirectory(dir);
} }
public void deleteNoSave() { public void deleteNoSave() {
eworlds.remove(this); plugin.getEditWorlds().remove(this);
for (Player player : this.world.getPlayers()) { for (Player player : world.getPlayers()) {
DPlayer dplayer = DPlayer.get(player); DPlayer dplayer = DPlayer.get(player);
dplayer.leave(); dplayer.leave();
} }
File dir = new File("DXL_Edit_" + this.id); File dir = new File("DXL_Edit_" + id);
p.copyDirectory(dir, new File(p.getDataFolder(), "/dungeons/" + this.dungeonname)); FileUtil.copyDirectory(dir, new File(plugin.getDataFolder(), "/maps/" + dungeonname));
p.deletenotusingfiles(new File(p.getDataFolder(), "/dungeons/" + this.dungeonname)); FileUtil.deletenotusingfiles(new File(plugin.getDataFolder(), "/maps/" + dungeonname));
p.getServer().unloadWorld(this.world, true); plugin.getServer().unloadWorld(world, true);
p.removeDirectory(dir); FileUtil.removeDirectory(dir);
} }
// Static // Static
public static EditWorld get(World world) { public static EditWorld get(World world) {
for (EditWorld eworld : eworlds) { for (EditWorld eworld : plugin.getEditWorlds()) {
if (eworld.world.equals(world)) { if (eworld.world.equals(world)) {
return eworld; return eworld;
} }
@ -132,7 +135,7 @@ public class EditWorld {
} }
public static EditWorld get(String name) { public static EditWorld get(String name) {
for (EditWorld eworld : eworlds) { for (EditWorld eworld : plugin.getEditWorlds()) {
if (eworld.dungeonname.equalsIgnoreCase(name)) { if (eworld.dungeonname.equalsIgnoreCase(name)) {
return eworld; return eworld;
} }
@ -142,26 +145,26 @@ public class EditWorld {
} }
public static void deleteAll() { public static void deleteAll() {
for (EditWorld eworld : eworlds) { for (EditWorld eworld : plugin.getEditWorlds()) {
eworld.delete(); eworld.delete();
} }
} }
public static EditWorld load(String name) { public static EditWorld load(String name) {
for (EditWorld eworld : eworlds) { for (EditWorld eworld : plugin.getEditWorlds()) {
if (eworld.dungeonname.equalsIgnoreCase(name)) { if (eworld.dungeonname.equalsIgnoreCase(name)) {
return eworld; return eworld;
} }
} }
File file = new File(p.getDataFolder(), "/dungeons/" + name); File file = new File(plugin.getDataFolder(), "/maps/" + name);
if (file.exists()) { if (file.exists()) {
EditWorld eworld = new EditWorld(); EditWorld eworld = new EditWorld();
eworld.dungeonname = name; eworld.dungeonname = name;
// World // World
p.copyDirectory(file, new File("DXL_Edit_" + eworld.id)); FileUtil.copyDirectory(file, new File("DXL_Edit_" + eworld.id));
// Id File // Id File
File idFile = new File("DXL_Edit_" + eworld.id + "/.id_" + name); File idFile = new File("DXL_Edit_" + eworld.id + "/.id_" + name);
@ -171,10 +174,10 @@ public class EditWorld {
e.printStackTrace(); e.printStackTrace();
} }
eworld.world = p.getServer().createWorld(WorldCreator.name("DXL_Edit_" + eworld.id)); eworld.world = plugin.getServer().createWorld(WorldCreator.name("DXL_Edit_" + eworld.id));
try { try {
ObjectInputStream os = new ObjectInputStream(new FileInputStream(new File(p.getDataFolder(), "/dungeons/" + eworld.dungeonname + "/DXLData.data"))); ObjectInputStream os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder(), "/maps/" + eworld.dungeonname + "/DXLData.data")));
int length = os.readInt(); int length = os.readInt();
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
int x = os.readInt(); int x = os.readInt();
@ -200,14 +203,14 @@ public class EditWorld {
public static boolean exist(String name) { public static boolean exist(String name) {
// Cheack Loaded EditWorlds // Cheack Loaded EditWorlds
for (EditWorld eworld : eworlds) { for (EditWorld eworld : plugin.getEditWorlds()) {
if (eworld.dungeonname.equalsIgnoreCase(name)) { if (eworld.dungeonname.equalsIgnoreCase(name)) {
return true; return true;
} }
} }
// Cheack Unloaded Worlds // Cheack Unloaded Worlds
File file = new File(p.getDataFolder(), "/dungeons/" + name); File file = new File(plugin.getDataFolder(), "/maps/" + name);
if (file.exists()) { if (file.exists()) {
return true; return true;
@ -217,15 +220,15 @@ public class EditWorld {
} }
public void msg(String msg) { public void msg(String msg) {
for (DPlayer dplayer : DPlayer.get(this.world)) { for (DPlayer dplayer : DPlayer.get(world)) {
p.msg(dplayer.player, msg); MessageUtil.sendMessage(dplayer.player, msg);
} }
} }
// Invite // Invite
public static boolean addInvitedPlayer(String eworldname, UUID uuid) { public static boolean addInvitedPlayer(String eworldname, UUID uuid) {
if (exist(eworldname)) { if (exist(eworldname)) {
DConfig config = new DConfig(new File(p.getDataFolder() + "/dungeons/" + eworldname, "config.yml")); WorldConfig config = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + eworldname, "config.yml"));
config.addInvitedPlayer(uuid.toString()); config.addInvitedPlayer(uuid.toString());
config.save(); config.save();
return true; return true;
@ -237,7 +240,7 @@ public class EditWorld {
public static boolean removeInvitedPlayer(String eworldname, UUID uuid, String name) { public static boolean removeInvitedPlayer(String eworldname, UUID uuid, String name) {
if (exist(eworldname)) { if (exist(eworldname)) {
DConfig config = new DConfig(new File(p.getDataFolder() + "/dungeons/" + eworldname, "config.yml")); WorldConfig config = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + eworldname, "config.yml"));
config.removeInvitedPlayers(uuid.toString(), name.toLowerCase()); config.removeInvitedPlayers(uuid.toString(), name.toLowerCase());
config.save(); config.save();
@ -261,13 +264,14 @@ public class EditWorld {
public static boolean isInvitedPlayer(String eworldname, UUID uuid, String name) { public static boolean isInvitedPlayer(String eworldname, UUID uuid, String name) {
if (exist(eworldname)) { if (exist(eworldname)) {
DConfig config = new DConfig(new File(p.getDataFolder() + "/dungeons/" + eworldname, "config.yml")); WorldConfig config = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + eworldname, "config.yml"));
// get player from both a 0.9.1 and lower and 0.9.2 and higher file // get player from both a 0.9.1 and lower and 0.9.2 and higher file
if (config.getInvitedPlayers().contains(name.toLowerCase()) || config.getInvitedPlayers().contains(uuid.toString())) if (config.getInvitedPlayers().contains(name.toLowerCase()) || config.getInvitedPlayers().contains(uuid.toString())) {
return true; return true;
} }
}
return false; return false;
}
} }
}

View File

@ -1,11 +1,16 @@
package com.dre.dungeonsxl; package io.github.dre2n.dungeonsxl.dungeon;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.mob.DMobType;
import io.github.dre2n.dungeonsxl.player.DClass;
import io.github.dre2n.dungeonsxl.util.IntegerUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@ -17,8 +22,11 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class DConfig { public class WorldConfig {
public static DConfig mainConfig = new DConfig();
static DungeonsXL plugin = DungeonsXL.getPlugin();
public static WorldConfig defaultConfig = new WorldConfig();
private File file; private File file;
@ -51,11 +59,11 @@ public class DConfig {
// MobTypes // MobTypes
private Set<DMobType> mobTypes = new HashSet<DMobType>(); private Set<DMobType> mobTypes = new HashSet<DMobType>();
public DConfig() { public WorldConfig() {
} }
public DConfig(File file) { public WorldConfig(File file) {
this.file = file; this.file = file;
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file); FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
@ -63,13 +71,13 @@ public class DConfig {
load(configFile); load(configFile);
} }
public DConfig(ConfigurationSection configFile) { public WorldConfig(ConfigurationSection configFile) {
load(configFile); load(configFile);
} }
// Load & Save // Load & Save
@SuppressWarnings("deprecation")
public void load(ConfigurationSection configFile) { public void load(ConfigurationSection configFile) {
/* Classes */ /* Classes */
ConfigurationSection configSetionClasses = configFile.getConfigurationSection("classes"); ConfigurationSection configSetionClasses = configFile.getConfigurationSection("classes");
if (configSetionClasses != null) { if (configSetionClasses != null) {
@ -77,7 +85,6 @@ public class DConfig {
for (String className : list) { for (String className : list) {
String name = className; String name = className;
boolean hasDog = configSetionClasses.getBoolean(className + ".dog"); boolean hasDog = configSetionClasses.getBoolean(className + ".dog");
/* Items */ /* Items */
List<String> items = configSetionClasses.getStringList(className + ".items"); List<String> items = configSetionClasses.getStringList(className + ".items");
CopyOnWriteArrayList<ItemStack> istacks = new CopyOnWriteArrayList<ItemStack>(); CopyOnWriteArrayList<ItemStack> istacks = new CopyOnWriteArrayList<ItemStack>();
@ -87,20 +94,18 @@ public class DConfig {
if (itemsplit.length > 0) { if (itemsplit.length > 0) {
int itemId = 0, itemData = 0, itemSize = 1, itemLvlEnchantment = 1; int itemId = 0, itemData = 0, itemSize = 1, itemLvlEnchantment = 1;
Enchantment itemEnchantment = null; Enchantment itemEnchantment = null;
// Check Id & Data // Check Id & Data
String[] idAndData = itemsplit[0].split("/"); String[] idAndData = itemsplit[0].split("/");
itemId = P.p.parseInt(idAndData[0]); itemId = IntegerUtil.parseInt(idAndData[0]);
if (idAndData.length > 1) { if (idAndData.length > 1) {
itemData = P.p.parseInt(idAndData[1]); itemData = IntegerUtil.parseInt(idAndData[1]);
} }
// Size // Size
if (itemsplit.length > 1) { if (itemsplit.length > 1) {
itemSize = P.p.parseInt(itemsplit[1]); itemSize = IntegerUtil.parseInt(itemsplit[1]);
} }
// Enchantment // Enchantment
if (itemsplit.length > 2) { if (itemsplit.length > 2) {
String[] enchantmentSplit = itemsplit[2].split("/"); String[] enchantmentSplit = itemsplit[2].split("/");
@ -108,7 +113,7 @@ public class DConfig {
itemEnchantment = Enchantment.getByName(enchantmentSplit[0]); itemEnchantment = Enchantment.getByName(enchantmentSplit[0]);
if (enchantmentSplit.length > 1) { if (enchantmentSplit.length > 1) {
itemLvlEnchantment = P.p.parseInt(enchantmentSplit[1]); itemLvlEnchantment = IntegerUtil.parseInt(enchantmentSplit[1]);
} }
} }
@ -117,13 +122,12 @@ public class DConfig {
if (itemEnchantment != null) { if (itemEnchantment != null) {
istack.addEnchantment(itemEnchantment, itemLvlEnchantment); istack.addEnchantment(itemEnchantment, itemLvlEnchantment);
} }
istacks.add(istack); istacks.add(istack);
} }
} }
/* Create Class */ /* Create Class */
this.dClasses.add(new DClass(name, istacks, hasDog)); dClasses.add(new DClass(name, istacks, hasDog));
} }
} }
@ -132,8 +136,8 @@ public class DConfig {
if (configSetionMessages != null) { if (configSetionMessages != null) {
Set<String> list = configSetionMessages.getKeys(false); Set<String> list = configSetionMessages.getKeys(false);
for (String messagePath : list) { for (String messagePath : list) {
int messageId = P.p.parseInt(messagePath); int messageId = IntegerUtil.parseInt(messagePath);
this.msgs.put(messageId, configSetionMessages.getString(messagePath)); msgs.put(messageId, configSetionMessages.getString(messagePath));
} }
} }
@ -141,7 +145,7 @@ public class DConfig {
if (configFile.contains("secureObjects")) { if (configFile.contains("secureObjects")) {
List<Integer> secureobjectlist = configFile.getIntegerList("secureObjects"); List<Integer> secureobjectlist = configFile.getIntegerList("secureObjects");
for (int i : secureobjectlist) { for (int i : secureobjectlist) {
this.secureObjects.add(Material.getMaterial(i)); secureObjects.add(Material.getMaterial(i));
} }
} }
@ -149,7 +153,7 @@ public class DConfig {
if (configFile.contains("invitedPlayers")) { if (configFile.contains("invitedPlayers")) {
List<String> invitedplayers = configFile.getStringList("invitedPlayers"); List<String> invitedplayers = configFile.getStringList("invitedPlayers");
for (String i : invitedplayers) { for (String i : invitedplayers) {
this.invitedPlayers.add(i); invitedPlayers.add(i);
} }
} }
@ -165,75 +169,75 @@ public class DConfig {
keepInventoryOnFinish = configFile.getBoolean("keepInventory"); keepInventoryOnFinish = configFile.getBoolean("keepInventory");
} }
} else { } else {
if (mainConfig.keepInventory) { if (plugin.getDefaultConfig().keepInventory) {
keepInventoryOnEnter = mainConfig.keepInventory; keepInventoryOnEnter = plugin.getDefaultConfig().keepInventory;
keepInventoryOnEscape = mainConfig.keepInventory; keepInventoryOnEscape = plugin.getDefaultConfig().keepInventory;
keepInventoryOnFinish = mainConfig.keepInventory; keepInventoryOnFinish = plugin.getDefaultConfig().keepInventory;
} }
} }
if (configFile.contains("keepInventoryOnEnter")) { if (configFile.contains("keepInventoryOnEnter")) {
keepInventoryOnEnter = configFile.getBoolean("keepInventoryOnEnter"); keepInventoryOnEnter = configFile.getBoolean("keepInventoryOnEnter");
} else { } else {
keepInventoryOnEnter = mainConfig.keepInventoryOnEnter; keepInventoryOnEnter = plugin.getDefaultConfig().keepInventoryOnEnter;
} }
if (configFile.contains("keepInventoryOnEscape")) { if (configFile.contains("keepInventoryOnEscape")) {
keepInventoryOnEscape = configFile.getBoolean("keepInventoryOnEscape"); keepInventoryOnEscape = configFile.getBoolean("keepInventoryOnEscape");
} else { } else {
keepInventoryOnEscape = mainConfig.keepInventoryOnEscape; keepInventoryOnEscape = plugin.getDefaultConfig().keepInventoryOnEscape;
} }
if (configFile.contains("keepInventoryOnFinish")) { if (configFile.contains("keepInventoryOnFinish")) {
keepInventoryOnFinish = configFile.getBoolean("keepInventoryOnFinish"); keepInventoryOnFinish = configFile.getBoolean("keepInventoryOnFinish");
} else { } else {
keepInventoryOnFinish = mainConfig.keepInventoryOnFinish; keepInventoryOnFinish = plugin.getDefaultConfig().keepInventoryOnFinish;
} }
if (configFile.contains("keepInventoryOnDeath")) { if (configFile.contains("keepInventoryOnDeath")) {
keepInventoryOnDeath = configFile.getBoolean("keepInventoryOnDeath"); keepInventoryOnDeath = configFile.getBoolean("keepInventoryOnDeath");
} else { } else {
keepInventoryOnDeath = mainConfig.keepInventoryOnDeath; keepInventoryOnDeath = plugin.getDefaultConfig().keepInventoryOnDeath;
} }
/* Lives */ /* Lives */
if (configFile.contains("initialLives")) { if (configFile.contains("initialLives")) {
initialLives = configFile.getInt("initialLives"); initialLives = configFile.getInt("initialLives");
} else { } else {
initialLives = mainConfig.getInitialLives(); initialLives = plugin.getDefaultConfig().getInitialLives();
} }
/* Lobby */ /* Lobby */
if (configFile.contains("isLobbyDisabled")) { if (configFile.contains("isLobbyDisabled")) {
isLobbyDisabled = configFile.getBoolean("isLobbyDisabled"); isLobbyDisabled = configFile.getBoolean("isLobbyDisabled");
} else { } else {
isLobbyDisabled = mainConfig.isLobbyDisabled; isLobbyDisabled = plugin.getDefaultConfig().isLobbyDisabled;
} }
/* Times */ /* Times */
if (configFile.contains("timeToNextPlay")) { if (configFile.contains("timeToNextPlay")) {
timeToNextPlay = configFile.getInt("timeToNextPlay"); timeToNextPlay = configFile.getInt("timeToNextPlay");
} else { } else {
timeToNextPlay = mainConfig.timeToNextPlay; timeToNextPlay = plugin.getDefaultConfig().timeToNextPlay;
} }
if (configFile.contains("timeToNextLoot")) { if (configFile.contains("timeToNextLoot")) {
timeToNextLoot = configFile.getInt("timeToNextLoot"); timeToNextLoot = configFile.getInt("timeToNextLoot");
} else { } else {
timeToNextLoot = mainConfig.timeToNextLoot; timeToNextLoot = plugin.getDefaultConfig().timeToNextLoot;
} }
if (configFile.contains("timeUntilKickOfflinePlayer")) { if (configFile.contains("timeUntilKickOfflinePlayer")) {
timeUntilKickOfflinePlayer = configFile.getInt("timeUntilKickOfflinePlayer"); timeUntilKickOfflinePlayer = configFile.getInt("timeUntilKickOfflinePlayer");
} else { } else {
timeUntilKickOfflinePlayer = mainConfig.timeUntilKickOfflinePlayer; timeUntilKickOfflinePlayer = plugin.getDefaultConfig().timeUntilKickOfflinePlayer;
} }
/* Dungeon Requirements */ /* Dungeon Requirements */
if (configFile.contains("fee")) { if (configFile.contains("fee")) {
fee = configFile.getDouble("fee"); fee = configFile.getDouble("fee");
} else { } else {
fee = mainConfig.fee; fee = plugin.getDefaultConfig().fee;
} }
if (configFile.contains("mustFinishOne")) { if (configFile.contains("mustFinishOne")) {
@ -254,12 +258,13 @@ public class DConfig {
/* Mobtypes */ /* Mobtypes */
configSetionMessages = configFile.getConfigurationSection("mobTypes"); configSetionMessages = configFile.getConfigurationSection("mobTypes");
this.mobTypes = DMobType.load(configSetionMessages); mobTypes = DMobType.load(configSetionMessages);
} }
@SuppressWarnings("deprecation")
public void save() { public void save() {
if (this.file != null) { if (file != null) {
FileConfiguration configFile = YamlConfiguration.loadConfiguration(this.file); FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
// Messages // Messages
for (Integer msgs : this.msgs.keySet()) { for (Integer msgs : this.msgs.keySet()) {
@ -269,17 +274,17 @@ public class DConfig {
// Secure Objects // Secure Objects
CopyOnWriteArrayList<Integer> secureObjectsids = new CopyOnWriteArrayList<Integer>(); CopyOnWriteArrayList<Integer> secureObjectsids = new CopyOnWriteArrayList<Integer>();
for (Material mat : this.secureObjects) { for (Material mat : secureObjects) {
secureObjectsids.add(mat.getId()); secureObjectsids.add(mat.getId());
} }
configFile.set("secureObjects", secureObjectsids); configFile.set("secureObjects", secureObjectsids);
// Invited Players // Invited Players
configFile.set("invitedPlayers", this.invitedPlayers); configFile.set("invitedPlayers", invitedPlayers);
try { try {
configFile.save(this.file); configFile.save(file);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -288,24 +293,24 @@ public class DConfig {
// Getters and Setters // Getters and Setters
public CopyOnWriteArrayList<DClass> getClasses() { public CopyOnWriteArrayList<DClass> getClasses() {
if (this.dClasses != null) { if (dClasses != null) {
if (!this.dClasses.isEmpty()) { if ( !dClasses.isEmpty()) {
return this.dClasses; return dClasses;
} }
} }
return mainConfig.dClasses; return plugin.getDefaultConfig().dClasses;
} }
public DClass getClass(String name) { public DClass getClass(String name) {
for (DClass dClass : this.dClasses) { for (DClass dClass : dClasses) {
if (dClass.name.equals(name)) { if (dClass.getName().equals(name)) {
return dClass; return dClass;
} }
} }
for (DClass dClass : mainConfig.dClasses) { for (DClass dClass : plugin.getDefaultConfig().dClasses) {
if (dClass.name.equals(name)) { if (dClass.getName().equals(name)) {
return dClass; return dClass;
} }
} }
@ -313,42 +318,42 @@ public class DConfig {
} }
public String getMsg(int id, boolean returnMainConfig) { public String getMsg(int id, boolean returnMainConfig) {
String msg = this.msgs.get(id); String msg = msgs.get(id);
if (msg != null) { if (msg != null) {
return this.msgs.get(id); return msgs.get(id);
} }
if (returnMainConfig) { if (returnMainConfig) {
return mainConfig.msgs.get(id); return plugin.getDefaultConfig().msgs.get(id);
} }
return null; return null;
} }
public void setMsg(String msg, int id) { public void setMsg(String msg, int id) {
this.msgs.put(id, msg); msgs.put(id, msg);
} }
public CopyOnWriteArrayList<String> getInvitedPlayers() { public CopyOnWriteArrayList<String> getInvitedPlayers() {
CopyOnWriteArrayList<String> tmpInvitedPlayers = new CopyOnWriteArrayList<String>(); CopyOnWriteArrayList<String> tmpInvitedPlayers = new CopyOnWriteArrayList<String>();
tmpInvitedPlayers.addAll(this.invitedPlayers); tmpInvitedPlayers.addAll(invitedPlayers);
tmpInvitedPlayers.addAll(mainConfig.invitedPlayers); tmpInvitedPlayers.addAll(plugin.getDefaultConfig().invitedPlayers);
return tmpInvitedPlayers; return tmpInvitedPlayers;
} }
public void addInvitedPlayer(String uuid) { public void addInvitedPlayer(String uuid) {
this.invitedPlayers.add(uuid); invitedPlayers.add(uuid);
} }
public void removeInvitedPlayers(String uuid, String name) { public void removeInvitedPlayers(String uuid, String name) {
this.invitedPlayers.remove(uuid); invitedPlayers.remove(uuid);
// remove player from a 0.9.1 and lower file // remove player from a 0.9.1 and lower file
this.invitedPlayers.remove(name); invitedPlayers.remove(name);
} }
public CopyOnWriteArrayList<Material> getSecureObjects() { public CopyOnWriteArrayList<Material> getSecureObjects() {
CopyOnWriteArrayList<Material> tmpSecureObjects = new CopyOnWriteArrayList<Material>(); CopyOnWriteArrayList<Material> tmpSecureObjects = new CopyOnWriteArrayList<Material>();
tmpSecureObjects.addAll(this.secureObjects); tmpSecureObjects.addAll(secureObjects);
tmpSecureObjects.addAll(mainConfig.secureObjects); tmpSecureObjects.addAll(plugin.getDefaultConfig().secureObjects);
return tmpSecureObjects; return tmpSecureObjects;
} }

View File

@ -1,7 +1,12 @@
package com.dre.dungeonsxl.game; package io.github.dre2n.dungeonsxl.dungeon.game;
import net.milkbowl.vault.item.Items; import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import net.milkbowl.vault.item.ItemInfo; import net.milkbowl.vault.item.ItemInfo;
import net.milkbowl.vault.item.Items;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
@ -10,27 +15,23 @@ import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.dre.dungeonsxl.DGroup;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.P;
public class GameChest { public class GameChest {
// Variables // Variables
public boolean isUsed = false; public boolean isUsed = false;
public Chest chest; public Chest chest;
public GameWorld gworld; public GameWorld gWorld;
public double moneyReward; public double moneyReward;
public GameChest(Block chest, GameWorld gworld, double moneyReward) { public GameChest(Block chest, GameWorld gWorld, double moneyReward) {
if (chest.getState() instanceof Chest) { if (chest.getState() instanceof Chest) {
this.chest = (Chest) chest.getState(); this.chest = (Chest) chest.getState();
this.gworld = gworld; this.gWorld = gWorld;
this.moneyReward = moneyReward; this.moneyReward = moneyReward;
gworld.gchests.add(this); gWorld.gameChests.add(this);
} }
} }
@ -41,12 +42,15 @@ public class GameChest {
if (dplayer != null) { if (dplayer != null) {
dplayer.treasureMoney = dplayer.treasureMoney + moneyReward; dplayer.treasureMoney = dplayer.treasureMoney + moneyReward;
String msg = ""; String msg = "";
for (ItemStack istack : this.chest.getInventory().getContents()) { for (ItemStack istack : chest.getInventory().getContents()) {
if (istack != null) { if (istack != null) {
dplayer.treasureInv.addItem(istack); dplayer.treasureInv.addItem(istack);
String name; String name;
if (istack.hasItemMeta() && istack.getItemMeta().hasDisplayName()) { if (istack.hasItemMeta() && istack.getItemMeta().hasDisplayName()) {
name = istack.getItemMeta().getDisplayName(); name = istack.getItemMeta().getDisplayName();
} else { } else {
ItemInfo itemInfo = Items.itemByStack(istack); ItemInfo itemInfo = Items.itemByStack(istack);
if (itemInfo != null) { if (itemInfo != null) {
@ -58,11 +62,12 @@ public class GameChest {
msg = msg + ChatColor.RED + " " + istack.getAmount() + " " + name + ChatColor.GOLD + ","; msg = msg + ChatColor.RED + " " + istack.getAmount() + " " + name + ChatColor.GOLD + ",";
} }
} }
msg = msg.substring(0, msg.length() - 1); msg = msg.substring(0, msg.length() - 1);
P.p.msg(player, P.p.language.get("Player_LootAdded", msg)); MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Player_LootAdded", msg));
if (moneyReward != 0) { if (moneyReward != 0) {
P.p.msg(player, P.p.language.get("Player_LootAdded", String.valueOf(moneyReward))); MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Player_LootAdded", String.valueOf(moneyReward)));
} }
} }
} }
@ -73,22 +78,24 @@ public class GameChest {
public static void onOpenInventory(InventoryOpenEvent event) { public static void onOpenInventory(InventoryOpenEvent event) {
InventoryView inventory = event.getView(); InventoryView inventory = event.getView();
GameWorld gworld = GameWorld.get(event.getPlayer().getWorld()); GameWorld gWorld = GameWorld.get(event.getPlayer().getWorld());
if (gworld != null) { if (gWorld != null) {
if (inventory.getTopInventory().getHolder() instanceof Chest) { if (inventory.getTopInventory().getHolder() instanceof Chest) {
Chest chest = (Chest) inventory.getTopInventory().getHolder(); Chest chest = (Chest) inventory.getTopInventory().getHolder();
for (GameChest gchest : gworld.gchests) { for (GameChest gchest : gWorld.gameChests) {
if (gchest.chest.equals(chest)) { if (gchest.chest.equals(chest)) {
if ( !gchest.isUsed) { if ( !gchest.isUsed) {
if (gchest.chest.getLocation().distance(chest.getLocation()) < 1) { if (gchest.chest.getLocation().distance(chest.getLocation()) < 1) {
gchest.addTreasure(DGroup.get(gworld)); gchest.addTreasure(DGroup.get(gWorld));
gchest.isUsed = true; gchest.isUsed = true;
event.setCancelled(true); event.setCancelled(true);
} }
} else { } else {
P.p.msg(P.p.getServer().getPlayer(event.getPlayer().getUniqueId()), ChatColor.RED + "Diese Kiste wurde schon geöffnet!"); MessageUtil.sendMessage(DungeonsXL.getPlugin().getServer().getPlayer(event.getPlayer().getUniqueId()), DungeonsXL.getPlugin().getDMessages().get("Error_ChestIsOpened"));
event.setCancelled(true); event.setCancelled(true);
} }
} }

View File

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

View File

@ -0,0 +1,368 @@
package io.github.dre2n.dungeonsxl.dungeon.game;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.dungeon.DungeonConfig;
import io.github.dre2n.dungeonsxl.dungeon.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.mob.DMob;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.sign.DSign;
import io.github.dre2n.dungeonsxl.trigger.RedstoneTrigger;
import io.github.dre2n.dungeonsxl.util.FileUtil;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Spider;
public class GameWorld {
static DungeonsXL plugin = DungeonsXL.getPlugin();
// Variables placeable
public boolean isTutorial;
public CopyOnWriteArrayList<GamePlaceableBlock> placeableBlocks = new CopyOnWriteArrayList<GamePlaceableBlock>();
public World world;
public String dungeonname;
public Location locLobby;
public Location locStart;
public boolean isPlaying = false;
public int id;
public CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<Material>();
public CopyOnWriteArrayList<Chunk> loadedChunks = new CopyOnWriteArrayList<Chunk>();
public CopyOnWriteArrayList<Sign> signClass = new CopyOnWriteArrayList<Sign>();
public CopyOnWriteArrayList<DMob> dMobs = new CopyOnWriteArrayList<DMob>();
public CopyOnWriteArrayList<GameChest> gameChests = new CopyOnWriteArrayList<GameChest>();
public CopyOnWriteArrayList<DSign> dSigns = new CopyOnWriteArrayList<DSign>();
private WorldConfig worldConfig;
public GameWorld() {
plugin.getGameWorlds().add(this);
// ID
id = -1;
int i = -1;
while (id == -1) {
i++;
boolean exist = false;
for (GameWorld gWorld : plugin.getGameWorlds()) {
if (gWorld.id == i) {
exist = true;
break;
}
}
if ( !exist) {
id = i;
}
}
}
public void checkSign(Block block) {
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
dSigns.add(DSign.create(sign, this));
}
}
public void startGame() {
isPlaying = true;
for (DSign dSign : dSigns) {
if (dSign != null) {
if ( !dSign.isOnDungeonInit()) {
dSign.onInit();
}
}
}
if (RedstoneTrigger.hasTriggers(this)) {
for (RedstoneTrigger trigger : RedstoneTrigger.getTriggersArray(this)) {
trigger.onTrigger();
}
}
for (DSign dSign : dSigns) {
if (dSign != null) {
if ( !dSign.hasTriggers()) {
dSign.onTrigger();
}
}
}
}
public void msg(String msg) {
for (DPlayer dplayer : DPlayer.get(world)) {
MessageUtil.sendMessage(dplayer.player, msg);
}
}
/**
* @return the worldConfig
*/
public WorldConfig getConfig() {
return worldConfig;
}
/**
* @param worldConfig
* the worldConfig to set
*/
public void setConfig(WorldConfig worldConfig) {
this.worldConfig = worldConfig;
}
/**
* @return the Dungeon that contains the GameWorld
*/
public Dungeon getDungeon() {
for (Dungeon dungeon : plugin.getDungeons().getDungeons()) {
DungeonConfig dungeonConfig = dungeon.getConfig();
if (dungeonConfig.getFloors().contains(this) || dungeonConfig.getStartFloor().equals(this) || dungeonConfig.getEndFloor().equals(this)) {
return dungeon;
}
}
return null;
}
// Statics
public static GameWorld get(World world) {
for (GameWorld gWorld : plugin.getGameWorlds()) {
if (gWorld.world.equals(world)) {
return gWorld;
}
}
return null;
}
public static void deleteAll() {
for (GameWorld gWorld : plugin.getGameWorlds()) {
gWorld.delete();
}
}
public static boolean canPlayDungeon(String dungeon, Player player) {
if (player.hasPermission("dungeonsxl.ignoretimelimit")) {
return true;
}
if (new File(plugin.getDataFolder() + "/maps/" + dungeon).isDirectory()) {
WorldConfig worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + dungeon, "config.yml"));
if (worldConfig.getTimeToNextPlay() != 0) {
// read PlayerConfig
Long time = getPlayerTime(dungeon, player);
if (time != -1) {
if (time + worldConfig.getTimeToNextPlay() * 1000 * 60 * 60 > System.currentTimeMillis()) {
return false;
}
}
}
} else {
return false;
}
return true;
}
public static boolean checkRequirements(String dungeon, Player player) {
/* if (plugin.permission.has(player, "dungeonsxl.ignoreRequirements") || player.isOp()) {
* return true; } */
if (new File(plugin.getDataFolder() + "/maps/" + dungeon).isDirectory() == false) {
return false;
}
WorldConfig worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + dungeon, "config.yml"));
if (plugin.getMainConfig().enableEconomy()) {
if ( !(DungeonsXL.getPlugin().economy.getBalance(player) >= worldConfig.getFee())) {
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 long getPlayerTime(String dungeon, Player player) {
File file = new File(plugin.getDataFolder() + "/maps/" + dungeon, "players.yml");
if ( !file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.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 void delete() {
plugin.getGameWorlds().remove(this);
plugin.getServer().unloadWorld(world, true);
File dir = new File("DXL_Game_" + id);
FileUtil.removeDirectory(dir);
}
public static GameWorld load(String name) {
File file = new File(plugin.getDataFolder(), "/maps/" + name);
if (file.exists()) {
GameWorld gWorld = new GameWorld();
gWorld.dungeonname = name;
// Unload empty eworlds
for (EditWorld eworld : plugin.getEditWorlds()) {
if (eworld.world.getPlayers().isEmpty()) {
eworld.delete();
}
}
// Config einlesen
gWorld.worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + gWorld.dungeonname, "config.yml"));
// Secure Objects
gWorld.secureObjects = gWorld.worldConfig.getSecureObjects();
// World
FileUtil.copyDirectory(file, new File("DXL_Game_" + gWorld.id));
// Id File
File idFile = new File("DXL_Game_" + gWorld.id + "/.id_" + name);
try {
idFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
gWorld.world = plugin.getServer().createWorld(WorldCreator.name("DXL_Game_" + gWorld.id));
ObjectInputStream os;
try {
os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder() + "/maps/" + gWorld.dungeonname + "/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 = gWorld.world.getBlockAt(x, y, z);
gWorld.checkSign(block);
}
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return gWorld;
}
return null;
}
public static void update() {
for (GameWorld gWorld : plugin.getGameWorlds()) {
// Update Spiders
for (LivingEntity mob : gWorld.world.getLivingEntities()) {
if (mob.getType() == EntityType.SPIDER || mob.getType() == EntityType.CAVE_SPIDER) {
Spider spider = (Spider) mob;
if (spider.getTarget() != null) {
if (spider.getTarget().getType() == EntityType.PLAYER) {
continue;
}
}
for (Entity player : spider.getNearbyEntities(10, 10, 10)) {
if (player.getType() == EntityType.PLAYER) {
spider.setTarget((LivingEntity) player);
}
}
}
}
}
}
}

View File

@ -1,4 +1,4 @@
package com.dre.dungeonsxl; package io.github.dre2n.dungeonsxl.file;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -9,15 +9,16 @@ import java.util.TreeMap;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
public class LanguageReader { public class DMessages {
private Map<String, String> entries = new TreeMap<String, String>(); private Map<String, String> entries = new TreeMap<String, String>();
private Map<String, String> defaults = new TreeMap<String, String>(); private Map<String, String> defaults = new TreeMap<String, String>();
private File file; private File file;
private boolean changed; private boolean changed;
public LanguageReader(File file) { public DMessages(File file) {
this.setDefaults(); setDefaults();
/* Load */ /* Load */
this.file = file; this.file = file;
@ -30,7 +31,7 @@ public class LanguageReader {
} }
/* Check */ /* Check */
this.check(); check();
} }
private void setDefaults() { private void setDefaults() {
@ -64,6 +65,7 @@ public class LanguageReader {
defaults.put("Player_BlockInfo", "&6Block-ID: &2&v1"); defaults.put("Player_BlockInfo", "&6Block-ID: &2&v1");
defaults.put("Player_Death", "&6You died, lives left: &2v1"); defaults.put("Player_Death", "&6You died, lives left: &2v1");
defaults.put("Player_DeathKick", "&2v1&6 died and lost his last life."); defaults.put("Player_DeathKick", "&2v1&6 died and lost his last life.");
defaults.put("Player_Treasures", "&1Treasures");
/* Cmds */ /* Cmds */
defaults.put("Cmd_Chat_DungeonChat", "&6You have entered the Dungeon-chat"); defaults.put("Cmd_Chat_DungeonChat", "&6You have entered the Dungeon-chat");
@ -72,15 +74,19 @@ public class LanguageReader {
defaults.put("Cmd_Chatspy_Start", "&You started spying the DXL-chat!"); defaults.put("Cmd_Chatspy_Start", "&You started spying the DXL-chat!");
defaults.put("Cmd_Invite_Success", "&6Player &4&v1&6 was successfully invited to edit the Dungeon &4&v2&6!"); defaults.put("Cmd_Invite_Success", "&6Player &4&v1&6 was successfully invited to edit the Dungeon &4&v2&6!");
defaults.put("Cmd_Leave_Success", "&6You have successfully left your group!"); defaults.put("Cmd_Leave_Success", "&6You have successfully left your group!");
defaults.put("Cmd_Main_Welcome", "&7Welcome to &4Dungeons&fXL");
defaults.put("Cmd_Main_Loaded", "&eDungeons: &o[&v1] &eLoaded: &o[&v2] &ePlayers: &o[&v3]");
defaults.put("Cmd_Main_Compatibility", "&eInternals: &o[&v1] &eVault: &o[&v2] &eMythicMobs: &o[&v3]");
defaults.put("Cmd_Main_Help", "&7Type in &o/dxl help&r&7 for further information.");
defaults.put("Cmd_Msg_Added", "&6New Message (&4&v1&6) added!"); defaults.put("Cmd_Msg_Added", "&6New Message (&4&v1&6) added!");
defaults.put("Cmd_Msg_Updated", "&6Message (&4&v1&6) updated!"); defaults.put("Cmd_Msg_Updated", "&6Message (&4&v1&6) updated!");
defaults.put("Cmd_Reload_Start", "&6Reloading DungeonsXL..."); defaults.put("Cmd_Reload_Done", "&7Successfully reloaded DungeonsXL.");
defaults.put("Cmd_Reload_Done", "&6DungeonsXL was successfully reloaded!");
defaults.put("Cmd_Save_Success", "&6Dungeon saved!"); defaults.put("Cmd_Save_Success", "&6Dungeon saved!");
defaults.put("Cmd_Uninvite_Success", "&4&v1&6 was successfully uninvited to edit the Dungeon &4&v1&6!"); defaults.put("Cmd_Uninvite_Success", "&4&v1&6 was successfully uninvited to edit the Dungeon &4&v1&6!");
defaults.put("Cmd_Lives", "&4v1&6 has &4v2 &6lives left."); defaults.put("Cmd_Lives", "&4v1&6 has &4v2 &6lives left.");
/* Errors */ /* Errors */
defaults.put("Error_ChestIsOpened", "&4This chest has already been opened.");
defaults.put("Error_Enderchest", "&4You cannot use an enderchest while in a Dungeon!"); defaults.put("Error_Enderchest", "&4You cannot use an enderchest while in a Dungeon!");
defaults.put("Error_Bed", "&4You cannot use a bed while in a Dungeon!"); defaults.put("Error_Bed", "&4You cannot use a bed while in a Dungeon!");
defaults.put("Error_Dispenser", "&4You cannot access this dispenser!"); defaults.put("Error_Dispenser", "&4You cannot access this dispenser!");
@ -106,6 +112,7 @@ public class LanguageReader {
defaults.put("Error_TutorialNotExist", "&4Tutorial dungeon does not exist!"); defaults.put("Error_TutorialNotExist", "&4Tutorial dungeon does not exist!");
defaults.put("Error_NoPortal", "&4You have to look at a portal!"); defaults.put("Error_NoPortal", "&4You have to look at a portal!");
defaults.put("Error_NoPlayerCommand", "&6/dxl &v1&4 cannot be executed as player!"); defaults.put("Error_NoPlayerCommand", "&6/dxl &v1&4 cannot be executed as player!");
defaults.put("Error_NoPlayerCommand", "&6/dxl &v1&4 cannot be executed as console!");
defaults.put("Error_SignWrongFormat", "&4The sign is not written correctly!"); defaults.put("Error_SignWrongFormat", "&4The sign is not written correctly!");
/* Help */ /* Help */
@ -113,11 +120,12 @@ public class LanguageReader {
defaults.put("Help_Cmd_Chatspy", "/dxl chatspy - Dis/enables the spymode"); defaults.put("Help_Cmd_Chatspy", "/dxl chatspy - Dis/enables the spymode");
defaults.put("Help_Cmd_Create", "/dxl create <name> - Creates a new dungeon"); defaults.put("Help_Cmd_Create", "/dxl create <name> - Creates a new dungeon");
defaults.put("Help_Cmd_Edit", "/dxl edit <name> - Edit an existing dungeon"); defaults.put("Help_Cmd_Edit", "/dxl edit <name> - Edit an existing dungeon");
defaults.put("Help_Cmd_Help", "/dxl help - Shows the help page"); defaults.put("Help_Cmd_Help", "/dxl help <page> - Shows the help page");
defaults.put("Help_Cmd_Invite", "/dxl invite <player> <dungeon> - Invite a player to edit a dungeon"); defaults.put("Help_Cmd_Invite", "/dxl invite <player> <dungeon> - Invite a player to edit a dungeon");
defaults.put("Help_Cmd_Leave", "/dxl leave - Leaves the current dungeon"); defaults.put("Help_Cmd_Leave", "/dxl leave - Leaves the current dungeon");
defaults.put("Help_Cmd_Escape", "/dxl escape - Leaves the current dungeon, without saving!"); defaults.put("Help_Cmd_Escape", "/dxl escape - Leaves the current dungeon, without saving!");
defaults.put("Help_Cmd_List", "/dxl list - Lists all dungeons"); defaults.put("Help_Cmd_List", "/dxl list <page> - Lists all dungeons");
defaults.put("Help_Cmd_Main", "/dxl - General status information");
defaults.put("Help_Cmd_Msg", "/dxl msg <id> '[msg]' - Show or edit a message"); defaults.put("Help_Cmd_Msg", "/dxl msg <id> '[msg]' - Show or edit a message");
defaults.put("Help_Cmd_Portal", "/dxl portal - Creates a portal that leads into a dungeon"); defaults.put("Help_Cmd_Portal", "/dxl portal - Creates a portal that leads into a dungeon");
defaults.put("Help_Cmd_DeletePortal", "/dxl deleteportal - Deletes the portal you are looking at"); defaults.put("Help_Cmd_DeletePortal", "/dxl deleteportal - Deletes the portal you are looking at");
@ -145,8 +153,9 @@ public class LanguageReader {
String filePath = file.getPath(); String filePath = file.getPath();
File temp = new File(filePath.substring(0, filePath.length() - 4) + "_old.yml"); File temp = new File(filePath.substring(0, filePath.length() - 4) + "_old.yml");
if (temp.exists()) if (temp.exists()) {
temp.delete(); temp.delete();
}
source.renameTo(temp); source.renameTo(temp);
@ -182,4 +191,5 @@ public class LanguageReader {
return entry; return entry;
} }
} }

View File

@ -0,0 +1,111 @@
package io.github.dre2n.dungeonsxl.file;
import io.github.dre2n.dungeonsxl.dungeon.WorldConfig;
import java.io.File;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
public class MainConfig {
private String language = "en";
private boolean enableEconomy = false;
/* Tutorial */
private boolean tutorialActivated = false;
private String tutorialDungeon = "tutorial";
private String tutorialStartGroup = "default";
private String tutorialEndGroup = "player";
/* Default Dungeon Settings */
public WorldConfig defaultDungeon;
public MainConfig(File file) {
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
/* Main Config */
if (configFile.contains("language")) {
language = configFile.getString("language");
}
if (configFile.contains("enableEconomy")) {
enableEconomy = configFile.getBoolean("enableEconomy");
}
if (configFile.contains("tutorial.activated")) {
tutorialActivated = configFile.getBoolean("tutorial.activated");
}
if (configFile.contains("tutorial.dungeon")) {
tutorialDungeon = configFile.getString("tutorial.dungeon");
}
if (configFile.contains("tutorial.startgroup")) {
tutorialStartGroup = configFile.getString("tutorial.startgroup");
}
if (configFile.contains("tutorial.endgroup")) {
tutorialEndGroup = configFile.getString("tutorial.endgroup");
}
/* Default Dungeon Config */
ConfigurationSection configSetion = configFile.getConfigurationSection("default");
if (configSetion != null) {
defaultDungeon = new WorldConfig(configSetion);
WorldConfig.defaultConfig = defaultDungeon;
}
}
/**
* @return the language
*/
public String getLanguage() {
return language;
}
/**
* @param language
* the language to set
*/
public void setLanguage(String language) {
this.language = language;
}
/**
* @return the enableEconomy
*/
public boolean enableEconomy() {
return enableEconomy;
}
/**
* @return the tutorialActivated
*/
public boolean isTutorialActivated() {
return tutorialActivated;
}
/**
* @return the tutorialDungeon
*/
public String getTutorialDungeon() {
return tutorialDungeon;
}
/**
* @return the tutorialStartGroup
*/
public String getTutorialStartGroup() {
return tutorialStartGroup;
}
/**
* @return the tutorialEndGroup
*/
public String getTutorialEndGroup() {
return tutorialEndGroup;
}
}

View File

@ -1,35 +1,37 @@
package com.dre.dungeonsxl; package io.github.dre2n.dungeonsxl.global;
import java.util.concurrent.CopyOnWriteArrayList; import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import org.bukkit.Material;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.dre.dungeonsxl.game.GameWorld;
public class DPortal { public class DPortal {
public static P p = P.p;
public static CopyOnWriteArrayList<DPortal> portals = new CopyOnWriteArrayList<DPortal>(); static DungeonsXL plugin = DungeonsXL.getPlugin();
public World world; private World world;
public Block block1, block2; private Block block1;
public boolean isActive; private Block block2;
public Player player; private boolean isActive;
private Player player;
public DPortal(boolean active) { public DPortal(boolean active) {
portals.add(this); plugin.getDPortals().add(this);
this.isActive = active; isActive = active;
} }
public void create() { public void create() {
this.player = null; player = null;
if (this.block1 != null && this.block2 != null) { if (block1 != null && block2 != null) {
int x1 = block1.getX(), y1 = block1.getY(), z1 = block1.getZ(); int x1 = block1.getX(), y1 = block1.getY(), z1 = block1.getZ();
int x2 = block2.getX(), y2 = block2.getY(), z2 = block2.getZ(); int x2 = block2.getX(), y2 = block2.getY(), z2 = block2.getZ();
int xcount = 0, ycount = 0, zcount = 0; int xcount = 0, ycount = 0, zcount = 0;
@ -56,12 +58,13 @@ public class DPortal {
do { do {
int zz = z1; int zz = z1;
do { do {
Material type = this.world.getBlockAt(xx, yy, zz).getType(); Material type = world.getBlockAt(xx, yy, zz).getType();
if (type == Material.AIR || type == Material.WATER || type == Material.STATIONARY_WATER || type == Material.LAVA || type == Material.STATIONARY_LAVA || type == Material.SAPLING if (type == Material.AIR || type == Material.WATER || type == Material.STATIONARY_WATER || type == Material.LAVA || type == Material.STATIONARY_LAVA
|| type == Material.WEB || type == Material.LONG_GRASS || type == Material.DEAD_BUSH || type == Material.PISTON_EXTENSION || type == Material.YELLOW_FLOWER || type == Material.SAPLING || type == Material.WEB || type == Material.LONG_GRASS || type == Material.DEAD_BUSH || type == Material.PISTON_EXTENSION
|| type == Material.RED_ROSE || type == Material.BROWN_MUSHROOM || type == Material.RED_MUSHROOM || type == Material.TORCH || type == Material.FIRE || type == Material.YELLOW_FLOWER || type == Material.RED_ROSE || type == Material.BROWN_MUSHROOM || type == Material.RED_MUSHROOM || type == Material.TORCH
|| type == Material.CROPS || type == Material.REDSTONE_WIRE || type == Material.REDSTONE_TORCH_OFF || type == Material.SNOW || type == Material.REDSTONE_TORCH_ON) { || type == Material.FIRE || type == Material.CROPS || type == Material.REDSTONE_WIRE || type == Material.REDSTONE_TORCH_OFF || type == Material.SNOW
this.world.getBlockAt(xx, yy, zz).setType(Material.PORTAL); || type == Material.REDSTONE_TORCH_ON) {
world.getBlockAt(xx, yy, zz).setType(Material.PORTAL);
} }
zz = zz + zcount; zz = zz + zcount;
@ -74,7 +77,7 @@ public class DPortal {
} while (xx != x2 + xcount); } while (xx != x2 + xcount);
} else { } else {
portals.remove(this); plugin.getDPortals().remove(this);
} }
} }
@ -95,17 +98,17 @@ public class DPortal {
} }
} else { } else {
p.msg(player, p.language.get("Error_DungeonNotExist", DGroup.get(player).getDungeonname())); MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_DungeonNotExist", DGroup.get(player).getDungeonname()));
} }
} else { } else {
p.msg(player, p.language.get("Error_NotInGroup")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_NotInGroup"));
} }
} }
public void delete() { public void delete() {
portals.remove(this); plugin.getDPortals().remove(this);
int x1 = block1.getX(), y1 = block1.getY(), z1 = block1.getZ(); int x1 = block1.getX(), y1 = block1.getY(), z1 = block1.getZ();
int x2 = block2.getX(), y2 = block2.getY(), z2 = block2.getZ(); int x2 = block2.getX(), y2 = block2.getY(), z2 = block2.getZ();
@ -133,10 +136,10 @@ public class DPortal {
do { do {
int zz = z1; int zz = z1;
do { do {
Material type = this.world.getBlockAt(xx, yy, zz).getType(); Material type = world.getBlockAt(xx, yy, zz).getType();
if (type == Material.PORTAL) { if (type == Material.PORTAL) {
this.world.getBlockAt(xx, yy, zz).setType(Material.AIR); world.getBlockAt(xx, yy, zz).setType(Material.AIR);
} }
zz = zz + zcount; zz = zz + zcount;
@ -155,34 +158,40 @@ public class DPortal {
} }
public static DPortal get(Block block) { public static DPortal get(Block block) {
for (DPortal portal : portals) { for (DPortal portal : plugin.getDPortals()) {
int x1 = portal.block1.getX(), y1 = portal.block1.getY(), z1 = portal.block1.getZ(); int x1 = portal.block1.getX(), y1 = portal.block1.getY(), z1 = portal.block1.getZ();
int x2 = portal.block2.getX(), y2 = portal.block2.getY(), z2 = portal.block2.getZ(); int x2 = portal.block2.getX(), y2 = portal.block2.getY(), z2 = portal.block2.getZ();
int x3 = block.getX(), y3 = block.getY(), z3 = block.getZ(); int x3 = block.getX(), y3 = block.getY(), z3 = block.getZ();
if (x1 > x2) { if (x1 > x2) {
if (x3 < x2 || x3 > x1) if (x3 < x2 || x3 > x1) {
continue; continue;
}
} else { } else {
if (x3 > x2 || x3 < x1) if (x3 > x2 || x3 < x1) {
continue; continue;
} }
}
if (y1 > y2) { if (y1 > y2) {
if (y3 < y2 || y3 > y1) if (y3 < y2 || y3 > y1) {
continue; continue;
}
} else { } else {
if (y3 > y2 || y3 < y1) if (y3 > y2 || y3 < y1) {
continue; continue;
} }
}
if (z1 > z2) { if (z1 > z2) {
if (z3 < z2 || z3 > z1) if (z3 < z2 || z3 > z1) {
continue; continue;
}
} else { } else {
if (z3 > z2 || z3 < z1) if (z3 > z2 || z3 < z1) {
continue; continue;
} }
}
return portal; return portal;
} }
@ -191,7 +200,7 @@ public class DPortal {
} }
public static DPortal get(Player player) { public static DPortal get(Player player) {
for (DPortal portal : portals) { for (DPortal portal : plugin.getDPortals()) {
if (portal.player == player) { if (portal.player == player) {
return portal; return portal;
} }
@ -202,7 +211,7 @@ public class DPortal {
// Save and Load // Save and Load
public static void save(FileConfiguration configFile) { public static void save(FileConfiguration configFile) {
int id = 0; int id = 0;
for (DPortal dportal : portals) { for (DPortal dportal : plugin.getDPortals()) {
id++; id++;
if (dportal.isActive) { if (dportal.isActive) {
String preString = "portal." + dportal.world.getName() + "." + id; String preString = "portal." + dportal.world.getName() + "." + id;
@ -219,7 +228,7 @@ public class DPortal {
} }
public static void load(FileConfiguration configFile) { public static void load(FileConfiguration configFile) {
for (World world : p.getServer().getWorlds()) { for (World world : plugin.getServer().getWorlds()) {
if (configFile.contains("portal." + world.getName())) { if (configFile.contains("portal." + world.getName())) {
int id = 0; int id = 0;
String preString; String preString;
@ -238,4 +247,79 @@ public class DPortal {
} }
} }
/**
* @return the world
*/
public World getWorld() {
return world;
}
/**
* @param world
* the world to set
*/
public void setWorld(World world) {
this.world = world;
}
/**
* @return the block1
*/
public Block getBlock1() {
return block1;
}
/**
* @param block1
* the block1 to set
*/
public void setBlock1(Block block1) {
this.block1 = block1;
}
/**
* @return the block2
*/
public Block getBlock2() {
return block2;
}
/**
* @param block2
* the block2 to set
*/
public void setBlock2(Block block2) {
this.block2 = block2;
}
/**
* @return the isActive
*/
public boolean isActive() {
return isActive;
}
/**
* @param isActive
* the isActive to set
*/
public void setActive(boolean isActive) {
this.isActive = isActive;
}
/**
* @return the player
*/
public Player getPlayer() {
return player;
}
/**
* @param player
* the player to set
*/
public void setPlayer(Player player) {
this.player = player;
}
} }

View File

@ -1,4 +1,10 @@
package com.dre.dungeonsxl; package io.github.dre2n.dungeonsxl.global;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.dungeon.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import java.io.File; import java.io.File;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@ -11,46 +17,46 @@ import org.bukkit.block.Sign;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.dre.dungeonsxl.game.GameWorld; public class GroupSign {
public class DGSign { static DungeonsXL plugin = DungeonsXL.getPlugin();
public static CopyOnWriteArrayList<DGSign> dgsigns = new CopyOnWriteArrayList<DGSign>();
// Sign Labels // Sign Labels
public static String strIsPlaying = ChatColor.DARK_RED + "Is Playing"; public static final String strIsPlaying = ChatColor.DARK_RED + "Is Playing";
public static String strFull = ChatColor.DARK_RED + "Full"; public static final String strFull = ChatColor.DARK_RED + "Full";
public static String strJoinGrp = ChatColor.DARK_GREEN + "Join Group"; public static final String strJoinGrp = ChatColor.DARK_GREEN + "Join Group";
public static String strNewGrp = ChatColor.DARK_GREEN + "New Group"; public static final String strNewGrp = ChatColor.DARK_GREEN + "New Group";
// Variables // Variables
public DGroup[] dgroups; private DGroup[] dgroups;
public String dungeonName; private String dungeonName;
public int maxPlayersPerGroup; private int maxPlayersPerGroup;
public Block startSign; private Block startSign;
public int directionX = 0, directionZ = 0; private int directionX = 0, directionZ = 0;
public int verticalSigns; private int verticalSigns;
public DGSign(Block startSign, String dungeonName, int maxGroups, int maxPlayersPerGroup) { public GroupSign(Block startSign, String dungeonName, int maxGroups, int maxPlayersPerGroup) {
dgsigns.add(this); plugin.getGroupSigns().add(this);
this.startSign = startSign; this.startSign = startSign;
this.dungeonName = dungeonName; this.dungeonName = dungeonName;
this.dgroups = new DGroup[maxGroups]; dgroups = new DGroup[maxGroups];
this.maxPlayersPerGroup = maxPlayersPerGroup; this.maxPlayersPerGroup = maxPlayersPerGroup;
this.verticalSigns = (int) Math.ceil((float) (1 + maxPlayersPerGroup) / 4); verticalSigns = (int) Math.ceil((float) (1 + maxPlayersPerGroup) / 4);
@SuppressWarnings("deprecation")
int[] direction = getDirection(this.startSign.getData()); int[] direction = getDirection(this.startSign.getData());
this.directionX = direction[0]; directionX = direction[0];
this.directionZ = direction[1]; directionZ = direction[1];
this.update(); update();
} }
public void update() { public void update() {
int i = 0; int i = 0;
for (DGroup dgroup : this.dgroups) { for (DGroup dgroup : dgroups) {
if ((this.startSign.getRelative(i * directionX, 0, i * directionZ).getState() instanceof Sign)) { if (startSign.getRelative(i * directionX, 0, i * directionZ).getState() instanceof Sign) {
Sign sign = (Sign) this.startSign.getRelative(i * directionX, 0, i * directionZ).getState(); Sign sign = (Sign) startSign.getRelative(i * directionX, 0, i * directionZ).getState();
// Reset Signs // Reset Signs
sign.setLine(0, ""); sign.setLine(0, "");
@ -71,9 +77,9 @@ public class DGSign {
// Set Signs // Set Signs
if (dgroup != null) { if (dgroup != null) {
if (dgroup.isPlaying) { if (dgroup.isPlaying()) {
sign.setLine(0, strIsPlaying); sign.setLine(0, strIsPlaying);
} else if (dgroup.getPlayers().size() >= this.maxPlayersPerGroup) { } else if (dgroup.getPlayers().size() >= maxPlayersPerGroup) {
sign.setLine(0, strFull); sign.setLine(0, strFull);
} else { } else {
sign.setLine(0, strJoinGrp); sign.setLine(0, strJoinGrp);
@ -102,7 +108,8 @@ public class DGSign {
// Static // Static
public static DGSign tryToCreate(Block startSign, String dungeonName, int maxGroups, int maxPlayersPerGroup) { @SuppressWarnings("deprecation")
public static GroupSign tryToCreate(Block startSign, String dungeonName, int maxGroups, int maxPlayersPerGroup) {
World world = startSign.getWorld(); World world = startSign.getWorld();
int direction = startSign.getData(); int direction = startSign.getData();
int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ(); int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ();
@ -179,63 +186,76 @@ public class DGSign {
for (Block block : changeBlocks) { for (Block block : changeBlocks) {
block.setTypeIdAndData(68, startSign.getData(), true); block.setTypeIdAndData(68, startSign.getData(), true);
} }
DGSign sign = new DGSign(startSign, dungeonName, maxGroups, maxPlayersPerGroup); GroupSign sign = new GroupSign(startSign, dungeonName, maxGroups, maxPlayersPerGroup);
return sign; return sign;
} }
@SuppressWarnings("deprecation")
public static boolean isRelativeSign(Block block, int x, int z) { public static boolean isRelativeSign(Block block, int x, int z) {
DGSign dgsign = getSign(block.getRelative(x, 0, z)); GroupSign dgsign = getSign(block.getRelative(x, 0, z));
if (dgsign != null) { if (dgsign != null) {
if (x == -1 && dgsign.startSign.getData() == 4) if (x == -1 && dgsign.startSign.getData() == 4) {
return true; return true;
if (x == 1 && dgsign.startSign.getData() == 5) }
if (x == 1 && dgsign.startSign.getData() == 5) {
return true; return true;
if (z == -1 && dgsign.startSign.getData() == 2) }
if (z == -1 && dgsign.startSign.getData() == 2) {
return true; return true;
if (z == 1 && dgsign.startSign.getData() == 3) }
if (z == 1 && dgsign.startSign.getData() == 3) {
return true; return true;
} }
}
return false; return false;
} }
public static DGSign getSign(Block block) { public static GroupSign getSign(Block block) {
if (block.getType() == Material.WALL_SIGN) { if (block.getType() == Material.WALL_SIGN) {
int x = block.getX(), y = block.getY(), z = block.getZ(); int x = block.getX(), y = block.getY(), z = block.getZ();
for (DGSign dgsign : dgsigns) { for (GroupSign dgsign : plugin.getGroupSigns()) {
int sx1 = dgsign.startSign.getX(), sy1 = dgsign.startSign.getY(), sz1 = dgsign.startSign.getZ(); int sx1 = dgsign.startSign.getX(), sy1 = dgsign.startSign.getY(), sz1 = dgsign.startSign.getZ();
int sx2 = sx1 + (dgsign.dgroups.length - 1) * dgsign.directionX; int sx2 = sx1 + (dgsign.dgroups.length - 1) * dgsign.directionX;
int sy2 = sy1 - dgsign.verticalSigns + 1; int sy2 = sy1 - dgsign.verticalSigns + 1;
int sz2 = sz1 + (dgsign.dgroups.length - 1) * dgsign.directionZ; int sz2 = sz1 + (dgsign.dgroups.length - 1) * dgsign.directionZ;
if (sx1 > sx2) { if (sx1 > sx2) {
if (x < sx2 || x > sx1) if (x < sx2 || x > sx1) {
continue; continue;
}
} else if (sx1 < sx2) { } else if (sx1 < sx2) {
if (x > sx2 || x < sx1) if (x > sx2 || x < sx1) {
continue; continue;
}
} else { } else {
if (x != sx1) if (x != sx1) {
continue; continue;
} }
}
if (sy1 > sy2) { if (sy1 > sy2) {
if (y < sy2 || y > sy1) if (y < sy2 || y > sy1) {
continue;
} else {
if (y != sy1)
continue; continue;
} }
if (sz1 > sz2) {
if (z < sz2 || z > sz1)
continue;
} else if (sz1 < sz2) {
if (z > sz2 || z < sz1)
continue;
} else { } else {
if (z != sz1) if (y != sy1) {
continue; continue;
} }
}
if (sz1 > sz2) {
if (z < sz2 || z > sz1) {
continue;
}
} else if (sz1 < sz2) {
if (z > sz2 || z < sz1) {
continue;
}
} else {
if (z != sz1) {
continue;
}
}
return dgsign; return dgsign;
} }
@ -245,7 +265,7 @@ public class DGSign {
public static boolean playerInteract(Block block, Player player) { public static boolean playerInteract(Block block, Player player) {
int x = block.getX(), y = block.getY(), z = block.getZ(); int x = block.getX(), y = block.getY(), z = block.getZ();
DGSign dgsign = getSign(block); GroupSign dgsign = getSign(block);
if (dgsign != null) { if (dgsign != null) {
if (GameWorld.canPlayDungeon(dgsign.dungeonName, player)) { if (GameWorld.canPlayDungeon(dgsign.dungeonName, player)) {
if (GameWorld.checkRequirements(dgsign.dungeonName, player)) { if (GameWorld.checkRequirements(dgsign.dungeonName, player)) {
@ -260,13 +280,14 @@ public class DGSign {
column = Math.abs(z - sz1); column = Math.abs(z - sz1);
} }
if ((topBlock.getState() instanceof Sign)) { if (topBlock.getState() instanceof Sign) {
Sign topSign = (Sign) topBlock.getState(); Sign topSign = (Sign) topBlock.getState();
if (topSign.getLine(0).equals(strNewGrp)) { if (topSign.getLine(0).equals(strNewGrp)) {
if (DGroup.get(player) == null) { if (DGroup.get(player) == null) {
dgsign.dgroups[column] = new DGroup(player, dgsign.dungeonName); dgsign.dgroups[column] = new DGroup(player, dgsign.dungeonName);
dgsign.update(); dgsign.update();
} }
} else if (topSign.getLine(0).equals(strJoinGrp)) { } else if (topSign.getLine(0).equals(strJoinGrp)) {
if (DGroup.get(player) == null) { if (DGroup.get(player) == null) {
dgsign.dgroups[column].addPlayer(player); dgsign.dgroups[column].addPlayer(player);
@ -275,15 +296,17 @@ public class DGSign {
} }
} }
} else { } else {
P.p.msg(player, P.p.language.get("Error_Requirements")); MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Error_Requirements"));
} }
} else { } else {
File file = new File(P.p.getDataFolder() + "/dungeons/" + dgsign.dungeonName, "config.yml"); File file = new File(DungeonsXL.getPlugin().getDataFolder() + "/maps/" + dgsign.dungeonName, "config.yml");
if (file != null) { if (file != null) {
DConfig confReader = new DConfig(file); WorldConfig confReader = new WorldConfig(file);
if (confReader != null) { if (confReader != null) {
P.p.msg(player, P.p.language.get("Error_Cooldown", "" + confReader.getTimeToNextPlay())); MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Error_Cooldown", "" + confReader.getTimeToNextPlay()));
} }
} }
} }
@ -295,13 +318,14 @@ public class DGSign {
public static void updatePerGroup(DGroup dgroupsearch) { public static void updatePerGroup(DGroup dgroupsearch) {
for (DGSign dgsign : dgsigns) { for (GroupSign dgsign : plugin.getGroupSigns()) {
int i = 0; int i = 0;
for (DGroup dgroup : dgsign.dgroups) { for (DGroup dgroup : dgsign.dgroups) {
if (dgroup != null) { if (dgroup != null) {
if (dgroup == dgroupsearch) { if (dgroup == dgroupsearch) {
if (dgroupsearch.isEmpty()) if (dgroupsearch.isEmpty()) {
dgsign.dgroups[i] = null; dgsign.dgroups[i] = null;
}
dgsign.update(); dgsign.update();
} }
} }
@ -333,7 +357,7 @@ public class DGSign {
public static void save(FileConfiguration configFile) { public static void save(FileConfiguration configFile) {
int id = 0; int id = 0;
for (DGSign dgsign : dgsigns) { for (GroupSign dgsign : plugin.getGroupSigns()) {
id++; id++;
String preString = "groupsign." + dgsign.startSign.getWorld().getName() + "." + id; String preString = "groupsign." + dgsign.startSign.getWorld().getName() + "." + id;
@ -351,7 +375,7 @@ public class DGSign {
} }
public static void load(FileConfiguration configFile) { public static void load(FileConfiguration configFile) {
for (World world : P.p.getServer().getWorlds()) { for (World world : DungeonsXL.getPlugin().getServer().getWorlds()) {
if (configFile.contains("groupsign." + world.getName())) { if (configFile.contains("groupsign." + world.getName())) {
int id = 0; int id = 0;
String preString; String preString;
@ -364,7 +388,7 @@ public class DGSign {
int maxPlayersPerGroup = configFile.getInt(preString + ".maxPlayersPerGroup"); int maxPlayersPerGroup = configFile.getInt(preString + ".maxPlayersPerGroup");
Block startSign = world.getBlockAt(configFile.getInt(preString + ".x"), configFile.getInt(preString + ".y"), configFile.getInt(preString + ".z")); Block startSign = world.getBlockAt(configFile.getInt(preString + ".x"), configFile.getInt(preString + ".y"), configFile.getInt(preString + ".z"));
new DGSign(startSign, dungeonName, maxGroups, maxPlayersPerGroup); new GroupSign(startSign, dungeonName, maxGroups, maxPlayersPerGroup);
} }
} while (configFile.contains(preString)); } while (configFile.contains(preString));
} }

View File

@ -1,6 +1,9 @@
package com.dre.dungeonsxl; package io.github.dre2n.dungeonsxl.global;
import java.util.concurrent.CopyOnWriteArrayList; import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -11,23 +14,24 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class LeaveSign { public class LeaveSign {
public static CopyOnWriteArrayList<LeaveSign> lsigns = new CopyOnWriteArrayList<LeaveSign>();
public Sign sign; static DungeonsXL plugin = DungeonsXL.getPlugin();
private Sign sign;
public LeaveSign(Sign sign) { public LeaveSign(Sign sign) {
lsigns.add(this); plugin.getLeaveSigns().add(this);
this.sign = sign; this.sign = sign;
this.setText(); setText();
} }
public void setText() { public void setText() {
this.sign.setLine(0, ChatColor.BLUE + "############"); sign.setLine(0, ChatColor.BLUE + "############");
this.sign.setLine(1, ChatColor.DARK_GREEN + "Leave"); sign.setLine(1, ChatColor.DARK_GREEN + "Leave");
this.sign.setLine(2, ""); sign.setLine(2, "");
this.sign.setLine(3, ChatColor.BLUE + "############"); sign.setLine(3, ChatColor.BLUE + "############");
this.sign.update(); sign.update();
} }
public static boolean playerInteract(Block block, Player player) { public static boolean playerInteract(Block block, Player player) {
@ -43,7 +47,7 @@ public class LeaveSign {
DGroup dgroup = DGroup.get(player); DGroup dgroup = DGroup.get(player);
if (dgroup != null) { if (dgroup != null) {
dgroup.removePlayer(player); dgroup.removePlayer(player);
P.p.msg(player, P.p.language.get("Player_LeaveGroup"));// ChatColor.YELLOW+"Du hast deine Gruppe erfolgreich verlassen!"); MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Player_LeaveGroup"));// ChatColor.YELLOW+"Du hast deine Gruppe erfolgreich verlassen!");
return true; return true;
} }
} }
@ -51,25 +55,30 @@ public class LeaveSign {
return false; return false;
} }
@SuppressWarnings("deprecation")
public static boolean isRelativeSign(Block block, int x, int z) { public static boolean isRelativeSign(Block block, int x, int z) {
LeaveSign lsign = getSign(block.getRelative(x, 0, z)); LeaveSign lsign = getSign(block.getRelative(x, 0, z));
if (lsign != null) { if (lsign != null) {
if (x == -1 && lsign.sign.getData().getData() == 4) if (x == -1 && lsign.sign.getData().getData() == 4) {
return true; return true;
if (x == 1 && lsign.sign.getData().getData() == 5) }
if (x == 1 && lsign.sign.getData().getData() == 5) {
return true; return true;
if (z == -1 && lsign.sign.getData().getData() == 2) }
if (z == -1 && lsign.sign.getData().getData() == 2) {
return true; return true;
if (z == 1 && lsign.sign.getData().getData() == 3) }
if (z == 1 && lsign.sign.getData().getData() == 3) {
return true; return true;
} }
}
return false; return false;
} }
public static LeaveSign getSign(Block block) { public static LeaveSign getSign(Block block) {
if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) { if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) {
for (LeaveSign leavesign : lsigns) { for (LeaveSign leavesign : plugin.getLeaveSigns()) {
if (block.getWorld() == leavesign.sign.getWorld()) { if (block.getWorld() == leavesign.sign.getWorld()) {
if (block.getLocation().distance(leavesign.sign.getBlock().getLocation()) < 1) { if (block.getLocation().distance(leavesign.sign.getBlock().getLocation()) < 1) {
return leavesign; return leavesign;
@ -83,7 +92,7 @@ public class LeaveSign {
// Save and Load // Save and Load
public static void save(FileConfiguration configFile) { public static void save(FileConfiguration configFile) {
int id = 0; int id = 0;
for (LeaveSign lsign : lsigns) { for (LeaveSign lsign : plugin.getLeaveSigns()) {
id++; id++;
String preString = "leavesign." + lsign.sign.getWorld().getName() + "." + id; String preString = "leavesign." + lsign.sign.getWorld().getName() + "." + id;
configFile.set(preString + ".x", lsign.sign.getX()); configFile.set(preString + ".x", lsign.sign.getX());
@ -93,7 +102,7 @@ public class LeaveSign {
} }
public static void load(FileConfiguration configFile) { public static void load(FileConfiguration configFile) {
for (World world : P.p.getServer().getWorlds()) { for (World world : DungeonsXL.getPlugin().getServer().getWorlds()) {
if (configFile.contains("leavesign." + world.getName())) { if (configFile.contains("leavesign." + world.getName())) {
int id = 0; int id = 0;
String preString; String preString;

View File

@ -1,10 +1,22 @@
package com.dre.dungeonsxl.listener; package io.github.dre2n.dungeonsxl.listener;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.dungeon.game.GamePlaceableBlock;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.global.DPortal;
import io.github.dre2n.dungeonsxl.global.GroupSign;
import io.github.dre2n.dungeonsxl.global.LeaveSign;
import io.github.dre2n.dungeonsxl.sign.DSign;
import io.github.dre2n.dungeonsxl.trigger.RedstoneTrigger;
import io.github.dre2n.dungeonsxl.util.IntegerUtil;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -16,16 +28,6 @@ import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.dre.dungeonsxl.DGSign;
import com.dre.dungeonsxl.DPortal;
import com.dre.dungeonsxl.P;
import com.dre.dungeonsxl.EditWorld;
import com.dre.dungeonsxl.LeaveSign;
import com.dre.dungeonsxl.game.GamePlaceableBlock;
import com.dre.dungeonsxl.game.GameWorld;
import com.dre.dungeonsxl.signs.DSign;
import com.dre.dungeonsxl.trigger.RedstoneTrigger;
public class BlockListener implements Listener { public class BlockListener implements Listener {
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
@ -49,13 +51,13 @@ public class BlockListener implements Listener {
} }
// Deny DGSignblocks destroying // Deny DGSignblocks destroying
if (DGSign.isRelativeSign(block, 1, 0) || DGSign.isRelativeSign(block, -1, 0) || DGSign.isRelativeSign(block, 0, 1) || DGSign.isRelativeSign(block, 0, -1)) { if (GroupSign.isRelativeSign(block, 1, 0) || GroupSign.isRelativeSign(block, -1, 0) || GroupSign.isRelativeSign(block, 0, 1) || GroupSign.isRelativeSign(block, 0, -1)) {
event.setCancelled(true); event.setCancelled(true);
} }
// DGSign destroying // DGSign destroying
if (DGSign.getSign(block) != null) { if (GroupSign.getSign(block) != null) {
DGSign.dgsigns.remove(DGSign.getSign(block)); DungeonsXL.getPlugin().getGroupSigns().remove(GroupSign.getSign(block));
} }
// Deny LeaveSignblocks destroying // Deny LeaveSignblocks destroying
@ -118,17 +120,17 @@ public class BlockListener implements Listener {
// Group Signs // Group Signs
if (eworld == null) { if (eworld == null) {
if (player.isOp() || P.p.permission.has(player, "dxl.sign")) { if (player.isOp() || player.hasPermission("dxl.sign")) {
if (lines[0].equalsIgnoreCase("[DXL]")) { if (lines[0].equalsIgnoreCase("[DXL]")) {
if (lines[1].equalsIgnoreCase("Group")) { if (lines[1].equalsIgnoreCase("Group")) {
String dungeonName = lines[2]; String dungeonName = lines[2];
String[] data = lines[3].split("\\,"); String[] data = lines[3].split("\\,");
if (data.length == 2) { if (data.length == 2) {
int maxGroups = P.p.parseInt(data[0]); int maxGroups = IntegerUtil.parseInt(data[0]);
int maxPlayersPerGroup = P.p.parseInt(data[1]); int maxPlayersPerGroup = IntegerUtil.parseInt(data[1]);
if (maxGroups > 0 && maxPlayersPerGroup > 0) { if (maxGroups > 0 && maxPlayersPerGroup > 0) {
if (DGSign.tryToCreate(event.getBlock(), dungeonName, maxGroups, maxPlayersPerGroup) != null) { if (GroupSign.tryToCreate(event.getBlock(), dungeonName, maxGroups, maxPlayersPerGroup) != null) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -153,16 +155,18 @@ public class BlockListener implements Listener {
DSign dsign = DSign.create(sign, null); DSign dsign = DSign.create(sign, null);
if (dsign != null) { if (dsign != null) {
if (player.isOp() || P.p.permission.has(player, dsign.getPermissions())) { if (player.isOp() || player.hasPermission(dsign.getPermissions())) {
if (dsign.check()) { if (dsign.check()) {
eworld.checkSign(block); eworld.checkSign(block);
eworld.sign.add(block); eworld.sign.add(block);
P.p.msg(player, P.p.language.get("Player_SignCreated")); MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Player_SignCreated"));
} else { } else {
P.p.msg(player, P.p.language.get("Error_SignWrongFormat")); MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Error_SignWrongFormat"));
} }
} else { } else {
P.p.msg(player, P.p.language.get("Error_NoPermissions")); MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Error_NoPermissions"));
} }
} }
} }
@ -191,7 +195,7 @@ public class BlockListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onBlockRedstoneEvent(BlockRedstoneEvent event) { public void onBlockRedstoneEvent(BlockRedstoneEvent event) {
new RedstoneEventTask(event.getBlock()).runTaskLater(P.p, 1); new RedstoneEventTask(event.getBlock()).runTaskLater(DungeonsXL.getPlugin(), 1);
} }
public class RedstoneEventTask extends BukkitRunnable { public class RedstoneEventTask extends BukkitRunnable {
@ -201,8 +205,9 @@ public class BlockListener implements Listener {
this.block = block; this.block = block;
} }
@Override
public void run() { public void run() {
for (GameWorld gworld : GameWorld.gworlds) { for (GameWorld gworld : DungeonsXL.getPlugin().getGameWorlds()) {
if (block.getWorld() == gworld.world) { if (block.getWorld() == gworld.world) {
RedstoneTrigger.updateAll(gworld); RedstoneTrigger.updateAll(gworld);
} }

View File

@ -0,0 +1,65 @@
package io.github.dre2n.dungeonsxl.listener;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import io.github.dre2n.dungeonsxl.command.DCommand;
import io.github.dre2n.dungeonsxl.file.DMessages;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class CommandListener implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd_notused, String arg, String[] args) {
DungeonsXL plugin = DungeonsXL.getPlugin();
if (args.length > 0) {
DMessages dMessages = plugin.getDMessages();
DCommand dCommand = plugin.getDCommands().getDCommand(args[0]);
if (dCommand != null) {
if (sender instanceof ConsoleCommandSender) {
if ( !dCommand.isConsoleCommand()) {
MessageUtil.sendMessage(sender, dMessages.get("Log_Error_NoConsoleCommand", dCommand.getCommand()));
return false;
}
}
if (sender instanceof Player) {
Player player = (Player) sender;
if ( !dCommand.isPlayerCommand()) {
MessageUtil.sendMessage(player, dMessages.get("Error_NoPlayerCommand", dCommand.getCommand()));
return false;
} else {
if (dCommand.getPermission() != null) {
if ( !dCommand.playerHasPermissions(player)) {
MessageUtil.sendMessage(player, dMessages.get("Error_NoPermissions"));
return false;
}
}
}
}
if (dCommand.getMinArgs() <= args.length - 1 & dCommand.getMaxArgs() >= args.length - 1 || dCommand.getMinArgs() == -1) {
dCommand.onExecute(args, sender);
return true;
} else {
dCommand.displayHelp(sender);
return true;
}
}
}
plugin.getDCommands().getDCommand("main").onExecute(null, sender);
return false;
}
}

View File

@ -1,4 +1,11 @@
package com.dre.dungeonsxl.listener; package io.github.dre2n.dungeonsxl.listener;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.global.DPortal;
import io.github.dre2n.dungeonsxl.global.GroupSign;
import io.github.dre2n.dungeonsxl.mob.DMob;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import java.util.List; import java.util.List;
@ -15,7 +22,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.EntityCombustByEntityEvent; import org.bukkit.event.entity.EntityCombustByEntityEvent;
import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -23,13 +29,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import com.dre.dungeonsxl.DGSign;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.DPortal;
import com.dre.dungeonsxl.EditWorld;
import com.dre.dungeonsxl.game.DMob;
import com.dre.dungeonsxl.game.GameWorld;
public class EntityListener implements Listener { public class EntityListener implements Listener {
@ -63,7 +63,7 @@ public class EntityListener implements Listener {
World world = event.getEntity().getWorld(); World world = event.getEntity().getWorld();
if (event.getEntity() instanceof LivingEntity) { if (event.getEntity() instanceof LivingEntity) {
LivingEntity entity = (LivingEntity) event.getEntity(); LivingEntity entity = event.getEntity();
GameWorld gworld = GameWorld.get(world); GameWorld gworld = GameWorld.get(world);
if (gworld != null) { if (gworld != null) {
if (gworld.isPlaying) { if (gworld.isPlaying) {
@ -123,6 +123,7 @@ public class EntityListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} else { } else {
if (entity == dplayer.wolf || entity2 == dplayer.wolf) { if (entity == dplayer.wolf || entity2 == dplayer.wolf) {
event.setCancelled(false); event.setCancelled(false);
@ -179,6 +180,7 @@ public class EntityListener implements Listener {
// Disable Creeper explosions in gameworlds // Disable Creeper explosions in gameworlds
event.setCancelled(true); event.setCancelled(true);
return; return;
} else { } else {
// Disable drops from TNT // Disable drops from TNT
event.setYield(0); event.setYield(0);
@ -199,7 +201,7 @@ public class EntityListener implements Listener {
// Signs // Signs
if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) { if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) {
if (DGSign.getSign(block) != null) { if (GroupSign.getSign(block) != null) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }

View File

@ -1,11 +1,11 @@
package com.dre.dungeonsxl.listener; package io.github.dre2n.dungeonsxl.listener;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import com.dre.dungeonsxl.game.GameWorld;
public class HangingListener implements Listener { public class HangingListener implements Listener {
@EventHandler @EventHandler
@ -15,4 +15,5 @@ public class HangingListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
} }
} }
} }

View File

@ -1,5 +1,22 @@
package com.dre.dungeonsxl.listener; package io.github.dre2n.dungeonsxl.listener;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.dungeon.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.DLootInventory;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.dungeon.game.GameChest;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.global.DPortal;
import io.github.dre2n.dungeonsxl.global.GroupSign;
import io.github.dre2n.dungeonsxl.global.LeaveSign;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.trigger.InteractTrigger;
import io.github.dre2n.dungeonsxl.trigger.UseItemTrigger;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import io.github.dre2n.dungeonsxl.util.MiscUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -10,6 +27,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
@ -24,22 +42,49 @@ import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.BookMeta;
import com.dre.dungeonsxl.DGSign; import org.bukkit.scheduler.BukkitRunnable;
import com.dre.dungeonsxl.DGroup;
import com.dre.dungeonsxl.DLootInventory;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.DPortal;
import com.dre.dungeonsxl.P;
import com.dre.dungeonsxl.EditWorld;
import com.dre.dungeonsxl.LeaveSign;
import com.dre.dungeonsxl.game.GameChest;
import com.dre.dungeonsxl.game.GameWorld;
import com.dre.dungeonsxl.trigger.InteractTrigger;
import com.dre.dungeonsxl.trigger.UseItemTrigger;
import com.dre.dungeonsxl.util.DUtility;
public class PlayerListener implements Listener { public class PlayerListener implements Listener {
public P p = P.p;
public DungeonsXL plugin = DungeonsXL.getPlugin();
@EventHandler(priority = EventPriority.HIGH)
public void onDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
final DPlayer dPlayer = DPlayer.get(player);
GameWorld gameWorld = GameWorld.get(player.getLocation().getWorld());
if (gameWorld != null) {
WorldConfig dConfig = gameWorld.getConfig();
if (dPlayer != null) {
dPlayer.lives = dPlayer.lives - 1;
if (dPlayer.lives == 0 && dPlayer.isReady) {
Bukkit.broadcastMessage(plugin.getDMessages().get("Player_DeathKick").replaceAll("v1", player.getName()).replaceAll("&", "\u00a7"));
// TODO: This Runnable is a workaround for a bug I couldn't find, yet...
new BukkitRunnable() {
public void run() {
dPlayer.leave();
}
}.runTaskLater(plugin, 1L);
} else if ( !(dPlayer.lives == -1)) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Player_Death").replaceAll("v1", String.valueOf(dPlayer.lives)));
} else if (dConfig != null) {
if (dConfig.getKeepInventoryOnDeath()) {
dPlayer.respawnInventory = event.getEntity().getInventory().getContents();
dPlayer.respawnArmor = event.getEntity().getInventory().getArmorContents();
// Delete all drops
for (ItemStack istack : event.getDrops()) {
istack.setType(Material.AIR);
}
}
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
@ -52,12 +97,13 @@ public class PlayerListener implements Listener {
if (event.getAction() != Action.LEFT_CLICK_BLOCK) { if (event.getAction() != Action.LEFT_CLICK_BLOCK) {
if (clickedBlock.getType() == Material.ENDER_CHEST) { if (clickedBlock.getType() == Material.ENDER_CHEST) {
if ( !player.isOp()) {// TODO: Permission if ( !player.isOp()) {// TODO: Permission
p.msg(player, p.language.get("Error_Enderchest")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Enderchest"));
event.setCancelled(true); event.setCancelled(true);
} }
} else if (clickedBlock.getType() == Material.BED_BLOCK) { } else if (clickedBlock.getType() == Material.BED_BLOCK) {
if ( !player.isOp()) {// TODO: Permission if ( !player.isOp()) {// TODO: Permission
p.msg(player, p.language.get("Error_Bed")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Bed"));
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -69,7 +115,7 @@ public class PlayerListener implements Listener {
if (event.getAction() != Action.LEFT_CLICK_BLOCK) { if (event.getAction() != Action.LEFT_CLICK_BLOCK) {
if (clickedBlock.getType() == Material.DISPENSER) { if (clickedBlock.getType() == Material.DISPENSER) {
if ( !player.isOp()) { if ( !player.isOp()) {
p.msg(player, p.language.get("Error_Dispenser")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Dispenser"));
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -82,17 +128,18 @@ public class PlayerListener implements Listener {
ItemStack item = event.getItem(); ItemStack item = event.getItem();
if (item.getType() == Material.WOOD_SWORD) { if (item.getType() == Material.WOOD_SWORD) {
if (clickedBlock != null) { if (clickedBlock != null) {
for (DPortal dportal : DPortal.portals) { for (DPortal dportal : plugin.getDPortals()) {
if (!dportal.isActive) { if ( !dportal.isActive()) {
if (dportal.player == player) { if (dportal.getPlayer() == player) {
if (dportal.block1 == null) { if (dportal.getBlock1() == null) {
dportal.block1 = event.getClickedBlock(); dportal.setBlock1(event.getClickedBlock());
p.msg(player, p.language.get("Player_PortalProgress")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Player_PortalProgress"));
} else if (dportal.block2 == null) {
dportal.block2 = event.getClickedBlock(); } else if (dportal.getBlock2() == null) {
dportal.isActive = true; dportal.setBlock2(event.getClickedBlock());
dportal.setActive(true);
dportal.create(); dportal.create();
p.msg(player, p.language.get("Player_PortalCreated")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Player_PortalCreated"));
} }
event.setCancelled(true); event.setCancelled(true);
} }
@ -123,6 +170,7 @@ public class PlayerListener implements Listener {
if (item.hasItemMeta()) { if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) { if (item.getItemMeta().hasDisplayName()) {
name = item.getItemMeta().getDisplayName(); name = item.getItemMeta().getDisplayName();
} else if (item.getType() == Material.WRITTEN_BOOK || item.getType() == Material.BOOK_AND_QUILL) { } else if (item.getType() == Material.WRITTEN_BOOK || item.getType() == Material.BOOK_AND_QUILL) {
if (item.getItemMeta() instanceof BookMeta) { if (item.getItemMeta() instanceof BookMeta) {
BookMeta meta = (BookMeta) item.getItemMeta(); BookMeta meta = (BookMeta) item.getItemMeta();
@ -149,7 +197,7 @@ public class PlayerListener implements Listener {
if (clickedBlock.getType() == Material.WALL_SIGN || clickedBlock.getType() == Material.SIGN_POST) { if (clickedBlock.getType() == Material.WALL_SIGN || clickedBlock.getType() == Material.SIGN_POST) {
// Check Group Signs // Check Group Signs
if (DGSign.playerInteract(event.getClickedBlock(), player)) { if (GroupSign.playerInteract(event.getClickedBlock(), player)) {
event.setCancelled(true); event.setCancelled(true);
} }
@ -171,7 +219,7 @@ public class PlayerListener implements Listener {
if (event.getAction() == Action.LEFT_CLICK_BLOCK) { if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
trigger.onTrigger(player); trigger.onTrigger(player);
} else { } else {
p.msg(player, p.language.get("Error_Leftklick")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Leftklick"));
} }
} }
@ -182,7 +230,7 @@ public class PlayerListener implements Listener {
if (event.getAction() == Action.LEFT_CLICK_BLOCK) { if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
dplayer.setClass(ChatColor.stripColor(classSign.getLine(1))); dplayer.setClass(ChatColor.stripColor(classSign.getLine(1)));
} else { } else {
p.msg(player, p.language.get("Error_Leftklick")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Leftklick"));
} }
return; return;
} }
@ -202,7 +250,7 @@ public class PlayerListener implements Listener {
// Deny dropping things at the lobby // Deny dropping things at the lobby
DGroup dgroup = DGroup.get(player); DGroup dgroup = DGroup.get(player);
if (dgroup != null) { if (dgroup != null) {
if (!dgroup.isPlaying) { if ( !dgroup.isPlaying()) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -214,10 +262,10 @@ public class PlayerListener implements Listener {
DPlayer dplayer = DPlayer.get(player); DPlayer dplayer = DPlayer.get(player);
GameWorld gworld = GameWorld.get(dplayer.world); GameWorld gworld = GameWorld.get(dplayer.world);
if (dplayer != null) { if (dplayer != null) {
for (Material material : gworld.config.getSecureObjects()) { for (Material material : gworld.getConfig().getSecureObjects()) {
if (material == event.getItemDrop().getItemStack().getType()) { if (material == event.getItemDrop().getItemStack().getType()) {
event.setCancelled(true); event.setCancelled(true);
p.msg(player, p.language.get("Error_Drop")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Drop"));
return; return;
} }
} }
@ -236,10 +284,12 @@ public class PlayerListener implements Listener {
if (eworld != null) { if (eworld != null) {
if (eworld.lobby == null) { if (eworld.lobby == null) {
event.setRespawnLocation(eworld.world.getSpawnLocation()); event.setRespawnLocation(eworld.world.getSpawnLocation());
} else { } else {
event.setRespawnLocation(eworld.lobby); event.setRespawnLocation(eworld.lobby);
} }
} }
} else { } else {
GameWorld gworld = GameWorld.get(dplayer.world); GameWorld gworld = GameWorld.get(dplayer.world);
@ -252,18 +302,19 @@ public class PlayerListener implements Listener {
// Da einige Plugins einen anderen Respawn setzen wird // Da einige Plugins einen anderen Respawn setzen wird
// ein Scheduler gestartet der den Player nach einer // ein Scheduler gestartet der den Player nach einer
// Sekunde teleportiert. // Sekunde teleportiert.
p.getServer().getScheduler().scheduleSyncDelayedTask(p, new RespawnRunnable(player, dgroup.getGworld().locStart), 10); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RespawnRunnable(player, dgroup.getGworld().locStart), 10);
if (dplayer.wolf != null) { if (dplayer.wolf != null) {
dplayer.wolf.teleport(dgroup.getGworld().locStart); dplayer.wolf.teleport(dgroup.getGworld().locStart);
} }
} else { } else {
event.setRespawnLocation(dplayer.checkpoint); event.setRespawnLocation(dplayer.checkpoint);
// Da einige Plugins einen anderen Respawn setzen wird // Da einige Plugins einen anderen Respawn setzen wird
// ein Scheduler gestartet der den Player nach einer // ein Scheduler gestartet der den Player nach einer
// Sekunde teleportiert. // Sekunde teleportiert.
p.getServer().getScheduler().scheduleSyncDelayedTask(p, new RespawnRunnable(player, dplayer.checkpoint), 10); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RespawnRunnable(player, dplayer.checkpoint), 10);
if (dplayer.wolf != null) { if (dplayer.wolf != null) {
dplayer.wolf.teleport(dplayer.checkpoint); dplayer.wolf.teleport(dplayer.checkpoint);
@ -279,6 +330,7 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
Location location = event.getFrom(); Location location = event.getFrom();
DPortal dportal = DPortal.get(location); DPortal dportal = DPortal.get(location);
if (dportal != null) { if (dportal != null) {
event.setCancelled(true); event.setCancelled(true);
dportal.teleport(player); dportal.teleport(player);
@ -289,6 +341,7 @@ public class PlayerListener implements Listener {
public void onPlayerTeleport(PlayerTeleportEvent event) { public void onPlayerTeleport(PlayerTeleportEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
DPlayer dplayer = DPlayer.get(player); DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) { if (dplayer != null) {
if (dplayer.world != event.getTo().getWorld()) { if (dplayer.world != event.getTo().getWorld()) {
if ( !player.isOp()) { if ( !player.isOp()) {
@ -319,16 +372,19 @@ public class PlayerListener implements Listener {
// Check GameWorld // Check GameWorld
GameWorld gWorld = GameWorld.get(player.getWorld()); GameWorld gWorld = GameWorld.get(player.getWorld());
if (gWorld != null) { if (gWorld != null) {
int timeUntilKickOfflinePlayer = gWorld.config.getTimeUntilKickOfflinePlayer(); int timeUntilKickOfflinePlayer = gWorld.getConfig().getTimeUntilKickOfflinePlayer();
if (timeUntilKickOfflinePlayer == 0) { if (timeUntilKickOfflinePlayer == 0) {
dPlayer.leave(); dPlayer.leave();
} else if (timeUntilKickOfflinePlayer > 0) { } else if (timeUntilKickOfflinePlayer > 0) {
dPlayer.msg(p.language.get("Player_Offline", dPlayer.player.getName(), "" + timeUntilKickOfflinePlayer)); dPlayer.msg(plugin.getDMessages().get("Player_Offline", dPlayer.player.getName(), "" + timeUntilKickOfflinePlayer));
dPlayer.offlineTime = System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000; dPlayer.offlineTime = System.currentTimeMillis() + timeUntilKickOfflinePlayer * 1000;
} else { } else {
dPlayer.msg(p.language.get("Player_OfflineNeverKick", dPlayer.player.getName())); dPlayer.msg(plugin.getDMessages().get("Player_OfflineNeverKick", dPlayer.player.getName()));
} }
} else if (dPlayer.isEditing) { } else if (dPlayer.isEditing) {
dPlayer.leave(); dPlayer.leave();
} }
@ -354,12 +410,12 @@ public class PlayerListener implements Listener {
} }
// Tutorial Mode // Tutorial Mode
if (p.mainConfig.tutorialActivated) { if (plugin.getMainConfig().isTutorialActivated()) {
if (DPlayer.get(player) == null) { if (DPlayer.get(player) == null) {
if (p.mainConfig.tutorialDungeon != null && p.mainConfig.tutorialStartGroup != null && p.mainConfig.tutorialEndGroup != null) { if (plugin.getMainConfig().getTutorialDungeon() != null && plugin.getMainConfig().getTutorialStartGroup() != null && plugin.getMainConfig().getTutorialEndGroup() != null) {
for (String group : p.permission.getPlayerGroups(player)) { for (String group : plugin.permission.getPlayerGroups(player)) {
if (p.mainConfig.tutorialStartGroup.equalsIgnoreCase(group)) { if (plugin.getMainConfig().getTutorialStartGroup().equalsIgnoreCase(group)) {
DGroup dgroup = new DGroup(player, p.mainConfig.tutorialDungeon); DGroup dgroup = new DGroup(player, plugin.getMainConfig().getTutorialDungeon());
if (dgroup.getGworld() == null) { if (dgroup.getGworld() == null) {
dgroup.setGworld(GameWorld.load(DGroup.get(player).getDungeonname())); dgroup.setGworld(GameWorld.load(DGroup.get(player).getDungeonname()));
@ -368,12 +424,13 @@ public class PlayerListener implements Listener {
if (dgroup.getGworld() != null) { if (dgroup.getGworld() != null) {
if (dgroup.getGworld().locLobby == null) { if (dgroup.getGworld().locLobby == null) {
new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().world.getSpawnLocation(), false);
} else { } else {
new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().locLobby, false); new DPlayer(player, dgroup.getGworld().world, dgroup.getGworld().locLobby, false);
} }
} else { } else {
p.msg(player, p.language.get("Error_TutorialNotExist")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_TutorialNotExist"));
} }
} }
} }
@ -385,19 +442,19 @@ public class PlayerListener implements Listener {
// Deny Player Cmds // Deny Player Cmds
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onPlayerCommand(PlayerCommandPreprocessEvent event) { public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
if (p.permission.has(event.getPlayer(), "dungeonsxl.cmd") || event.getPlayer().isOp()) { if (event.getPlayer().hasPermission("dungeonsxl.cmd")) {
return; return;
} }
DPlayer dplayer = DPlayer.get(event.getPlayer()); DPlayer dplayer = DPlayer.get(event.getPlayer());
if (dplayer != null) { if (dplayer != null) {
if (dplayer.isEditing && p.permission.has(event.getPlayer(), "dungeonsxl.cmdedit") || event.getPlayer().isOp()){ if (dplayer.isEditing && event.getPlayer().hasPermission("dungeonsxl.cmdedit") || event.getPlayer().isOp()) {
return; return;
} }
String[] splittedCmd = event.getMessage().split(" "); String[] splittedCmd = event.getMessage().split(" ");
if ( !splittedCmd[0].equalsIgnoreCase("/dungeon") && !splittedCmd[0].equalsIgnoreCase("/dungeonsxl") && !splittedCmd[0].equalsIgnoreCase("/dxl")) { if ( !splittedCmd[0].equalsIgnoreCase("/dungeon") && !splittedCmd[0].equalsIgnoreCase("/dungeonsxl") && !splittedCmd[0].equalsIgnoreCase("/dxl")) {
p.msg(event.getPlayer(), p.language.get("Error_Cmd")); MessageUtil.sendMessage(event.getPlayer(), plugin.getDMessages().get("Error_Cmd"));
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -412,16 +469,16 @@ public class PlayerListener implements Listener {
@EventHandler @EventHandler
public void onInventoryClose(InventoryCloseEvent event) { public void onInventoryClose(InventoryCloseEvent event) {
Player player = (Player) event.getPlayer(); Player player = (Player) event.getPlayer();
for (DLootInventory inventory : DLootInventory.LootInventorys) { for (DLootInventory inventory : plugin.getDLootInventories()) {
if (event.getView() == inventory.inventoryView) { if (event.getView() == inventory.getInventoryView()) {
if (System.currentTimeMillis() - inventory.time > 500) { if (System.currentTimeMillis() - inventory.getTime() > 500) {
for (ItemStack istack : inventory.inventory.getContents()) { for (ItemStack istack : inventory.getInventory().getContents()) {
if (istack != null) { if (istack != null) {
player.getWorld().dropItem(player.getLocation(), istack); player.getWorld().dropItem(player.getLocation(), istack);
} }
} }
DLootInventory.LootInventorys.remove(inventory); plugin.getDLootInventories().remove(inventory);
} }
} }
} }
@ -438,8 +495,8 @@ public class PlayerListener implements Listener {
if (player.getLocation().getBlock().getRelative(0, 1, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, -1, 0).getType() != Material.PORTAL if (player.getLocation().getBlock().getRelative(0, 1, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, -1, 0).getType() != Material.PORTAL
&& player.getLocation().getBlock().getRelative(1, 0, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative( -1, 0, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(1, 0, 0).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative( -1, 0, 0).getType() != Material.PORTAL
&& player.getLocation().getBlock().getRelative(0, 0, 1).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, 0, -1).getType() != Material.PORTAL) { && player.getLocation().getBlock().getRelative(0, 0, 1).getType() != Material.PORTAL && player.getLocation().getBlock().getRelative(0, 0, -1).getType() != Material.PORTAL) {
inventory.inventoryView = inventory.player.openInventory(inventory.inventory); inventory.setInventoryView(inventory.getPlayer().openInventory(inventory.getInventory()));
inventory.time = System.currentTimeMillis(); inventory.setTime(System.currentTimeMillis());
} }
} }
} }
@ -458,21 +515,20 @@ public class PlayerListener implements Listener {
@Override @Override
public void run() { public void run() {
if (this.player.getLocation().distance(this.location) > 2) { if (player.getLocation().distance(location) > 2) {
DUtility.secureTeleport(this.player, this.location); MiscUtil.secureTeleport(player, location);
} }
DPlayer dplayer = DPlayer.get(this.player); DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) { if (dplayer != null) {
// Respawn Items // Respawn Items
if (dplayer.respawnInventory != null || dplayer.respawnArmor != null) { if (dplayer.respawnInventory != null || dplayer.respawnArmor != null) {
this.player.getInventory().setContents(dplayer.respawnInventory); player.getInventory().setContents(dplayer.respawnInventory);
this.player.getInventory().setArmorContents(dplayer.respawnArmor); player.getInventory().setArmorContents(dplayer.respawnArmor);
dplayer.respawnInventory = null; dplayer.respawnInventory = null;
dplayer.respawnArmor = null; dplayer.respawnArmor = null;
} }
// DungeonsXL.p.updateInventory(this.player);
} }
} }
} }

View File

@ -1,12 +1,12 @@
package com.dre.dungeonsxl.listener; package io.github.dre2n.dungeonsxl.listener;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.event.world.ChunkUnloadEvent;
import com.dre.dungeonsxl.game.GameWorld;
public class WorldListener implements Listener { public class WorldListener implements Listener {
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
@ -18,4 +18,5 @@ public class WorldListener implements Listener {
} }
} }
} }
} }

View File

@ -1,4 +1,7 @@
package com.dre.dungeonsxl.game; package io.github.dre2n.dungeonsxl.mob;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.trigger.MobTrigger;
import java.util.Random; import java.util.Random;
@ -6,19 +9,16 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.dre.dungeonsxl.DMobType;
import com.dre.dungeonsxl.trigger.MobTrigger;
public class DMob { public class DMob {
// Variables // Variables
public LivingEntity entity; private LivingEntity entity;
public DMobType type; private DMobType type;
public String trigger; private String trigger;
public DMob(LivingEntity entity, GameWorld gworld, DMobType type) { public DMob(LivingEntity entity, GameWorld gworld, DMobType type) {
gworld.dmobs.add(this); gworld.dMobs.add(this);
this.entity = entity; this.entity = entity;
this.type = type; this.type = type;
@ -32,7 +32,7 @@ public class DMob {
} }
public DMob(LivingEntity entity, GameWorld gworld, DMobType type, String trigger) { public DMob(LivingEntity entity, GameWorld gworld, DMobType type, String trigger) {
gworld.dmobs.add(this); gworld.dMobs.add(this);
this.entity = entity; this.entity = entity;
this.type = type; this.type = type;
@ -47,15 +47,17 @@ public class DMob {
} }
// Statics // Statics
@SuppressWarnings("deprecation")
public static void onDeath(EntityDeathEvent event) { public static void onDeath(EntityDeathEvent event) {
if (event.getEntity() instanceof LivingEntity) { if (event.getEntity() instanceof LivingEntity) {
LivingEntity victim = (LivingEntity) event.getEntity(); LivingEntity victim = event.getEntity();
GameWorld gworld = GameWorld.get(victim.getWorld()); GameWorld gworld = GameWorld.get(victim.getWorld());
String name = null; String name = null;
if (gworld != null) { if (gworld != null) {
for (DMob dmob : gworld.dmobs) { for (DMob dmob : gworld.dMobs) {
if (dmob.entity == victim) { if (dmob.entity == victim) {
if (dmob.type != null) { if (dmob.type != null) {
for (ItemStack item : dmob.type.getDrops().keySet()) { for (ItemStack item : dmob.type.getDrops().keySet()) {
Random randomGenerator = new Random(); Random randomGenerator = new Random();
@ -66,8 +68,10 @@ public class DMob {
} }
} }
name = dmob.type.getName(); name = dmob.type.getName();
} else if (dmob.type == null && dmob.trigger != null) {// <=MythicMobs mob } else if (dmob.type == null && dmob.trigger != null) {// <=MythicMobs mob
name = dmob.trigger; name = dmob.trigger;
} else { } else {
name = victim.getType().getName(); name = victim.getType().getName();
} }
@ -77,11 +81,12 @@ public class DMob {
trigger.onTrigger(); trigger.onTrigger();
} }
gworld.dmobs.remove(dmob); gworld.dMobs.remove(dmob);
return; return;
} }
} }
} }
} }
} }
} }

View File

@ -1,10 +1,15 @@
package com.dre.dungeonsxl; package io.github.dre2n.dungeonsxl.mob;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.util.IntegerUtil;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -16,10 +21,9 @@ import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import com.dre.dungeonsxl.game.DMob;
import com.dre.dungeonsxl.game.GameWorld;
public class DMobType { public class DMobType {
private String name; private String name;
private EntityType type; private EntityType type;
@ -33,10 +37,6 @@ public class DMobType {
private Map<ItemStack, Integer> drops = new HashMap<ItemStack, Integer>(); private Map<ItemStack, Integer> drops = new HashMap<ItemStack, Integer>();
public Map<ItemStack, Integer> getDrops() {
return this.drops;
}
/* Extra Values for different Mob Types */ /* Extra Values for different Mob Types */
private boolean isWitherSkeleton = false; private boolean isWitherSkeleton = false;
private String ocelotType = null; private String ocelotType = null;
@ -100,6 +100,7 @@ public class DMobType {
} }
// Load Config // Load Config
@SuppressWarnings("deprecation")
public static Set<DMobType> load(ConfigurationSection configFile) { public static Set<DMobType> load(ConfigurationSection configFile) {
Set<DMobType> set = new HashSet<DMobType>(); Set<DMobType> set = new HashSet<DMobType>();
if (configFile != null) { if (configFile != null) {
@ -181,12 +182,12 @@ public class DMobType {
String[] splittedEnchantment = enchantment.split(" "); String[] splittedEnchantment = enchantment.split(" ");
if (Enchantment.getByName(splittedEnchantment[0].toUpperCase()) != null) { if (Enchantment.getByName(splittedEnchantment[0].toUpperCase()) != null) {
if (splittedEnchantment.length > 1) { if (splittedEnchantment.length > 1) {
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), P.p.parseInt(splittedEnchantment[1]), true); itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), IntegerUtil.parseInt(splittedEnchantment[1]), true);
} else { } else {
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), 1, true); itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), 1, true);
} }
} else { } else {
P.p.log(P.p.language.get("Log_Error_MobEnchantment", splittedEnchantment[0])); DungeonsXL.getPlugin().log(DungeonsXL.getPlugin().getDMessages().get("Log_Error_MobEnchantment", splittedEnchantment[0]));
} }
} }
} }
@ -209,12 +210,12 @@ public class DMobType {
/* Add Item to the drops map */ /* Add Item to the drops map */
item.setItemMeta(itemMeta); item.setItemMeta(itemMeta);
mobType.drops.put(item, chance); mobType.getDrops().put(item, chance);
} }
} }
} else { } else {
P.p.log(P.p.language.get("Log_Error_MobType", configFile.getString(mobName + ".Type"))); DungeonsXL.getPlugin().log(DungeonsXL.getPlugin().getDMessages().get("Log_Error_MobType", configFile.getString(mobName + ".Type")));
} }
} }
} }
@ -229,8 +230,8 @@ public class DMobType {
} }
} }
if (P.p.mainConfig.defaultDungeon != null) { if (DungeonsXL.getPlugin().getMainConfig().defaultDungeon != null) {
for (DMobType mobType : P.p.mainConfig.defaultDungeon.getMobTypes()) { for (DMobType mobType : DungeonsXL.getPlugin().getMainConfig().defaultDungeon.getMobTypes()) {
if (mobType.name.equalsIgnoreCase(name)) { if (mobType.name.equalsIgnoreCase(name)) {
return mobType; return mobType;
} }
@ -240,7 +241,34 @@ public class DMobType {
return null; return null;
} }
/**
* @return the name
*/
public String getName() { public String getName() {
return name; return name;
} }
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the drops
*/
public Map<ItemStack, Integer> getDrops() {
return drops;
}
/**
* @param drops
* the drops to set
*/
public void setDrops(Map<ItemStack, Integer> drops) {
this.drops = drops;
}
} }

View File

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

View File

@ -0,0 +1,153 @@
package io.github.dre2n.dungeonsxl.player;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.dungeon.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.global.GroupSign;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import java.io.File;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.entity.Player;
public class DGroup {
static DungeonsXL plugin = DungeonsXL.getPlugin();
private CopyOnWriteArrayList<Player> players = new CopyOnWriteArrayList<Player>();
private String dungeonname;
private GameWorld gWorld;
private boolean playing;
public DGroup(Player player, String dungeonname) {
plugin.getDGroups().add(this);
getPlayers().add(player);
playing = false;
setDungeonname(dungeonname);
}
// Getters and setters
public CopyOnWriteArrayList<Player> getPlayers() {
return players;
}
public void setPlayers(CopyOnWriteArrayList<Player> players) {
this.players = players;
}
public GameWorld getGworld() {
return gWorld;
}
public void setGworld(GameWorld gWorld) {
this.gWorld = gWorld;
}
public String getDungeonname() {
return dungeonname;
}
public void setDungeonname(String dungeonname) {
this.dungeonname = dungeonname;
}
/**
* @return if the group is playing
*/
public boolean isPlaying() {
return playing;
}
/**
* @param playing
* set if the group is playing
*/
public void setPlaying(boolean playing) {
this.playing = playing;
}
public void addPlayer(Player player) {
// Send message
for (Player groupPlayer : getPlayers()) {
MessageUtil.sendMessage(groupPlayer, DungeonsXL.getPlugin().getDMessages().get("Player_JoinGroup", player.getName()));
}
// Add player
getPlayers().add(player);
}
public void removePlayer(Player player) {
getPlayers().remove(player);
GroupSign.updatePerGroup(this);
// Send message
for (Player groupPlayer : getPlayers()) {
MessageUtil.sendMessage(groupPlayer, DungeonsXL.getPlugin().getDMessages().get("Player_LeftGroup", player.getName()));
}
// Check group
if (isEmpty()) {
remove();
}
}
public boolean isEmpty() {
return getPlayers().isEmpty();
}
public void remove() {
plugin.getDGroups().remove(this);
GroupSign.updatePerGroup(this);
}
public void startGame() {
playing = true;
getGworld().startGame();
for (Player player : getPlayers()) {
DPlayer dplayer = DPlayer.get(player);
dplayer.respawn();
if (DungeonsXL.getPlugin().getMainConfig().enableEconomy()) {
File file = new File(DungeonsXL.getPlugin().getDataFolder() + "/maps/" + dungeonname + "/config.yml");
if (file != null) {
WorldConfig confReader = new WorldConfig(file);
if (confReader != null) {
DungeonsXL.getPlugin().economy.withdrawPlayer(player, confReader.getFee());
}
}
}
}
GroupSign.updatePerGroup(this);
}
// Statics
public static DGroup get(Player player) {
for (DGroup dgroup : plugin.getDGroups()) {
if (dgroup.getPlayers().contains(player)) {
return dgroup;
}
}
return null;
}
public static DGroup get(GameWorld gWorld) {
for (DGroup dgroup : plugin.getDGroups()) {
if (dgroup.getGworld() == gWorld) {
return dgroup;
}
}
return null;
}
public static void leaveGroup(Player player) {
for (DGroup dgroup : plugin.getDGroups()) {
if (dgroup.getPlayers().contains(player)) {
dgroup.getPlayers().remove(player);
}
}
}
}

View File

@ -1,4 +1,13 @@
package com.dre.dungeonsxl; package io.github.dre2n.dungeonsxl.player;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.dungeon.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.DLootInventory;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.trigger.DistanceTrigger;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import io.github.dre2n.dungeonsxl.util.MiscUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -9,27 +18,22 @@ import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Sign;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.event.block.SignChangeEvent; import org.bukkit.block.Sign;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Damageable; import org.bukkit.entity.Damageable;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf; import org.bukkit.entity.Wolf;
import org.bukkit.potion.PotionEffect; import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import com.dre.dungeonsxl.game.GameWorld;
import com.dre.dungeonsxl.trigger.DistanceTrigger;
import com.dre.dungeonsxl.util.DUtility;
public class DPlayer { public class DPlayer {
public static P p = P.p;
public static CopyOnWriteArrayList<DPlayer> players = new CopyOnWriteArrayList<DPlayer>(); static DungeonsXL plugin = DungeonsXL.getPlugin();
// Variables // Variables
public Player player; public Player player;
@ -53,102 +57,96 @@ public class DPlayer {
public ItemStack[] respawnArmor; public ItemStack[] respawnArmor;
public String[] linesCopy; public String[] linesCopy;
public Inventory treasureInv = P.p.getServer().createInventory(player, 45, "Belohnungen"); public Inventory treasureInv = DungeonsXL.getPlugin().getServer().createInventory(player, 45, plugin.getDMessages().get("Player_Treasures"));
public double treasureMoney = 0; public double treasureMoney = 0;
public int initialLives = -1; public int initialLives = -1;
public int lives;
public DPlayer(Player player, World world, Location teleport, boolean isEditing) { public DPlayer(Player player, World world, Location teleport, boolean isEditing) {
players.add(this); plugin.getDPlayers().add(this);
this.player = player; this.player = player;
this.world = world; this.world = world;
double health = ((Damageable) player).getHealth(); double health = ((Damageable) player).getHealth();
this.savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), player.getLevel(), savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), player.getLevel(),
player.getTotalExperience(), (int) health, player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects()); player.getTotalExperience(), (int) health, player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects());
this.isEditing = isEditing; this.isEditing = isEditing;
if (this.isEditing) { if (this.isEditing) {
this.player.setGameMode(GameMode.CREATIVE); this.player.setGameMode(GameMode.CREATIVE);
this.clearPlayerData(); clearPlayerData();
} else { } else {
this.player.setGameMode(GameMode.SURVIVAL); this.player.setGameMode(GameMode.SURVIVAL);
DConfig dConfig = GameWorld.get(world).config; WorldConfig dConfig = GameWorld.get(world).getConfig();
if (!(dConfig.getKeepInventoryOnEnter())) { if ( !dConfig.getKeepInventoryOnEnter()) {
this.clearPlayerData(); clearPlayerData();
} }
if (dConfig.isLobbyDisabled()) { if (dConfig.isLobbyDisabled()) {
this.ready(); ready();
} }
initialLives = GameWorld.get(world).config.getInitialLives(); initialLives = GameWorld.get(world).getConfig().getInitialLives();
lives = initialLives;
} }
// Lives MiscUtil.secureTeleport(this.player, teleport);
p.lives.put(this.player, initialLives);
DUtility.secureTeleport(this.player, teleport);
} }
public void clearPlayerData() { public void clearPlayerData() {
this.player.getInventory().clear(); player.getInventory().clear();
this.player.getInventory().setArmorContents(null); player.getInventory().setArmorContents(null);
this.player.setTotalExperience(0); player.setTotalExperience(0);
this.player.setLevel(0); player.setLevel(0);
this.player.setHealth(20); player.setHealth(20);
this.player.setFoodLevel(20); player.setFoodLevel(20);
for (PotionEffect effect : this.player.getActivePotionEffects()) { for (PotionEffect effect : player.getActivePotionEffects()) {
this.player.removePotionEffect(effect.getType()); player.removePotionEffect(effect.getType());
} }
} }
public void escape() { public void escape() {
remove(this); remove(this);
this.savePlayer.reset(false); savePlayer.reset(false);
} }
public void leave() { public void leave() {
remove(this); remove(this);
// Lives if ( !isEditing) {
if (p.lives.containsKey(player)) { WorldConfig dConfig = GameWorld.get(world).getConfig();
p.lives.remove(player); if (isFinished) {
} savePlayer.reset(dConfig.getKeepInventoryOnFinish());
} else {
if (!this.isEditing) { savePlayer.reset(dConfig.getKeepInventoryOnEscape());
DConfig dConfig = GameWorld.get(world).config;
if (this.isFinished) {
this.savePlayer.reset(dConfig.getKeepInventoryOnFinish());
}
else {
this.savePlayer.reset(dConfig.getKeepInventoryOnEscape());
} }
} else { } else {
this.savePlayer.reset(false); savePlayer.reset(false);
} }
if (this.isEditing) { if (isEditing) {
EditWorld eworld = EditWorld.get(this.world); EditWorld eworld = EditWorld.get(world);
if (eworld != null) { if (eworld != null) {
eworld.save(); eworld.save();
} }
} else { } else {
GameWorld gworld = GameWorld.get(this.world); GameWorld gworld = GameWorld.get(world);
DGroup dgroup = DGroup.get(this.player); DGroup dgroup = DGroup.get(player);
if (dgroup != null) { if (dgroup != null) {
dgroup.removePlayer(this.player); dgroup.removePlayer(player);
} }
// Belohnung // Belohnung
if (!this.isinTestMode) {// Nur wenn man nicht am Testen ist if ( !isinTestMode) {// Nur wenn man nicht am Testen ist
if (isFinished) { if (isFinished) {
this.addTreasure(); addTreasure();
p.economy.depositPlayer(this.player, treasureMoney); plugin.economy.depositPlayer(player, treasureMoney);
// Set Time // Set Time
File file = new File(p.getDataFolder() + "/dungeons/" + gworld.dungeonname, "players.yml"); File file = new File(plugin.getDataFolder() + "/maps/" + gworld.dungeonname, "players.yml");
if ( !file.exists()) { if ( !file.exists()) {
try { try {
@ -170,8 +168,8 @@ public class DPlayer {
// Tutorial Permissions // Tutorial Permissions
if (gworld.isTutorial) { if (gworld.isTutorial) {
p.permission.playerAddGroup(this.player, p.mainConfig.tutorialEndGroup); plugin.permission.playerAddGroup(player, plugin.getMainConfig().getTutorialEndGroup());
p.permission.playerRemoveGroup(this.player, p.mainConfig.tutorialStartGroup); plugin.permission.playerRemoveGroup(player, plugin.getMainConfig().getTutorialStartGroup());
} }
} }
} }
@ -184,7 +182,7 @@ public class DPlayer {
do { do {
groupplayer = dgroup.getPlayers().get(i); groupplayer = dgroup.getPlayers().get(i);
if (groupplayer != null) { if (groupplayer != null) {
for (ItemStack istack : this.player.getInventory()) { for (ItemStack istack : player.getInventory()) {
if (istack != null) { if (istack != null) {
if (gworld.secureObjects.contains(istack.getType())) { if (gworld.secureObjects.contains(istack.getType())) {
groupplayer.getInventory().addItem(istack); groupplayer.getInventory().addItem(istack);
@ -200,10 +198,10 @@ public class DPlayer {
} }
public void ready() { public void ready() {
this.isReady = true; isReady = true;
DGroup dgroup = DGroup.get(this.player); DGroup dgroup = DGroup.get(player);
if (!dgroup.isPlaying) { if ( !dgroup.isPlaying()) {
if (dgroup != null) { if (dgroup != null) {
for (Player player : dgroup.getPlayers()) { for (Player player : dgroup.getPlayers()) {
DPlayer dplayer = get(player); DPlayer dplayer = get(player);
@ -215,44 +213,74 @@ public class DPlayer {
dgroup.startGame(); dgroup.startGame();
} else { } else {
this.respawn(); respawn();
} }
} }
public void respawn() { public void respawn() {
DGroup dgroup = DGroup.get(this.player); DGroup dgroup = DGroup.get(player);
if (this.checkpoint == null) { if (checkpoint == null) {
DUtility.secureTeleport(this.player, dgroup.getGworld().locStart); MiscUtil.secureTeleport(player, dgroup.getGworld().locStart);
} else { } else {
DUtility.secureTeleport(this.player, this.checkpoint); MiscUtil.secureTeleport(player, checkpoint);
} }
if (this.wolf != null) { if (wolf != null) {
this.wolf.teleport(this.player); wolf.teleport(player);
} }
// Respawn Items // Respawn Items
if (GameWorld.get(world).config.getKeepInventoryOnDeath()) { if (GameWorld.get(world).getConfig().getKeepInventoryOnDeath()) {
if (this.respawnInventory != null || this.respawnArmor != null) { org.bukkit.Bukkit.broadcastMessage("deactivated code triggered");
this.player.getInventory().setContents(this.respawnInventory); if (respawnInventory != null || respawnArmor != null) {
this.player.getInventory().setArmorContents(this.respawnArmor); player.getInventory().setContents(respawnInventory);
this.respawnInventory = null; player.getInventory().setArmorContents(respawnArmor);
this.respawnArmor = null; respawnInventory = null;
respawnArmor = null;
} }
// P.p.updateInventory(this.player); // P.plugin.updateInventory(this.player);
} }
} }
public void finish() { public void finishFloor() {
p.msg(this.player, p.language.get("Player_FinishedDungeon")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Player_FinishedDungeon"));
this.isFinished = true; isFinished = true;
DGroup dgroup = DGroup.get(player);
if (dgroup == null) {
return;
}
if ( !dgroup.isPlaying()) {
return;
}
DGroup dgroup = DGroup.get(this.player);
if (dgroup != null) {
if (dgroup.isPlaying) {
for (Player player : dgroup.getPlayers()) { for (Player player : dgroup.getPlayers()) {
DPlayer dplayer = get(player); DPlayer dplayer = get(player);
if ( !dplayer.isFinished) { if ( !dplayer.isFinished) {
p.msg(this.player, p.language.get("Player_WaitForOtherPlayers")); MessageUtil.sendMessage(this.player, plugin.getDMessages().get("Player_WaitForOtherPlayers"));
return;
}
}
for (Player player : dgroup.getPlayers()) {
DPlayer dPlayer = get(player);
dPlayer.isFinished = false;
}
dgroup.isPlaying();
}
public void finish() {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Player_FinishedDungeon"));
isFinished = true;
DGroup dgroup = DGroup.get(player);
if (dgroup != null) {
if (dgroup.isPlaying()) {
for (Player player : dgroup.getPlayers()) {
DPlayer dplayer = get(player);
if ( !dplayer.isFinished) {
MessageUtil.sendMessage(this.player, plugin.getDMessages().get("Player_WaitForOtherPlayers"));
return; return;
} }
} }
@ -266,25 +294,26 @@ public class DPlayer {
} }
public void msg(String msg) { public void msg(String msg) {
if (this.isEditing) { if (isEditing) {
EditWorld eworld = EditWorld.get(this.world); EditWorld eworld = EditWorld.get(world);
eworld.msg(msg); eworld.msg(msg);
for (Player player : p.chatSpyer) { for (Player player : plugin.getChatSpyers()) {
if ( !eworld.world.getPlayers().contains(player)) { if ( !eworld.world.getPlayers().contains(player)) {
p.msg(player, ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + msg); MessageUtil.sendMessage(player, ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + msg);
} }
} }
} else { } else {
GameWorld gworld = GameWorld.get(this.world); GameWorld gworld = GameWorld.get(world);
gworld.msg(msg); gworld.msg(msg);
for (Player player : p.chatSpyer) { for (Player player : plugin.getChatSpyers()) {
if ( !gworld.world.getPlayers().contains(player)) { if ( !gworld.world.getPlayers().contains(player)) {
p.msg(player, ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + msg); MessageUtil.sendMessage(player, ChatColor.GREEN + "[Chatspy] " + ChatColor.WHITE + msg);
} }
} }
} }
} }
@SuppressWarnings("deprecation")
public void poke(Block block) { public void poke(Block block) {
if (block.getState() instanceof Sign) { if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState(); Sign sign = (Sign) block.getState();
@ -292,7 +321,7 @@ public class DPlayer {
if (lines[0].equals("") && lines[1].equals("") && lines[2].equals("") && lines[3].equals("")) { if (lines[0].equals("") && lines[1].equals("") && lines[2].equals("") && lines[3].equals("")) {
if (linesCopy != null) { if (linesCopy != null) {
SignChangeEvent event = new SignChangeEvent(block, player, linesCopy); SignChangeEvent event = new SignChangeEvent(block, player, linesCopy);
p.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
if ( !event.isCancelled()) { if ( !event.isCancelled()) {
sign.setLine(0, event.getLine(0)); sign.setLine(0, event.getLine(0));
sign.setLine(1, event.getLine(1)); sign.setLine(1, event.getLine(1));
@ -303,82 +332,83 @@ public class DPlayer {
} }
} else { } else {
linesCopy = lines; linesCopy = lines;
p.msg(player, p.language.get("Player_SignCopied")); MessageUtil.sendMessage(player, plugin.getDMessages().get("Player_SignCopied"));
} }
} else { } else {
String info = "" + block.getType(); String info = "" + block.getType();
if (block.getData() != 0) { if (block.getData() != 0) {
info = info + "," + block.getData(); info = info + "," + block.getData();
} }
p.msg(player, p.language.get("Player_BlockInfo", info)); MessageUtil.sendMessage(player, plugin.getDMessages().get("Player_BlockInfo", info));
} }
} }
public void setClass(String classname) { public void setClass(String classname) {
GameWorld gworld = GameWorld.get(this.player.getWorld()); GameWorld gworld = GameWorld.get(player.getWorld());
if (gworld == null) if (gworld == null) {
return; return;
}
DClass dclass = gworld.config.getClass(classname); DClass dclass = gworld.getConfig().getClass(classname);
if (dclass != null) { if (dclass != null) {
if (this.dclass != dclass) { if (this.dclass != dclass) {
this.dclass = dclass; this.dclass = dclass;
/* Set Dog */ /* Set Dog */
if (this.wolf != null) { if (wolf != null) {
this.wolf.remove(); wolf.remove();
this.wolf = null; wolf = null;
} }
if (dclass.hasDog) { if (dclass.hasDog()) {
this.wolf = (Wolf) this.world.spawnEntity(this.player.getLocation(), EntityType.WOLF); wolf = (Wolf) world.spawnEntity(player.getLocation(), EntityType.WOLF);
this.wolf.setTamed(true); wolf.setTamed(true);
this.wolf.setOwner(this.player); wolf.setOwner(player);
double maxHealth = ((Damageable) wolf).getMaxHealth(); double maxHealth = ((Damageable) wolf).getMaxHealth();
this.wolf.setHealth(maxHealth); wolf.setHealth(maxHealth);
} }
/* Delete Inventory */ /* Delete Inventory */
this.player.getInventory().clear(); player.getInventory().clear();
this.player.getInventory().setArmorContents(null); player.getInventory().setArmorContents(null);
player.getInventory().setItemInHand(new ItemStack(Material.AIR)); player.getInventory().setItemInHand(new ItemStack(Material.AIR));
// Remove Potion Effects // Remove Potion Effects
for (PotionEffect effect : this.player.getActivePotionEffects()) { for (PotionEffect effect : player.getActivePotionEffects()) {
this.player.removePotionEffect(effect.getType()); player.removePotionEffect(effect.getType());
} }
// Reset lvl // Reset lvl
this.player.setTotalExperience(0); player.setTotalExperience(0);
this.player.setLevel(0); player.setLevel(0);
/* Set Inventory */ /* Set Inventory */
for (ItemStack istack : dclass.items) { for (ItemStack istack : dclass.getItems()) {
// Leggings // Leggings
if (istack.getType() == Material.LEATHER_LEGGINGS || istack.getType() == Material.CHAINMAIL_LEGGINGS || istack.getType() == Material.IRON_LEGGINGS if (istack.getType() == Material.LEATHER_LEGGINGS || istack.getType() == Material.CHAINMAIL_LEGGINGS || istack.getType() == Material.IRON_LEGGINGS
|| istack.getType() == Material.DIAMOND_LEGGINGS || istack.getType() == Material.GOLD_LEGGINGS) { || istack.getType() == Material.DIAMOND_LEGGINGS || istack.getType() == Material.GOLD_LEGGINGS) {
this.player.getInventory().setLeggings(istack); player.getInventory().setLeggings(istack);
} }
// Helmet // Helmet
else if (istack.getType() == Material.LEATHER_HELMET || istack.getType() == Material.CHAINMAIL_HELMET || istack.getType() == Material.IRON_HELMET else if (istack.getType() == Material.LEATHER_HELMET || istack.getType() == Material.CHAINMAIL_HELMET || istack.getType() == Material.IRON_HELMET
|| istack.getType() == Material.DIAMOND_HELMET || istack.getType() == Material.GOLD_HELMET) { || istack.getType() == Material.DIAMOND_HELMET || istack.getType() == Material.GOLD_HELMET) {
this.player.getInventory().setHelmet(istack); player.getInventory().setHelmet(istack);
} }
// Chestplate // Chestplate
else if (istack.getType() == Material.LEATHER_CHESTPLATE || istack.getType() == Material.CHAINMAIL_CHESTPLATE || istack.getType() == Material.IRON_CHESTPLATE else if (istack.getType() == Material.LEATHER_CHESTPLATE || istack.getType() == Material.CHAINMAIL_CHESTPLATE || istack.getType() == Material.IRON_CHESTPLATE
|| istack.getType() == Material.DIAMOND_CHESTPLATE || istack.getType() == Material.GOLD_CHESTPLATE) { || istack.getType() == Material.DIAMOND_CHESTPLATE || istack.getType() == Material.GOLD_CHESTPLATE) {
this.player.getInventory().setChestplate(istack); player.getInventory().setChestplate(istack);
} }
// Boots // Boots
else if (istack.getType() == Material.LEATHER_BOOTS || istack.getType() == Material.CHAINMAIL_BOOTS || istack.getType() == Material.IRON_BOOTS else if (istack.getType() == Material.LEATHER_BOOTS || istack.getType() == Material.CHAINMAIL_BOOTS || istack.getType() == Material.IRON_BOOTS
|| istack.getType() == Material.DIAMOND_BOOTS || istack.getType() == Material.GOLD_BOOTS) { || istack.getType() == Material.DIAMOND_BOOTS || istack.getType() == Material.GOLD_BOOTS) {
this.player.getInventory().setBoots(istack); player.getInventory().setBoots(istack);
} }
else { else {
this.player.getInventory().addItem(istack); player.getInventory().addItem(istack);
} }
} }
} }
@ -390,16 +420,16 @@ public class DPlayer {
} }
public void addTreasure() { public void addTreasure() {
new DLootInventory(this.player, this.treasureInv.getContents()); new DLootInventory(player, treasureInv.getContents());
} }
// Static // Static
public static void remove(DPlayer player) { public static void remove(DPlayer player) {
players.remove(player); plugin.getDPlayers().remove(player);
} }
public static DPlayer get(Player player) { public static DPlayer get(Player player) {
for (DPlayer dplayer : players) { for (DPlayer dplayer : plugin.getDPlayers()) {
if (dplayer.player.equals(player)) { if (dplayer.player.equals(player)) {
return dplayer; return dplayer;
} }
@ -408,7 +438,7 @@ public class DPlayer {
} }
public static DPlayer get(String name) { public static DPlayer get(String name) {
for (DPlayer dplayer : players) { for (DPlayer dplayer : plugin.getDPlayers()) {
if (dplayer.player.getName().equalsIgnoreCase(name)) { if (dplayer.player.getName().equalsIgnoreCase(name)) {
return dplayer; return dplayer;
} }
@ -417,28 +447,28 @@ public class DPlayer {
} }
public static CopyOnWriteArrayList<DPlayer> get(World world) { public static CopyOnWriteArrayList<DPlayer> get(World world) {
CopyOnWriteArrayList<DPlayer> dplayers = new CopyOnWriteArrayList<DPlayer>(); CopyOnWriteArrayList<DPlayer> dPlayers = new CopyOnWriteArrayList<DPlayer>();
for (DPlayer dplayer : players) { for (DPlayer dplayer : plugin.getDPlayers()) {
if (dplayer.world == world) { if (dplayer.world == world) {
dplayers.add(dplayer); dPlayers.add(dplayer);
} }
} }
return dplayers; return dPlayers;
} }
public static void update(boolean updateSecond) { public static void update(boolean updateSecond) {
for (DPlayer dplayer : players) { for (DPlayer dplayer : plugin.getDPlayers()) {
if ( !updateSecond) { if ( !updateSecond) {
if ( !dplayer.player.getWorld().equals(dplayer.world)) { if ( !dplayer.player.getWorld().equals(dplayer.world)) {
if (dplayer.isEditing) { if (dplayer.isEditing) {
EditWorld eworld = EditWorld.get(dplayer.world); EditWorld eworld = EditWorld.get(dplayer.world);
if (eworld != null) { if (eworld != null) {
if (eworld.lobby == null) { if (eworld.lobby == null) {
DUtility.secureTeleport(dplayer.player, eworld.world.getSpawnLocation()); MiscUtil.secureTeleport(dplayer.player, eworld.world.getSpawnLocation());
} else { } else {
DUtility.secureTeleport(dplayer.player, eworld.lobby); MiscUtil.secureTeleport(dplayer.player, eworld.lobby);
} }
} }
} else { } else {
@ -446,12 +476,12 @@ public class DPlayer {
if (gworld != null) { if (gworld != null) {
DGroup dgroup = DGroup.get(dplayer.player); DGroup dgroup = DGroup.get(dplayer.player);
if (dplayer.checkpoint == null) { if (dplayer.checkpoint == null) {
DUtility.secureTeleport(dplayer.player, dgroup.getGworld().locStart); MiscUtil.secureTeleport(dplayer.player, dgroup.getGworld().locStart);
if (dplayer.wolf != null) { if (dplayer.wolf != null) {
dplayer.wolf.teleport(dgroup.getGworld().locStart); dplayer.wolf.teleport(dgroup.getGworld().locStart);
} }
} else { } else {
DUtility.secureTeleport(dplayer.player, dplayer.checkpoint); MiscUtil.secureTeleport(dplayer.player, dplayer.checkpoint);
if (dplayer.wolf != null) { if (dplayer.wolf != null) {
dplayer.wolf.teleport(dplayer.checkpoint); dplayer.wolf.teleport(dplayer.checkpoint);
} }
@ -484,7 +514,7 @@ public class DPlayer {
} }
} }
// Kick offline players // Kick offline plugin.getDPlayers()
if (dplayer.offlineTime > 0) { if (dplayer.offlineTime > 0) {
if (dplayer.offlineTime < System.currentTimeMillis()) { if (dplayer.offlineTime < System.currentTimeMillis()) {
dplayer.leave(); dplayer.leave();
@ -497,4 +527,5 @@ public class DPlayer {
} }
} }
} }
} }

View File

@ -1,4 +1,8 @@
package com.dre.dungeonsxl; package io.github.dre2n.dungeonsxl.player;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.util.MiscUtil;
import io.github.dre2n.dungeonsxl.util.offlineplayerutil.OfflinePlayerUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -13,13 +17,12 @@ import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import com.dre.dungeonsxl.util.DUtility;
public class DSavePlayer { public class DSavePlayer {
private static P p = P.p;
static DungeonsXL plugin = DungeonsXL.getPlugin();
private static CopyOnWriteArrayList<DSavePlayer> savePlayers = new CopyOnWriteArrayList<DSavePlayer>(); private static CopyOnWriteArrayList<DSavePlayer> savePlayers = new CopyOnWriteArrayList<DSavePlayer>();
@ -60,57 +63,53 @@ public class DSavePlayer {
} }
public void reset(boolean keepInventory) { public void reset(boolean keepInventory) {
Player onlinePlayer = p.getServer().getPlayer(this.playerName); @SuppressWarnings("deprecation")
Player player = plugin.getServer().getPlayer(playerName);
boolean offline = false;
if (player == null) {
player = OfflinePlayerUtil.getOfflinePlayer(playerName, UUID.fromString(uuid), oldLocation);
offline = true;
}
if (player == null) {
return;
}
try { try {
if (onlinePlayer != null) {
/* Player is online */
if ( !keepInventory) { if ( !keepInventory) {
onlinePlayer.getInventory().setContents(this.oldInventory); player.getInventory().setContents(oldInventory);
onlinePlayer.getInventory().setArmorContents(this.oldArmor); player.getInventory().setArmorContents(oldArmor);
onlinePlayer.setTotalExperience(this.oldExp); player.setTotalExperience(oldExp);
onlinePlayer.setLevel(this.oldLvl); player.setLevel(oldLvl);
onlinePlayer.setHealth(this.oldHealth); player.setHealth(oldHealth);
onlinePlayer.setFoodLevel(this.oldFoodLevel); player.setFoodLevel(oldFoodLevel);
onlinePlayer.setGameMode(this.oldGamemode); player.setGameMode(oldGamemode);
onlinePlayer.setFireTicks(this.oldFireTicks); player.setFireTicks(oldFireTicks);
for (PotionEffect effect : onlinePlayer.getActivePotionEffects()) { for (PotionEffect effect : player.getActivePotionEffects()) {
onlinePlayer.removePotionEffect(effect.getType()); player.removePotionEffect(effect.getType());
} }
onlinePlayer.addPotionEffects(this.oldPotionEffects); // Causes NPE if offline
} if ( !offline) {
DUtility.secureTeleport(onlinePlayer, this.oldLocation); player.addPotionEffects(oldPotionEffects);
} else {
/* Player is offline */
Player offlinePlayer = p.getOfflinePlayer(this.playerName, UUID.fromString(uuid), this.oldLocation);
if (offlinePlayer != null && !keepInventory) {
offlinePlayer.getInventory().setContents(this.oldInventory);
offlinePlayer.getInventory().setArmorContents(this.oldArmor);
offlinePlayer.setTotalExperience(this.oldExp);
offlinePlayer.setLevel(this.oldLvl);
offlinePlayer.setHealth(this.oldHealth);
offlinePlayer.setFoodLevel(this.oldFoodLevel);
offlinePlayer.setGameMode(this.oldGamemode);
offlinePlayer.setFireTicks(this.oldFireTicks);
for (PotionEffect effect : offlinePlayer.getActivePotionEffects()) {
offlinePlayer.removePotionEffect(effect.getType());
}
//causes NP
//offlinePlayer.addPotionEffects(this.oldPotionEffects);
offlinePlayer.saveData(); } else {
player.saveData();
} }
} }
if ( !offline) {
MiscUtil.secureTeleport(player, oldLocation);
}
} catch (NullPointerException exception) { } catch (NullPointerException exception) {
P.p.log("Corrupt playerdata detected and removed!"); plugin.log("Corrupted playerdata detected and removed!");
} }
savePlayers.remove(this); savePlayers.remove(this);
save(); save();
} }
// Static // Static
@SuppressWarnings("deprecation")
public static void save() { public static void save() {
FileConfiguration configFile = new YamlConfiguration(); FileConfiguration configFile = new YamlConfiguration();
@ -134,15 +133,15 @@ public class DSavePlayer {
} }
try { try {
configFile.save(new File(p.getDataFolder(), "savePlayers.yml")); configFile.save(new File(plugin.getDataFolder(), "savePlayers.yml"));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings({"unchecked", "deprecation"})
public static void load() { public static void load() {
FileConfiguration configFile = YamlConfiguration.loadConfiguration(new File(p.getDataFolder(), "savePlayers.yml")); FileConfiguration configFile = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "savePlayers.yml"));
for (String playerName : configFile.getKeys(false)) { for (String playerName : configFile.getKeys(false)) {
// Load uuid // Load uuid
@ -165,9 +164,9 @@ public class DSavePlayer {
Collection<PotionEffect> oldPotionEffects = (Collection<PotionEffect>) configFile.get(playerName + ".oldPotionEffects"); Collection<PotionEffect> oldPotionEffects = (Collection<PotionEffect>) configFile.get(playerName + ".oldPotionEffects");
// Location // Location
World world = p.getServer().getWorld(configFile.getString(playerName + ".oldLocation.world")); World world = plugin.getServer().getWorld(configFile.getString(playerName + ".oldLocation.world"));
if (world == null) { if (world == null) {
world = p.getServer().getWorlds().get(0); world = plugin.getServer().getWorlds().get(0);
} }
Location oldLocation = new Location(world, configFile.getDouble(playerName + ".oldLocation.x"), configFile.getDouble(playerName + ".oldLocation.y"), configFile.getDouble(playerName Location oldLocation = new Location(world, configFile.getDouble(playerName + ".oldLocation.x"), configFile.getDouble(playerName + ".oldLocation.y"), configFile.getDouble(playerName

View File

@ -1,10 +1,12 @@
package com.dre.dungeonsxl.signs; package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.util.IntegerUtil;
import org.bukkit.block.Sign;
import org.bukkit.Material; import org.bukkit.Material;
import com.dre.dungeonsxl.game.GameWorld; import org.bukkit.block.Sign;
public class SIGNBlock extends DSign { public class BlockSign extends DSign {
public static String name = "Block"; public static String name = "Block";
public String buildPermissions = "dxl.sign.block"; public String buildPermissions = "dxl.sign.block";
@ -18,30 +20,29 @@ public class SIGNBlock extends DSign {
private byte offBlockData = 0x0; private byte offBlockData = 0x0;
private byte onBlockData = 0x0; private byte onBlockData = 0x0;
public SIGNBlock(Sign sign, GameWorld gworld) { public BlockSign(Sign sign, GameWorld gworld) {
super(sign, gworld); super(sign, gworld);
} }
@Override @Override
public boolean check() { public boolean check() {
// TODO Auto-generated method stub
return true; return true;
} }
@SuppressWarnings("deprecation")
@Override @Override
public void onInit() { public void onInit() {
String lines[] = sign.getLines(); String lines[] = getSign().getLines();
if ( !lines[1].equals("")) { if ( !lines[1].equals("")) {
String line1[] = lines[1].split(","); String line1[] = lines[1].split(",");
Material offBlock = Material.matchMaterial(line1[0]); Material offBlock = Material.matchMaterial(line1[0]);
if (offBlock != null) { if (offBlock != null) {
offBlockId = offBlock.getId(); offBlockId = offBlock.getId();
} else { } else {
offBlockId = p.parseInt(line1[0]); offBlockId = IntegerUtil.parseInt(line1[0]);
} }
if (line1.length > 1) { if (line1.length > 1) {
offBlockData = (byte) p.parseInt(line1[1]); offBlockData = (byte) IntegerUtil.parseInt(line1[1]);
} }
} }
@ -51,29 +52,31 @@ public class SIGNBlock extends DSign {
if (onBlock != null) { if (onBlock != null) {
onBlockId = onBlock.getId(); onBlockId = onBlock.getId();
} else { } else {
onBlockId = p.parseInt(line2[0]); onBlockId = IntegerUtil.parseInt(line2[0]);
} }
if (line2.length > 1) { if (line2.length > 1) {
onBlockData = (byte) p.parseInt(line2[1]); onBlockData = (byte) IntegerUtil.parseInt(line2[1]);
} }
} }
sign.getBlock().setTypeIdAndData(offBlockId, offBlockData, true); getSign().getBlock().setTypeIdAndData(offBlockId, offBlockData, true);
initialized = true; initialized = true;
} }
@SuppressWarnings("deprecation")
@Override @Override
public void onTrigger() { public void onTrigger() {
if (initialized && !active) { if (initialized && !active) {
sign.getBlock().setTypeIdAndData(onBlockId, onBlockData, true); getSign().getBlock().setTypeIdAndData(onBlockId, onBlockData, true);
active = true; active = true;
} }
} }
@SuppressWarnings("deprecation")
@Override @Override
public void onDisable() { public void onDisable() {
if (initialized && active) { if (initialized && active) {
sign.getBlock().setTypeIdAndData(offBlockId, offBlockData, true); getSign().getBlock().setTypeIdAndData(offBlockId, offBlockData, true);
active = false; active = false;
} }
} }
@ -87,4 +90,5 @@ public class SIGNBlock extends DSign {
public boolean isOnDungeonInit() { public boolean isOnDungeonInit() {
return onDungeonInit; return onDungeonInit;
} }
} }

View File

@ -1,4 +1,9 @@
package com.dre.dungeonsxl.signs; package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.util.MessageUtil;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@ -6,11 +11,7 @@ import org.bukkit.Material;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.dre.dungeonsxl.DPlayer; public class CheckpointSign extends DSign {
import com.dre.dungeonsxl.P;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNCheckpoint extends DSign {
public static String name = "Checkpoint"; public static String name = "Checkpoint";
private String buildPermissions = "dxl.sign.checkpoint"; private String buildPermissions = "dxl.sign.checkpoint";
@ -20,20 +21,18 @@ public class SIGNCheckpoint extends DSign {
private boolean initialized; private boolean initialized;
private CopyOnWriteArrayList<DPlayer> done = new CopyOnWriteArrayList<DPlayer>(); private CopyOnWriteArrayList<DPlayer> done = new CopyOnWriteArrayList<DPlayer>();
public SIGNCheckpoint(Sign sign, GameWorld gworld) { public CheckpointSign(Sign sign, GameWorld gWorld) {
super(sign, gworld); super(sign, gWorld);
} }
@Override @Override
public boolean check() { public boolean check() {
// TODO Auto-generated method stub
return true; return true;
} }
@Override @Override
public void onInit() { public void onInit() {
sign.getBlock().setType(Material.AIR); getSign().getBlock().setType(Material.AIR);
initialized = true; initialized = true;
} }
@ -41,9 +40,9 @@ public class SIGNCheckpoint extends DSign {
@Override @Override
public void onTrigger() { public void onTrigger() {
if (initialized) { if (initialized) {
for (DPlayer dplayer : DPlayer.get(this.gworld.world)) { for (DPlayer dplayer : DPlayer.get(getGWorld().world)) {
dplayer.setCheckpoint(this.sign.getLocation()); dplayer.setCheckpoint(getSign().getLocation());
P.p.msg(dplayer.player, P.p.language.get("Player_CheckpointReached")); MessageUtil.sendMessage(dplayer.player, DungeonsXL.getPlugin().getDMessages().get("Player_CheckpointReached"));
} }
remove(); remove();
@ -57,11 +56,11 @@ public class SIGNCheckpoint extends DSign {
if (dplayer != null) { if (dplayer != null) {
if ( !done.contains(dplayer)) { if ( !done.contains(dplayer)) {
done.add(dplayer); done.add(dplayer);
dplayer.setCheckpoint(this.sign.getLocation()); dplayer.setCheckpoint(getSign().getLocation());
P.p.msg(player, P.p.language.get("Player_CheckpointReached")); MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Player_CheckpointReached"));
} }
} }
if (done.size() >= DPlayer.get(this.gworld.world).size()) { if (done.size() >= DPlayer.get(getGWorld().world).size()) {
remove(); remove();
} }
} }

View File

@ -0,0 +1,61 @@
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.dungeon.game.GameChest;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import org.bukkit.Material;
import org.bukkit.block.Sign;
public class ChestSign extends DSign {
public static String name = "Chest";
public String buildPermissions = "dxl.sign.chest";
public boolean onDungeonInit = false;
// Variables
private double moneyReward;
public ChestSign(Sign sign, GameWorld gWorld) {
super(sign, gWorld);
}
@Override
public boolean check() {
String lines[] = getSign().getLines();
if (lines[1].equals("")) {
return false;
}
return true;
}
@Override
public void onInit() {
String lines[] = getSign().getLines();
if ( !lines[1].equals("")) {
moneyReward = Double.parseDouble(lines[1]);
}
for (int i = -1; i <= 1; i++) {
if (getSign().getBlock().getRelative(i, 0, 0).getType() == Material.CHEST) {
new GameChest(getSign().getBlock().getRelative(i, 0, 0), getGWorld(), moneyReward);
}
if (getSign().getBlock().getRelative(0, 0, i).getType() == Material.CHEST) {
new GameChest(getSign().getBlock().getRelative(0, 0, i), getGWorld(), moneyReward);
}
if (getSign().getBlock().getRelative(0, i, 0).getType() == Material.CHEST) {
new GameChest(getSign().getBlock().getRelative(0, i, 0), getGWorld(), moneyReward);
}
}
getSign().getBlock().setType(Material.AIR);
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

View File

@ -0,0 +1,56 @@
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.util.IntegerUtil;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.block.Sign;
public class ChunkUpdaterSign extends DSign {
public static String name = "ChunkUpdater";
public String buildPermissions = "dxl.sign.chunkupdater";
public boolean onDungeonInit = true;
public ChunkUpdaterSign(Sign sign, GameWorld gWorld) {
super(sign, gWorld);
}
@Override
public boolean check() {
// TODO Auto-generated method stub
return true;
}
@Override
public void onInit() {
String lines[] = getSign().getLines();
Chunk chunk = getGWorld().world.getChunkAt(getSign().getBlock());
if ( !lines[1].equals("")) {
Integer radius = IntegerUtil.parseInt(lines[1]);
for (int x = -radius; x < radius; x++) {
for (int z = -radius; z < radius; z++) {
Chunk chunk1 = getGWorld().world.getChunkAt(chunk.getX() - x, chunk.getZ() - z);
chunk1.load();
getGWorld().loadedChunks.add(chunk1);
}
}
} else {
chunk.load();
getGWorld().loadedChunks.add(chunk);
}
getSign().getBlock().setType(Material.AIR);
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

View File

@ -0,0 +1,82 @@
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.global.GroupSign;
import io.github.dre2n.dungeonsxl.player.DClass;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
public class ClassesSign extends DSign {
public static String name = "Classes";
public String buildPermissions = "dxl.sign.classes";
public boolean onDungeonInit = true;
public ClassesSign(Sign sign, GameWorld gWorld) {
super(sign, gWorld);
}
@Override
public boolean check() {
return true;
}
@SuppressWarnings("deprecation")
@Override
public void onInit() {
if ( !getGWorld().getConfig().isLobbyDisabled()) {
int[] direction = GroupSign.getDirection(getSign().getBlock().getData());
int directionX = direction[0];
int directionZ = direction[1];
int xx = 0, zz = 0;
for (DClass dclass : getGWorld().getConfig().getClasses()) {
// Check existing signs
boolean isContinued = true;
for (Sign isusedsign : getGWorld().signClass) {
if (dclass.getName().equalsIgnoreCase(ChatColor.stripColor(isusedsign.getLine(1)))) {
isContinued = false;
}
}
if (isContinued) {
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();
getGWorld().signClass.add(classSign);
} else {
break;
}
xx = xx + directionX;
zz = zz + directionZ;
}
}
} else {
getSign().getBlock().setType(Material.AIR);
}
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

View File

@ -0,0 +1,91 @@
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.commandsxl.CCommand;
import io.github.dre2n.commandsxl.CommandsXL;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.trigger.InteractTrigger;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
public class CommandSign extends DSign {
public static String name = "Cmd";
public String buildPermissions = "dxl.sign.cmd";
public boolean onDungeonInit = false;
// Variables
private CCommand cCommand;
private String command;
private String executor;
private boolean initialized;
public CommandSign(Sign sign, GameWorld gWorld) {
super(sign, gWorld);
}
@Override
public boolean check() {
// TODO Auto-generated method stub
return true;
}
@Override
public void onInit() {
command = getSign().getLine(1);
executor = getSign().getLine(2);
cCommand = CommandsXL.getCCommands().getCCommand(command);
if (getTriggers().isEmpty()) {
InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), getGWorld());
if (trigger != null) {
trigger.addListener(this);
getTriggers().add(trigger);
}
getSign().setLine(0, ChatColor.DARK_BLUE + "############");
getSign().setLine(1, ChatColor.DARK_GREEN + command);
getSign().setLine(2, "");
getSign().setLine(3, ChatColor.DARK_BLUE + "############");
getSign().update();
} else {
getSign().getBlock().setType(Material.AIR);
}
initialized = true;
}
@Override
public boolean onPlayerTrigger(Player player) {
if (executor.equalsIgnoreCase("Console")) {
cCommand.execute(player, Bukkit.getConsoleSender(), true);
} else if (executor.equalsIgnoreCase("OP")) {
cCommand.execute(player, player, true);
} else {
cCommand.execute(player, player, false);
}
return true;
}
@Override
public void onTrigger() {
if (initialized) {
remove();
}
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

View File

@ -0,0 +1,220 @@
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.trigger.Trigger;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
public abstract class DSign {
static DungeonsXL plugin = DungeonsXL.getPlugin();
private Sign sign;
private GameWorld gWorld;
// List of Triggers
private Set<Trigger> triggers = new HashSet<Trigger>();
public DSign(Sign sign, GameWorld gWorld) {
this.setSign(sign);
this.gWorld = gWorld;
// Check Trigger
if (gWorld != null) {
String line3 = sign.getLine(3).replaceAll("\\s", "");
String[] triggerTypes = line3.split(",");
for (String triggerString : triggerTypes) {
if ( !triggerString.equals("")) {
String type = triggerString.substring(0, 1);
String value = null;
if (triggerString.length() > 1) {
value = triggerString.substring(1);
}
Trigger trigger = Trigger.getOrCreate(type, value, this);
if (trigger != null) {
trigger.addListener(this);
addTrigger(trigger);
}
}
}
}
}
/**
* @return the sign
*/
public Sign getSign() {
return sign;
}
/**
* @param sign
* the sign to set
*/
public void setSign(Sign sign) {
this.sign = sign;
}
/**
* @return the gWorld
*/
public GameWorld getGWorld() {
return gWorld;
}
/**
* @return the triggers
*/
public Set<Trigger> getTriggers() {
return triggers;
}
/**
* @param trigger
* the trigger to add
*/
public void addTrigger(Trigger trigger) {
addTrigger(trigger);
}
/**
* @param trigger
* the trigger to remove
*/
public void removeTrigger(Trigger trigger) {
triggers.remove(trigger);
}
public void onInit() {
}
public void onTrigger() {
}
public boolean onPlayerTrigger(Player player) {
return false;
}
public void onDisable() {
}
public void onUpdate() {
for (Trigger trigger : triggers) {
if ( !trigger.triggered) {
onDisable();
return;
}
if (triggers.size() == 1) {
if (trigger.player != null) {
if (onPlayerTrigger(trigger.player)) {
return;
}
}
}
}
onTrigger();
}
public void remove() {
for (Trigger trigger : triggers) {
trigger.removeListener(this);
}
gWorld.dSigns.remove(this);
}
public boolean hasTriggers() {
return !triggers.isEmpty();
}
public static DSign create(Sign sign, GameWorld gWorld) {
String[] lines = sign.getLines();
DSign dSign = null;
if (lines[0].equalsIgnoreCase("[" + CheckpointSign.name + "]")) {
dSign = new CheckpointSign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + ChestSign.name + "]")) {
dSign = new ChestSign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + ChunkUpdaterSign.name + "]")) {
dSign = new ChunkUpdaterSign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + ClassesSign.name + "]")) {
dSign = new ClassesSign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + CommandSign.name + "]")) {
dSign = new CommandSign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + EndSign.name + "]")) {
dSign = new EndSign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + LeaveSign.name + "]")) {
dSign = new LeaveSign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + LobbySign.name + "]")) {
dSign = new LobbySign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + MobSign.name + "]")) {
dSign = new MobSign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + MsgSign.name + "]")) {
dSign = new MsgSign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + MythicMobsSign.name + "]")) {
dSign = new MythicMobsSign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + PlaceSign.name + "]")) {
dSign = new PlaceSign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + ReadySign.name + "]")) {
dSign = new ReadySign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + SoundMsgSign.name + "]")) {
dSign = new SoundMsgSign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + StartSign.name + "]")) {
dSign = new StartSign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + TriggerSign.name + "]")) {
dSign = new TriggerSign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + InteractSign.name + "]")) {
dSign = new InteractSign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + RedstoneSign.name + "]")) {
dSign = new RedstoneSign(sign, gWorld);
} else if (lines[0].equalsIgnoreCase("[" + BlockSign.name + "]")) {
dSign = new BlockSign(sign, gWorld);
}
if (dSign != null && gWorld != null) {
if (dSign.isOnDungeonInit()) {
dSign.onInit();
}
}
return dSign;
}
// Abstract methods
public abstract boolean check();
public abstract String getPermissions();
public abstract boolean isOnDungeonInit();
}

View File

@ -0,0 +1,75 @@
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.trigger.InteractTrigger;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
public class EndSign extends DSign {
public static String name = "End";
public String buildPermissions = "dxl.sign.end";
public boolean onDungeonInit = false;
public EndSign(Sign sign, GameWorld gWorld) {
super(sign, gWorld);
}
@Override
public boolean check() {
// TODO Auto-generated method stub
return true;
}
@Override
public void onInit() {
if (getTriggers().isEmpty()) {
InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), getGWorld());
if (trigger != null) {
trigger.addListener(this);
addTrigger(trigger);
}
getSign().setLine(0, ChatColor.DARK_BLUE + "############");
getSign().setLine(1, ChatColor.DARK_GREEN + "End");
getSign().setLine(2, "");
getSign().setLine(3, ChatColor.DARK_BLUE + "############");
getSign().update();
} else {
getSign().getBlock().setType(Material.AIR);
}
}
@Override
public boolean onPlayerTrigger(Player player) {
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
if ( !dplayer.isFinished) {
dplayer.finish();
}
}
return true;
}
@Override
public void onTrigger() {
for (DPlayer dplayer : DungeonsXL.getPlugin().getDPlayers()) {
dplayer.finish();
}
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

View File

@ -0,0 +1,87 @@
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.trigger.InteractTrigger;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
public class FloorSign extends DSign {
public static String name = "Floor";
public String buildPermissions = "dxl.sign.floor";
public boolean onDungeonInit = false;
private String floor;
public FloorSign(Sign sign, GameWorld gWorld) {
super(sign, gWorld);
}
@Override
public boolean check() {
String lines[] = getSign().getLines();
if ( !lines[1].equals("") && !lines[2].equals("")) {
if (lines[1] != null) {
String[] atributes = lines[2].split(",");
if (atributes.length == 2) {
return true;
}
}
}
return false;
}
@Override
public void onInit() {
if (getTriggers().isEmpty()) {
InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), getGWorld());
if (trigger != null) {
trigger.addListener(this);
addTrigger(trigger);
}
getSign().setLine(0, ChatColor.DARK_BLUE + "############");
getSign().setLine(1, ChatColor.DARK_GREEN + "ENTER");
if (floor != null) {
getSign().setLine(2, ChatColor.DARK_GREEN + "NEXT FLOOR");
}
getSign().setLine(3, ChatColor.DARK_BLUE + "############");
getSign().update();
} else {
getSign().getBlock().setType(Material.AIR);
}
}
@Override
public boolean onPlayerTrigger(Player player) {
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
if ( !dplayer.isFinished) {
dplayer.finishFloor();
}
}
return true;
}
@Override
public void onTrigger() {
for (DPlayer dplayer : DungeonsXL.getPlugin().getDPlayers()) {
dplayer.finish();
}
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

View File

@ -1,30 +1,31 @@
package com.dre.dungeonsxl.signs; package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.trigger.InteractTrigger;
import io.github.dre2n.dungeonsxl.util.IntegerUtil;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.bukkit.block.Sign;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.game.GameWorld; public class InteractSign extends DSign {
import com.dre.dungeonsxl.EditWorld;
import com.dre.dungeonsxl.trigger.InteractTrigger;
public class SIGNInteract extends DSign {
public static String name = "Interact"; public static String name = "Interact";
public String buildPermissions = "dxl.sign.trigger"; public String buildPermissions = "dxl.sign.trigger";
public boolean onDungeonInit = true; public boolean onDungeonInit = true;
public SIGNInteract(Sign sign, GameWorld gworld) { public InteractSign(Sign sign, GameWorld gWorld) {
super(sign, gworld); super(sign, gWorld);
} }
@Override @Override
public boolean check() { public boolean check() {
Set<Integer> used = new HashSet<Integer>(); Set<Integer> used = new HashSet<Integer>();
for (Block block : EditWorld.get(sign.getLocation().getWorld()).sign) { for (Block block : EditWorld.get(getSign().getLocation().getWorld()).sign) {
if (block != null) { if (block != null) {
if ( !block.getChunk().isLoaded()) { if ( !block.getChunk().isLoaded()) {
block.getChunk().load(); block.getChunk().load();
@ -32,21 +33,21 @@ public class SIGNInteract extends DSign {
if (block.getState() instanceof Sign) { if (block.getState() instanceof Sign) {
Sign rsign = (Sign) block.getState(); Sign rsign = (Sign) block.getState();
if (rsign.getLine(0).equalsIgnoreCase("[" + name + "]")) { if (rsign.getLine(0).equalsIgnoreCase("[" + name + "]")) {
used.add(p.parseInt(rsign.getLine(1))); used.add(IntegerUtil.parseInt(rsign.getLine(1)));
} }
} }
} }
} }
int id = 1; int id = 1;
if (sign.getLine(1).equalsIgnoreCase("")) { if (getSign().getLine(1).equalsIgnoreCase("")) {
if (used.size() != 0) { if (used.size() != 0) {
while (used.contains(id)) { while (used.contains(id)) {
id++; id++;
} }
} }
} else { } else {
id = p.parseInt(sign.getLine(1)); id = IntegerUtil.parseInt(getSign().getLine(1));
if (id == 0 || used.contains(id)) { if (id == 0 || used.contains(id)) {
return false; return false;
} else { } else {
@ -54,24 +55,24 @@ public class SIGNInteract extends DSign {
} }
} }
sign.setLine(1, id + ""); getSign().setLine(1, id + "");
p.getServer().getScheduler().scheduleSyncDelayedTask(p, new UpdateTask(), 2); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new UpdateTask(), 2);
return true; return true;
} }
@Override @Override
public void onInit() { public void onInit() {
InteractTrigger trigger = InteractTrigger.getOrCreate(p.parseInt(sign.getLine(1)), sign.getBlock(), gworld); InteractTrigger trigger = InteractTrigger.getOrCreate(IntegerUtil.parseInt(getSign().getLine(1)), getSign().getBlock(), getGWorld());
if (trigger != null) { if (trigger != null) {
trigger.addListener(this); trigger.addListener(this);
this.triggers.add(trigger); addTrigger(trigger);
} }
sign.setLine(0, ChatColor.DARK_BLUE + "############"); getSign().setLine(0, ChatColor.DARK_BLUE + "############");
sign.setLine(1, ChatColor.GREEN + sign.getLine(2)); getSign().setLine(1, ChatColor.GREEN + getSign().getLine(2));
sign.setLine(2, ChatColor.GREEN + sign.getLine(3)); getSign().setLine(2, ChatColor.GREEN + getSign().getLine(3));
sign.setLine(3, ChatColor.DARK_BLUE + "############"); getSign().setLine(3, ChatColor.DARK_BLUE + "############");
sign.update(); getSign().update();
} }
@Override @Override
@ -96,7 +97,7 @@ public class SIGNInteract extends DSign {
@Override @Override
public void run() { public void run() {
sign.update(); getSign().update();
} }
} }
} }

View File

@ -0,0 +1,73 @@
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.trigger.InteractTrigger;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
public class LeaveSign extends DSign {
public static String name = "Leave";
public String buildPermissions = "dxl.sign.leave";
public boolean onDungeonInit = true;
public LeaveSign(Sign sign, GameWorld gWorld) {
super(sign, gWorld);
}
@Override
public boolean check() {
// TODO Auto-generated method stub
return true;
}
@Override
public void onInit() {
if (getTriggers().isEmpty()) {
InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), getGWorld());
if (trigger != null) {
trigger.addListener(this);
addTrigger(trigger);
}
getSign().setLine(0, ChatColor.DARK_BLUE + "############");
getSign().setLine(1, ChatColor.DARK_GREEN + "Leave");
getSign().setLine(2, "");
getSign().setLine(3, ChatColor.DARK_BLUE + "############");
getSign().update();
} else {
getSign().getBlock().setType(Material.AIR);
}
}
@Override
public boolean onPlayerTrigger(Player player) {
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
dplayer.leave();
}
return true;
}
@Override
public void onTrigger() {
for (DPlayer dplayer : DungeonsXL.getPlugin().getDPlayers()) {
dplayer.leave();
}
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

View File

@ -1,18 +1,18 @@
package com.dre.dungeonsxl.signs; package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GameWorld; public class LobbySign extends DSign {
public class SIGNLobby extends DSign {
public static String name = "Lobby"; public static String name = "Lobby";
public String buildPermissions = "dxl.sign.lobby"; public String buildPermissions = "dxl.sign.lobby";
public boolean onDungeonInit = true; public boolean onDungeonInit = true;
public SIGNLobby(Sign sign, GameWorld gworld) { public LobbySign(Sign sign, GameWorld gWorld) {
super(sign, gworld); super(sign, gWorld);
} }
@Override @Override
@ -24,8 +24,8 @@ public class SIGNLobby extends DSign {
@Override @Override
public void onInit() { public void onInit() {
gworld.locLobby = sign.getLocation(); getGWorld().locLobby = getSign().getLocation();
sign.getBlock().setType(Material.AIR); getSign().getBlock().setType(Material.AIR);
} }
@Override @Override

View File

@ -1,5 +1,11 @@
package com.dre.dungeonsxl.signs; package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import io.github.dre2n.dungeonsxl.mob.DMob;
import io.github.dre2n.dungeonsxl.mob.DMobType;
import io.github.dre2n.dungeonsxl.util.IntegerUtil;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
@ -8,13 +14,8 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Skeleton; import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.Location;
import com.dre.dungeonsxl.DMobType; public class MobSign extends DSign {
import com.dre.dungeonsxl.game.DMob;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNMob extends DSign {
public static String name = "Mob"; public static String name = "Mob";
public String buildPermissions = "dxl.sign.mob"; public String buildPermissions = "dxl.sign.mob";
@ -29,13 +30,13 @@ public class SIGNMob extends DSign {
private boolean active; private boolean active;
private int taskId = -1; private int taskId = -1;
public SIGNMob(Sign sign, GameWorld gworld) { public MobSign(Sign sign, GameWorld gWorld) {
super(sign, gworld); super(sign, gWorld);
} }
@Override @Override
public boolean check() { public boolean check() {
String lines[] = sign.getLines(); String lines[] = getSign().getLines();
if ( !lines[1].equals("") && !lines[2].equals("")) { if ( !lines[1].equals("") && !lines[2].equals("")) {
if (lines[1] != null) { if (lines[1] != null) {
String[] atributes = lines[2].split(","); String[] atributes = lines[2].split(",");
@ -50,19 +51,19 @@ public class SIGNMob extends DSign {
@Override @Override
public void onInit() { public void onInit() {
String lines[] = sign.getLines(); String lines[] = getSign().getLines();
if ( !lines[1].equals("") && !lines[2].equals("")) { if ( !lines[1].equals("") && !lines[2].equals("")) {
String mob = lines[1]; String mob = lines[1];
if (mob != null) { if (mob != null) {
String[] atributes = lines[2].split(","); String[] atributes = lines[2].split(",");
if (atributes.length == 2) { if (atributes.length == 2) {
this.mob = mob; this.mob = mob;
this.maxinterval = p.parseInt(atributes[0]); maxinterval = IntegerUtil.parseInt(atributes[0]);
this.amount = p.parseInt(atributes[1]); amount = IntegerUtil.parseInt(atributes[1]);
} }
} }
} }
sign.getBlock().setType(Material.AIR); getSign().getBlock().setType(Material.AIR);
initialized = true; initialized = true;
} }
@ -72,7 +73,7 @@ public class SIGNMob extends DSign {
if (initialized && !active) { if (initialized && !active) {
MobSpawnScheduler scheduler = new MobSpawnScheduler(this); MobSpawnScheduler scheduler = new MobSpawnScheduler(this);
taskId = p.getServer().getScheduler().scheduleSyncRepeatingTask(p, scheduler, 0L, 20L); taskId = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, scheduler, 0L, 20L);
active = true; active = true;
} }
@ -90,27 +91,28 @@ public class SIGNMob extends DSign {
public void killTask() { public void killTask() {
if (initialized && active) { if (initialized && active) {
if (taskId != -1) { if (taskId != -1) {
p.getServer().getScheduler().cancelTask(taskId); plugin.getServer().getScheduler().cancelTask(taskId);
taskId = -1; taskId = -1;
} }
} }
} }
public class MobSpawnScheduler implements Runnable { public class MobSpawnScheduler implements Runnable {
private SIGNMob sign; private MobSign sign;
public MobSpawnScheduler(SIGNMob sign) { public MobSpawnScheduler(MobSign sign) {
this.sign = sign; this.sign = sign;
} }
@SuppressWarnings("deprecation")
@Override @Override
public void run() { public void run() {
if (sign.interval <= 0) { if (sign.interval <= 0) {
World world = sign.sign.getWorld(); World world = sign.getSign().getWorld();
GameWorld gworld = GameWorld.get(world); GameWorld gWorld = GameWorld.get(world);
if (gworld != null) { if (gWorld != null) {
Location spawnLoc = sign.sign.getLocation().add(0.5, 0, 0.5); Location spawnLoc = sign.getSign().getLocation().add(0.5, 0, 0.5);
// Check normal mobs // Check normal mobs
if (EntityType.fromName(sign.mob) != null) { if (EntityType.fromName(sign.mob) != null) {
@ -128,12 +130,12 @@ public class SIGNMob extends DSign {
// Disable Despawning // Disable Despawning
entity.setRemoveWhenFarAway(false); entity.setRemoveWhenFarAway(false);
new DMob(entity, sign.gworld, null); new DMob(entity, sign.getGWorld(), null);
} }
} }
// Check custom mobs // Check custom mobs
DMobType mobType = DMobType.get(sign.mob, gworld.config.getMobTypes()); DMobType mobType = DMobType.get(sign.mob, gWorld.getConfig().getMobTypes());
if (mobType != null) { if (mobType != null) {
mobType.spawn(GameWorld.get(world), spawnLoc); mobType.spawn(GameWorld.get(world), spawnLoc);

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