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,273 +1,277 @@
package com.dre.dungeonsxl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
public class EditWorld {
private static P p = P.p;
public static CopyOnWriteArrayList<EditWorld> eworlds = new CopyOnWriteArrayList<EditWorld>();
// Variables
public World world;
public String owner;
public String name;
public String dungeonname;
public int id;
public Location lobby;
public CopyOnWriteArrayList<String> invitedPlayers = new CopyOnWriteArrayList<String>();
public CopyOnWriteArrayList<Block> sign = new CopyOnWriteArrayList<Block>();
public EditWorld() {
eworlds.add(this);
// ID
this.id = -1;
int i = -1;
while (this.id == -1) {
i++;
boolean exist = false;
for (EditWorld eworld : eworlds) {
if (eworld.id == i) {
exist = true;
break;
}
}
if (!exist)
this.id = i;
}
name = "DXL_Edit_" + this.id;
}
public void generate() {
WorldCreator creator = WorldCreator.name(name);
creator.type(WorldType.FLAT);
creator.generateStructures(false);
this.world = p.getServer().createWorld(creator);
}
public void save() {
this.world.save();
try {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(new File(p.getDataFolder(), "/dungeons/" + this.dungeonname + "/DXLData.data")));
out.writeInt(this.sign.size());
for (Block sign : this.sign) {
out.writeInt(sign.getX());
out.writeInt(sign.getY());
out.writeInt(sign.getZ());
}
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void checkSign(Block block) {
if ((block.getState() instanceof Sign)) {
Sign sign = (Sign) block.getState();
String[] lines = sign.getLines();
if (lines[0].equalsIgnoreCase("[lobby]")) {
this.lobby = block.getLocation();
}
}
}
public void delete() {
eworlds.remove(this);
for (Player player : this.world.getPlayers()) {
DPlayer dplayer = DPlayer.get(player);
dplayer.leave();
}
p.getServer().unloadWorld(this.world, true);
File dir = new File("DXL_Edit_" + this.id);
p.copyDirectory(dir, new File(p.getDataFolder(), "/dungeons/" + this.dungeonname));
p.deletenotusingfiles(new File(p.getDataFolder(), "/dungeons/" + this.dungeonname));
p.removeDirectory(dir);
}
public void deleteNoSave() {
eworlds.remove(this);
for (Player player : this.world.getPlayers()) {
DPlayer dplayer = DPlayer.get(player);
dplayer.leave();
}
File dir = new File("DXL_Edit_" + this.id);
p.copyDirectory(dir, new File(p.getDataFolder(), "/dungeons/" + this.dungeonname));
p.deletenotusingfiles(new File(p.getDataFolder(), "/dungeons/" + this.dungeonname));
p.getServer().unloadWorld(this.world, true);
p.removeDirectory(dir);
}
// Static
public static EditWorld get(World world) {
for (EditWorld eworld : eworlds) {
if (eworld.world.equals(world)) {
return eworld;
}
}
return null;
}
public static EditWorld get(String name) {
for (EditWorld eworld : eworlds) {
if (eworld.dungeonname.equalsIgnoreCase(name)) {
return eworld;
}
}
return null;
}
public static void deleteAll() {
for (EditWorld eworld : eworlds) {
eworld.delete();
}
}
public static EditWorld load(String name) {
for (EditWorld eworld : eworlds) {
if (eworld.dungeonname.equalsIgnoreCase(name)) {
return eworld;
}
}
File file = new File(p.getDataFolder(), "/dungeons/" + name);
if (file.exists()) {
EditWorld eworld = new EditWorld();
eworld.dungeonname = name;
// World
p.copyDirectory(file, new File("DXL_Edit_" + eworld.id));
// Id File
File idFile = new File("DXL_Edit_" + eworld.id + "/.id_" + name);
try {
idFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
eworld.world = p.getServer().createWorld(WorldCreator.name("DXL_Edit_" + eworld.id));
try {
ObjectInputStream os = new ObjectInputStream(new FileInputStream(new File(p.getDataFolder(), "/dungeons/" + eworld.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 = eworld.world.getBlockAt(x, y, z);
eworld.checkSign(block);
eworld.sign.add(block);
}
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return eworld;
}
return null;
}
public static boolean exist(String name) {
// Cheack Loaded EditWorlds
for (EditWorld eworld : eworlds) {
if (eworld.dungeonname.equalsIgnoreCase(name)) {
return true;
}
}
// Cheack Unloaded Worlds
File file = new File(p.getDataFolder(), "/dungeons/" + name);
if (file.exists()) {
return true;
}
return false;
}
public void msg(String msg) {
for (DPlayer dplayer : DPlayer.get(this.world)) {
p.msg(dplayer.player, msg);
}
}
// Invite
public static boolean addInvitedPlayer(String eworldname, UUID uuid) {
if (exist(eworldname)) {
DConfig config = new DConfig(new File(p.getDataFolder() + "/dungeons/" + eworldname, "config.yml"));
config.addInvitedPlayer(uuid.toString());
config.save();
return true;
}
return false;
}
public static boolean removeInvitedPlayer(String eworldname, UUID uuid, String name) {
if (exist(eworldname)) {
DConfig config = new DConfig(new File(p.getDataFolder() + "/dungeons/" + eworldname, "config.yml"));
config.removeInvitedPlayers(uuid.toString(), name.toLowerCase());
config.save();
// Kick Player
EditWorld eworld = EditWorld.get(eworldname);
if (eworld != null) {
DPlayer player = DPlayer.get(name);
if (player != null) {
if (eworld.world.getPlayers().contains(player.player)) {
player.leave();
}
}
}
return true;
}
return false;
}
public static boolean isInvitedPlayer(String eworldname, UUID uuid, String name) {
if (exist(eworldname)) {
DConfig config = new DConfig(new File(p.getDataFolder() + "/dungeons/" + eworldname, "config.yml"));
// get player from both a 0.9.1 and lower and 0.9.2 and higher file
if (config.getInvitedPlayers().contains(name.toLowerCase()) || config.getInvitedPlayers().contains(uuid.toString()))
return true;
}
return false;
}
}
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.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
public class EditWorld {
static DungeonsXL plugin = DungeonsXL.getPlugin();
// Variables
public World world;
public String owner;
public String name;
public String dungeonname;
public int id;
public Location lobby;
public CopyOnWriteArrayList<String> invitedPlayers = new CopyOnWriteArrayList<String>();
public CopyOnWriteArrayList<Block> sign = new CopyOnWriteArrayList<Block>();
public EditWorld() {
plugin.getEditWorlds().add(this);
// ID
id = -1;
int i = -1;
while (id == -1) {
i++;
boolean exist = false;
for (EditWorld eworld : plugin.getEditWorlds()) {
if (eworld.id == i) {
exist = true;
break;
}
}
if ( !exist) {
id = i;
}
}
name = "DXL_Edit_" + id;
}
public void generate() {
WorldCreator creator = WorldCreator.name(name);
creator.type(WorldType.FLAT);
creator.generateStructures(false);
world = plugin.getServer().createWorld(creator);
}
public void save() {
world.save();
try {
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(new File(plugin.getDataFolder(), "/maps/" + dungeonname + "/DXLData.data")));
out.writeInt(sign.size());
for (Block sign : this.sign) {
out.writeInt(sign.getX());
out.writeInt(sign.getY());
out.writeInt(sign.getZ());
}
out.close();
} catch (IOException exception) {
}
}
public void checkSign(Block block) {
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
String[] lines = sign.getLines();
if (lines[0].equalsIgnoreCase("[lobby]")) {
lobby = block.getLocation();
}
}
}
public void delete() {
plugin.getEditWorlds().remove(this);
for (Player player : world.getPlayers()) {
DPlayer dplayer = DPlayer.get(player);
dplayer.leave();
}
plugin.getServer().unloadWorld(world, true);
File dir = new File("DXL_Edit_" + id);
FileUtil.copyDirectory(dir, new File(plugin.getDataFolder(), "/maps/" + dungeonname));
FileUtil.deletenotusingfiles(new File(plugin.getDataFolder(), "/maps/" + dungeonname));
FileUtil.removeDirectory(dir);
}
public void deleteNoSave() {
plugin.getEditWorlds().remove(this);
for (Player player : world.getPlayers()) {
DPlayer dplayer = DPlayer.get(player);
dplayer.leave();
}
File dir = new File("DXL_Edit_" + id);
FileUtil.copyDirectory(dir, new File(plugin.getDataFolder(), "/maps/" + dungeonname));
FileUtil.deletenotusingfiles(new File(plugin.getDataFolder(), "/maps/" + dungeonname));
plugin.getServer().unloadWorld(world, true);
FileUtil.removeDirectory(dir);
}
// Static
public static EditWorld get(World world) {
for (EditWorld eworld : plugin.getEditWorlds()) {
if (eworld.world.equals(world)) {
return eworld;
}
}
return null;
}
public static EditWorld get(String name) {
for (EditWorld eworld : plugin.getEditWorlds()) {
if (eworld.dungeonname.equalsIgnoreCase(name)) {
return eworld;
}
}
return null;
}
public static void deleteAll() {
for (EditWorld eworld : plugin.getEditWorlds()) {
eworld.delete();
}
}
public static EditWorld load(String name) {
for (EditWorld eworld : plugin.getEditWorlds()) {
if (eworld.dungeonname.equalsIgnoreCase(name)) {
return eworld;
}
}
File file = new File(plugin.getDataFolder(), "/maps/" + name);
if (file.exists()) {
EditWorld eworld = new EditWorld();
eworld.dungeonname = name;
// World
FileUtil.copyDirectory(file, new File("DXL_Edit_" + eworld.id));
// Id File
File idFile = new File("DXL_Edit_" + eworld.id + "/.id_" + name);
try {
idFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
eworld.world = plugin.getServer().createWorld(WorldCreator.name("DXL_Edit_" + eworld.id));
try {
ObjectInputStream os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder(), "/maps/" + eworld.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 = eworld.world.getBlockAt(x, y, z);
eworld.checkSign(block);
eworld.sign.add(block);
}
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return eworld;
}
return null;
}
public static boolean exist(String name) {
// Cheack Loaded EditWorlds
for (EditWorld eworld : plugin.getEditWorlds()) {
if (eworld.dungeonname.equalsIgnoreCase(name)) {
return true;
}
}
// Cheack Unloaded Worlds
File file = new File(plugin.getDataFolder(), "/maps/" + name);
if (file.exists()) {
return true;
}
return false;
}
public void msg(String msg) {
for (DPlayer dplayer : DPlayer.get(world)) {
MessageUtil.sendMessage(dplayer.player, msg);
}
}
// Invite
public static boolean addInvitedPlayer(String eworldname, UUID uuid) {
if (exist(eworldname)) {
WorldConfig config = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + eworldname, "config.yml"));
config.addInvitedPlayer(uuid.toString());
config.save();
return true;
}
return false;
}
public static boolean removeInvitedPlayer(String eworldname, UUID uuid, String name) {
if (exist(eworldname)) {
WorldConfig config = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + eworldname, "config.yml"));
config.removeInvitedPlayers(uuid.toString(), name.toLowerCase());
config.save();
// Kick Player
EditWorld eworld = EditWorld.get(eworldname);
if (eworld != null) {
DPlayer player = DPlayer.get(name);
if (player != null) {
if (eworld.world.getPlayers().contains(player.player)) {
player.leave();
}
}
}
return true;
}
return false;
}
public static boolean isInvitedPlayer(String eworldname, UUID uuid, String name) {
if (exist(eworldname)) {
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
if (config.getInvitedPlayers().contains(name.toLowerCase()) || config.getInvitedPlayers().contains(uuid.toString())) {
return true;
}
}
return false;
}
}

View File

