#48: Script system for mobs and classes

This commit is contained in:
Daniel Saukel 2016-05-15 00:49:01 +02:00
parent 3896e14ef4
commit 1b7842ea80
34 changed files with 620 additions and 450 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/nb-configuration.xml
/target
/dependency-reduced-pom.xml
licenseheader.txt

View File

@ -32,7 +32,9 @@ import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GameTypes;
import io.github.dre2n.dungeonsxl.global.GlobalProtections;
import io.github.dre2n.dungeonsxl.listener.*;
import io.github.dre2n.dungeonsxl.mob.DMobTypes;
import io.github.dre2n.dungeonsxl.mob.ExternalMobProviders;
import io.github.dre2n.dungeonsxl.player.DClasses;
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPermissions;
@ -69,6 +71,8 @@ public class DungeonsXL extends BRPlugin {
public static File MAPS;
public static File SCRIPTS;
public static File ANNOUNCERS;
public static File CLASSES;
public static File MOBS;
private DataConfig dataConfig;
private MainConfig mainConfig;
@ -85,6 +89,8 @@ public class DungeonsXL extends BRPlugin {
private ExternalMobProviders dMobProviders;
private DPlayers dPlayers;
private Announcers announcers;
private DClasses dClasses;
private DMobTypes dMobTypes;
private BukkitTask announcerTask;
private BukkitTask worldUnloadTask;
@ -142,6 +148,8 @@ public class DungeonsXL extends BRPlugin {
loadExternalMobProviders();
loadDPlayers();
loadAnnouncers(ANNOUNCERS);
loadDClasses(CLASSES);
loadDMobTypes(MOBS);
manager.registerEvents(new EntityListener(), this);
manager.registerEvents(new GUIListener(), this);
@ -224,6 +232,16 @@ public class DungeonsXL extends BRPlugin {
if (!ANNOUNCERS.exists()) {
ANNOUNCERS.mkdir();
}
CLASSES = new File(CLASSES, "classes");
if (!CLASSES.exists()) {
CLASSES.mkdir();
}
MOBS = new File(MOBS, "mobs");
if (!MOBS.exists()) {
MOBS.mkdir();
}
}
// Save and load
@ -497,6 +515,34 @@ public class DungeonsXL extends BRPlugin {
announcers = new Announcers(file);
}
/**
* @return the loaded instance of DClasses
*/
public DClasses getDClasses() {
return dClasses;
}
/**
* load / reload a new instance of DClasses
*/
public void loadDClasses(File file) {
dClasses = new DClasses(file);
}
/**
* @return the loaded instance of DMobTypes
*/
public DMobTypes getDMobTypes() {
return dMobTypes;
}
/**
* load / reload a new instance of DMobTypes
*/
public void loadDMobTypes(File file) {
dMobTypes = new DMobTypes(file);
}
/**
* @return the worldUnloadTask
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -24,6 +24,7 @@ import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent;
import io.github.dre2n.dungeonsxl.player.DGroup;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -32,6 +33,8 @@ import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@ -58,6 +61,45 @@ public class Announcer {
private List<DGroup> dGroups;
private List<ItemStack> buttons;
/**
* @param file
* the script file
*/
public Announcer(File file) {
this(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file));
}
/**
* @param name
* the name of the Announcer
* @param config
* the config that stores the information
*/
public Announcer(String name, FileConfiguration config) {
this.name = name;
description = config.getStringList("description");
worlds = config.getStringList("worlds");
String identifier = config.getString("identifier");
boolean multiFloor = config.getBoolean("multiFloor");
if (multiFloor) {
dungeonName = identifier;
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
if (dungeon != null) {
mapName = dungeon.getConfig().getStartFloor();
}
} else {
mapName = identifier;
}
maxGroupsPerGame = (short) config.getInt("maxGroupsPerGame");
dGroups = new ArrayList<>(Collections.nCopies(maxGroupsPerGame + 1, (DGroup) null));
maxPlayersPerGroup = config.getInt("maxPlayersPerGroup");
}
/**
* @param name
* the name of the Announcer

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,14 +17,10 @@
package io.github.dre2n.dungeonsxl.announcer;
import io.github.dre2n.commons.util.FileUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.task.AnnouncerTask;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.Inventory;
/**
@ -37,20 +33,7 @@ public class Announcers {
public Announcers(File file) {
if (file.isDirectory()) {
for (File script : FileUtil.getFilesForFolder(file)) {
FileConfiguration config = YamlConfiguration.loadConfiguration(script);
String name = script.getName().substring(0, script.getName().length() - 4);
String identifier = config.getString("identifier");
List<String> description = config.getStringList("description");
List<String> worlds = null;
if (config.contains("worlds")) {
worlds = config.getStringList("worlds");
}
boolean multiFloor = config.getBoolean("multiFloor");
short maxGroupsPerGame = (short) config.getInt("maxGroupsPerGame");
int maxPlayersPerGroup = config.getInt("maxPlayersPerGroup");
announcers.add(new Announcer(name, description, worlds, identifier, multiFloor, maxGroupsPerGame, maxPlayersPerGroup));
announcers.add(new Announcer(script));
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -32,9 +32,9 @@ import org.bukkit.plugin.PluginManager;
* @author Frank Baumann, Daniel Saukel
*/
public class ReloadCommand extends BRCommand {
DungeonsXL plugin = DungeonsXL.getInstance();
public ReloadCommand() {
setCommand("reload");
setMinArgs(0);
@ -44,11 +44,11 @@ public class ReloadCommand extends BRCommand {
setPlayerCommand(true);
setConsoleCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
PluginManager plugins = Bukkit.getServer().getPluginManager();
int maps = new File(plugin.getDataFolder() + "/maps").listFiles().length;
int dungeons = new File(plugin.getDataFolder() + "/dungeons").listFiles().length;
int loaded = plugin.getEditWorlds().size() + plugin.getGameWorlds().size();
@ -83,11 +83,13 @@ public class ReloadCommand extends BRCommand {
plugin.loadDSigns();
plugin.loadDungeons();
plugin.loadAnnouncers(DungeonsXL.ANNOUNCERS);
plugin.loadDClasses(DungeonsXL.CLASSES);
plugin.loadDMobTypes(DungeonsXL.MOBS);
MessageUtil.sendPluginTag(sender, plugin);
MessageUtil.sendCenteredMessage(sender, DMessages.CMD_RELOAD_DONE.getMessage());
MessageUtil.sendCenteredMessage(sender, DMessages.CMD_MAIN_LOADED.getMessage(String.valueOf(maps), String.valueOf(dungeons), String.valueOf(loaded), String.valueOf(players)));
MessageUtil.sendCenteredMessage(sender, DMessages.CMD_MAIN_COMPATIBILITY.getMessage(String.valueOf(internals), vault, mythicMobs));
}
}

View File

@ -21,8 +21,6 @@ import io.github.dre2n.commons.util.NumberUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.game.GameRules;
import io.github.dre2n.dungeonsxl.game.GameType;
import io.github.dre2n.dungeonsxl.mob.DMobType;
import io.github.dre2n.dungeonsxl.player.DClass;
import io.github.dre2n.dungeonsxl.requirement.FeeLevelRequirement;
import io.github.dre2n.dungeonsxl.requirement.FeeMoneyRequirement;
import io.github.dre2n.dungeonsxl.requirement.Requirement;
@ -37,8 +35,6 @@ import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
/**
* @author Frank Baumann, Milan Albrecht, Daniel Saukel
@ -69,59 +65,6 @@ public class WorldConfig extends GameRules {
// Load & Save
public void load(ConfigurationSection configFile) {
/* Classes */
ConfigurationSection configSectionClasses = configFile.getConfigurationSection("classes");
if (configSectionClasses != null) {
Set<String> list = configSectionClasses.getKeys(false);
for (String className : list) {
String name = className;
boolean hasDog = configSectionClasses.getBoolean(className + ".dog");
/* Items */
List<String> items = configSectionClasses.getStringList(className + ".items");
CopyOnWriteArrayList<ItemStack> itemStacks = new CopyOnWriteArrayList<>();
for (String item : items) {
String[] itemSplit = item.split(",");
if (itemSplit.length > 0) {
int itemId = 0, itemData = 0, itemSize = 1, itemLvlEnchantment = 1;
Enchantment itemEnchantment = null;
// Check Id & Data
String[] idAndData = itemSplit[0].split("/");
itemId = NumberUtil.parseInt(idAndData[0]);
if (idAndData.length > 1) {
itemData = NumberUtil.parseInt(idAndData[1]);
}
// Size
if (itemSplit.length > 1) {
itemSize = NumberUtil.parseInt(itemSplit[1]);
}
// Enchantment
if (itemSplit.length > 2) {
String[] enchantmentSplit = itemSplit[2].split("/");
itemEnchantment = Enchantment.getByName(enchantmentSplit[0]);
if (enchantmentSplit.length > 1) {
itemLvlEnchantment = NumberUtil.parseInt(enchantmentSplit[1]);
}
}
// Add Item to Stacks
ItemStack itemStack = new ItemStack(itemId, itemSize, (short) itemData);
if (itemEnchantment != null) {
itemStack.addEnchantment(itemEnchantment, itemLvlEnchantment);
}
itemStacks.add(itemStack);
}
}
/* Create Class */
dClasses.add(new DClass(name, itemStacks, hasDog));
}
}
/* Messages */
ConfigurationSection configSectionMessages = configFile.getConfigurationSection("message");
if (configSectionMessages != null) {
@ -268,10 +211,6 @@ public class WorldConfig extends GameRules {
timeLastPlayed = configFile.getInt("timeLastPlayed");
}
/* Mobtypes */
configSectionMessages = configFile.getConfigurationSection("mobTypes");
mobTypes = DMobType.load(configSectionMessages);
if (configFile.contains("gameCommandWhitelist")) {
gameCommandWhitelist = configFile.getStringList("gameCommandWhitelist");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,16 +17,12 @@
package io.github.dre2n.dungeonsxl.game;
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.requirement.Requirement;
import io.github.dre2n.dungeonsxl.reward.Reward;
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 org.bukkit.GameMode;
import org.bukkit.Material;
@ -68,10 +64,6 @@ public class GameRules {
DEFAULT_VALUES.finishedAll = null;
DEFAULT_VALUES.rewards = new ArrayList<>();
/* Scripts */
DEFAULT_VALUES.dClasses = new ArrayList<>();
DEFAULT_VALUES.mobTypes = new HashSet<>();
/* Commands and permissions */
DEFAULT_VALUES.gameCommandWhitelist = new ArrayList<>();
DEFAULT_VALUES.gamePermissions = new ArrayList<>();
@ -111,10 +103,6 @@ public class GameRules {
protected List<String> finishedAll;
protected List<Reward> rewards;
/* Scripts */
protected List<DClass> dClasses;
protected Set<DMobType> mobTypes;
/* Commands and permissions */
protected List<String> gameCommandWhitelist;
protected List<String> gamePermissions;
@ -124,33 +112,6 @@ public class GameRules {
protected List<Material> secureObjects;
/* Getters and setters */
/**
* @return the classes
*/
public List<DClass> getClasses() {
if (dClasses != null) {
if (!dClasses.isEmpty()) {
return dClasses;
}
}
return new ArrayList<>();
}
/**
* @param name
* the name of the class
*/
public DClass getClass(String name) {
for (DClass dClass : dClasses) {
if (dClass.getName().equals(name)) {
return dClass;
}
}
return null;
}
// keepInventory
/**
* @return if the inventory shall be kept when the player enters the dungeon
@ -307,14 +268,6 @@ public class GameRules {
return rewards;
}
// Scripts
/**
* @return the mobTypes
*/
public Set<DMobType> getMobTypes() {
return mobTypes;
}
// Commands and permissions
/**
* @return the gameCommandWhitelist
@ -483,19 +436,6 @@ public class GameRules {
rewards = defaultValues.rewards;
}
/* Scripts */
if (dClasses == null) {
dClasses = defaultValues.dClasses;
} else if (defaultValues.dClasses != null) {
dClasses.addAll(defaultValues.dClasses);
}
if (mobTypes == null) {
mobTypes = defaultValues.mobTypes;
} else if (defaultValues.mobTypes != null) {
mobTypes.addAll(defaultValues.mobTypes);
}
/* Commands and permissions */
if (gameCommandWhitelist == null) {
gameCommandWhitelist = defaultValues.gameCommandWhitelist;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -22,14 +22,16 @@ import io.github.dre2n.commons.util.messageutil.MessageUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@ -51,11 +53,11 @@ public class DMobType {
private int maxHealth;
private ItemStack ItemHand;
private ItemStack ItemHelmet;
private ItemStack ItemChestplate;
private ItemStack ItemLeggings;
private ItemStack ItemBoots;
private ItemStack itemHand;
private ItemStack itemHelmet;
private ItemStack itemChestplate;
private ItemStack itemLeggings;
private ItemStack itemBoots;
private Map<ItemStack, Integer> drops = new HashMap<>();
@ -63,204 +65,136 @@ public class DMobType {
private boolean witherSkeleton = false;
private String ocelotType = null;
/* Methods */
/**
* @param file
* the script file
*/
public DMobType(File file) {
this(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file));
}
/**
* @param name
* the name of the Announcer
* @param config
* the config that stores the information
*/
public DMobType(String name, FileConfiguration config) {
this.name = name;
// Read Mobs
EntityType type = EntityType.fromName(config.getString("type"));
// Load MaxHealth
if (config.contains("maxHealth")) {
maxHealth = config.getInt("maxHealth");
}
// Load Items
if (config.contains("itemHelmet")) {
itemHelmet = new ItemStack(config.getInt("itemHelmet"));
}
if (config.contains("itemChestplate")) {
itemChestplate = new ItemStack(config.getInt("itemChestplate"));
}
if (config.contains("itemBoots")) {
itemBoots = new ItemStack(config.getInt("itemBoots"));
}
if (config.contains("itemLeggings")) {
itemLeggings = new ItemStack(config.getInt("itemLeggings"));
}
if (config.contains("itemHand")) {
itemHand = new ItemStack(config.getInt("itemHand"));
}
// Load different Mob options
if (config.contains("isWitherSkeleton")) {
witherSkeleton = config.getBoolean("isWitherSkeleton");
}
if (config.contains("ocelotType")) {
ocelotType = config.getString("ocelotType");
}
// Drops
ConfigurationSection configSetion = config.getConfigurationSection("drops");
if (configSetion != null) {
Set<String> list = configSetion.getKeys(false);
for (String dropPath : list) {
ItemStack item = null;
ItemMeta itemMeta = null;
int chance = 100;
/* Item Stack */
Material mat = Material.getMaterial(configSetion.getInt(dropPath + ".id"));
int amount = 1;
short data = 0;
if (configSetion.contains(dropPath + ".amount")) {
amount = configSetion.getInt(dropPath + ".amount");
}
if (configSetion.contains(dropPath + ".data")) {
data = Short.parseShort(configSetion.getString(dropPath + ".data"));
}
item = new ItemStack(mat, amount, data);
itemMeta = item.getItemMeta();
/* Enchantments */
if (configSetion.contains(dropPath + ".enchantments")) {
for (String enchantment : configSetion.getStringList(dropPath + ".enchantments")) {
String[] splittedEnchantment = enchantment.split(" ");
if (Enchantment.getByName(splittedEnchantment[0].toUpperCase()) != null) {
if (splittedEnchantment.length > 1) {
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), NumberUtil.parseInt(splittedEnchantment[1]), true);
} else {
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), 1, true);
}
} else {
MessageUtil.log(DMessages.LOG_ERROR_MOB_ENCHANTMENT.getMessage(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);
getDrops().put(item, chance);
}
}
}
/**
* @param name
* the name of the DMobType
* @param type
* the EntityType of the mob
*/
public DMobType(String name, EntityType type) {
this.name = name;
this.type = type;
}
public void spawn(GameWorld gameWorld, Location loc) {
if (type == null) {
return;
}
if (!type.isAlive()) {
return;
}
LivingEntity entity = (LivingEntity) gameWorld.getWorld().spawnEntity(loc, type);
/* Set the Items */
entity.getEquipment().setItemInHand(ItemHand);
entity.getEquipment().setHelmet(ItemHelmet);
entity.getEquipment().setChestplate(ItemChestplate);
entity.getEquipment().setLeggings(ItemLeggings);
entity.getEquipment().setBoots(ItemBoots);
/* Check mob specified stuff */
if (type == EntityType.SKELETON) {
if (witherSkeleton) {
((Skeleton) entity).setSkeletonType(SkeletonType.WITHER);
} else {
((Skeleton) entity).setSkeletonType(SkeletonType.NORMAL);
}
}
if (type == EntityType.OCELOT) {
Ocelot ocelot = (Ocelot) entity;
if (EnumUtil.isValidEnum(Ocelot.Type.class, ocelotType.toUpperCase())) {
ocelot.setCatType(Ocelot.Type.valueOf(ocelotType.toUpperCase()));
}
}
/* Set Health */
if (maxHealth > 0) {
entity.setMaxHealth(maxHealth);
entity.setHealth(maxHealth);
}
/* Disable Despawning */
entity.setRemoveWhenFarAway(false);
/* Spawn Mob */
new DMob(entity, gameWorld, this);
}
// Load Config
public static Set<DMobType> load(ConfigurationSection configFile) {
Set<DMobType> set = new HashSet<>();
if (configFile == null) {
return set;
}
// Read Mobs
for (String mobName : configFile.getKeys(false)) {
EntityType type = EntityType.fromName(configFile.getString(mobName + ".Type"));
if (type == null) {
MessageUtil.log(DMessages.LOG_ERROR_MOBTYPE.getMessage(configFile.getString(mobName + ".Type")));
continue;
}
DMobType mobType = new DMobType(mobName, type);
set.add(mobType);
// Load MaxHealth
if (configFile.contains(mobName + ".MaxHealth")) {
mobType.maxHealth = configFile.getInt(mobName + ".MaxHealth");
}
// Load Items
if (configFile.contains(mobName + ".ItemHelmet")) {
mobType.ItemHelmet = new ItemStack(configFile.getInt(mobName + ".ItemHelmet"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemHelmet"))).getItem();
}
if (configFile.contains(mobName + ".ItemChestplate")) {
mobType.ItemChestplate = new ItemStack(configFile.getInt(mobName + ".ItemChestplate"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemChestplate"))).getItem();
}
if (configFile.contains(mobName + ".ItemBoots")) {
mobType.ItemBoots = new ItemStack(configFile.getInt(mobName + ".ItemBoots"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemBoots"))).getItem();
}
if (configFile.contains(mobName + ".ItemLeggings")) {
mobType.ItemLeggings = new ItemStack(configFile.getInt(mobName + ".ItemLeggings"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemLeggings"))).getItem();
}
if (configFile.contains(mobName + ".ItemHand")) {
mobType.ItemHand = new ItemStack(configFile.getInt(mobName + ".ItemHand"));// CraftItemStack.asNMSCopy(new
// ItemStack(configFile.getInt(mobName+".ItemHand"))).getItem();
}
// Load different Mob options
if (configFile.contains(mobName + ".isWitherSkeleton")) {
mobType.witherSkeleton = configFile.getBoolean(mobName + ".isWitherSkeleton");
}
if (configFile.contains(mobName + ".ocelotType")) {
mobType.ocelotType = configFile.getString(mobName + ".ocelotType");
}
// Drops
ConfigurationSection configSetion = configFile.getConfigurationSection(mobName + ".drops");
if (configSetion != null) {
Set<String> list = configSetion.getKeys(false);
for (String dropPath : list) {
ItemStack item = null;
ItemMeta itemMeta = null;
int chance = 100;
/* Item Stack */
Material mat = Material.getMaterial(configSetion.getInt(dropPath + ".id"));
int amount = 1;
short data = 0;
if (configSetion.contains(dropPath + ".amount")) {
amount = configSetion.getInt(dropPath + ".amount");
}
if (configSetion.contains(dropPath + ".data")) {
data = Short.parseShort(configSetion.getString(dropPath + ".data"));
}
item = new ItemStack(mat, amount, data);
itemMeta = item.getItemMeta();
/* Enchantments */
if (configSetion.contains(dropPath + ".enchantments")) {
for (String enchantment : configSetion.getStringList(dropPath + ".enchantments")) {
String[] splittedEnchantment = enchantment.split(" ");
if (Enchantment.getByName(splittedEnchantment[0].toUpperCase()) != null) {
if (splittedEnchantment.length > 1) {
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), NumberUtil.parseInt(splittedEnchantment[1]), true);
} else {
itemMeta.addEnchant(Enchantment.getByName(splittedEnchantment[0].toUpperCase()), 1, true);
}
} else {
MessageUtil.log(DMessages.LOG_ERROR_MOB_ENCHANTMENT.getMessage(splittedEnchantment[0]));
}
}
}
/* Item Name */
if (configSetion.contains(dropPath + ".name")) {
itemMeta.setDisplayName(configSetion.getString(dropPath + ".name"));
}
/* Item Lore */
if (configSetion.contains(dropPath + ".lore")) {
String[] lore = configSetion.getString(dropPath + ".lore").split("//");
itemMeta.setLore(Arrays.asList(lore));
}
/* Drop chance */
if (configSetion.contains(dropPath + ".chance")) {
chance = configSetion.getInt(dropPath + ".chance");
}
/* Add Item to the drops map */
item.setItemMeta(itemMeta);
mobType.getDrops().put(item, chance);
}
}
}
return set;
}
// Get
public static DMobType getByName(String name, Set<DMobType> mobTypes) {
for (DMobType mobType : mobTypes) {
if (mobType.name.equalsIgnoreCase(name)) {
return mobType;
}
}
if (plugin.getMainConfig().getDefaultWorldConfig() != null) {
for (DMobType mobType : plugin.getMainConfig().getDefaultWorldConfig().getMobTypes()) {
if (mobType.name.equalsIgnoreCase(name)) {
return mobType;
}
}
}
return null;
}
/* Getters and setters */
/**
* @return the name
*/
@ -309,76 +243,76 @@ public class DMobType {
/**
* @return the itemHand
*/
public ItemStack getItemHand() {
return ItemHand;
public ItemStack getitemHand() {
return itemHand;
}
/**
* @param itemHand
* the itemHand to set
*/
public void setItemHand(ItemStack itemHand) {
ItemHand = itemHand;
public void setitemHand(ItemStack itemHand) {
this.itemHand = itemHand;
}
/**
* @return the itemHelmet
*/
public ItemStack getItemHelmet() {
return ItemHelmet;
public ItemStack getitemHelmet() {
return itemHelmet;
}
/**
* @param itemHelmet
* the itemHelmet to set
*/
public void setItemHelmet(ItemStack itemHelmet) {
ItemHelmet = itemHelmet;
public void setitemHelmet(ItemStack itemHelmet) {
this.itemHelmet = itemHelmet;
}
/**
* @return the itemChestplate
*/
public ItemStack getItemChestplate() {
return ItemChestplate;
public ItemStack getitemChestplate() {
return itemChestplate;
}
/**
* @param itemChestplate
* the itemChestplate to set
*/
public void setItemChestplate(ItemStack itemChestplate) {
ItemChestplate = itemChestplate;
public void setitemChestplate(ItemStack itemChestplate) {
this.itemChestplate = itemChestplate;
}
/**
* @return the itemLeggings
*/
public ItemStack getItemLeggings() {
return ItemLeggings;
public ItemStack getitemLeggings() {
return itemLeggings;
}
/**
* @param itemLeggings
* the itemLeggings to set
*/
public void setItemLeggings(ItemStack itemLeggings) {
ItemLeggings = itemLeggings;
public void setitemLeggings(ItemStack itemLeggings) {
this.itemLeggings = itemLeggings;
}
/**
* @return the itemBoots
*/
public ItemStack getItemBoots() {
return ItemBoots;
public ItemStack getitemBoots() {
return itemBoots;
}
/**
* @param itemBoots
* the itemBoots to set
*/
public void setItemBoots(ItemStack itemBoots) {
ItemBoots = itemBoots;
public void setitemBoots(ItemStack itemBoots) {
this.itemBoots = itemBoots;
}
/**
@ -426,4 +360,52 @@ public class DMobType {
this.ocelotType = ocelotType;
}
/* Actions */
public void spawn(GameWorld gameWorld, Location loc) {
if (type == null) {
return;
}
if (!type.isAlive()) {
return;
}
LivingEntity entity = (LivingEntity) gameWorld.getWorld().spawnEntity(loc, type);
/* Set the Items */
entity.getEquipment().setItemInHand(itemHand);
entity.getEquipment().setHelmet(itemHelmet);
entity.getEquipment().setChestplate(itemChestplate);
entity.getEquipment().setLeggings(itemLeggings);
entity.getEquipment().setBoots(itemBoots);
/* Check mob specified stuff */
if (type == EntityType.SKELETON) {
if (witherSkeleton) {
((Skeleton) entity).setSkeletonType(SkeletonType.WITHER);
} else {
((Skeleton) entity).setSkeletonType(SkeletonType.NORMAL);
}
}
if (type == EntityType.OCELOT) {
Ocelot ocelot = (Ocelot) entity;
if (EnumUtil.isValidEnum(Ocelot.Type.class, ocelotType.toUpperCase())) {
ocelot.setCatType(Ocelot.Type.valueOf(ocelotType.toUpperCase()));
}
}
/* Set Health */
if (maxHealth > 0) {
entity.setMaxHealth(maxHealth);
entity.setHealth(maxHealth);
}
/* Disable Despawning */
entity.setRemoveWhenFarAway(false);
/* Spawn Mob */
new DMob(entity, gameWorld, this);
}
}

View File

@ -0,0 +1,75 @@
/*
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.dre2n.dungeonsxl.mob;
import io.github.dre2n.commons.util.FileUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* @author Daniel Saukel
*/
public class DMobTypes {
private List<DMobType> dMobTypes = new ArrayList<>();
public DMobTypes(File file) {
if (file.isDirectory()) {
for (File script : FileUtil.getFilesForFolder(file)) {
dMobTypes.add(new DMobType(script));
}
}
}
/**
* @return the dMobType that has the name
*/
public DMobType getByName(String name) {
for (DMobType dMobType : dMobTypes) {
if (dMobType.getName().equals(name)) {
return dMobType;
}
}
return null;
}
/**
* @return the dMobTypes
*/
public List<DMobType> getDMobTypes() {
return dMobTypes;
}
/**
* @param dMobType
* the DMobType to add
*/
public void addDMobType(DMobType dMobType) {
dMobTypes.add(dMobType);
}
/**
* @param dMobType
* the DMobType to remove
*/
public void removeDMobType(DMobType dMobType) {
dMobTypes.remove(dMobType);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -16,7 +16,12 @@
*/
package io.github.dre2n.dungeonsxl.player;
import java.util.concurrent.CopyOnWriteArrayList;
import io.github.dre2n.dungeonsxl.util.ItemUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
/**
@ -24,31 +29,31 @@ import org.bukkit.inventory.ItemStack;
*/
public class DClass {
private CopyOnWriteArrayList<ItemStack> items = new CopyOnWriteArrayList<>();
private String name;
private List<ItemStack> items = new ArrayList<>();
private boolean dog;
public DClass(String name, CopyOnWriteArrayList<ItemStack> items, boolean dog) {
public DClass(File file) {
this(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file));
}
public DClass(String name, FileConfiguration config) {
if (config.contains("items")) {
items = ItemUtil.fromConfig(config);
}
if (config.contains("dog")) {
dog = config.getBoolean("dog");
}
}
public DClass(String name, List<ItemStack> items, boolean dog) {
this.items = items;
this.name = name;
this.dog = dog;
}
/**
* @return the items
*/
public CopyOnWriteArrayList<ItemStack> getItems() {
return items;
}
/**
* @param itemStack
* the ItemStack to add
*/
public void setItems(ItemStack itemStack) {
items.add(itemStack);
}
/**
* @return the name
*/
@ -57,11 +62,26 @@ public class DClass {
}
/**
* @param name
* the name to set
* @return the items
*/
public void setName(String name) {
this.name = name;
public List<ItemStack> getItems() {
return items;
}
/**
* @param itemStack
* the ItemStack to add
*/
public void addItem(ItemStack itemStack) {
items.add(itemStack);
}
/**
* @param itemStack
* the ItemStack to remove
*/
public void removeItem(ItemStack itemStack) {
items.remove(itemStack);
}
/**

View File

@ -0,0 +1,75 @@
/*
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.dre2n.dungeonsxl.player;
import io.github.dre2n.commons.util.FileUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* @author Daniel Saukel
*/
public class DClasses {
private List<DClass> dClasses = new ArrayList<>();
public DClasses(File file) {
if (file.isDirectory()) {
for (File script : FileUtil.getFilesForFolder(file)) {
dClasses.add(new DClass(script));
}
}
}
/**
* @return the dClass that has the name
*/
public DClass getByName(String name) {
for (DClass dClass : dClasses) {
if (dClass.getName().equals(name)) {
return dClass;
}
}
return null;
}
/**
* @return the dClasses
*/
public List<DClass> getDClasses() {
return dClasses;
}
/**
* @param dClass
* the DClass to add
*/
public void addDClass(DClass dClass) {
dClasses.add(dClass);
}
/**
* @param dClass
* the DClass to remove
*/
public void removeDClass(DClass dClass) {
dClasses.remove(dClass);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -193,7 +193,7 @@ public class DGamePlayer extends DInstancePlayer {
return;
}
DClass dClass = game.getRules().getClass(className);
DClass dClass = plugin.getDClasses().getByName(className);
if (dClass != null) {
if (this.dClass != dClass) {
this.dClass = dClass;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -16,12 +16,10 @@
*/
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.global.GroupSign;
import io.github.dre2n.dungeonsxl.player.DClass;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
/**
@ -31,13 +29,34 @@ public class ClassesSign extends DSign {
private DSignType type = DSignTypeDefault.CLASSES;
private DClass dClass;
public ClassesSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
}
/* Getters and setters */
/**
* @return the DClass of the sign
*/
public DClass getDClass() {
return dClass;
}
/**
* @param dClass
* the DClass to set
*/
public void setDClass(DClass dClass) {
this.dClass = dClass;
}
/* Actions */
@Override
public boolean check() {
return true;
String[] lines = getSign().getLines();
dClass = plugin.getDClasses().getByName(lines[1]);
return dClass != null;
}
@Override
@ -47,45 +66,14 @@ public class ClassesSign extends DSign {
return;
}
int[] direction = GroupSign.getDirection(getSign().getBlock().getData());
int directionX = direction[0];
int directionZ = direction[1];
getSign().setLine(0, ChatColor.DARK_BLUE + "############");
getSign().setLine(1, ChatColor.DARK_GREEN + dClass.getName());
getSign().setLine(2, "");
getSign().setLine(3, ChatColor.DARK_BLUE + "############");
getSign().update();
int xx = 0, zz = 0;
for (DClass dclass : getGame().getRules().getClasses()) {
getGameWorld().getSignClass().add(getSign());
// Check existing signs
boolean isContinued = true;
for (Sign isusedsign : getGameWorld().getSignClass()) {
if (dclass.getName().equalsIgnoreCase(ChatColor.stripColor(isusedsign.getLine(1)))) {
isContinued = false;
}
}
if (!isContinued) {
continue;
}
Block classBlock = getSign().getBlock().getRelative(xx, 0, zz);
if (classBlock.getData() == getSign().getData().getData() && classBlock.getType() == Material.WALL_SIGN && classBlock.getState() instanceof Sign) {
Sign classSign = (Sign) classBlock.getState();
classSign.setLine(0, ChatColor.DARK_BLUE + "############");
classSign.setLine(1, ChatColor.DARK_GREEN + dclass.getName());
classSign.setLine(2, "");
classSign.setLine(3, ChatColor.DARK_BLUE + "############");
classSign.update();
getGameWorld().getSignClass().add(classSign);
} else {
break;
}
xx = xx + directionX;
zz = zz + directionZ;
}
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -16,6 +16,7 @@
*/
package io.github.dre2n.dungeonsxl.task;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.mob.DMob;
import io.github.dre2n.dungeonsxl.mob.DMobType;
import io.github.dre2n.dungeonsxl.sign.DMobSign;
@ -71,7 +72,7 @@ public class MobSpawnTask extends BukkitRunnable {
}
// Check custom mobs
DMobType mobType = DMobType.getByName(sign.getMob(), gameWorld.getGame().getRules().getMobTypes());
DMobType mobType = DungeonsXL.getInstance().getDMobTypes().getByName(sign.getMob());
if (mobType != null) {
mobType.spawn(GameWorld.getByWorld(world), spawnLoc);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 Daniel Saukel
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -0,0 +1,76 @@
/*
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.dre2n.dungeonsxl.util;
import io.github.dre2n.commons.util.NumberUtil;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
/**
* @author Frank Baumann, Daniel Saukel
*/
@Deprecated
public class ItemUtil {
public static List<ItemStack> fromConfig(ConfigurationSection configSectionClasses) {
List<String> items = configSectionClasses.getStringList("items");
CopyOnWriteArrayList<ItemStack> itemStacks = new CopyOnWriteArrayList<>();
for (String item : items) {
String[] itemSplit = item.split(",");
if (itemSplit.length > 0) {
int itemId = 0, itemData = 0, itemSize = 1, itemLvlEnchantment = 1;
Enchantment itemEnchantment = null;
// Check Id & Data
String[] idAndData = itemSplit[0].split("/");
itemId = NumberUtil.parseInt(idAndData[0]);
if (idAndData.length > 1) {
itemData = NumberUtil.parseInt(idAndData[1]);
}
// Size
if (itemSplit.length > 1) {
itemSize = NumberUtil.parseInt(itemSplit[1]);
}
// Enchantment
if (itemSplit.length > 2) {
String[] enchantmentSplit = itemSplit[2].split("/");
itemEnchantment = Enchantment.getByName(enchantmentSplit[0]);
if (enchantmentSplit.length > 1) {
itemLvlEnchantment = NumberUtil.parseInt(enchantmentSplit[1]);
}
}
// Add Item to Stacks
ItemStack itemStack = new ItemStack(itemId, itemSize, (short) itemData);
if (itemEnchantment != null) {
itemStack.addEnchantment(itemEnchantment, itemLvlEnchantment);
}
itemStacks.add(itemStack);
}
}
return itemStacks;
}
}