@ -1,414 +1,419 @@
package com.dre.dungeonsxl;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
public class DConfig {
public static DConfig mainConfig = new DConfig();
private File file;
private boolean keepInventory = false;
private boolean keepInventoryOnEnter = false;
private boolean keepInventoryOnEscape = false;
private boolean keepInventoryOnFinish = false;
private boolean keepInventoryOnDeath = true;
private CopyOnWriteArrayList<DClass> dClasses = new CopyOnWriteArrayList<DClass>();
private Map<Integer, String> msgs = new HashMap<Integer, String>();
private CopyOnWriteArrayList<String> invitedPlayers = new CopyOnWriteArrayList<String>();
private CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<Material>();
private int initialLives = 3;
private boolean isLobbyDisabled = false;
private int timeToNextPlay = 0;
private int timeToNextLoot = 0;
private int timeUntilKickOfflinePlayer = -1;
private double fee = 0;
private List<String> finishedOne;
private List<String> finishedAll;
private int timeLastPlayed = 0;
// MobTypes
private Set<DMobType> mobTypes = new HashSet<DMobType>();
public DConfig() {
}
public DConfig(File file) {
this.file = file;
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
load(configFile);
}
public DConfig(ConfigurationSection configFile) {
load(configFile);
}
// Load & Save
public void load(ConfigurationSection configFile) {
/* Classes */
ConfigurationSection configSetionClasses = configFile.getConfigurationSection("classes");
if (configSetionClasses != null) {
Set<String> list = configSetionClasses.getKeys(false);
for (String className : list) {
String name = className;
boolean hasDog = configSetionClasses.getBoolean(className + ".dog");
/* Items */
List<String> items = configSetionClasses.getStringList(className + ".items");
CopyOnWriteArrayList<ItemStack> istacks = new CopyOnWriteArrayList<ItemStack>();
for (String item : items) {
String[] itemsplit = item.split(",");
if (itemsplit.length > 0) {
int itemId = 0, itemData = 0, itemSize = 1, itemLvlEnchantment = 1;
Enchantment itemEnchantment = null;
// Check Id & Data
String[] idAndData = itemsplit[0].split("/");
itemId = P.p.parseInt(idAndData[0]);
if (idAndData.length > 1) {
itemData = P.p.parseInt(idAndData[1]);
}
// Size
if (itemsplit.length > 1) {
itemSize = P.p.parseInt(itemsplit[1]);
}
// Enchantment
if (itemsplit.length > 2) {
String[] enchantmentSplit = itemsplit[2].split("/");
itemEnchantment = Enchantment.getByName(enchantmentSplit[0]);
if (enchantmentSplit.length > 1) {
itemLvlEnchantment = P.p.parseInt(enchantmentSplit[1]);
}
}
// Add Item to Stacks
ItemStack istack = new ItemStack(itemId, itemSize, (short) itemData);
if (itemEnchantment != null) {
istack.addEnchantment(itemEnchantment, itemLvlEnchantment);
}
istacks.add(istack);
}
}
/* Create Class */
this.dClasses.add(new DClass(name, istacks, hasDog));
}
}
/* Messages */
ConfigurationSection configSetionMessages = configFile.getConfigurationSection("message");
if (configSetionMessages != null) {
Set<String> list = configSetionMessages.getKeys(false);
for (String messagePath : list) {
int messageId = P.p.parseInt(messagePath);
this.msgs.put(messageId, configSetionMessages.getString(messagePath));
}
}
/* Secure Objects */
if (configFile.contains("secureObjects")) {
List<Integer> secureobjectlist = configFile.getIntegerList("secureObjects");
for (int i : secureobjectlist) {
this.secureObjects.add(Material.getMaterial(i));
}
}
/* Invited Players */
if (configFile.contains("invitedPlayers")) {
List<String> invitedplayers = configFile.getStringList("invitedPlayers");
for (String i : invitedplayers) {
this.invitedPlayers.add(i);
}
}
/* Keep Inventory */
if (configFile.contains("keepInventory")) {
if (!configFile.contains("keepInventoryOnEnter")) {
keepInventoryOnEnter = configFile.getBoolean("keepInventory");
}
if (!configFile.contains("keepInventoryOnEscape")) {
keepInventoryOnEscape = configFile.getBoolean("keepInventory");
}
if (!configFile.contains("keepInventoryOnFinish")) {
keepInventoryOnFinish = configFile.getBoolean("keepInventory");
}
} else {
if (mainConfig.keepInventory) {
keepInventoryOnEnter = mainConfig.keepInventory;
keepInventoryOnEscape = mainConfig.keepInventory;
keepInventoryOnFinish = mainConfig.keepInventory;
}
}
if (configFile.contains("keepInventoryOnEnter")) {
keepInventoryOnEnter = configFile.getBoolean("keepInventoryOnEnter");
} else {
keepInventoryOnEnter = mainConfig.keepInventoryOnEnter;
}
if (configFile.contains("keepInventoryOnEscape")) {
keepInventoryOnEscape = configFile.getBoolean("keepInventoryOnEscape");
} else {
keepInventoryOnEscape = mainConfig.keepInventoryOnEscape;
}
if (configFile.contains("keepInventoryOnFinish")) {
keepInventoryOnFinish = configFile.getBoolean("keepInventoryOnFinish");
} else {
keepInventoryOnFinish = mainConfig.keepInventoryOnFinish;
}
if (configFile.contains("keepInventoryOnDeath")) {
keepInventoryOnDeath = configFile.getBoolean("keepInventoryOnDeath");
} else {
keepInventoryOnDeath = mainConfig.keepInventoryOnDeath;
}
/* Lives */
if (configFile.contains("initialLives")) {
initialLives = configFile.getInt("initialLives");
} else {
initialLives = mainConfig.getInitialLives();
}
/* Lobby */
if (configFile.contains("isLobbyDisabled")) {
isLobbyDisabled = configFile.getBoolean("isLobbyDisabled");
} else {
isLobbyDisabled = mainConfig.isLobbyDisabled;
}
/* Times */
if (configFile.contains("timeToNextPlay")) {
timeToNextPlay = configFile.getInt("timeToNextPlay");
} else {
timeToNextPlay = mainConfig.timeToNextPlay;
}
if (configFile.contains("timeToNextLoot")) {
timeToNextLoot = configFile.getInt("timeToNextLoot");
} else {
timeToNextLoot = mainConfig.timeToNextLoot;
}
if (configFile.contains("timeUntilKickOfflinePlayer")) {
timeUntilKickOfflinePlayer = configFile.getInt("timeUntilKickOfflinePlayer");
} else {
timeUntilKickOfflinePlayer = mainConfig.timeUntilKickOfflinePlayer;
}
/* Dungeon Requirements */
if (configFile.contains("fee")) {
fee = configFile.getDouble("fee");
} else {
fee = mainConfig.fee;
}
if (configFile.contains("mustFinishOne")) {
finishedOne = configFile.getStringList("mustFinishOne");
} else {
finishedOne = new ArrayList<String>();
}
if (configFile.contains("mustFinishAll")) {
finishedAll = configFile.getStringList("mustFinishAll");
} else {
finishedAll = new ArrayList<String>();
}
if (configFile.contains("timeLastPlayed")) {
timeLastPlayed = configFile.getInt("timeLastPlayed");
}
/* Mobtypes */
configSetionMessages = configFile.getConfigurationSection("mobTypes");
this.mobTypes = DMobType.load(configSetionMessages);
}
public void save() {
if (this.file != null) {
FileConfiguration configFile = YamlConfiguration.loadConfiguration(this.file);
// Messages
for (Integer msgs : this.msgs.keySet()) {
configFile.set("message." + msgs, this.msgs.get(msgs));
}
// Secure Objects
CopyOnWriteArrayList<Integer> secureObjectsids = new CopyOnWriteArrayList<Integer>();
for (Material mat : this.secureObjects) {
secureObjectsids.add(mat.getId());
}
configFile.set("secureObjects", secureObjectsids);
// Invited Players
configFile.set("invitedPlayers", this.invitedPlayers);
try {
configFile.save(this.file);
} catch (IOException e) {
e.printStackTrace();
}
}
}
// Getters and Setters
public CopyOnWriteArrayList<DClass> getClasses() {
if (this.dClasses != null) {
if (!this.dClasses.isEmpty()) {
return this.dClasses;
}
}
return mainConfig.dClasses;
}
public DClass getClass(String name) {
for (DClass dClass : this.dClasses) {
if (dClass.name.equals(name)) {
return dClass;
}
}
for (DClass dClass : mainConfig.dClasses) {
if (dClass.name.equals(name)) {
return dClass;
}
}
return null;
}
public String getMsg(int id, boolean returnMainConfig) {
String msg = this.msgs.get(id);
if (msg != null) {
return this.msgs.get(id);
}
if (returnMainConfig) {
return mainConfig.msgs.get(id);
}
return null;
}
public void setMsg(String msg, int id) {
this.msgs.put(id, msg);
}
public CopyOnWriteArrayList<String> getInvitedPlayers() {
CopyOnWriteArrayList<String> tmpInvitedPlayers = new CopyOnWriteArrayList<String>();
tmpInvitedPlayers.addAll(this.invitedPlayers);
tmpInvitedPlayers.addAll(mainConfig.invitedPlayers);
return tmpInvitedPlayers;
}
public void addInvitedPlayer(String uuid) {
this.invitedPlayers.add(uuid);
}
public void removeInvitedPlayers(String uuid, String name) {
this.invitedPlayers.remove(uuid);
// remove player from a 0.9.1 and lower file
this.invitedPlayers.remove(name);
}
public CopyOnWriteArrayList<Material> getSecureObjects() {
CopyOnWriteArrayList<Material> tmpSecureObjects = new CopyOnWriteArrayList<Material>();
tmpSecureObjects.addAll(this.secureObjects);
tmpSecureObjects.addAll(mainConfig.secureObjects);
return tmpSecureObjects;
}
public boolean getKeepInventoryOnEnter() {
return keepInventoryOnEnter;
}
public boolean getKeepInventoryOnEscape() {
return keepInventoryOnEscape;
}
public boolean getKeepInventoryOnFinish() {
return keepInventoryOnFinish;
}
public boolean getKeepInventoryOnDeath() {
return keepInventoryOnDeath;
}
public int getInitialLives() {
return initialLives;
}
public boolean isLobbyDisabled() {
return isLobbyDisabled;
}
public int getTimeToNextPlay() {
return timeToNextPlay;
}
public int getTimeToNextLoot() {
return timeToNextLoot;
}
public int getTimeUntilKickOfflinePlayer() {
return timeUntilKickOfflinePlayer;
}
public int getTimeLastPlayed() {
return timeLastPlayed;
}
public double getFee() {
return fee;
}
public List<String> getFinishedAll() {
return finishedAll;
}
public List<String> getFinished() {
List<String> merge = new ArrayList<String>();
merge.addAll(finishedAll);
merge.addAll(finishedOne);
return merge;
}
public Set<DMobType> getMobTypes() {
return mobTypes;
}
}
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.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
public class WorldConfig {
static DungeonsXL plugin = DungeonsXL.getPlugin();
public static WorldConfig defaultConfig = new WorldConfig();
private File file;
private boolean keepInventory = false;
private boolean keepInventoryOnEnter = false;
private boolean keepInventoryOnEscape = false;
private boolean keepInventoryOnFinish = false;
private boolean keepInventoryOnDeath = true;
private CopyOnWriteArrayList<DClass> dClasses = new CopyOnWriteArrayList<DClass>();
private Map<Integer, String> msgs = new HashMap<Integer, String>();
private CopyOnWriteArrayList<String> invitedPlayers = new CopyOnWriteArrayList<String>();
private CopyOnWriteArrayList<Material> secureObjects = new CopyOnWriteArrayList<Material>();
private int initialLives = 3;
private boolean isLobbyDisabled = false;
private int timeToNextPlay = 0;
private int timeToNextLoot = 0;
private int timeUntilKickOfflinePlayer = -1;
private double fee = 0;
private List<String> finishedOne;
private List<String> finishedAll;
private int timeLastPlayed = 0;
// MobTypes
private Set<DMobType> mobTypes = new HashSet<DMobType>();
public WorldConfig() {
}
public WorldConfig(File file) {
this.file = file;
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
load(configFile);
}
public WorldConfig(ConfigurationSection configFile) {
load(configFile);
}
// Load & Save
@SuppressWarnings("deprecation")
public void load(ConfigurationSection configFile) {
/* Classes */
ConfigurationSection configSetionClasses = configFile.getConfigurationSection("classes");
if (configSetionClasses != null) {
Set<String> list = configSetionClasses.getKeys(false);
for (String className : list) {
String name = className;
boolean hasDog = configSetionClasses.getBoolean(className + ".dog");
/* Items */
List<String> items = configSetionClasses.getStringList(className + ".items");
CopyOnWriteArrayList<ItemStack> istacks = new CopyOnWriteArrayList<ItemStack>();
for (String item : items) {
String[] itemsplit = item.split(",");
if (itemsplit.length > 0) {
int itemId = 0, itemData = 0, itemSize = 1, itemLvlEnchantment = 1;
Enchantment itemEnchantment = null;
// Check Id & Data
String[] idAndData = itemsplit[0].split("/");
itemId = IntegerUtil.parseInt(idAndData[0]);
if (idAndData.length > 1) {
itemData = IntegerUtil.parseInt(idAndData[1]);
}
// Size
if (itemsplit.length > 1) {
itemSize = IntegerUtil.parseInt(itemsplit[1]);
}
// Enchantment
if (itemsplit.length > 2) {
String[] enchantmentSplit = itemsplit[2].split("/");
itemEnchantment = Enchantment.getByName(enchantmentSplit[0]);
if (enchantmentSplit.length > 1) {
itemLvlEnchantment = IntegerUtil.parseInt(enchantmentSplit[1]);
}
}
// Add Item to Stacks
ItemStack istack = new ItemStack(itemId, itemSize, (short) itemData);
if (itemEnchantment != null) {
istack.addEnchantment(itemEnchantment, itemLvlEnchantment);
}
istacks.add(istack);
}
}
/* Create Class */
dClasses.add(new DClass(name, istacks, hasDog));
}
}
/* Messages */
ConfigurationSection configSetionMessages = configFile.getConfigurationSection("message");
if (configSetionMessages != null) {
Set<String> list = configSetionMessages.getKeys(false);
for (String messagePath : list) {
int messageId = IntegerUtil.parseInt(messagePath);
msgs.put(messageId, configSetionMessages.getString(messagePath));
}
}
/* Secure Objects */
if (configFile.contains("secureObjects")) {
List<Integer> secureobjectlist = configFile.getIntegerList("secureObjects");
for (int i : secureobjectlist) {
secureObjects.add(Material.getMaterial(i));
}
}
/* Invited Players */
if (configFile.contains("invitedPlayers")) {
List<String> invitedplayers = configFile.getStringList("invitedPlayers");
for (String i : invitedplayers) {
invitedPlayers.add(i);
}
}
/* Keep Inventory */
if (configFile.contains("keepInventory")) {
if ( !configFile.contains("keepInventoryOnEnter")) {
keepInventoryOnEnter = configFile.getBoolean("keepInventory");
}
if ( !configFile.contains("keepInventoryOnEscape")) {
keepInventoryOnEscape = configFile.getBoolean("keepInventory");
}
if ( !configFile.contains("keepInventoryOnFinish")) {
keepInventoryOnFinish = configFile.getBoolean("keepInventory");
}
} else {
if (plugin.getDefaultConfig().keepInventory) {
keepInventoryOnEnter = plugin.getDefaultConfig().keepInventory;
keepInventoryOnEscape = plugin.getDefaultConfig().keepInventory;
keepInventoryOnFinish = plugin.getDefaultConfig().keepInventory;
}
}
if (configFile.contains("keepInventoryOnEnter")) {
keepInventoryOnEnter = configFile.getBoolean("keepInventoryOnEnter");
} else {
keepInventoryOnEnter = plugin.getDefaultConfig().keepInventoryOnEnter;
}
if (configFile.contains("keepInventoryOnEscape")) {
keepInventoryOnEscape = configFile.getBoolean("keepInventoryOnEscape");
} else {
keepInventoryOnEscape = plugin.getDefaultConfig().keepInventoryOnEscape;
}
if (configFile.contains("keepInventoryOnFinish")) {
keepInventoryOnFinish = configFile.getBoolean("keepInventoryOnFinish");
} else {
keepInventoryOnFinish = plugin.getDefaultConfig().keepInventoryOnFinish;
}
if (configFile.contains("keepInventoryOnDeath")) {
keepInventoryOnDeath = configFile.getBoolean("keepInventoryOnDeath");
} else {
keepInventoryOnDeath = plugin.getDefaultConfig().keepInventoryOnDeath;
}
/* Lives */
if (configFile.contains("initialLives")) {
initialLives = configFile.getInt("initialLives");
} else {
initialLives = plugin.getDefaultConfig().getInitialLives();
}
/* Lobby */
if (configFile.contains("isLobbyDisabled")) {
isLobbyDisabled = configFile.getBoolean("isLobbyDisabled");
} else {
isLobbyDisabled = plugin.getDefaultConfig().isLobbyDisabled;
}
/* Times */
if (configFile.contains("timeToNextPlay")) {
timeToNextPlay = configFile.getInt("timeToNextPlay");
} else {
timeToNextPlay = plugin.getDefaultConfig().timeToNextPlay;
}
if (configFile.contains("timeToNextLoot")) {
timeToNextLoot = configFile.getInt("timeToNextLoot");
} else {
timeToNextLoot = plugin.getDefaultConfig().timeToNextLoot;
}
if (configFile.contains("timeUntilKickOfflinePlayer")) {
timeUntilKickOfflinePlayer = configFile.getInt("timeUntilKickOfflinePlayer");
} else {
timeUntilKickOfflinePlayer = plugin.getDefaultConfig().timeUntilKickOfflinePlayer;
}
/* Dungeon Requirements */
if (configFile.contains("fee")) {
fee = configFile.getDouble("fee");
} else {
fee = plugin.getDefaultConfig().fee;
}
if (configFile.contains("mustFinishOne")) {
finishedOne = configFile.getStringList("mustFinishOne");
} else {
finishedOne = new ArrayList<String>();
}
if (configFile.contains("mustFinishAll")) {
finishedAll = configFile.getStringList("mustFinishAll");
} else {
finishedAll = new ArrayList<String>();
}
if (configFile.contains("timeLastPlayed")) {
timeLastPlayed = configFile.getInt("timeLastPlayed");
}
/* Mobtypes */
configSetionMessages = configFile.getConfigurationSection("mobTypes");
mobTypes = DMobType.load(configSetionMessages);
}
@SuppressWarnings("deprecation")
public void save() {
if (file != null) {
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
// Messages
for (Integer msgs : this.msgs.keySet()) {
configFile.set("message." + msgs, this.msgs.get(msgs));
}
// Secure Objects
CopyOnWriteArrayList<Integer> secureObjectsids = new CopyOnWriteArrayList<Integer>();
for (Material mat : secureObjects) {
secureObjectsids.add(mat.getId());
}
configFile.set("secureObjects", secureObjectsids);
// Invited Players
configFile.set("invitedPlayers", invitedPlayers);
try {
configFile.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
}
// Getters and Setters
public CopyOnWriteArrayList<DClass> getClasses() {
if (dClasses != null) {
if ( !dClasses.isEmpty()) {
return dClasses;
}
}
return plugin.getDefaultConfig().dClasses;
}
public DClass getClass(String name) {
for (DClass dClass : dClasses) {
if (dClass.getName().equals(name)) {
return dClass;
}
}
for (DClass dClass : plugin.getDefaultConfig().dClasses) {
if (dClass.getName().equals(name)) {
return dClass;
}
}
return null;
}
public String getMsg(int id, boolean returnMainConfig) {
String msg = msgs.get(id);
if (msg != null) {
return msgs.get(id);
}
if (returnMainConfig) {
return plugin.getDefaultConfig().msgs.get(id);
}
return null;
}
public void setMsg(String msg, int id) {
msgs.put(id, msg);
}
public CopyOnWriteArrayList<String> getInvitedPlayers() {
CopyOnWriteArrayList<String> tmpInvitedPlayers = new CopyOnWriteArrayList<String>();
tmpInvitedPlayers.addAll(invitedPlayers);
tmpInvitedPlayers.addAll(plugin.getDefaultConfig().invitedPlayers);
return tmpInvitedPlayers;
}
public void addInvitedPlayer(String uuid) {
invitedPlayers.add(uuid);
}
public void removeInvitedPlayers(String uuid, String name) {
invitedPlayers.remove(uuid);
// remove player from a 0.9.1 and lower file
invitedPlayers.remove(name);
}
public CopyOnWriteArrayList<Material> getSecureObjects() {
CopyOnWriteArrayList<Material> tmpSecureObjects = new CopyOnWriteArrayList<Material>();
tmpSecureObjects.addAll(secureObjects);
tmpSecureObjects.addAll(plugin.getDefaultConfig().secureObjects);
return tmpSecureObjects;
}
public boolean getKeepInventoryOnEnter() {
return keepInventoryOnEnter;
}
public boolean getKeepInventoryOnEscape() {
return keepInventoryOnEscape;
}
public boolean getKeepInventoryOnFinish() {
return keepInventoryOnFinish;
}
public boolean getKeepInventoryOnDeath() {
return keepInventoryOnDeath;
}
public int getInitialLives() {
return initialLives;
}
public boolean isLobbyDisabled() {
return isLobbyDisabled;
}
public int getTimeToNextPlay() {
return timeToNextPlay;
}
public int getTimeToNextLoot() {
return timeToNextLoot;
}
public int getTimeUntilKickOfflinePlayer() {
return timeUntilKickOfflinePlayer;
}
public int getTimeLastPlayed() {
return timeLastPlayed;
}
public double getFee() {
return fee;
}
public List<String> getFinishedAll() {
return finishedAll;
}
public List<String> getFinished() {
List<String> merge = new ArrayList<String>();
merge.addAll(finishedAll);
merge.addAll(finishedOne);
return merge;
}
public Set<DMobType> getMobTypes() {
return mobTypes;
}
}

View File

@ -1,100 +1,107 @@
package com.dre.dungeonsxl.game;
import net.milkbowl.vault.item.Items;
import net.milkbowl.vault.item.ItemInfo;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import com.dre.dungeonsxl.DGroup;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.P;
public class GameChest {
// Variables
public boolean isUsed = false;
public Chest chest;
public GameWorld gworld;
public double moneyReward;
public GameChest(Block chest, GameWorld gworld, double moneyReward) {
if (chest.getState() instanceof Chest) {
this.chest = (Chest) chest.getState();
this.gworld = gworld;
this.moneyReward = moneyReward;
gworld.gchests.add(this);
}
}
public void addTreasure(DGroup dgroup) {
if (dgroup != null) {
for (Player player : dgroup.getPlayers()) {
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
dplayer.treasureMoney = dplayer.treasureMoney + moneyReward;
String msg = "";
for (ItemStack istack : this.chest.getInventory().getContents()) {
if (istack != null) {
dplayer.treasureInv.addItem(istack);
String name;
if (istack.hasItemMeta() && istack.getItemMeta().hasDisplayName()) {
name = istack.getItemMeta().getDisplayName();
} else {
ItemInfo itemInfo = Items.itemByStack(istack);
if (itemInfo != null) {
name = itemInfo.getName();
} else {
name = istack.getType().name();
}
}
msg = msg + ChatColor.RED + " " + istack.getAmount() + " " + name + ChatColor.GOLD + ",";
}
}
msg = msg.substring(0, msg.length() - 1);
P.p.msg(player, P.p.language.get("Player_LootAdded", msg));
if (moneyReward != 0) {
P.p.msg(player, P.p.language.get("Player_LootAdded", String.valueOf(moneyReward)));
}
}
}
}
}
// Statics
public static void onOpenInventory(InventoryOpenEvent event) {
InventoryView inventory = event.getView();
GameWorld gworld = GameWorld.get(event.getPlayer().getWorld());
if (gworld != null) {
if (inventory.getTopInventory().getHolder() instanceof Chest) {
Chest chest = (Chest) inventory.getTopInventory().getHolder();
for (GameChest gchest : gworld.gchests) {
if (gchest.chest.equals(chest)) {
if (!gchest.isUsed) {
if (gchest.chest.getLocation().distance(chest.getLocation()) < 1) {
gchest.addTreasure(DGroup.get(gworld));
gchest.isUsed = true;
event.setCancelled(true);
}
} else {
P.p.msg(P.p.getServer().getPlayer(event.getPlayer().getUniqueId()), ChatColor.RED + "Diese Kiste wurde schon geöffnet!");
event.setCancelled(true);
}
}
}
}
}
}
}
package io.github.dre2n.dungeonsxl.dungeon.game;
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.Items;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
public class GameChest {
// Variables
public boolean isUsed = false;
public Chest chest;
public GameWorld gWorld;
public double moneyReward;
public GameChest(Block chest, GameWorld gWorld, double moneyReward) {
if (chest.getState() instanceof Chest) {
this.chest = (Chest) chest.getState();
this.gWorld = gWorld;
this.moneyReward = moneyReward;
gWorld.gameChests.add(this);
}
}
public void addTreasure(DGroup dgroup) {
if (dgroup != null) {
for (Player player : dgroup.getPlayers()) {
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
dplayer.treasureMoney = dplayer.treasureMoney + moneyReward;
String msg = "";
for (ItemStack istack : chest.getInventory().getContents()) {
if (istack != null) {
dplayer.treasureInv.addItem(istack);
String name;
if (istack.hasItemMeta() && istack.getItemMeta().hasDisplayName()) {
name = istack.getItemMeta().getDisplayName();
} else {
ItemInfo itemInfo = Items.itemByStack(istack);
if (itemInfo != null) {
name = itemInfo.getName();
} else {
name = istack.getType().name();
}
}
msg = msg + ChatColor.RED + " " + istack.getAmount() + " " + name + ChatColor.GOLD + ",";
}
}
msg = msg.substring(0, msg.length() - 1);
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Player_LootAdded", msg));
if (moneyReward != 0) {
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Player_LootAdded", String.valueOf(moneyReward)));
}
}
}
}
}
// Statics
public static void onOpenInventory(InventoryOpenEvent event) {
InventoryView inventory = event.getView();
GameWorld gWorld = GameWorld.get(event.getPlayer().getWorld());
if (gWorld != null) {
if (inventory.getTopInventory().getHolder() instanceof Chest) {
Chest chest = (Chest) inventory.getTopInventory().getHolder();
for (GameChest gchest : gWorld.gameChests) {
if (gchest.chest.equals(chest)) {
if ( !gchest.isUsed) {
if (gchest.chest.getLocation().distance(chest.getLocation()) < 1) {
gchest.addTreasure(DGroup.get(gWorld));
gchest.isUsed = true;
event.setCancelled(true);
}
} else {
MessageUtil.sendMessage(DungeonsXL.getPlugin().getServer().getPlayer(event.getPlayer().getUniqueId()), DungeonsXL.getPlugin().getDMessages().get("Error_ChestIsOpened"));
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,185 +1,195 @@
package com.dre.dungeonsxl;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
public class LanguageReader {
private Map<String, String> entries = new TreeMap<String, String>();
private Map<String, String> defaults = new TreeMap<String, String>();
private File file;
private boolean changed;
public LanguageReader(File file) {
this.setDefaults();
/* Load */
this.file = file;
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
Set<String> keySet = configFile.getKeys(false);
for (String key : keySet) {
entries.put(key, configFile.getString(key));
}
/* Check */
this.check();
}
private void setDefaults() {
/* Log */
defaults.put("Log_NewDungeon", "&6New Dungeon");
defaults.put("Log_GenerateNewWorld", "&6Generate new world...");
defaults.put("Log_WorldGenerationFinished", "&6World generation finished!");
defaults.put("Log_Error_MobEnchantment", "&4Error at loading mob.yml: Enchantment &6&v1&4 doesn't exist!");
defaults.put("Log_Error_MobType", "&4Error at loading mob.yml: Mob &6&v1&4 doesn't exist!");
defaults.put("Log_Error_NoConsoleCommand", "&6/dxl &v1&4 can not be executed as Console!");
/* Player */
defaults.put("Player_CheckpointReached", "&6Checkpoint reached!");
defaults.put("Player_LootAdded", "&4&v1&6 have been added to your reward inventory!");
defaults.put("Player_Ready", "&6You are now ready for the Dungeon!");
defaults.put("Player_FinishedDungeon", "&6You successfully finished the Dungeon!");
defaults.put("Player_WaitForOtherPlayers", "&6Waiting for teammates...");
defaults.put("Player_LeaveGroup", "&6You have successfully left your group!");
defaults.put("Player_Offline", "&Player &4&v1&6 went offline. In &4&v2&6 seconds he will autmatically be kicked from the Dungeon!");
defaults.put("Player_OfflineNever", "&Player &4&v1&6 went offline. He will &4not&6 be kicked from the Dungeon automatically!");
defaults.put("Player_LeftGroup", "&Player &4&v1&6 has left the Group!");
defaults.put("Player_JoinGroup", "&Player &4&v1&6 has joined the Group!");
defaults.put("Player_PortalAbort", "&6Portal creation cancelled!");
defaults.put("Player_PortalIntroduction", "&6Click the two edges of the Portal with the wooden sword!");
defaults.put("Player_PortalDeleted", "&6Portal deleted!");
defaults.put("Player_PortalProgress", "&6First Block, now the second one!");
defaults.put("Player_PortalCreated", "&6Portal created!");
defaults.put("Player_SignCreated", "&6Sign created!");
defaults.put("Player_SignCopied", "&6Copied!");
defaults.put("Player_BlockInfo", "&6Block-ID: &2&v1");
defaults.put("Player_Death", "&6You died, lives left: &2v1");
defaults.put("Player_DeathKick", "&2v1&6 died and lost his last life.");
/* Cmds */
defaults.put("Cmd_Chat_DungeonChat", "&6You have entered the Dungeon-chat");
defaults.put("Cmd_Chat_NormalChat", "&6You are now in the public chat");
defaults.put("Cmd_Chatspy_Stopped", "&6You stopped 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_Leave_Success", "&6You have successfully left your group!");
defaults.put("Cmd_Msg_Added", "&6New Message (&4&v1&6) added!");
defaults.put("Cmd_Msg_Updated", "&6Message (&4&v1&6) updated!");
defaults.put("Cmd_Reload_Start", "&6Reloading DungeonsXL...");
defaults.put("Cmd_Reload_Done", "&6DungeonsXL was successfully reloaded!");
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_Lives", "&4v1&6 has &4v2 &6lives left.");
/* Errors */
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_Dispenser", "&4You cannot access this dispenser!");
defaults.put("Error_Ready", "&4Choose your class first!");
defaults.put("Error_Cooldown", "&4You can only enter this Dungeon every &6&v1&4 hours!");
defaults.put("Error_Requirements", "&4You don't fulfill the requirements for this Dungeon!");
defaults.put("Error_Leftklick", "&4You have to use Left-Click on this sign!");
defaults.put("Error_Drop", "&4You cannot drop safe items");
defaults.put("Error_Cmd", "&4Commands are not allowed while in a dungeon!");
defaults.put("Error_NotInGroup", "&4You have to join a group first!");
defaults.put("Error_NoPermissions", "&4You have no permission to do this!");
defaults.put("Error_CmdNotExist1", "&4Command &6&v1&4 does not exist!");
defaults.put("Error_CmdNotExist2", "&4Pleaser enter &6/dxl help&4 for help!");
defaults.put("Error_NotInDungeon", "&4You are not in a dungeon!");
defaults.put("Error_DungeonNotExist", "&4Dungeon &6&v1&4 does not exist!");
defaults.put("Error_LeaveDungeon", "&4You have to leave your current dungeon first!");
defaults.put("Error_NameToLong", "&4The name may not be longer than 15 characters!");
defaults.put("Error_LeaveGroup", "&4You have to leave your group first!");
defaults.put("Error_NoLeaveInTutorial", "&4You cannot use this command in the tutorial!");
defaults.put("Error_MsgIdNotExist", "&4Message with Id &6&v1&4 does not exist!");
defaults.put("Error_MsgFormat", "&4The Message has to be between \"!");
defaults.put("Error_MsgNoInt", "&4Argument <id> has to include a number!");
defaults.put("Error_TutorialNotExist", "&4Tutorial dungeon does not exist!");
defaults.put("Error_NoPortal", "&4You have to look at a portal!");
defaults.put("Error_NoPlayerCommand", "&6/dxl &v1&4 can not be executed as player!");
defaults.put("Error_SignWrongFormat", "&4The sign is not written correctly!");
/* Help */
defaults.put("Help_Cmd_Chat", "/dxl chat - Change the Chat-Mode");
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_Edit", "/dxl edit <name> - Edit an existing dungeon");
defaults.put("Help_Cmd_Help", "/dxl help - Shows the help page");
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_Escape", "/dxl escape - Leaves the current dungeon, without saving!");
defaults.put("Help_Cmd_List", "/dxl list - Lists all dungeons");
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_DeletePortal", "/dxl deleteportal - Deletes the portal you are looking at");
defaults.put("Help_Cmd_Reload", "/dxl reload - Reloads the plugin");
defaults.put("Help_Cmd_Save", "/dxl save - Saves the current dungeon");
defaults.put("Help_Cmd_Play", "/dxl play [dungeon]");
defaults.put("Help_Cmd_Test", "/dxl test [dungeon] - Tests a dungeon");
defaults.put("Help_Cmd_Lives", "/dxl lives <player> - Shows the lives a player has left");
defaults.put("Help_Cmd_Uninvite", "/dxl uninvite <player> <dungeon> - Uninvite a player to edit a dungeon");
}
private void check() {
for (String defaultEntry : defaults.keySet()) {
if (!entries.containsKey(defaultEntry)) {
entries.put(defaultEntry, defaults.get(defaultEntry));
changed = true;
}
}
}
public void save() {
if (changed) {
/* Copy old File */
File source = new File(file.getPath());
String filePath = file.getPath();
File temp = new File(filePath.substring(0, filePath.length() - 4) + "_old.yml");
if (temp.exists())
temp.delete();
source.renameTo(temp);
/* Save */
FileConfiguration configFile = new YamlConfiguration();
for (String key : entries.keySet()) {
configFile.set(key, entries.get(key));
}
try {
configFile.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public String get(String key, String... args) {
String entry = entries.get(key);
if (entry != null) {
int i = 0;
for (String arg : args) {
i++;
if(arg != null){
entry = entry.replace("&v" + i, arg);
} else {
entry = entry.replace("&v" + i, "null");
}
}
}
return entry;
}
}
package io.github.dre2n.dungeonsxl.file;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
public class DMessages {
private Map<String, String> entries = new TreeMap<String, String>();
private Map<String, String> defaults = new TreeMap<String, String>();
private File file;
private boolean changed;
public DMessages(File file) {
setDefaults();
/* Load */
this.file = file;
FileConfiguration configFile = YamlConfiguration.loadConfiguration(file);
Set<String> keySet = configFile.getKeys(false);
for (String key : keySet) {
entries.put(key, configFile.getString(key));
}
/* Check */
check();
}
private void setDefaults() {
/* Log */
defaults.put("Log_NewDungeon", "&6New Dungeon");
defaults.put("Log_GenerateNewWorld", "&6Generate new world...");
defaults.put("Log_WorldGenerationFinished", "&6World generation finished!");
defaults.put("Log_Error_MobEnchantment", "&4Error at loading mob.yml: Enchantment &6&v1&4 doesn't exist!");
defaults.put("Log_Error_MobType", "&4Error at loading mob.yml: Mob &6&v1&4 doesn't exist!");
defaults.put("Log_Error_NoConsoleCommand", "&6/dxl &v1&4 can not be executed as Console!");
/* Player */
defaults.put("Player_CheckpointReached", "&6Checkpoint reached!");
defaults.put("Player_LootAdded", "&4&v1&6 have been added to your reward inventory!");
defaults.put("Player_Ready", "&6You are now ready for the Dungeon!");
defaults.put("Player_FinishedDungeon", "&6You successfully finished the Dungeon!");
defaults.put("Player_WaitForOtherPlayers", "&6Waiting for teammates...");
defaults.put("Player_LeaveGroup", "&6You have successfully left your group!");
defaults.put("Player_Offline", "&Player &4&v1&6 went offline. In &4&v2&6 seconds he will autmatically be kicked from the Dungeon!");
defaults.put("Player_OfflineNever", "&Player &4&v1&6 went offline. He will &4not&6 be kicked from the Dungeon automatically!");
defaults.put("Player_LeftGroup", "&Player &4&v1&6 has left the Group!");
defaults.put("Player_JoinGroup", "&Player &4&v1&6 has joined the Group!");
defaults.put("Player_PortalAbort", "&6Portal creation cancelled!");
defaults.put("Player_PortalIntroduction", "&6Click the two edges of the Portal with the wooden sword!");
defaults.put("Player_PortalDeleted", "&6Portal deleted!");
defaults.put("Player_PortalProgress", "&6First Block, now the second one!");
defaults.put("Player_PortalCreated", "&6Portal created!");
defaults.put("Player_SignCreated", "&6Sign created!");
defaults.put("Player_SignCopied", "&6Copied!");
defaults.put("Player_BlockInfo", "&6Block-ID: &2&v1");
defaults.put("Player_Death", "&6You died, lives left: &2v1");
defaults.put("Player_DeathKick", "&2v1&6 died and lost his last life.");
defaults.put("Player_Treasures", "&1Treasures");
/* Cmds */
defaults.put("Cmd_Chat_DungeonChat", "&6You have entered the Dungeon-chat");
defaults.put("Cmd_Chat_NormalChat", "&6You are now in the public chat");
defaults.put("Cmd_Chatspy_Stopped", "&6You stopped 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_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_Updated", "&6Message (&4&v1&6) updated!");
defaults.put("Cmd_Reload_Done", "&7Successfully reloaded DungeonsXL.");
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_Lives", "&4v1&6 has &4v2 &6lives left.");
/* 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_Bed", "&4You cannot use a bed while in a Dungeon!");
defaults.put("Error_Dispenser", "&4You cannot access this dispenser!");
defaults.put("Error_Ready", "&4Choose your class first!");
defaults.put("Error_Cooldown", "&4You can only enter this Dungeon every &6&v1&4 hours!");
defaults.put("Error_Requirements", "&4You don't fulfill the requirements for this Dungeon!");
defaults.put("Error_Leftklick", "&4You have to use Left-Click on this sign!");
defaults.put("Error_Drop", "&4You cannot drop safe items");
defaults.put("Error_Cmd", "&4Commands are not allowed while in a dungeon!");
defaults.put("Error_NotInGroup", "&4You have to join a group first!");
defaults.put("Error_NoPermissions", "&4You have no permission to do this!");
defaults.put("Error_CmdNotExist1", "&4Command &6&v1&4 does not exist!");
defaults.put("Error_CmdNotExist2", "&4Pleaser enter &6/dxl help&4 for help!");
defaults.put("Error_NotInDungeon", "&4You are not in a dungeon!");
defaults.put("Error_DungeonNotExist", "&4Dungeon &6&v1&4 does not exist!");
defaults.put("Error_LeaveDungeon", "&4You have to leave your current dungeon first!");
defaults.put("Error_NameToLong", "&4The name may not be longer than 15 characters!");
defaults.put("Error_LeaveGroup", "&4You have to leave your group first!");
defaults.put("Error_NoLeaveInTutorial", "&4You cannot use this command in the tutorial!");
defaults.put("Error_MsgIdNotExist", "&4Message with Id &6&v1&4 does not exist!");
defaults.put("Error_MsgFormat", "&4The Message has to be between \"!");
defaults.put("Error_MsgNoInt", "&4Argument <id> has to include a number!");
defaults.put("Error_TutorialNotExist", "&4Tutorial dungeon does not exist!");
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 console!");
defaults.put("Error_SignWrongFormat", "&4The sign is not written correctly!");
/* Help */
defaults.put("Help_Cmd_Chat", "/dxl chat - Change the Chat-Mode");
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_Edit", "/dxl edit <name> - Edit an existing dungeon");
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_Leave", "/dxl leave - Leaves the current dungeon");
defaults.put("Help_Cmd_Escape", "/dxl escape - Leaves the current dungeon, without saving!");
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_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_Reload", "/dxl reload - Reloads the plugin");
defaults.put("Help_Cmd_Save", "/dxl save - Saves the current dungeon");
defaults.put("Help_Cmd_Play", "/dxl play [dungeon]");
defaults.put("Help_Cmd_Test", "/dxl test [dungeon] - Tests a dungeon");
defaults.put("Help_Cmd_Lives", "/dxl lives <player> - Shows the lives a player has left");
defaults.put("Help_Cmd_Uninvite", "/dxl uninvite <player> <dungeon> - Uninvite a player to edit a dungeon");
}
private void check() {
for (String defaultEntry : defaults.keySet()) {
if ( !entries.containsKey(defaultEntry)) {
entries.put(defaultEntry, defaults.get(defaultEntry));
changed = true;
}
}
}
public void save() {
if (changed) {
/* Copy old File */
File source = new File(file.getPath());
String filePath = file.getPath();
File temp = new File(filePath.substring(0, filePath.length() - 4) + "_old.yml");
if (temp.exists()) {
temp.delete();
}
source.renameTo(temp);
/* Save */
FileConfiguration configFile = new YamlConfiguration();
for (String key : entries.keySet()) {
configFile.set(key, entries.get(key));
}
try {
configFile.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public String get(String key, String... args) {
String entry = entries.get(key);
if (entry != null) {
int i = 0;
for (String arg : args) {
i++;
if (arg != null) {
entry = entry.replace("&v" + i, arg);
} else {
entry = entry.replace("&v" + i, "null");
}
}
}
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,241 +1,325 @@
package com.dre.dungeonsxl;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Material;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.game.GameWorld;
public class DPortal {
public static P p = P.p;
public static CopyOnWriteArrayList<DPortal> portals = new CopyOnWriteArrayList<DPortal>();
public World world;
public Block block1, block2;
public boolean isActive;
public Player player;
public DPortal(boolean active) {
portals.add(this);
this.isActive = active;
}
public void create() {
this.player = null;
if (this.block1 != null && this.block2 != null) {
int x1 = block1.getX(), y1 = block1.getY(), z1 = block1.getZ();
int x2 = block2.getX(), y2 = block2.getY(), z2 = block2.getZ();
int xcount = 0, ycount = 0, zcount = 0;
if (x1 > x2) {
xcount = -1;
} else if (x1 < x2) {
xcount = 1;
}
if (y1 > y2) {
ycount = -1;
} else if (y1 < y2) {
ycount = 1;
}
if (z1 > z2) {
zcount = -1;
} else if (z1 < z2) {
zcount = 1;
}
int xx = x1;
do {
int yy = y1;
do {
int zz = z1;
do {
Material type = this.world.getBlockAt(xx, yy, zz).getType();
if (type == Material.AIR || type == Material.WATER || type == Material.STATIONARY_WATER || type == Material.LAVA || type == Material.STATIONARY_LAVA || type == Material.SAPLING
|| type == Material.WEB || type == Material.LONG_GRASS || type == Material.DEAD_BUSH || type == Material.PISTON_EXTENSION || type == Material.YELLOW_FLOWER
|| type == Material.RED_ROSE || type == Material.BROWN_MUSHROOM || type == Material.RED_MUSHROOM || type == Material.TORCH || type == Material.FIRE
|| type == Material.CROPS || type == Material.REDSTONE_WIRE || type == Material.REDSTONE_TORCH_OFF || type == Material.SNOW || type == Material.REDSTONE_TORCH_ON) {
this.world.getBlockAt(xx, yy, zz).setType(Material.PORTAL);
}
zz = zz + zcount;
} while (zz != z2 + zcount);
yy = yy + ycount;
} while (yy != y2 + ycount);
xx = xx + xcount;
} while (xx != x2 + xcount);
} else {
portals.remove(this);
}
}
public void teleport(Player player) {
DGroup dgroup = DGroup.get(player);
if (dgroup != null) {
if (dgroup.getGworld() == null) {
dgroup.setGworld(GameWorld.load(DGroup.get(player).getDungeonname()));
}
if (dgroup.getGworld() != null) {
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_DungeonNotExist", DGroup.get(player).getDungeonname()));
}
} else {
p.msg(player, p.language.get("Error_NotInGroup"));
}
}
public void delete() {
portals.remove(this);
int x1 = block1.getX(), y1 = block1.getY(), z1 = block1.getZ();
int x2 = block2.getX(), y2 = block2.getY(), z2 = block2.getZ();
int xcount = 0, ycount = 0, zcount = 0;
if (x1 > x2) {
xcount = -1;
} else if (x1 < x2) {
xcount = 1;
}
if (y1 > y2) {
ycount = -1;
} else if (y1 < y2) {
ycount = 1;
}
if (z1 > z2) {
zcount = -1;
} else if (z1 < z2) {
zcount = 1;
}
int xx = x1;
do {
int yy = y1;
do {
int zz = z1;
do {
Material type = this.world.getBlockAt(xx, yy, zz).getType();
if (type == Material.PORTAL) {
this.world.getBlockAt(xx, yy, zz).setType(Material.AIR);
}
zz = zz + zcount;
} while (zz != z2 + zcount);
yy = yy + ycount;
} while (yy != y2 + ycount);
xx = xx + xcount;
} while (xx != x2 + xcount);
}
// Statics
public static DPortal get(Location location) {
return get(location.getBlock());
}
public static DPortal get(Block block) {
for (DPortal portal : portals) {
int x1 = portal.block1.getX(), y1 = portal.block1.getY(), z1 = portal.block1.getZ();
int x2 = portal.block2.getX(), y2 = portal.block2.getY(), z2 = portal.block2.getZ();
int x3 = block.getX(), y3 = block.getY(), z3 = block.getZ();
if (x1 > x2) {
if (x3 < x2 || x3 > x1)
continue;
} else {
if (x3 > x2 || x3 < x1)
continue;
}
if (y1 > y2) {
if (y3 < y2 || y3 > y1)
continue;
} else {
if (y3 > y2 || y3 < y1)
continue;
}
if (z1 > z2) {
if (z3 < z2 || z3 > z1)
continue;
} else {
if (z3 > z2 || z3 < z1)
continue;
}
return portal;
}
return null;
}
public static DPortal get(Player player) {
for (DPortal portal : portals) {
if (portal.player == player) {
return portal;
}
}
return null;
}
// Save and Load
public static void save(FileConfiguration configFile) {
int id = 0;
for (DPortal dportal : portals) {
id++;
if (dportal.isActive) {
String preString = "portal." + dportal.world.getName() + "." + id;
// Location1
configFile.set(preString + ".loc1.x", dportal.block1.getX());
configFile.set(preString + ".loc1.y", dportal.block1.getY());
configFile.set(preString + ".loc1.z", dportal.block1.getZ());
// Location1
configFile.set(preString + ".loc2.x", dportal.block2.getX());
configFile.set(preString + ".loc2.y", dportal.block2.getY());
configFile.set(preString + ".loc2.z", dportal.block2.getZ());
}
}
}
public static void load(FileConfiguration configFile) {
for (World world : p.getServer().getWorlds()) {
if (configFile.contains("portal." + world.getName())) {
int id = 0;
String preString;
do {
id++;
preString = "portal." + world.getName() + "." + id + ".";
if (configFile.contains(preString)) {
DPortal dportal = new DPortal(true);
dportal.world = world;
dportal.block1 = world.getBlockAt(configFile.getInt(preString + "loc1.x"), configFile.getInt(preString + "loc1.y"), configFile.getInt(preString + "loc1.z"));
dportal.block2 = world.getBlockAt(configFile.getInt(preString + "loc2.x"), configFile.getInt(preString + "loc2.y"), configFile.getInt(preString + "loc2.z"));
dportal.create();
}
} while (configFile.contains(preString));
}
}
}
}
package io.github.dre2n.dungeonsxl.global;
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.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
public class DPortal {
static DungeonsXL plugin = DungeonsXL.getPlugin();
private World world;
private Block block1;
private Block block2;
private boolean isActive;
private Player player;
public DPortal(boolean active) {
plugin.getDPortals().add(this);
isActive = active;
}
public void create() {
player = null;
if (block1 != null && block2 != null) {
int x1 = block1.getX(), y1 = block1.getY(), z1 = block1.getZ();
int x2 = block2.getX(), y2 = block2.getY(), z2 = block2.getZ();
int xcount = 0, ycount = 0, zcount = 0;
if (x1 > x2) {
xcount = -1;
} else if (x1 < x2) {
xcount = 1;
}
if (y1 > y2) {
ycount = -1;
} else if (y1 < y2) {
ycount = 1;
}
if (z1 > z2) {
zcount = -1;
} else if (z1 < z2) {
zcount = 1;
}
int xx = x1;
do {
int yy = y1;
do {
int zz = z1;
do {
Material type = world.getBlockAt(xx, yy, zz).getType();
if (type == Material.AIR || type == Material.WATER || type == Material.STATIONARY_WATER || type == Material.LAVA || type == Material.STATIONARY_LAVA
|| type == Material.SAPLING || type == Material.WEB || type == Material.LONG_GRASS || type == Material.DEAD_BUSH || type == Material.PISTON_EXTENSION
|| type == Material.YELLOW_FLOWER || type == Material.RED_ROSE || type == Material.BROWN_MUSHROOM || type == Material.RED_MUSHROOM || type == Material.TORCH
|| type == Material.FIRE || type == Material.CROPS || type == Material.REDSTONE_WIRE || type == Material.REDSTONE_TORCH_OFF || type == Material.SNOW
|| type == Material.REDSTONE_TORCH_ON) {
world.getBlockAt(xx, yy, zz).setType(Material.PORTAL);
}
zz = zz + zcount;
} while (zz != z2 + zcount);
yy = yy + ycount;
} while (yy != y2 + ycount);
xx = xx + xcount;
} while (xx != x2 + xcount);
} else {
plugin.getDPortals().remove(this);
}
}
public void teleport(Player player) {
DGroup dgroup = DGroup.get(player);
if (dgroup != null) {
if (dgroup.getGworld() == null) {
dgroup.setGworld(GameWorld.load(DGroup.get(player).getDungeonname()));
}
if (dgroup.getGworld() != null) {
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 {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_DungeonNotExist", DGroup.get(player).getDungeonname()));
}
} else {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_NotInGroup"));
}
}
public void delete() {
plugin.getDPortals().remove(this);
int x1 = block1.getX(), y1 = block1.getY(), z1 = block1.getZ();
int x2 = block2.getX(), y2 = block2.getY(), z2 = block2.getZ();
int xcount = 0, ycount = 0, zcount = 0;
if (x1 > x2) {
xcount = -1;
} else if (x1 < x2) {
xcount = 1;
}
if (y1 > y2) {
ycount = -1;
} else if (y1 < y2) {
ycount = 1;
}
if (z1 > z2) {
zcount = -1;
} else if (z1 < z2) {
zcount = 1;
}
int xx = x1;
do {
int yy = y1;
do {
int zz = z1;
do {
Material type = world.getBlockAt(xx, yy, zz).getType();
if (type == Material.PORTAL) {
world.getBlockAt(xx, yy, zz).setType(Material.AIR);
}
zz = zz + zcount;
} while (zz != z2 + zcount);
yy = yy + ycount;
} while (yy != y2 + ycount);
xx = xx + xcount;
} while (xx != x2 + xcount);
}
// Statics
public static DPortal get(Location location) {
return get(location.getBlock());
}
public static DPortal get(Block block) {
for (DPortal portal : plugin.getDPortals()) {
int x1 = portal.block1.getX(), y1 = portal.block1.getY(), z1 = portal.block1.getZ();
int x2 = portal.block2.getX(), y2 = portal.block2.getY(), z2 = portal.block2.getZ();
int x3 = block.getX(), y3 = block.getY(), z3 = block.getZ();
if (x1 > x2) {
if (x3 < x2 || x3 > x1) {
continue;
}
} else {
if (x3 > x2 || x3 < x1) {
continue;
}
}
if (y1 > y2) {
if (y3 < y2 || y3 > y1) {
continue;
}
} else {
if (y3 > y2 || y3 < y1) {
continue;
}
}
if (z1 > z2) {
if (z3 < z2 || z3 > z1) {
continue;
}
} else {
if (z3 > z2 || z3 < z1) {
continue;
}
}
return portal;
}
return null;
}
public static DPortal get(Player player) {
for (DPortal portal : plugin.getDPortals()) {
if (portal.player == player) {
return portal;
}
}
return null;
}
// Save and Load
public static void save(FileConfiguration configFile) {
int id = 0;
for (DPortal dportal : plugin.getDPortals()) {
id++;
if (dportal.isActive) {
String preString = "portal." + dportal.world.getName() + "." + id;
// Location1
configFile.set(preString + ".loc1.x", dportal.block1.getX());
configFile.set(preString + ".loc1.y", dportal.block1.getY());
configFile.set(preString + ".loc1.z", dportal.block1.getZ());
// Location1
configFile.set(preString + ".loc2.x", dportal.block2.getX());
configFile.set(preString + ".loc2.y", dportal.block2.getY());
configFile.set(preString + ".loc2.z", dportal.block2.getZ());
}
}
}
public static void load(FileConfiguration configFile) {
for (World world : plugin.getServer().getWorlds()) {
if (configFile.contains("portal." + world.getName())) {
int id = 0;
String preString;
do {
id++;
preString = "portal." + world.getName() + "." + id + ".";
if (configFile.contains(preString)) {
DPortal dportal = new DPortal(true);
dportal.world = world;
dportal.block1 = world.getBlockAt(configFile.getInt(preString + "loc1.x"), configFile.getInt(preString + "loc1.y"), configFile.getInt(preString + "loc1.z"));
dportal.block2 = world.getBlockAt(configFile.getInt(preString + "loc2.x"), configFile.getInt(preString + "loc2.y"), configFile.getInt(preString + "loc2.z"));
dportal.create();
}
} while (configFile.contains(preString));
}
}
}
/**
* @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,375 +1,399 @@
package com.dre.dungeonsxl;
import java.io.File;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.game.GameWorld;
public class DGSign {
public static CopyOnWriteArrayList<DGSign> dgsigns = new CopyOnWriteArrayList<DGSign>();
// Sign Labels
public static String strIsPlaying = ChatColor.DARK_RED + "Is Playing";
public static String strFull = ChatColor.DARK_RED + "Full";
public static String strJoinGrp = ChatColor.DARK_GREEN + "Join Group";
public static String strNewGrp = ChatColor.DARK_GREEN + "New Group";
// Variables
public DGroup[] dgroups;
public String dungeonName;
public int maxPlayersPerGroup;
public Block startSign;
public int directionX = 0, directionZ = 0;
public int verticalSigns;
public DGSign(Block startSign, String dungeonName, int maxGroups, int maxPlayersPerGroup) {
dgsigns.add(this);
this.startSign = startSign;
this.dungeonName = dungeonName;
this.dgroups = new DGroup[maxGroups];
this.maxPlayersPerGroup = maxPlayersPerGroup;
this.verticalSigns = (int) Math.ceil((float) (1 + maxPlayersPerGroup) / 4);
int[] direction = getDirection(this.startSign.getData());
this.directionX = direction[0];
this.directionZ = direction[1];
this.update();
}
public void update() {
int i = 0;
for (DGroup dgroup : this.dgroups) {
if ((this.startSign.getRelative(i * directionX, 0, i * directionZ).getState() instanceof Sign)) {
Sign sign = (Sign) this.startSign.getRelative(i * directionX, 0, i * directionZ).getState();
// Reset Signs
sign.setLine(0, "");
sign.setLine(1, "");
sign.setLine(2, "");
sign.setLine(3, "");
int yy = -1;
while (sign.getBlock().getRelative(0, yy, 0).getState() instanceof Sign) {
Sign subsign = (Sign) sign.getBlock().getRelative(0, yy, 0).getState();
subsign.setLine(0, "");
subsign.setLine(1, "");
subsign.setLine(2, "");
subsign.setLine(3, "");
subsign.update();
yy--;
}
// Set Signs
if (dgroup != null) {
if (dgroup.isPlaying) {
sign.setLine(0, strIsPlaying);
} else if (dgroup.getPlayers().size() >= this.maxPlayersPerGroup) {
sign.setLine(0, strFull);
} else {
sign.setLine(0, strJoinGrp);
}
int j = 1;
Sign rowSign = sign;
for (Player player : dgroup.getPlayers()) {
if (j > 3) {
j = 0;
rowSign = (Sign) sign.getBlock().getRelative(0, -1, 0).getState();
}
if (rowSign != null) {
rowSign.setLine(j, player.getName());
}
j++;
rowSign.update();
}
} else {
sign.setLine(0, strNewGrp);
}
sign.update();
}
i++;
}
}
// Static
public static DGSign tryToCreate(Block startSign, String dungeonName, int maxGroups, int maxPlayersPerGroup) {
World world = startSign.getWorld();
int direction = startSign.getData();
int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ();
int verticalSigns = (int) Math.ceil((float) (1 + maxPlayersPerGroup) / 4);
CopyOnWriteArrayList<Block> changeBlocks = new CopyOnWriteArrayList<Block>();
int xx, yy, zz;
switch (direction) {
case 2:
zz = z;
for (yy = y; yy > y - verticalSigns; yy--) {
for (xx = x; xx > x - maxGroups; xx--) {
Block block = world.getBlockAt(xx, yy, zz);
if (block.getType() != Material.AIR && block.getType() != Material.WALL_SIGN) {
return null;
}
if (block.getRelative(0, 0, 1).getType() == Material.AIR) {
return null;
}
changeBlocks.add(block);
}
}
break;
case 3:
zz = z;
for (yy = y; yy > y - verticalSigns; yy--) {
for (xx = x; xx < x + maxGroups; xx++) {
Block block = world.getBlockAt(xx, yy, zz);
if (block.getType() != Material.AIR && block.getType() != Material.WALL_SIGN) {
return null;
}
if (block.getRelative(0, 0, -1).getType() == Material.AIR) {
return null;
}
changeBlocks.add(block);
}
}
break;
case 4:
xx = x;
for (yy = y; yy > y - verticalSigns; yy--) {
for (zz = z; zz < z + maxGroups; zz++) {
Block block = world.getBlockAt(xx, yy, zz);
if (block.getType() != Material.AIR && block.getType() != Material.WALL_SIGN) {
return null;
}
if (block.getRelative(1, 0, 0).getType() == Material.AIR) {
return null;
}
changeBlocks.add(block);
}
}
break;
case 5:
xx = x;
for (yy = y; yy > y - verticalSigns; yy--) {
for (zz = z; zz > z - maxGroups; zz--) {
Block block = world.getBlockAt(xx, yy, zz);
if (block.getType() != Material.AIR && block.getType() != Material.WALL_SIGN) {
return null;
}
if (block.getRelative(-1, 0, 0).getType() == Material.AIR) {
return null;
}
changeBlocks.add(block);
}
}
break;
}
for (Block block : changeBlocks) {
block.setTypeIdAndData(68, startSign.getData(), true);
}
DGSign sign = new DGSign(startSign, dungeonName, maxGroups, maxPlayersPerGroup);
return sign;
}
public static boolean isRelativeSign(Block block, int x, int z) {
DGSign dgsign = getSign(block.getRelative(x, 0, z));
if (dgsign != null) {
if (x == -1 && dgsign.startSign.getData() == 4)
return true;
if (x == 1 && dgsign.startSign.getData() == 5)
return true;
if (z == -1 && dgsign.startSign.getData() == 2)
return true;
if (z == 1 && dgsign.startSign.getData() == 3)
return true;
}
return false;
}
public static DGSign getSign(Block block) {
if (block.getType() == Material.WALL_SIGN) {
int x = block.getX(), y = block.getY(), z = block.getZ();
for (DGSign dgsign : dgsigns) {
int sx1 = dgsign.startSign.getX(), sy1 = dgsign.startSign.getY(), sz1 = dgsign.startSign.getZ();
int sx2 = sx1 + (dgsign.dgroups.length - 1) * dgsign.directionX;
int sy2 = sy1 - dgsign.verticalSigns + 1;
int sz2 = sz1 + (dgsign.dgroups.length - 1) * dgsign.directionZ;
if (sx1 > sx2) {
if (x < sx2 || x > sx1)
continue;
} else if (sx1 < sx2) {
if (x > sx2 || x < sx1)
continue;
} else {
if (x != sx1)
continue;
}
if (sy1 > sy2) {
if (y < sy2 || y > sy1)
continue;
} else {
if (y != sy1)
continue;
}
if (sz1 > sz2) {
if (z < sz2 || z > sz1)
continue;
} else if (sz1 < sz2) {
if (z > sz2 || z < sz1)
continue;
} else {
if (z != sz1)
continue;
}
return dgsign;
}
}
return null;
}
public static boolean playerInteract(Block block, Player player) {
int x = block.getX(), y = block.getY(), z = block.getZ();
DGSign dgsign = getSign(block);
if (dgsign != null) {
if (GameWorld.canPlayDungeon(dgsign.dungeonName, player)) {
if (GameWorld.checkRequirements(dgsign.dungeonName, player)) {
int sx1 = dgsign.startSign.getX(), sy1 = dgsign.startSign.getY(), sz1 = dgsign.startSign.getZ();
Block topBlock = block.getRelative(0, sy1 - y, 0);
int column;
if (dgsign.directionX != 0) {
column = Math.abs(x - sx1);
} else {
column = Math.abs(z - sz1);
}
if ((topBlock.getState() instanceof Sign)) {
Sign topSign = (Sign) topBlock.getState();
if (topSign.getLine(0).equals(strNewGrp)) {
if (DGroup.get(player) == null) {
dgsign.dgroups[column] = new DGroup(player, dgsign.dungeonName);
dgsign.update();
}
} else if (topSign.getLine(0).equals(strJoinGrp)) {
if (DGroup.get(player) == null) {
dgsign.dgroups[column].addPlayer(player);
dgsign.update();
}
}
}
} else {
P.p.msg(player, P.p.language.get("Error_Requirements"));
}
} else {
File file = new File(P.p.getDataFolder() + "/dungeons/" + dgsign.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()));
}
}
}
return true;
}
return false;
}
public static void updatePerGroup(DGroup dgroupsearch) {
for (DGSign dgsign : dgsigns) {
int i = 0;
for (DGroup dgroup : dgsign.dgroups) {
if (dgroup != null) {
if (dgroup == dgroupsearch) {
if (dgroupsearch.isEmpty())
dgsign.dgroups[i] = null;
dgsign.update();
}
}
i++;
}
}
}
public static int[] getDirection(byte data) {
int[] direction = new int[2];
switch (data) {
case 2:
direction[0] = -1;
break;
case 3:
direction[0] = 1;
break;
case 4:
direction[1] = 1;
break;
case 5:
direction[1] = -1;
break;
}
return direction;
}
// Save and Load
public static void save(FileConfiguration configFile) {
int id = 0;
for (DGSign dgsign : dgsigns) {
id++;
String preString = "groupsign." + dgsign.startSign.getWorld().getName() + "." + id;
// Location
configFile.set(preString + ".x", dgsign.startSign.getX());
configFile.set(preString + ".y", dgsign.startSign.getY());
configFile.set(preString + ".z", dgsign.startSign.getZ());
// Etc.
configFile.set(preString + ".dungeon", dgsign.dungeonName);
configFile.set(preString + ".maxGroups", dgsign.dgroups.length);
configFile.set(preString + ".maxPlayersPerGroup", dgsign.maxPlayersPerGroup);
}
}
public static void load(FileConfiguration configFile) {
for (World world : P.p.getServer().getWorlds()) {
if (configFile.contains("groupsign." + world.getName())) {
int id = 0;
String preString;
do {
id++;
preString = "groupsign." + world.getName() + "." + id + ".";
if (configFile.contains(preString)) {
String dungeonName = configFile.getString(preString + ".dungeon");
int maxGroups = configFile.getInt(preString + ".maxGroups");
int maxPlayersPerGroup = configFile.getInt(preString + ".maxPlayersPerGroup");
Block startSign = world.getBlockAt(configFile.getInt(preString + ".x"), configFile.getInt(preString + ".y"), configFile.getInt(preString + ".z"));
new DGSign(startSign, dungeonName, maxGroups, maxPlayersPerGroup);
}
} while (configFile.contains(preString));
}
}
}
}
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.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
public class GroupSign {
static DungeonsXL plugin = DungeonsXL.getPlugin();
// Sign Labels
public static final String strIsPlaying = ChatColor.DARK_RED + "Is Playing";
public static final String strFull = ChatColor.DARK_RED + "Full";
public static final String strJoinGrp = ChatColor.DARK_GREEN + "Join Group";
public static final String strNewGrp = ChatColor.DARK_GREEN + "New Group";
// Variables
private DGroup[] dgroups;
private String dungeonName;
private int maxPlayersPerGroup;
private Block startSign;
private int directionX = 0, directionZ = 0;
private int verticalSigns;
public GroupSign(Block startSign, String dungeonName, int maxGroups, int maxPlayersPerGroup) {
plugin.getGroupSigns().add(this);
this.startSign = startSign;
this.dungeonName = dungeonName;
dgroups = new DGroup[maxGroups];
this.maxPlayersPerGroup = maxPlayersPerGroup;
verticalSigns = (int) Math.ceil((float) (1 + maxPlayersPerGroup) / 4);
@SuppressWarnings("deprecation")
int[] direction = getDirection(this.startSign.getData());
directionX = direction[0];
directionZ = direction[1];
update();
}
public void update() {
int i = 0;
for (DGroup dgroup : dgroups) {
if (startSign.getRelative(i * directionX, 0, i * directionZ).getState() instanceof Sign) {
Sign sign = (Sign) startSign.getRelative(i * directionX, 0, i * directionZ).getState();
// Reset Signs
sign.setLine(0, "");
sign.setLine(1, "");
sign.setLine(2, "");
sign.setLine(3, "");
int yy = -1;
while (sign.getBlock().getRelative(0, yy, 0).getState() instanceof Sign) {
Sign subsign = (Sign) sign.getBlock().getRelative(0, yy, 0).getState();
subsign.setLine(0, "");
subsign.setLine(1, "");
subsign.setLine(2, "");
subsign.setLine(3, "");
subsign.update();
yy--;
}
// Set Signs
if (dgroup != null) {
if (dgroup.isPlaying()) {
sign.setLine(0, strIsPlaying);
} else if (dgroup.getPlayers().size() >= maxPlayersPerGroup) {
sign.setLine(0, strFull);
} else {
sign.setLine(0, strJoinGrp);
}
int j = 1;
Sign rowSign = sign;
for (Player player : dgroup.getPlayers()) {
if (j > 3) {
j = 0;
rowSign = (Sign) sign.getBlock().getRelative(0, -1, 0).getState();
}
if (rowSign != null) {
rowSign.setLine(j, player.getName());
}
j++;
rowSign.update();
}
} else {
sign.setLine(0, strNewGrp);
}
sign.update();
}
i++;
}
}
// Static
@SuppressWarnings("deprecation")
public static GroupSign tryToCreate(Block startSign, String dungeonName, int maxGroups, int maxPlayersPerGroup) {
World world = startSign.getWorld();
int direction = startSign.getData();
int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ();
int verticalSigns = (int) Math.ceil((float) (1 + maxPlayersPerGroup) / 4);
CopyOnWriteArrayList<Block> changeBlocks = new CopyOnWriteArrayList<Block>();
int xx, yy, zz;
switch (direction) {
case 2:
zz = z;
for (yy = y; yy > y - verticalSigns; yy--) {
for (xx = x; xx > x - maxGroups; xx--) {
Block block = world.getBlockAt(xx, yy, zz);
if (block.getType() != Material.AIR && block.getType() != Material.WALL_SIGN) {
return null;
}
if (block.getRelative(0, 0, 1).getType() == Material.AIR) {
return null;
}
changeBlocks.add(block);
}
}
break;
case 3:
zz = z;
for (yy = y; yy > y - verticalSigns; yy--) {
for (xx = x; xx < x + maxGroups; xx++) {
Block block = world.getBlockAt(xx, yy, zz);
if (block.getType() != Material.AIR && block.getType() != Material.WALL_SIGN) {
return null;
}
if (block.getRelative(0, 0, -1).getType() == Material.AIR) {
return null;
}
changeBlocks.add(block);
}
}
break;
case 4:
xx = x;
for (yy = y; yy > y - verticalSigns; yy--) {
for (zz = z; zz < z + maxGroups; zz++) {
Block block = world.getBlockAt(xx, yy, zz);
if (block.getType() != Material.AIR && block.getType() != Material.WALL_SIGN) {
return null;
}
if (block.getRelative(1, 0, 0).getType() == Material.AIR) {
return null;
}
changeBlocks.add(block);
}
}
break;
case 5:
xx = x;
for (yy = y; yy > y - verticalSigns; yy--) {
for (zz = z; zz > z - maxGroups; zz--) {
Block block = world.getBlockAt(xx, yy, zz);
if (block.getType() != Material.AIR && block.getType() != Material.WALL_SIGN) {
return null;
}
if (block.getRelative( -1, 0, 0).getType() == Material.AIR) {
return null;
}
changeBlocks.add(block);
}
}
break;
}
for (Block block : changeBlocks) {
block.setTypeIdAndData(68, startSign.getData(), true);
}
GroupSign sign = new GroupSign(startSign, dungeonName, maxGroups, maxPlayersPerGroup);
return sign;
}
@SuppressWarnings("deprecation")
public static boolean isRelativeSign(Block block, int x, int z) {
GroupSign dgsign = getSign(block.getRelative(x, 0, z));
if (dgsign != null) {
if (x == -1 && dgsign.startSign.getData() == 4) {
return true;
}
if (x == 1 && dgsign.startSign.getData() == 5) {
return true;
}
if (z == -1 && dgsign.startSign.getData() == 2) {
return true;
}
if (z == 1 && dgsign.startSign.getData() == 3) {
return true;
}
}
return false;
}
public static GroupSign getSign(Block block) {
if (block.getType() == Material.WALL_SIGN) {
int x = block.getX(), y = block.getY(), z = block.getZ();
for (GroupSign dgsign : plugin.getGroupSigns()) {
int sx1 = dgsign.startSign.getX(), sy1 = dgsign.startSign.getY(), sz1 = dgsign.startSign.getZ();
int sx2 = sx1 + (dgsign.dgroups.length - 1) * dgsign.directionX;
int sy2 = sy1 - dgsign.verticalSigns + 1;
int sz2 = sz1 + (dgsign.dgroups.length - 1) * dgsign.directionZ;
if (sx1 > sx2) {
if (x < sx2 || x > sx1) {
continue;
}
} else if (sx1 < sx2) {
if (x > sx2 || x < sx1) {
continue;
}
} else {
if (x != sx1) {
continue;
}
}
if (sy1 > sy2) {
if (y < sy2 || y > sy1) {
continue;
}
} else {
if (y != sy1) {
continue;
}
}
if (sz1 > sz2) {
if (z < sz2 || z > sz1) {
continue;
}
} else if (sz1 < sz2) {
if (z > sz2 || z < sz1) {
continue;
}
} else {
if (z != sz1) {
continue;
}
}
return dgsign;
}
}
return null;
}
public static boolean playerInteract(Block block, Player player) {
int x = block.getX(), y = block.getY(), z = block.getZ();
GroupSign dgsign = getSign(block);
if (dgsign != null) {
if (GameWorld.canPlayDungeon(dgsign.dungeonName, player)) {
if (GameWorld.checkRequirements(dgsign.dungeonName, player)) {
int sx1 = dgsign.startSign.getX(), sy1 = dgsign.startSign.getY(), sz1 = dgsign.startSign.getZ();
Block topBlock = block.getRelative(0, sy1 - y, 0);
int column;
if (dgsign.directionX != 0) {
column = Math.abs(x - sx1);
} else {
column = Math.abs(z - sz1);
}
if (topBlock.getState() instanceof Sign) {
Sign topSign = (Sign) topBlock.getState();
if (topSign.getLine(0).equals(strNewGrp)) {
if (DGroup.get(player) == null) {
dgsign.dgroups[column] = new DGroup(player, dgsign.dungeonName);
dgsign.update();
}
} else if (topSign.getLine(0).equals(strJoinGrp)) {
if (DGroup.get(player) == null) {
dgsign.dgroups[column].addPlayer(player);
dgsign.update();
}
}
}
} else {
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Error_Requirements"));
}
} else {
File file = new File(DungeonsXL.getPlugin().getDataFolder() + "/maps/" + dgsign.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 true;
}
return false;
}
public static void updatePerGroup(DGroup dgroupsearch) {
for (GroupSign dgsign : plugin.getGroupSigns()) {
int i = 0;
for (DGroup dgroup : dgsign.dgroups) {
if (dgroup != null) {
if (dgroup == dgroupsearch) {
if (dgroupsearch.isEmpty()) {
dgsign.dgroups[i] = null;
}
dgsign.update();
}
}
i++;
}
}
}
public static int[] getDirection(byte data) {
int[] direction = new int[2];
switch (data) {
case 2:
direction[0] = -1;
break;
case 3:
direction[0] = 1;
break;
case 4:
direction[1] = 1;
break;
case 5:
direction[1] = -1;
break;
}
return direction;
}
// Save and Load
public static void save(FileConfiguration configFile) {
int id = 0;
for (GroupSign dgsign : plugin.getGroupSigns()) {
id++;
String preString = "groupsign." + dgsign.startSign.getWorld().getName() + "." + id;
// Location
configFile.set(preString + ".x", dgsign.startSign.getX());
configFile.set(preString + ".y", dgsign.startSign.getY());
configFile.set(preString + ".z", dgsign.startSign.getZ());
// Etc.
configFile.set(preString + ".dungeon", dgsign.dungeonName);
configFile.set(preString + ".maxGroups", dgsign.dgroups.length);
configFile.set(preString + ".maxPlayersPerGroup", dgsign.maxPlayersPerGroup);
}
}
public static void load(FileConfiguration configFile) {
for (World world : DungeonsXL.getPlugin().getServer().getWorlds()) {
if (configFile.contains("groupsign." + world.getName())) {
int id = 0;
String preString;
do {
id++;
preString = "groupsign." + world.getName() + "." + id + ".";
if (configFile.contains(preString)) {
String dungeonName = configFile.getString(preString + ".dungeon");
int maxGroups = configFile.getInt(preString + ".maxGroups");
int maxPlayersPerGroup = configFile.getInt(preString + ".maxPlayersPerGroup");
Block startSign = world.getBlockAt(configFile.getInt(preString + ".x"), configFile.getInt(preString + ".y"), configFile.getInt(preString + ".z"));
new GroupSign(startSign, dungeonName, maxGroups, maxPlayersPerGroup);
}
} while (configFile.contains(preString));
}
}
}
}

View File

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

View File

@ -1,214 +1,219 @@
package com.dre.dungeonsxl.listener;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.SignChangeEvent;
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 {
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPhysics(BlockPhysicsEvent event) {
if (event.getBlock().getType() == Material.PORTAL) {
if (DPortal.get(event.getBlock()) != null) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
// Deny DPortal destroying
if (block.getType() == Material.PORTAL) {
if (DPortal.get(event.getBlock()) != null) {
event.setCancelled(true);
}
}
// Deny DGSignblocks destroying
if (DGSign.isRelativeSign(block, 1, 0) || DGSign.isRelativeSign(block, -1, 0) || DGSign.isRelativeSign(block, 0, 1) || DGSign.isRelativeSign(block, 0, -1)) {
event.setCancelled(true);
}
// DGSign destroying
if (DGSign.getSign(block) != null) {
DGSign.dgsigns.remove(DGSign.getSign(block));
}
// Deny LeaveSignblocks destroying
if (LeaveSign.isRelativeSign(block, 1, 0) || LeaveSign.isRelativeSign(block, -1, 0) || LeaveSign.isRelativeSign(block, 0, 1) || LeaveSign.isRelativeSign(block, 0, -1)) {
event.setCancelled(true);
}
// LeaveSign destroying
if (LeaveSign.getSign(block) != null) {
event.setCancelled(true);
// LeaveSign.lsigns.remove(LeaveSign.getSign(block));
}
// Editworld Signs
EditWorld eworld = EditWorld.get(block.getWorld());
if (eworld != null) {
eworld.sign.remove(event.getBlock());
}
// Deny GameWorld Blocks
GameWorld gworld = GameWorld.get(block.getWorld());
if (gworld != null) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event) {
Block block = event.getBlock();
// Deny GameWorld Blocks
GameWorld gworld = GameWorld.get(block.getWorld());
if (gworld != null) {
if (!GamePlaceableBlock.canBuildHere(block, block.getFace(event.getBlockAgainst()), event.getItemInHand().getType(), gworld)) {
// Workaround for a bug that would allow 3-Block-high jumping
Location loc = event.getPlayer().getLocation();
if (loc.getY() > block.getY() + 1.0 && loc.getY() <= block.getY() + 1.5) {
if (loc.getX() >= block.getX() - 0.3 && loc.getX() <= block.getX() + 1.3) {
if (loc.getZ() >= block.getZ() - 0.3 && loc.getZ() <= block.getZ() + 1.3) {
loc.setX(block.getX() + 0.5);
loc.setY(block.getY());
loc.setZ(block.getZ() + 0.5);
event.getPlayer().teleport(loc);
}
}
}
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
String[] lines = event.getLines();
EditWorld eworld = EditWorld.get(player.getWorld());
// Group Signs
if (eworld == null) {
if (player.isOp() || P.p.permission.has(player, "dxl.sign")) {
if (lines[0].equalsIgnoreCase("[DXL]")) {
if (lines[1].equalsIgnoreCase("Group")) {
String dungeonName = lines[2];
String[] data = lines[3].split("\\,");
if (data.length == 2) {
int maxGroups = P.p.parseInt(data[0]);
int maxPlayersPerGroup = P.p.parseInt(data[1]);
if (maxGroups > 0 && maxPlayersPerGroup > 0) {
if (DGSign.tryToCreate(event.getBlock(), dungeonName, maxGroups, maxPlayersPerGroup) != null) {
event.setCancelled(true);
}
}
}
} else if (lines[1].equalsIgnoreCase("Leave")) {
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
new LeaveSign(sign);
}
event.setCancelled(true);
}
}
}
} else { // Editworld Signs
Sign sign = (Sign) block.getState();
if (sign != null) {
sign.setLine(0, lines[0]);
sign.setLine(1, lines[1]);
sign.setLine(2, lines[2]);
sign.setLine(3, lines[3]);
DSign dsign = DSign.create(sign, null);
if (dsign != null) {
if (player.isOp() || P.p.permission.has(player, dsign.getPermissions())) {
if (dsign.check()) {
eworld.checkSign(block);
eworld.sign.add(block);
P.p.msg(player, P.p.language.get("Player_SignCreated"));
} else {
P.p.msg(player, P.p.language.get("Error_SignWrongFormat"));
}
} else {
P.p.msg(player, P.p.language.get("Error_NoPermissions"));
}
}
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockSpread(BlockSpreadEvent event) {
Block block = event.getBlock();
// Block the Spread off Vines
if (block.getType() == Material.VINE) {
// Check GameWorlds
GameWorld gworld = GameWorld.get(event.getBlock().getWorld());
if (gworld != null) {
event.setCancelled(true);
}
// Check EditWorlds
EditWorld eworld = EditWorld.get(event.getBlock().getWorld());
if (eworld != null) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockRedstoneEvent(BlockRedstoneEvent event) {
new RedstoneEventTask(event.getBlock()).runTaskLater(P.p, 1);
}
public class RedstoneEventTask extends BukkitRunnable {
private final Block block;
public RedstoneEventTask(final Block block) {
this.block = block;
}
public void run() {
for (GameWorld gworld : GameWorld.gworlds) {
if (block.getWorld() == gworld.world) {
RedstoneTrigger.updateAll(gworld);
}
}
}
}
}
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.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.scheduler.BukkitRunnable;
public class BlockListener implements Listener {
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPhysics(BlockPhysicsEvent event) {
if (event.getBlock().getType() == Material.PORTAL) {
if (DPortal.get(event.getBlock()) != null) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
// Deny DPortal destroying
if (block.getType() == Material.PORTAL) {
if (DPortal.get(event.getBlock()) != null) {
event.setCancelled(true);
}
}
// Deny DGSignblocks destroying
if (GroupSign.isRelativeSign(block, 1, 0) || GroupSign.isRelativeSign(block, -1, 0) || GroupSign.isRelativeSign(block, 0, 1) || GroupSign.isRelativeSign(block, 0, -1)) {
event.setCancelled(true);
}
// DGSign destroying
if (GroupSign.getSign(block) != null) {
DungeonsXL.getPlugin().getGroupSigns().remove(GroupSign.getSign(block));
}
// Deny LeaveSignblocks destroying
if (LeaveSign.isRelativeSign(block, 1, 0) || LeaveSign.isRelativeSign(block, -1, 0) || LeaveSign.isRelativeSign(block, 0, 1) || LeaveSign.isRelativeSign(block, 0, -1)) {
event.setCancelled(true);
}
// LeaveSign destroying
if (LeaveSign.getSign(block) != null) {
event.setCancelled(true);
// LeaveSign.lsigns.remove(LeaveSign.getSign(block));
}
// Editworld Signs
EditWorld eworld = EditWorld.get(block.getWorld());
if (eworld != null) {
eworld.sign.remove(event.getBlock());
}
// Deny GameWorld Blocks
GameWorld gworld = GameWorld.get(block.getWorld());
if (gworld != null) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event) {
Block block = event.getBlock();
// Deny GameWorld Blocks
GameWorld gworld = GameWorld.get(block.getWorld());
if (gworld != null) {
if ( !GamePlaceableBlock.canBuildHere(block, block.getFace(event.getBlockAgainst()), event.getItemInHand().getType(), gworld)) {
// Workaround for a bug that would allow 3-Block-high jumping
Location loc = event.getPlayer().getLocation();
if (loc.getY() > block.getY() + 1.0 && loc.getY() <= block.getY() + 1.5) {
if (loc.getX() >= block.getX() - 0.3 && loc.getX() <= block.getX() + 1.3) {
if (loc.getZ() >= block.getZ() - 0.3 && loc.getZ() <= block.getZ() + 1.3) {
loc.setX(block.getX() + 0.5);
loc.setY(block.getY());
loc.setZ(block.getZ() + 0.5);
event.getPlayer().teleport(loc);
}
}
}
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
String[] lines = event.getLines();
EditWorld eworld = EditWorld.get(player.getWorld());
// Group Signs
if (eworld == null) {
if (player.isOp() || player.hasPermission("dxl.sign")) {
if (lines[0].equalsIgnoreCase("[DXL]")) {
if (lines[1].equalsIgnoreCase("Group")) {
String dungeonName = lines[2];
String[] data = lines[3].split("\\,");
if (data.length == 2) {
int maxGroups = IntegerUtil.parseInt(data[0]);
int maxPlayersPerGroup = IntegerUtil.parseInt(data[1]);
if (maxGroups > 0 && maxPlayersPerGroup > 0) {
if (GroupSign.tryToCreate(event.getBlock(), dungeonName, maxGroups, maxPlayersPerGroup) != null) {
event.setCancelled(true);
}
}
}
} else if (lines[1].equalsIgnoreCase("Leave")) {
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
new LeaveSign(sign);
}
event.setCancelled(true);
}
}
}
} else { // Editworld Signs
Sign sign = (Sign) block.getState();
if (sign != null) {
sign.setLine(0, lines[0]);
sign.setLine(1, lines[1]);
sign.setLine(2, lines[2]);
sign.setLine(3, lines[3]);
DSign dsign = DSign.create(sign, null);
if (dsign != null) {
if (player.isOp() || player.hasPermission(dsign.getPermissions())) {
if (dsign.check()) {
eworld.checkSign(block);
eworld.sign.add(block);
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Player_SignCreated"));
} else {
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Error_SignWrongFormat"));
}
} else {
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Error_NoPermissions"));
}
}
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockSpread(BlockSpreadEvent event) {
Block block = event.getBlock();
// Block the Spread off Vines
if (block.getType() == Material.VINE) {
// Check GameWorlds
GameWorld gworld = GameWorld.get(event.getBlock().getWorld());
if (gworld != null) {
event.setCancelled(true);
}
// Check EditWorlds
EditWorld eworld = EditWorld.get(event.getBlock().getWorld());
if (eworld != null) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockRedstoneEvent(BlockRedstoneEvent event) {
new RedstoneEventTask(event.getBlock()).runTaskLater(DungeonsXL.getPlugin(), 1);
}
public class RedstoneEventTask extends BukkitRunnable {
private final Block block;
public RedstoneEventTask(final Block block) {
this.block = block;
}
@Override
public void run() {
for (GameWorld gworld : DungeonsXL.getPlugin().getGameWorlds()) {
if (block.getWorld() == gworld.world) {
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,209 +1,211 @@
package com.dre.dungeonsxl.listener;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.EntityCombustByEntityEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import 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 {
// Remove drops from breaking Signs
@EventHandler(priority = EventPriority.HIGH)
public void onItemSpawn(ItemSpawnEvent event) {
if (GameWorld.get(event.getLocation().getWorld()) != null) {
if (event.getEntity().getItemStack().getType() == Material.SIGN) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onCreatureSpawn(CreatureSpawnEvent event) {
World world = event.getLocation().getWorld();
EditWorld eworld = EditWorld.get(world);
GameWorld gworld = GameWorld.get(world);
if (eworld != null || gworld != null) {
if (event.getSpawnReason() == SpawnReason.CHUNK_GEN || event.getSpawnReason() == SpawnReason.BREEDING || event.getSpawnReason() == SpawnReason.NATURAL
|| event.getSpawnReason() == SpawnReason.DEFAULT) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDeath(EntityDeathEvent event) {
World world = event.getEntity().getWorld();
if (event.getEntity() instanceof LivingEntity) {
LivingEntity entity = (LivingEntity) event.getEntity();
GameWorld gworld = GameWorld.get(world);
if (gworld != null) {
if (gworld.isPlaying) {
if (entity.getType() != EntityType.PLAYER) {
event.getDrops().clear();
DMob.onDeath(event);
}
}
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDamage(EntityDamageEvent event) {
World world = event.getEntity().getWorld();
GameWorld gworld = GameWorld.get(world);
if (gworld != null) {
// Deny all Damage in Lobby
if (!gworld.isPlaying) {
event.setCancelled(true);
}
// Deny all Damage from Players to Players
if (event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) event;
Entity entity = sub.getDamager();
Entity entity2 = sub.getEntity();
if (entity instanceof Projectile) {
entity = (Entity) ((Projectile) entity).getShooter();
}
if (entity instanceof Player && entity2 instanceof Player) {
event.setCancelled(true);
}
if (entity instanceof LivingEntity && entity2 instanceof LivingEntity) {
if (!(entity instanceof Player) && !(entity2 instanceof Player)) {
event.setCancelled(true);
}
// Check Dogs
if (entity instanceof Player || entity2 instanceof Player) {
for (DPlayer dplayer : DPlayer.get(gworld.world)) {
if (dplayer.wolf != null) {
if (entity == dplayer.wolf || entity2 == dplayer.wolf) {
event.setCancelled(true);
return;
}
}
}
}
for (DPlayer dplayer : DPlayer.get(gworld.world)) {
if (dplayer.wolf != null) {
if (entity instanceof Player || entity2 instanceof Player) {
if (entity == dplayer.wolf || entity2 == dplayer.wolf) {
event.setCancelled(true);
return;
}
} else {
if (entity == dplayer.wolf || entity2 == dplayer.wolf) {
event.setCancelled(false);
return;
}
}
}
}
}
}
}
}
// Deny food in Lobby
@EventHandler(priority = EventPriority.HIGH)
public void onFoodLevelChange(FoodLevelChangeEvent event) {
World world = event.getEntity().getWorld();
GameWorld gworld = GameWorld.get(world);
if (gworld != null) {
if (!gworld.isPlaying) {
event.setCancelled(true);
}
}
}
// Zombie/skeleton combustion from the sun.
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityCombust(EntityCombustEvent event) {
GameWorld gworld = GameWorld.get(event.getEntity().getWorld());
if (gworld != null) {
event.setCancelled(true);
}
}
// Allow Other combustion
@EventHandler(priority = EventPriority.HIGH)
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
GameWorld gworld = GameWorld.get(event.getEntity().getWorld());
if (gworld != null) {
if (event.isCancelled()) {
event.setCancelled(false);
}
}
}
// Explosions
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
GameWorld gworld = GameWorld.get(event.getEntity().getWorld());
if (gworld != null) {
if (event.getEntity() instanceof LivingEntity) {
// Disable Creeper explosions in gameworlds
event.setCancelled(true);
return;
} else {
// Disable drops from TNT
event.setYield(0);
}
}
// Prevent Portal and Sign Destroying
List<Block> blocklist = event.blockList();
for (Block block : blocklist) {
// Portals
if (block.getType() == Material.PORTAL) {
if (DPortal.get(block) != null) {
event.setCancelled(true);
return;
}
}
// Signs
if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) {
if (DGSign.getSign(block) != null) {
event.setCancelled(true);
return;
}
}
}
}
}
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 org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityCombustByEntityEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
public class EntityListener implements Listener {
// Remove drops from breaking Signs
@EventHandler(priority = EventPriority.HIGH)
public void onItemSpawn(ItemSpawnEvent event) {
if (GameWorld.get(event.getLocation().getWorld()) != null) {
if (event.getEntity().getItemStack().getType() == Material.SIGN) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onCreatureSpawn(CreatureSpawnEvent event) {
World world = event.getLocation().getWorld();
EditWorld eworld = EditWorld.get(world);
GameWorld gworld = GameWorld.get(world);
if (eworld != null || gworld != null) {
if (event.getSpawnReason() == SpawnReason.CHUNK_GEN || event.getSpawnReason() == SpawnReason.BREEDING || event.getSpawnReason() == SpawnReason.NATURAL
|| event.getSpawnReason() == SpawnReason.DEFAULT) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDeath(EntityDeathEvent event) {
World world = event.getEntity().getWorld();
if (event.getEntity() instanceof LivingEntity) {
LivingEntity entity = event.getEntity();
GameWorld gworld = GameWorld.get(world);
if (gworld != null) {
if (gworld.isPlaying) {
if (entity.getType() != EntityType.PLAYER) {
event.getDrops().clear();
DMob.onDeath(event);
}
}
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDamage(EntityDamageEvent event) {
World world = event.getEntity().getWorld();
GameWorld gworld = GameWorld.get(world);
if (gworld != null) {
// Deny all Damage in Lobby
if ( !gworld.isPlaying) {
event.setCancelled(true);
}
// Deny all Damage from Players to Players
if (event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) event;
Entity entity = sub.getDamager();
Entity entity2 = sub.getEntity();
if (entity instanceof Projectile) {
entity = (Entity) ((Projectile) entity).getShooter();
}
if (entity instanceof Player && entity2 instanceof Player) {
event.setCancelled(true);
}
if (entity instanceof LivingEntity && entity2 instanceof LivingEntity) {
if ( !(entity instanceof Player) && !(entity2 instanceof Player)) {
event.setCancelled(true);
}
// Check Dogs
if (entity instanceof Player || entity2 instanceof Player) {
for (DPlayer dplayer : DPlayer.get(gworld.world)) {
if (dplayer.wolf != null) {
if (entity == dplayer.wolf || entity2 == dplayer.wolf) {
event.setCancelled(true);
return;
}
}
}
}
for (DPlayer dplayer : DPlayer.get(gworld.world)) {
if (dplayer.wolf != null) {
if (entity instanceof Player || entity2 instanceof Player) {
if (entity == dplayer.wolf || entity2 == dplayer.wolf) {
event.setCancelled(true);
return;
}
} else {
if (entity == dplayer.wolf || entity2 == dplayer.wolf) {
event.setCancelled(false);
return;
}
}
}
}
}
}
}
}
// Deny food in Lobby
@EventHandler(priority = EventPriority.HIGH)
public void onFoodLevelChange(FoodLevelChangeEvent event) {
World world = event.getEntity().getWorld();
GameWorld gworld = GameWorld.get(world);
if (gworld != null) {
if ( !gworld.isPlaying) {
event.setCancelled(true);
}
}
}
// Zombie/skeleton combustion from the sun.
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityCombust(EntityCombustEvent event) {
GameWorld gworld = GameWorld.get(event.getEntity().getWorld());
if (gworld != null) {
event.setCancelled(true);
}
}
// Allow Other combustion
@EventHandler(priority = EventPriority.HIGH)
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
GameWorld gworld = GameWorld.get(event.getEntity().getWorld());
if (gworld != null) {
if (event.isCancelled()) {
event.setCancelled(false);
}
}
}
// Explosions
@EventHandler
public void onEntityExplode(EntityExplodeEvent event) {
GameWorld gworld = GameWorld.get(event.getEntity().getWorld());
if (gworld != null) {
if (event.getEntity() instanceof LivingEntity) {
// Disable Creeper explosions in gameworlds
event.setCancelled(true);
return;
} else {
// Disable drops from TNT
event.setYield(0);
}
}
// Prevent Portal and Sign Destroying
List<Block> blocklist = event.blockList();
for (Block block : blocklist) {
// Portals
if (block.getType() == Material.PORTAL) {
if (DPortal.get(block) != null) {
event.setCancelled(true);
return;
}
}
// Signs
if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) {
if (GroupSign.getSign(block) != null) {
event.setCancelled(true);
return;
}
}
}
}
}

View File

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

View File

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

View File

@ -1,87 +1,92 @@
package com.dre.dungeonsxl.game;
import java.util.Random;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import com.dre.dungeonsxl.DMobType;
import com.dre.dungeonsxl.trigger.MobTrigger;
public class DMob {
// Variables
public LivingEntity entity;
public DMobType type;
public String trigger;
public DMob(LivingEntity entity, GameWorld gworld, DMobType type) {
gworld.dmobs.add(this);
this.entity = entity;
this.type = type;
/* Remove DropChance of equipment */
this.entity.getEquipment().setHelmetDropChance(0);
this.entity.getEquipment().setChestplateDropChance(0);
this.entity.getEquipment().setLeggingsDropChance(0);
this.entity.getEquipment().setBootsDropChance(0);
this.entity.getEquipment().setItemInHandDropChance(0);
}
public DMob(LivingEntity entity, GameWorld gworld, DMobType type, String trigger) {
gworld.dmobs.add(this);
this.entity = entity;
this.type = type;
this.trigger = trigger;
/* Remove DropChance of equipment */
this.entity.getEquipment().setHelmetDropChance(0);
this.entity.getEquipment().setChestplateDropChance(0);
this.entity.getEquipment().setLeggingsDropChance(0);
this.entity.getEquipment().setBootsDropChance(0);
this.entity.getEquipment().setItemInHandDropChance(0);
}
// Statics
public static void onDeath(EntityDeathEvent event) {
if (event.getEntity() instanceof LivingEntity) {
LivingEntity victim = (LivingEntity) event.getEntity();
GameWorld gworld = GameWorld.get(victim.getWorld());
String name = null;
if (gworld != null) {
for (DMob dmob : gworld.dmobs) {
if (dmob.entity == victim) {
if (dmob.type != null) {
for (ItemStack item : dmob.type.getDrops().keySet()) {
Random randomGenerator = new Random();
int random = randomGenerator.nextInt(100);
if (dmob.type.getDrops().get(item) > random) {
event.getDrops().add(item);
}
}
name = dmob.type.getName();
} else if (dmob.type == null && dmob.trigger != null) {// <=MythicMobs mob
name = dmob.trigger;
} else {
name = victim.getType().getName();
}
MobTrigger trigger = MobTrigger.get(name, gworld);
if (trigger != null) {
trigger.onTrigger();
}
gworld.dmobs.remove(dmob);
return;
}
}
}
}
}
}
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 org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
public class DMob {
// Variables
private LivingEntity entity;
private DMobType type;
private String trigger;
public DMob(LivingEntity entity, GameWorld gworld, DMobType type) {
gworld.dMobs.add(this);
this.entity = entity;
this.type = type;
/* Remove DropChance of equipment */
this.entity.getEquipment().setHelmetDropChance(0);
this.entity.getEquipment().setChestplateDropChance(0);
this.entity.getEquipment().setLeggingsDropChance(0);
this.entity.getEquipment().setBootsDropChance(0);
this.entity.getEquipment().setItemInHandDropChance(0);
}
public DMob(LivingEntity entity, GameWorld gworld, DMobType type, String trigger) {
gworld.dMobs.add(this);
this.entity = entity;
this.type = type;
this.trigger = trigger;
/* Remove DropChance of equipment */
this.entity.getEquipment().setHelmetDropChance(0);
this.entity.getEquipment().setChestplateDropChance(0);
this.entity.getEquipment().setLeggingsDropChance(0);
this.entity.getEquipment().setBootsDropChance(0);
this.entity.getEquipment().setItemInHandDropChance(0);
}
// Statics
@SuppressWarnings("deprecation")
public static void onDeath(EntityDeathEvent event) {
if (event.getEntity() instanceof LivingEntity) {
LivingEntity victim = event.getEntity();
GameWorld gworld = GameWorld.get(victim.getWorld());
String name = null;
if (gworld != null) {
for (DMob dmob : gworld.dMobs) {
if (dmob.entity == victim) {
if (dmob.type != null) {
for (ItemStack item : dmob.type.getDrops().keySet()) {
Random randomGenerator = new Random();
int random = randomGenerator.nextInt(100);
if (dmob.type.getDrops().get(item) > random) {
event.getDrops().add(item);
}
}
name = dmob.type.getName();
} else if (dmob.type == null && dmob.trigger != null) {// <=MythicMobs mob
name = dmob.trigger;
} else {
name = victim.getType().getName();
}
MobTrigger trigger = MobTrigger.get(name, gworld);
if (trigger != null) {
trigger.onTrigger();
}
gworld.dMobs.remove(dmob);
return;
}
}
}
}
}
}

View File

@ -1,246 +1,274 @@
package com.dre.dungeonsxl;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import com.dre.dungeonsxl.game.DMob;
import com.dre.dungeonsxl.game.GameWorld;
public class DMobType {
private String name;
private EntityType type;
private int maxHealth;
private ItemStack ItemHand;
private ItemStack ItemHelmet;
private ItemStack ItemChestplate;
private ItemStack ItemLeggings;
private ItemStack ItemBoots;
private Map<ItemStack, Integer> drops = new HashMap<ItemStack, Integer>();
public Map<ItemStack, Integer> getDrops() {
return this.drops;
}
/* Extra Values for different Mob Types */
private boolean isWitherSkeleton = false;
private String ocelotType = null;
/* Methods */
public DMobType(String name, EntityType type) {
this.name = name;
this.type = type;
}
public void spawn(GameWorld gWorld, Location loc) {
if (type != null) {
if (type.isAlive()) {
LivingEntity entity = (LivingEntity) gWorld.world.spawnEntity(loc, type);
/* Set the Items */
entity.getEquipment().setItemInHand(ItemHand);
entity.getEquipment().setHelmet(ItemHelmet);
entity.getEquipment().setChestplate(ItemChestplate);
entity.getEquipment().setLeggings(ItemLeggings);
entity.getEquipment().setBoots(ItemBoots);
/* Check mob specified stuff */
if (type == EntityType.SKELETON) {
if (isWitherSkeleton) {
((Skeleton) entity).setSkeletonType(SkeletonType.WITHER);
} else {
((Skeleton) entity).setSkeletonType(SkeletonType.NORMAL);
}
}
if (type == EntityType.OCELOT) {
Ocelot ocelot = (Ocelot) entity;
if (ocelotType != null) {
if (ocelotType.equalsIgnoreCase("BLACK_CAT")) {
ocelot.setCatType(Ocelot.Type.BLACK_CAT);
} else if (ocelotType.equalsIgnoreCase("RED_CAT")) {
ocelot.setCatType(Ocelot.Type.RED_CAT);
} else if (ocelotType.equalsIgnoreCase("SIAMESE_CAT")) {
ocelot.setCatType(Ocelot.Type.SIAMESE_CAT);
} else if (ocelotType.equalsIgnoreCase("WILD_OCELOT")) {
ocelot.setCatType(Ocelot.Type.WILD_OCELOT);
}
}
}
/* Set Health */
if (maxHealth > 0) {
entity.setMaxHealth(maxHealth);
entity.setHealth(maxHealth);
}
/* Disable Despawning */
entity.setRemoveWhenFarAway(false);
/* Spawn Mob */
new DMob(entity, gWorld, this);
}
}
}
// Load Config
public static Set<DMobType> load(ConfigurationSection configFile) {
Set<DMobType> set = new HashSet<DMobType>();
if (configFile != null) {
// Read Mobs
for (String mobName : configFile.getKeys(false)) {
EntityType type = EntityType.fromName(configFile.getString(mobName + ".Type"));
if (type != null) {
DMobType mobType = new DMobType(mobName, type);
set.add(mobType);
// Load MaxHealth
if (configFile.contains(mobName + ".MaxHealth")) {
mobType.maxHealth = configFile.getInt(mobName + ".MaxHealth");
}
// Load Items
if (configFile.contains(mobName + ".ItemHelmet")) {
mobType.ItemHelmet = new ItemStack(configFile.getInt(mobName + ".ItemHelmet"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemHelmet"))).getItem();
}
if (configFile.contains(mobName + ".ItemChestplate")) {
mobType.ItemChestplate = new ItemStack(configFile.getInt(mobName + ".ItemChestplate"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemChestplate"))).getItem();
}
if (configFile.contains(mobName + ".ItemBoots")) {
mobType.ItemBoots = new ItemStack(configFile.getInt(mobName + ".ItemBoots"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemBoots"))).getItem();
}
if (configFile.contains(mobName + ".ItemLeggings")) {
mobType.ItemLeggings = new ItemStack(configFile.getInt(mobName + ".ItemLeggings"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemLeggings"))).getItem();
}
if (configFile.contains(mobName + ".ItemHand")) {
mobType.ItemHand = new ItemStack(configFile.getInt(mobName + ".ItemHand"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemHand"))).getItem();
}
// Load different Mob options
if (configFile.contains(mobName + ".isWitherSkeleton")) {
mobType.isWitherSkeleton = configFile.getBoolean(mobName + ".isWitherSkeleton");
}
if (configFile.contains(mobName + ".ocelotType")) {
mobType.ocelotType = configFile.getString(mobName + ".ocelotType");
}
// Drops
ConfigurationSection configSetion = configFile.getConfigurationSection(mobName + ".drops");
if (configSetion != null) {
Set<String> list = configSetion.getKeys(false);
for (String dropPath : list) {
ItemStack item = null;
ItemMeta itemMeta = null;
int chance = 100;
/* Item Stack */
Material mat = Material.getMaterial(configSetion.getInt(dropPath + ".id"));
int amount = 1;
short data = 0;
if (configSetion.contains(dropPath + ".amount")) {
amount = configSetion.getInt(dropPath + ".amount");
}
if (configSetion.contains(dropPath + ".data")) {
data = Short.parseShort(configSetion.getString(dropPath + ".data"));
}
item = new ItemStack(mat, amount, data);
itemMeta = item.getItemMeta();
/* Enchantments */
if (configSetion.contains(dropPath + ".enchantments")) {
for (String enchantment : configSetion.getStringList(dropPath + ".enchantments")) {
String[] splittedEnchantment = enchantment.split(" ");
if (Enchantment.getByName(splittedEnchantment[0].toUpperCase()) != null) {
if (splittedEnchantment.length > 1) {
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), P.p.parseInt(splittedEnchantment[1]), true);
} else {
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), 1, true);
}
} else {
P.p.log(P.p.language.get("Log_Error_MobEnchantment", splittedEnchantment[0]));
}
}
}
/* Item Name */
if (configSetion.contains(dropPath + ".name")) {
itemMeta.setDisplayName(configSetion.getString(dropPath + ".name"));
}
/* Item Lore */
if (configSetion.contains(dropPath + ".lore")) {
String[] lore = configSetion.getString(dropPath + ".lore").split("//");
itemMeta.setLore(Arrays.asList(lore));
}
/* Drop chance */
if (configSetion.contains(dropPath + ".chance")) {
chance = configSetion.getInt(dropPath + ".chance");
}
/* Add Item to the drops map */
item.setItemMeta(itemMeta);
mobType.drops.put(item, chance);
}
}
} else {
P.p.log(P.p.language.get("Log_Error_MobType", configFile.getString(mobName + ".Type")));
}
}
}
return set;
}
// Get
public static DMobType get(String name, Set<DMobType> mobTypes) {
for (DMobType mobType : mobTypes) {
if (mobType.name.equalsIgnoreCase(name)) {
return mobType;
}
}
if (P.p.mainConfig.defaultDungeon != null) {
for (DMobType mobType : P.p.mainConfig.defaultDungeon.getMobTypes()) {
if (mobType.name.equalsIgnoreCase(name)) {
return mobType;
}
}
}
return null;
}
public String getName() {
return name;
}
}
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.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class DMobType {
private String name;
private EntityType type;
private int maxHealth;
private ItemStack ItemHand;
private ItemStack ItemHelmet;
private ItemStack ItemChestplate;
private ItemStack ItemLeggings;
private ItemStack ItemBoots;
private Map<ItemStack, Integer> drops = new HashMap<ItemStack, Integer>();
/* Extra Values for different Mob Types */
private boolean isWitherSkeleton = false;
private String ocelotType = null;
/* Methods */
public DMobType(String name, EntityType type) {
this.name = name;
this.type = type;
}
public void spawn(GameWorld gWorld, Location loc) {
if (type != null) {
if (type.isAlive()) {
LivingEntity entity = (LivingEntity) gWorld.world.spawnEntity(loc, type);
/* Set the Items */
entity.getEquipment().setItemInHand(ItemHand);
entity.getEquipment().setHelmet(ItemHelmet);
entity.getEquipment().setChestplate(ItemChestplate);
entity.getEquipment().setLeggings(ItemLeggings);
entity.getEquipment().setBoots(ItemBoots);
/* Check mob specified stuff */
if (type == EntityType.SKELETON) {
if (isWitherSkeleton) {
((Skeleton) entity).setSkeletonType(SkeletonType.WITHER);
} else {
((Skeleton) entity).setSkeletonType(SkeletonType.NORMAL);
}
}
if (type == EntityType.OCELOT) {
Ocelot ocelot = (Ocelot) entity;
if (ocelotType != null) {
if (ocelotType.equalsIgnoreCase("BLACK_CAT")) {
ocelot.setCatType(Ocelot.Type.BLACK_CAT);
} else if (ocelotType.equalsIgnoreCase("RED_CAT")) {
ocelot.setCatType(Ocelot.Type.RED_CAT);
} else if (ocelotType.equalsIgnoreCase("SIAMESE_CAT")) {
ocelot.setCatType(Ocelot.Type.SIAMESE_CAT);
} else if (ocelotType.equalsIgnoreCase("WILD_OCELOT")) {
ocelot.setCatType(Ocelot.Type.WILD_OCELOT);
}
}
}
/* Set Health */
if (maxHealth > 0) {
entity.setMaxHealth(maxHealth);
entity.setHealth(maxHealth);
}
/* Disable Despawning */
entity.setRemoveWhenFarAway(false);
/* Spawn Mob */
new DMob(entity, gWorld, this);
}
}
}
// Load Config
@SuppressWarnings("deprecation")
public static Set<DMobType> load(ConfigurationSection configFile) {
Set<DMobType> set = new HashSet<DMobType>();
if (configFile != null) {
// Read Mobs
for (String mobName : configFile.getKeys(false)) {
EntityType type = EntityType.fromName(configFile.getString(mobName + ".Type"));
if (type != null) {
DMobType mobType = new DMobType(mobName, type);
set.add(mobType);
// Load MaxHealth
if (configFile.contains(mobName + ".MaxHealth")) {
mobType.maxHealth = configFile.getInt(mobName + ".MaxHealth");
}
// Load Items
if (configFile.contains(mobName + ".ItemHelmet")) {
mobType.ItemHelmet = new ItemStack(configFile.getInt(mobName + ".ItemHelmet"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemHelmet"))).getItem();
}
if (configFile.contains(mobName + ".ItemChestplate")) {
mobType.ItemChestplate = new ItemStack(configFile.getInt(mobName + ".ItemChestplate"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemChestplate"))).getItem();
}
if (configFile.contains(mobName + ".ItemBoots")) {
mobType.ItemBoots = new ItemStack(configFile.getInt(mobName + ".ItemBoots"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemBoots"))).getItem();
}
if (configFile.contains(mobName + ".ItemLeggings")) {
mobType.ItemLeggings = new ItemStack(configFile.getInt(mobName + ".ItemLeggings"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemLeggings"))).getItem();
}
if (configFile.contains(mobName + ".ItemHand")) {
mobType.ItemHand = new ItemStack(configFile.getInt(mobName + ".ItemHand"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemHand"))).getItem();
}
// Load different Mob options
if (configFile.contains(mobName + ".isWitherSkeleton")) {
mobType.isWitherSkeleton = configFile.getBoolean(mobName + ".isWitherSkeleton");
}
if (configFile.contains(mobName + ".ocelotType")) {
mobType.ocelotType = configFile.getString(mobName + ".ocelotType");
}
// Drops
ConfigurationSection configSetion = configFile.getConfigurationSection(mobName + ".drops");
if (configSetion != null) {
Set<String> list = configSetion.getKeys(false);
for (String dropPath : list) {
ItemStack item = null;
ItemMeta itemMeta = null;
int chance = 100;
/* Item Stack */
Material mat = Material.getMaterial(configSetion.getInt(dropPath + ".id"));
int amount = 1;
short data = 0;
if (configSetion.contains(dropPath + ".amount")) {
amount = configSetion.getInt(dropPath + ".amount");
}
if (configSetion.contains(dropPath + ".data")) {
data = Short.parseShort(configSetion.getString(dropPath + ".data"));
}
item = new ItemStack(mat, amount, data);
itemMeta = item.getItemMeta();
/* Enchantments */
if (configSetion.contains(dropPath + ".enchantments")) {
for (String enchantment : configSetion.getStringList(dropPath + ".enchantments")) {
String[] splittedEnchantment = enchantment.split(" ");
if (Enchantment.getByName(splittedEnchantment[0].toUpperCase()) != null) {
if (splittedEnchantment.length > 1) {
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), IntegerUtil.parseInt(splittedEnchantment[1]), true);
} else {
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), 1, true);
}
} else {
DungeonsXL.getPlugin().log(DungeonsXL.getPlugin().getDMessages().get("Log_Error_MobEnchantment", splittedEnchantment[0]));
}
}
}
/* Item Name */
if (configSetion.contains(dropPath + ".name")) {
itemMeta.setDisplayName(configSetion.getString(dropPath + ".name"));
}
/* Item Lore */
if (configSetion.contains(dropPath + ".lore")) {
String[] lore = configSetion.getString(dropPath + ".lore").split("//");
itemMeta.setLore(Arrays.asList(lore));
}
/* Drop chance */
if (configSetion.contains(dropPath + ".chance")) {
chance = configSetion.getInt(dropPath + ".chance");
}
/* Add Item to the drops map */
item.setItemMeta(itemMeta);
mobType.getDrops().put(item, chance);
}
}
} else {
DungeonsXL.getPlugin().log(DungeonsXL.getPlugin().getDMessages().get("Log_Error_MobType", configFile.getString(mobName + ".Type")));
}
}
}
return set;
}
// Get
public static DMobType get(String name, Set<DMobType> mobTypes) {
for (DMobType mobType : mobTypes) {
if (mobType.name.equalsIgnoreCase(name)) {
return mobType;
}
}
if (DungeonsXL.getPlugin().getMainConfig().defaultDungeon != null) {
for (DMobType mobType : DungeonsXL.getPlugin().getMainConfig().defaultDungeon.getMobTypes()) {
if (mobType.name.equalsIgnoreCase(name)) {
return mobType;
}
}
}
return null;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the 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,182 +1,181 @@
package com.dre.dungeonsxl;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.inventory.ItemStack;
import com.dre.dungeonsxl.util.DUtility;
public class DSavePlayer {
private static P p = P.p;
private static CopyOnWriteArrayList<DSavePlayer> savePlayers = new CopyOnWriteArrayList<DSavePlayer>();
// Variables
private String playerName;
private String uuid;
private Location oldLocation;
private ItemStack[] oldInventory;
private ItemStack[] oldArmor;
private int oldLvl;
private int oldExp;
private int oldHealth;
private int oldFoodLevel;
private int oldFireTicks;
private GameMode oldGamemode;
private Collection<PotionEffect> oldPotionEffects;
public DSavePlayer(String playerName, UUID uuid, Location oldLocation, ItemStack[] oldInventory, ItemStack[] oldArmor, int oldLvl, int oldExp, int oldHealth, int oldFoodLevel, int oldFireTicks,
GameMode oldGamemode, Collection<PotionEffect> oldPotionEffects) {
savePlayers.add(this);
this.playerName = playerName;
this.uuid = uuid.toString();
this.oldLocation = oldLocation;
this.oldInventory = oldInventory;
this.oldArmor = oldArmor;
this.oldExp = oldExp;
this.oldHealth = oldHealth;
this.oldFoodLevel = oldFoodLevel;
this.oldGamemode = oldGamemode;
this.oldLvl = oldLvl;
this.oldFireTicks = oldFireTicks;
this.oldPotionEffects = oldPotionEffects;
save();
}
public void reset(boolean keepInventory) {
Player onlinePlayer = p.getServer().getPlayer(this.playerName);
try{
if (onlinePlayer != null) {
/* Player is online */
if (!keepInventory) {
onlinePlayer.getInventory().setContents(this.oldInventory);
onlinePlayer.getInventory().setArmorContents(this.oldArmor);
onlinePlayer.setTotalExperience(this.oldExp);
onlinePlayer.setLevel(this.oldLvl);
onlinePlayer.setHealth(this.oldHealth);
onlinePlayer.setFoodLevel(this.oldFoodLevel);
onlinePlayer.setGameMode(this.oldGamemode);
onlinePlayer.setFireTicks(this.oldFireTicks);
for (PotionEffect effect : onlinePlayer.getActivePotionEffects()) {
onlinePlayer.removePotionEffect(effect.getType());
}
onlinePlayer.addPotionEffects(this.oldPotionEffects);
}
DUtility.secureTeleport(onlinePlayer, this.oldLocation);
} 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();
}
}
} catch (NullPointerException exception) {
P.p.log("Corrupt playerdata detected and removed!");
}
savePlayers.remove(this);
save();
}
// Static
public static void save() {
FileConfiguration configFile = new YamlConfiguration();
for (DSavePlayer savePlayer : savePlayers) {
configFile.set(savePlayer.playerName + ".uuid", savePlayer.uuid);
configFile.set(savePlayer.playerName + ".oldGamemode", savePlayer.oldGamemode.getValue());
configFile.set(savePlayer.playerName + ".oldFireTicks", savePlayer.oldFireTicks);
configFile.set(savePlayer.playerName + ".oldFoodLevel", savePlayer.oldFoodLevel);
configFile.set(savePlayer.playerName + ".oldHealth", savePlayer.oldHealth);
configFile.set(savePlayer.playerName + ".oldExp", savePlayer.oldExp);
configFile.set(savePlayer.playerName + ".oldLvl", savePlayer.oldLvl);
configFile.set(savePlayer.playerName + ".oldArmor", savePlayer.oldArmor);
configFile.set(savePlayer.playerName + ".oldInventory", savePlayer.oldInventory);
configFile.set(savePlayer.playerName + ".oldLocation.x", savePlayer.oldLocation.getX());
configFile.set(savePlayer.playerName + ".oldLocation.y", savePlayer.oldLocation.getY());
configFile.set(savePlayer.playerName + ".oldLocation.z", savePlayer.oldLocation.getZ());
configFile.set(savePlayer.playerName + ".oldLocation.yaw", savePlayer.oldLocation.getYaw());
configFile.set(savePlayer.playerName + ".oldLocation.pitch", savePlayer.oldLocation.getPitch());
configFile.set(savePlayer.playerName + ".oldLocation.world", savePlayer.oldLocation.getWorld().getName());
configFile.set(savePlayer.playerName + ".oldPotionEffects", savePlayer.oldPotionEffects);
}
try {
configFile.save(new File(p.getDataFolder(), "savePlayers.yml"));
} catch (IOException e) {
e.printStackTrace();
}
}
@SuppressWarnings("unchecked")
public static void load() {
FileConfiguration configFile = YamlConfiguration.loadConfiguration(new File(p.getDataFolder(), "savePlayers.yml"));
for (String playerName : configFile.getKeys(false)) {
// Load uuid
UUID uuid = UUID.fromString(configFile.getString(playerName + ".uuid"));
// Load inventory data
ArrayList<ItemStack> oldInventoryList = (ArrayList<ItemStack>) configFile.get(playerName + ".oldInventory");
ArrayList<ItemStack> oldArmorList = (ArrayList<ItemStack>) configFile.get(playerName + ".oldArmor");
ItemStack[] oldInventory = oldInventoryList.toArray(new ItemStack[oldInventoryList.size()]);
ItemStack[] oldArmor = oldArmorList.toArray(new ItemStack[oldArmorList.size()]);
// Load other data
int oldLvl = configFile.getInt(playerName + ".oldLvl");
int oldExp = configFile.getInt(playerName + ".oldExp");
int oldHealth = configFile.getInt(playerName + ".oldHealth");
int oldFoodLevel = configFile.getInt(playerName + ".oldFoodLevel");
int oldFireTicks = configFile.getInt(playerName + ".oldFireTicks");
GameMode oldGamemode = GameMode.getByValue(configFile.getInt(playerName + ".oldGamemode"));
Collection<PotionEffect> oldPotionEffects = (Collection<PotionEffect>) configFile.get(playerName + ".oldPotionEffects");
// Location
World world = p.getServer().getWorld(configFile.getString(playerName + ".oldLocation.world"));
if (world == null) {
world = p.getServer().getWorlds().get(0);
}
Location oldLocation = new Location(world, configFile.getDouble(playerName + ".oldLocation.x"), configFile.getDouble(playerName + ".oldLocation.y"), configFile.getDouble(playerName
+ ".oldLocation.z"), configFile.getInt(playerName + ".oldLocation.yaw"), configFile.getInt(playerName + ".oldLocation.pitch"));
// Create Player
DSavePlayer savePlayer = new DSavePlayer(playerName, uuid, oldLocation, oldInventory, oldArmor, oldLvl, oldExp, oldHealth, oldFoodLevel, oldFireTicks, oldGamemode, oldPotionEffects);
savePlayer.reset(false);
}
}
}
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.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
public class DSavePlayer {
static DungeonsXL plugin = DungeonsXL.getPlugin();
private static CopyOnWriteArrayList<DSavePlayer> savePlayers = new CopyOnWriteArrayList<DSavePlayer>();
// Variables
private String playerName;
private String uuid;
private Location oldLocation;
private ItemStack[] oldInventory;
private ItemStack[] oldArmor;
private int oldLvl;
private int oldExp;
private int oldHealth;
private int oldFoodLevel;
private int oldFireTicks;
private GameMode oldGamemode;
private Collection<PotionEffect> oldPotionEffects;
public DSavePlayer(String playerName, UUID uuid, Location oldLocation, ItemStack[] oldInventory, ItemStack[] oldArmor, int oldLvl, int oldExp, int oldHealth, int oldFoodLevel, int oldFireTicks,
GameMode oldGamemode, Collection<PotionEffect> oldPotionEffects) {
savePlayers.add(this);
this.playerName = playerName;
this.uuid = uuid.toString();
this.oldLocation = oldLocation;
this.oldInventory = oldInventory;
this.oldArmor = oldArmor;
this.oldExp = oldExp;
this.oldHealth = oldHealth;
this.oldFoodLevel = oldFoodLevel;
this.oldGamemode = oldGamemode;
this.oldLvl = oldLvl;
this.oldFireTicks = oldFireTicks;
this.oldPotionEffects = oldPotionEffects;
save();
}
public void reset(boolean keepInventory) {
@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 {
if ( !keepInventory) {
player.getInventory().setContents(oldInventory);
player.getInventory().setArmorContents(oldArmor);
player.setTotalExperience(oldExp);
player.setLevel(oldLvl);
player.setHealth(oldHealth);
player.setFoodLevel(oldFoodLevel);
player.setGameMode(oldGamemode);
player.setFireTicks(oldFireTicks);
for (PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType());
}
// Causes NPE if offline
if ( !offline) {
player.addPotionEffects(oldPotionEffects);
} else {
player.saveData();
}
}
if ( !offline) {
MiscUtil.secureTeleport(player, oldLocation);
}
} catch (NullPointerException exception) {
plugin.log("Corrupted playerdata detected and removed!");
}
savePlayers.remove(this);
save();
}
// Static
@SuppressWarnings("deprecation")
public static void save() {
FileConfiguration configFile = new YamlConfiguration();
for (DSavePlayer savePlayer : savePlayers) {
configFile.set(savePlayer.playerName + ".uuid", savePlayer.uuid);
configFile.set(savePlayer.playerName + ".oldGamemode", savePlayer.oldGamemode.getValue());
configFile.set(savePlayer.playerName + ".oldFireTicks", savePlayer.oldFireTicks);
configFile.set(savePlayer.playerName + ".oldFoodLevel", savePlayer.oldFoodLevel);
configFile.set(savePlayer.playerName + ".oldHealth", savePlayer.oldHealth);
configFile.set(savePlayer.playerName + ".oldExp", savePlayer.oldExp);
configFile.set(savePlayer.playerName + ".oldLvl", savePlayer.oldLvl);
configFile.set(savePlayer.playerName + ".oldArmor", savePlayer.oldArmor);
configFile.set(savePlayer.playerName + ".oldInventory", savePlayer.oldInventory);
configFile.set(savePlayer.playerName + ".oldLocation.x", savePlayer.oldLocation.getX());
configFile.set(savePlayer.playerName + ".oldLocation.y", savePlayer.oldLocation.getY());
configFile.set(savePlayer.playerName + ".oldLocation.z", savePlayer.oldLocation.getZ());
configFile.set(savePlayer.playerName + ".oldLocation.yaw", savePlayer.oldLocation.getYaw());
configFile.set(savePlayer.playerName + ".oldLocation.pitch", savePlayer.oldLocation.getPitch());
configFile.set(savePlayer.playerName + ".oldLocation.world", savePlayer.oldLocation.getWorld().getName());
configFile.set(savePlayer.playerName + ".oldPotionEffects", savePlayer.oldPotionEffects);
}
try {
configFile.save(new File(plugin.getDataFolder(), "savePlayers.yml"));
} catch (IOException e) {
e.printStackTrace();
}
}
@SuppressWarnings({"unchecked", "deprecation"})
public static void load() {
FileConfiguration configFile = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "savePlayers.yml"));
for (String playerName : configFile.getKeys(false)) {
// Load uuid
UUID uuid = UUID.fromString(configFile.getString(playerName + ".uuid"));
// Load inventory data
ArrayList<ItemStack> oldInventoryList = (ArrayList<ItemStack>) configFile.get(playerName + ".oldInventory");
ArrayList<ItemStack> oldArmorList = (ArrayList<ItemStack>) configFile.get(playerName + ".oldArmor");
ItemStack[] oldInventory = oldInventoryList.toArray(new ItemStack[oldInventoryList.size()]);
ItemStack[] oldArmor = oldArmorList.toArray(new ItemStack[oldArmorList.size()]);
// Load other data
int oldLvl = configFile.getInt(playerName + ".oldLvl");
int oldExp = configFile.getInt(playerName + ".oldExp");
int oldHealth = configFile.getInt(playerName + ".oldHealth");
int oldFoodLevel = configFile.getInt(playerName + ".oldFoodLevel");
int oldFireTicks = configFile.getInt(playerName + ".oldFireTicks");
GameMode oldGamemode = GameMode.getByValue(configFile.getInt(playerName + ".oldGamemode"));
Collection<PotionEffect> oldPotionEffects = (Collection<PotionEffect>) configFile.get(playerName + ".oldPotionEffects");
// Location
World world = plugin.getServer().getWorld(configFile.getString(playerName + ".oldLocation.world"));
if (world == null) {
world = plugin.getServer().getWorlds().get(0);
}
Location oldLocation = new Location(world, configFile.getDouble(playerName + ".oldLocation.x"), configFile.getDouble(playerName + ".oldLocation.y"), configFile.getDouble(playerName
+ ".oldLocation.z"), configFile.getInt(playerName + ".oldLocation.yaw"), configFile.getInt(playerName + ".oldLocation.pitch"));
// Create Player
DSavePlayer savePlayer = new DSavePlayer(playerName, uuid, oldLocation, oldInventory, oldArmor, oldLvl, oldExp, oldHealth, oldFoodLevel, oldFireTicks, oldGamemode, oldPotionEffects);
savePlayer.reset(false);
}
}
}

View File

@ -1,15 +1,17 @@
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 com.dre.dungeonsxl.game.GameWorld;
public class SIGNBlock extends DSign {
import org.bukkit.block.Sign;
public class BlockSign extends DSign {
public static String name = "Block";
public String buildPermissions = "dxl.sign.block";
public boolean onDungeonInit = false;
// Variables
private boolean initialized;
private boolean active;
@ -17,74 +19,76 @@ public class SIGNBlock extends DSign {
private int onBlockId = 0;
private byte offBlockData = 0x0;
private byte onBlockData = 0x0;
public SIGNBlock(Sign sign, GameWorld gworld) {
public BlockSign(Sign sign, GameWorld gworld) {
super(sign, gworld);
}
@Override
public boolean check() {
// TODO Auto-generated method stub
return true;
}
@SuppressWarnings("deprecation")
@Override
public void onInit() {
String lines[] = sign.getLines();
if (!lines[1].equals("")) {
String lines[] = getSign().getLines();
if ( !lines[1].equals("")) {
String line1[] = lines[1].split(",");
Material offBlock = Material.matchMaterial(line1[0]);
if (offBlock != null) {
offBlockId = offBlock.getId();
} else {
offBlockId = p.parseInt(line1[0]);
offBlockId = IntegerUtil.parseInt(line1[0]);
}
if (line1.length > 1) {
offBlockData = (byte) p.parseInt(line1[1]);
offBlockData = (byte) IntegerUtil.parseInt(line1[1]);
}
}
if (!lines[2].equals("")) {
if ( !lines[2].equals("")) {
String line2[] = lines[2].split(",");
Material onBlock = Material.matchMaterial(line2[0]);
if (onBlock != null) {
onBlockId = onBlock.getId();
} else {
onBlockId = p.parseInt(line2[0]);
onBlockId = IntegerUtil.parseInt(line2[0]);
}
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;
}
@SuppressWarnings("deprecation")
@Override
public void onTrigger() {
if (initialized && !active) {
sign.getBlock().setTypeIdAndData(onBlockId, onBlockData, true);
getSign().getBlock().setTypeIdAndData(onBlockId, onBlockData, true);
active = true;
}
}
@SuppressWarnings("deprecation")
@Override
public void onDisable() {
if (initialized && active) {
sign.getBlock().setTypeIdAndData(offBlockId, offBlockData, true);
getSign().getBlock().setTypeIdAndData(offBlockId, offBlockData, true);
active = false;
}
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

View File

@ -1,80 +1,79 @@
package com.dre.dungeonsxl.signs;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import com.dre.dungeonsxl.DPlayer;
import com.dre.dungeonsxl.P;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNCheckpoint extends DSign {
public static String name = "Checkpoint";
private String buildPermissions = "dxl.sign.checkpoint";
private boolean onDungeonInit = false;
// Variables
private boolean initialized;
private CopyOnWriteArrayList<DPlayer> done = new CopyOnWriteArrayList<DPlayer>();
public SIGNCheckpoint(Sign sign, GameWorld gworld) {
super(sign, gworld);
}
@Override
public boolean check() {
// TODO Auto-generated method stub
return true;
}
@Override
public void onInit() {
sign.getBlock().setType(Material.AIR);
initialized = true;
}
@Override
public void onTrigger() {
if (initialized) {
for (DPlayer dplayer : DPlayer.get(this.gworld.world)) {
dplayer.setCheckpoint(this.sign.getLocation());
P.p.msg(dplayer.player, P.p.language.get("Player_CheckpointReached"));
}
remove();
}
}
@Override
public boolean onPlayerTrigger(Player player) {
if (initialized) {
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
if (!done.contains(dplayer)) {
done.add(dplayer);
dplayer.setCheckpoint(this.sign.getLocation());
P.p.msg(player, P.p.language.get("Player_CheckpointReached"));
}
}
if (done.size() >= DPlayer.get(this.gworld.world).size()) {
remove();
}
}
return true;
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}
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 org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
public class CheckpointSign extends DSign {
public static String name = "Checkpoint";
private String buildPermissions = "dxl.sign.checkpoint";
private boolean onDungeonInit = false;
// Variables
private boolean initialized;
private CopyOnWriteArrayList<DPlayer> done = new CopyOnWriteArrayList<DPlayer>();
public CheckpointSign(Sign sign, GameWorld gWorld) {
super(sign, gWorld);
}
@Override
public boolean check() {
return true;
}
@Override
public void onInit() {
getSign().getBlock().setType(Material.AIR);
initialized = true;
}
@Override
public void onTrigger() {
if (initialized) {
for (DPlayer dplayer : DPlayer.get(getGWorld().world)) {
dplayer.setCheckpoint(getSign().getLocation());
MessageUtil.sendMessage(dplayer.player, DungeonsXL.getPlugin().getDMessages().get("Player_CheckpointReached"));
}
remove();
}
}
@Override
public boolean onPlayerTrigger(Player player) {
if (initialized) {
DPlayer dplayer = DPlayer.get(player);
if (dplayer != null) {
if ( !done.contains(dplayer)) {
done.add(dplayer);
dplayer.setCheckpoint(getSign().getLocation());
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Player_CheckpointReached"));
}
}
if (done.size() >= DPlayer.get(getGWorld().world).size()) {
remove();
}
}
return true;
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

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,102 +1,103 @@
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.Set;
import org.bukkit.block.Sign;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
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;
import com.dre.dungeonsxl.EditWorld;
import com.dre.dungeonsxl.trigger.InteractTrigger;
public class SIGNInteract extends DSign {
public class InteractSign extends DSign {
public static String name = "Interact";
public String buildPermissions = "dxl.sign.trigger";
public boolean onDungeonInit = true;
public SIGNInteract(Sign sign, GameWorld gworld) {
super(sign, gworld);
public InteractSign(Sign sign, GameWorld gWorld) {
super(sign, gWorld);
}
@Override
public boolean check() {
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.getChunk().isLoaded()) {
if ( !block.getChunk().isLoaded()) {
block.getChunk().load();
}
if (block.getState() instanceof Sign) {
Sign rsign = (Sign) block.getState();
if (rsign.getLine(0).equalsIgnoreCase("[" + name + "]")) {
used.add(p.parseInt(rsign.getLine(1)));
used.add(IntegerUtil.parseInt(rsign.getLine(1)));
}
}
}
}
int id = 1;
if (sign.getLine(1).equalsIgnoreCase("")) {
if (getSign().getLine(1).equalsIgnoreCase("")) {
if (used.size() != 0) {
while (used.contains(id)) {
id++;
}
}
} else {
id = p.parseInt(sign.getLine(1));
id = IntegerUtil.parseInt(getSign().getLine(1));
if (id == 0 || used.contains(id)) {
return false;
} else {
return true;
}
}
sign.setLine(1, id + "");
p.getServer().getScheduler().scheduleSyncDelayedTask(p, new UpdateTask(), 2);
getSign().setLine(1, id + "");
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new UpdateTask(), 2);
return true;
}
@Override
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) {
trigger.addListener(this);
this.triggers.add(trigger);
addTrigger(trigger);
}
sign.setLine(0, ChatColor.DARK_BLUE + "############");
sign.setLine(1, ChatColor.GREEN + sign.getLine(2));
sign.setLine(2, ChatColor.GREEN + sign.getLine(3));
sign.setLine(3, ChatColor.DARK_BLUE + "############");
sign.update();
getSign().setLine(0, ChatColor.DARK_BLUE + "############");
getSign().setLine(1, ChatColor.GREEN + getSign().getLine(2));
getSign().setLine(2, ChatColor.GREEN + getSign().getLine(3));
getSign().setLine(3, ChatColor.DARK_BLUE + "############");
getSign().update();
}
@Override
public boolean onPlayerTrigger(Player player) {
return true;
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
public class UpdateTask implements Runnable {
public UpdateTask() {
}
@Override
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,40 +1,40 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNLobby extends DSign {
public static String name = "Lobby";
public String buildPermissions = "dxl.sign.lobby";
public boolean onDungeonInit = true;
public SIGNLobby(Sign sign, GameWorld gworld) {
super(sign, gworld);
}
@Override
public boolean check() {
// TODO Auto-generated method stub
return true;
}
@Override
public void onInit() {
gworld.locLobby = sign.getLocation();
sign.getBlock().setType(Material.AIR);
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
import org.bukkit.Material;
import org.bukkit.block.Sign;
public class LobbySign extends DSign {
public static String name = "Lobby";
public String buildPermissions = "dxl.sign.lobby";
public boolean onDungeonInit = true;
public LobbySign(Sign sign, GameWorld gWorld) {
super(sign, gWorld);
}
@Override
public boolean check() {
// TODO Auto-generated method stub
return true;
}
@Override
public void onInit() {
getGWorld().locLobby = getSign().getLocation();
getSign().getBlock().setType(Material.AIR);
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

View File

@ -1,170 +1,172 @@
package com.dre.dungeonsxl.signs;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Sign;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.Location;
import com.dre.dungeonsxl.DMobType;
import com.dre.dungeonsxl.game.DMob;
import com.dre.dungeonsxl.game.GameWorld;
public class SIGNMob extends DSign {
public static String name = "Mob";
public String buildPermissions = "dxl.sign.mob";
public boolean onDungeonInit = false;
// Variables
private String mob;
private int maxinterval = 1;
private int interval = 0;
private int amount = 1;
private boolean initialized;
private boolean active;
private int taskId = -1;
public SIGNMob(Sign sign, GameWorld gworld) {
super(sign, gworld);
}
@Override
public boolean check() {
String lines[] = sign.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() {
String lines[] = sign.getLines();
if (!lines[1].equals("") && !lines[2].equals("")) {
String mob = lines[1];
if (mob != null) {
String[] atributes = lines[2].split(",");
if (atributes.length == 2) {
this.mob = mob;
this.maxinterval = p.parseInt(atributes[0]);
this.amount = p.parseInt(atributes[1]);
}
}
}
sign.getBlock().setType(Material.AIR);
initialized = true;
}
@Override
public void onTrigger() {
if (initialized && !active) {
MobSpawnScheduler scheduler = new MobSpawnScheduler(this);
taskId = p.getServer().getScheduler().scheduleSyncRepeatingTask(p, scheduler, 0L, 20L);
active = true;
}
}
@Override
public void onDisable() {
if (initialized && active) {
killTask();
interval = 0;
active = false;
}
}
public void killTask() {
if (initialized && active) {
if (taskId != -1) {
p.getServer().getScheduler().cancelTask(taskId);
taskId = -1;
}
}
}
public class MobSpawnScheduler implements Runnable {
private SIGNMob sign;
public MobSpawnScheduler(SIGNMob sign) {
this.sign = sign;
}
@Override
public void run() {
if (sign.interval <= 0) {
World world = sign.sign.getWorld();
GameWorld gworld = GameWorld.get(world);
if (gworld != null) {
Location spawnLoc = sign.sign.getLocation().add(0.5, 0, 0.5);
// Check normal mobs
if (EntityType.fromName(sign.mob) != null) {
if (EntityType.fromName(sign.mob).isAlive()) {
LivingEntity entity = (LivingEntity) world.spawnEntity(spawnLoc, EntityType.fromName(sign.mob));
// Add Bow to normal Skeletons
if (entity.getType() == EntityType.SKELETON) {
Skeleton skeleton = (Skeleton) entity;
if (skeleton.getSkeletonType() == SkeletonType.NORMAL) {
skeleton.getEquipment().setItemInHand(new ItemStack(Material.BOW));
}
}
// Disable Despawning
entity.setRemoveWhenFarAway(false);
new DMob(entity, sign.gworld, null);
}
}
// Check custom mobs
DMobType mobType = DMobType.get(sign.mob, gworld.config.getMobTypes());
if (mobType != null) {
mobType.spawn(GameWorld.get(world), spawnLoc);
}
// Set the amount
if (amount != -1) {
if (amount > 1) {
amount--;
} else {
killTask();
sign.remove();
}
}
sign.interval = sign.maxinterval;
} else {
sign.killTask();
}
}
sign.interval--;
}
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}
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.World;
import org.bukkit.block.Sign;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.inventory.ItemStack;
public class MobSign extends DSign {
public static String name = "Mob";
public String buildPermissions = "dxl.sign.mob";
public boolean onDungeonInit = false;
// Variables
private String mob;
private int maxinterval = 1;
private int interval = 0;
private int amount = 1;
private boolean initialized;
private boolean active;
private int taskId = -1;
public MobSign(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() {
String lines[] = getSign().getLines();
if ( !lines[1].equals("") && !lines[2].equals("")) {
String mob = lines[1];
if (mob != null) {
String[] atributes = lines[2].split(",");
if (atributes.length == 2) {
this.mob = mob;
maxinterval = IntegerUtil.parseInt(atributes[0]);
amount = IntegerUtil.parseInt(atributes[1]);
}
}
}
getSign().getBlock().setType(Material.AIR);
initialized = true;
}
@Override
public void onTrigger() {
if (initialized && !active) {
MobSpawnScheduler scheduler = new MobSpawnScheduler(this);
taskId = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, scheduler, 0L, 20L);
active = true;
}
}
@Override
public void onDisable() {
if (initialized && active) {
killTask();
interval = 0;
active = false;
}
}
public void killTask() {
if (initialized && active) {
if (taskId != -1) {
plugin.getServer().getScheduler().cancelTask(taskId);
taskId = -1;
}
}
}
public class MobSpawnScheduler implements Runnable {
private MobSign sign;
public MobSpawnScheduler(MobSign sign) {
this.sign = sign;
}
@SuppressWarnings("deprecation")
@Override
public void run() {
if (sign.interval <= 0) {
World world = sign.getSign().getWorld();
GameWorld gWorld = GameWorld.get(world);
if (gWorld != null) {
Location spawnLoc = sign.getSign().getLocation().add(0.5, 0, 0.5);
// Check normal mobs
if (EntityType.fromName(sign.mob) != null) {
if (EntityType.fromName(sign.mob).isAlive()) {
LivingEntity entity = (LivingEntity) world.spawnEntity(spawnLoc, EntityType.fromName(sign.mob));
// Add Bow to normal Skeletons
if (entity.getType() == EntityType.SKELETON) {
Skeleton skeleton = (Skeleton) entity;
if (skeleton.getSkeletonType() == SkeletonType.NORMAL) {
skeleton.getEquipment().setItemInHand(new ItemStack(Material.BOW));
}
}
// Disable Despawning
entity.setRemoveWhenFarAway(false);
new DMob(entity, sign.getGWorld(), null);
}
}
// Check custom mobs
DMobType mobType = DMobType.get(sign.mob, gWorld.getConfig().getMobTypes());
if (mobType != null) {
mobType.spawn(GameWorld.get(world), spawnLoc);
}
// Set the amount
if (amount != -1) {
if (amount > 1) {
amount--;
} else {
killTask();
sign.remove();
}
}
sign.interval = sign.maxinterval;
} else {
sign.killTask();
}
}
sign.interval--;
}
}
@Override
public String getPermissions() {
return buildPermissions;
}
@Override
public boolean isOnDungeonInit() {
return onDungeonInit;
}
}

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