#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 /nb-configuration.xml
/target /target
/dependency-reduced-pom.xml /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.game.GameTypes;
import io.github.dre2n.dungeonsxl.global.GlobalProtections; import io.github.dre2n.dungeonsxl.global.GlobalProtections;
import io.github.dre2n.dungeonsxl.listener.*; 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.mob.ExternalMobProviders;
import io.github.dre2n.dungeonsxl.player.DClasses;
import io.github.dre2n.dungeonsxl.player.DGamePlayer; import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPermissions; import io.github.dre2n.dungeonsxl.player.DPermissions;
@ -69,6 +71,8 @@ public class DungeonsXL extends BRPlugin {
public static File MAPS; public static File MAPS;
public static File SCRIPTS; public static File SCRIPTS;
public static File ANNOUNCERS; public static File ANNOUNCERS;
public static File CLASSES;
public static File MOBS;
private DataConfig dataConfig; private DataConfig dataConfig;
private MainConfig mainConfig; private MainConfig mainConfig;
@ -85,6 +89,8 @@ public class DungeonsXL extends BRPlugin {
private ExternalMobProviders dMobProviders; private ExternalMobProviders dMobProviders;
private DPlayers dPlayers; private DPlayers dPlayers;
private Announcers announcers; private Announcers announcers;
private DClasses dClasses;
private DMobTypes dMobTypes;
private BukkitTask announcerTask; private BukkitTask announcerTask;
private BukkitTask worldUnloadTask; private BukkitTask worldUnloadTask;
@ -142,6 +148,8 @@ public class DungeonsXL extends BRPlugin {
loadExternalMobProviders(); loadExternalMobProviders();
loadDPlayers(); loadDPlayers();
loadAnnouncers(ANNOUNCERS); loadAnnouncers(ANNOUNCERS);
loadDClasses(CLASSES);
loadDMobTypes(MOBS);
manager.registerEvents(new EntityListener(), this); manager.registerEvents(new EntityListener(), this);
manager.registerEvents(new GUIListener(), this); manager.registerEvents(new GUIListener(), this);
@ -224,6 +232,16 @@ public class DungeonsXL extends BRPlugin {
if (!ANNOUNCERS.exists()) { if (!ANNOUNCERS.exists()) {
ANNOUNCERS.mkdir(); 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 // Save and load
@ -497,6 +515,34 @@ public class DungeonsXL extends BRPlugin {
announcers = new Announcers(file); announcers = new Announcers(file);
} }
/**
* @return the loaded instance of DClasses
*/
public DClasses getDClasses() {
return dClasses;
}
/**
* load / reload a new instance of DClasses
*/
public void loadDClasses(File file) {
dClasses = new DClasses(file);
}
/**
* @return the loaded instance of DMobTypes
*/
public DMobTypes getDMobTypes() {
return dMobTypes;
}
/**
* load / reload a new instance of DMobTypes
*/
public void loadDMobTypes(File file) {
dMobTypes = new DMobTypes(file);
}
/** /**
* @return the worldUnloadTask * @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 * 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 * 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.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent; import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent;
import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DGroup;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; 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 net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -58,6 +61,45 @@ public class Announcer {
private List<DGroup> dGroups; private List<DGroup> dGroups;
private List<ItemStack> buttons; 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 * @param name
* the name of the Announcer * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -17,14 +17,10 @@
package io.github.dre2n.dungeonsxl.announcer; package io.github.dre2n.dungeonsxl.announcer;
import io.github.dre2n.commons.util.FileUtil; 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
/** /**
@ -37,20 +33,7 @@ public class Announcers {
public Announcers(File file) { public Announcers(File file) {
if (file.isDirectory()) { if (file.isDirectory()) {
for (File script : FileUtil.getFilesForFolder(file)) { for (File script : FileUtil.getFilesForFolder(file)) {
FileConfiguration config = YamlConfiguration.loadConfiguration(script); announcers.add(new Announcer(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));
} }
} }
} }

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 * 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 * 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 * 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 * it under the terms of the GNU General Public License as published by

View File

@ -83,6 +83,8 @@ public class ReloadCommand extends BRCommand {
plugin.loadDSigns(); plugin.loadDSigns();
plugin.loadDungeons(); plugin.loadDungeons();
plugin.loadAnnouncers(DungeonsXL.ANNOUNCERS); plugin.loadAnnouncers(DungeonsXL.ANNOUNCERS);
plugin.loadDClasses(DungeonsXL.CLASSES);
plugin.loadDMobTypes(DungeonsXL.MOBS);
MessageUtil.sendPluginTag(sender, plugin); MessageUtil.sendPluginTag(sender, plugin);
MessageUtil.sendCenteredMessage(sender, DMessages.CMD_RELOAD_DONE.getMessage()); MessageUtil.sendCenteredMessage(sender, DMessages.CMD_RELOAD_DONE.getMessage());

View File

@ -21,8 +21,6 @@ import io.github.dre2n.commons.util.NumberUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.game.GameRules; import io.github.dre2n.dungeonsxl.game.GameRules;
import io.github.dre2n.dungeonsxl.game.GameType; 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.FeeLevelRequirement;
import io.github.dre2n.dungeonsxl.requirement.FeeMoneyRequirement; import io.github.dre2n.dungeonsxl.requirement.FeeMoneyRequirement;
import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.requirement.Requirement;
@ -37,8 +35,6 @@ import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
/** /**
* @author Frank Baumann, Milan Albrecht, Daniel Saukel * @author Frank Baumann, Milan Albrecht, Daniel Saukel
@ -69,59 +65,6 @@ public class WorldConfig extends GameRules {
// Load & Save // Load & Save
public void load(ConfigurationSection configFile) { 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 */ /* Messages */
ConfigurationSection configSectionMessages = configFile.getConfigurationSection("message"); ConfigurationSection configSectionMessages = configFile.getConfigurationSection("message");
if (configSectionMessages != null) { if (configSectionMessages != null) {
@ -268,10 +211,6 @@ public class WorldConfig extends GameRules {
timeLastPlayed = configFile.getInt("timeLastPlayed"); timeLastPlayed = configFile.getInt("timeLastPlayed");
} }
/* Mobtypes */
configSectionMessages = configFile.getConfigurationSection("mobTypes");
mobTypes = DMobType.load(configSectionMessages);
if (configFile.contains("gameCommandWhitelist")) { if (configFile.contains("gameCommandWhitelist")) {
gameCommandWhitelist = configFile.getStringList("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 * 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 * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -17,16 +17,12 @@
package io.github.dre2n.dungeonsxl.game; package io.github.dre2n.dungeonsxl.game;
import io.github.dre2n.dungeonsxl.DungeonsXL; 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.requirement.Requirement;
import io.github.dre2n.dungeonsxl.reward.Reward; import io.github.dre2n.dungeonsxl.reward.Reward;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material; import org.bukkit.Material;
@ -68,10 +64,6 @@ public class GameRules {
DEFAULT_VALUES.finishedAll = null; DEFAULT_VALUES.finishedAll = null;
DEFAULT_VALUES.rewards = new ArrayList<>(); DEFAULT_VALUES.rewards = new ArrayList<>();
/* Scripts */
DEFAULT_VALUES.dClasses = new ArrayList<>();
DEFAULT_VALUES.mobTypes = new HashSet<>();
/* Commands and permissions */ /* Commands and permissions */
DEFAULT_VALUES.gameCommandWhitelist = new ArrayList<>(); DEFAULT_VALUES.gameCommandWhitelist = new ArrayList<>();
DEFAULT_VALUES.gamePermissions = new ArrayList<>(); DEFAULT_VALUES.gamePermissions = new ArrayList<>();
@ -111,10 +103,6 @@ public class GameRules {
protected List<String> finishedAll; protected List<String> finishedAll;
protected List<Reward> rewards; protected List<Reward> rewards;
/* Scripts */
protected List<DClass> dClasses;
protected Set<DMobType> mobTypes;
/* Commands and permissions */ /* Commands and permissions */
protected List<String> gameCommandWhitelist; protected List<String> gameCommandWhitelist;
protected List<String> gamePermissions; protected List<String> gamePermissions;
@ -124,33 +112,6 @@ public class GameRules {
protected List<Material> secureObjects; protected List<Material> secureObjects;
/* Getters and setters */ /* 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 // keepInventory
/** /**
* @return if the inventory shall be kept when the player enters the dungeon * @return if the inventory shall be kept when the player enters the dungeon
@ -307,14 +268,6 @@ public class GameRules {
return rewards; return rewards;
} }
// Scripts
/**
* @return the mobTypes
*/
public Set<DMobType> getMobTypes() {
return mobTypes;
}
// Commands and permissions // Commands and permissions
/** /**
* @return the gameCommandWhitelist * @return the gameCommandWhitelist
@ -483,19 +436,6 @@ public class GameRules {
rewards = defaultValues.rewards; 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 */ /* Commands and permissions */
if (gameCommandWhitelist == null) { if (gameCommandWhitelist == null) {
gameCommandWhitelist = defaultValues.gameCommandWhitelist; 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.world.GameWorld; import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -51,11 +53,11 @@ public class DMobType {
private int maxHealth; private int maxHealth;
private ItemStack ItemHand; private ItemStack itemHand;
private ItemStack ItemHelmet; private ItemStack itemHelmet;
private ItemStack ItemChestplate; private ItemStack itemChestplate;
private ItemStack ItemLeggings; private ItemStack itemLeggings;
private ItemStack ItemBoots; private ItemStack itemBoots;
private Map<ItemStack, Integer> drops = new HashMap<>(); private Map<ItemStack, Integer> drops = new HashMap<>();
@ -63,121 +65,63 @@ public class DMobType {
private boolean witherSkeleton = false; private boolean witherSkeleton = false;
private String ocelotType = null; private String ocelotType = null;
/* Methods */ /**
public DMobType(String name, EntityType type) { * @param file
* the script file
*/
public DMobType(File file) {
this(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file));
}
/**
* @param name
* the name of the Announcer
* @param config
* the config that stores the information
*/
public DMobType(String name, FileConfiguration config) {
this.name = name; 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 // Read Mobs
for (String mobName : configFile.getKeys(false)) { EntityType type = EntityType.fromName(config.getString("type"));
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 // Load MaxHealth
if (configFile.contains(mobName + ".MaxHealth")) { if (config.contains("maxHealth")) {
mobType.maxHealth = configFile.getInt(mobName + ".MaxHealth"); maxHealth = config.getInt("maxHealth");
} }
// Load Items // Load Items
if (configFile.contains(mobName + ".ItemHelmet")) { if (config.contains("itemHelmet")) {
mobType.ItemHelmet = new ItemStack(configFile.getInt(mobName + ".ItemHelmet"));// CraftItemStack.asNMSCopy(new itemHelmet = new ItemStack(config.getInt("itemHelmet"));
// ItemStack(configFile.getInt(mobName+".ItemHelmet"))).getItem();
} }
if (configFile.contains(mobName + ".ItemChestplate")) { if (config.contains("itemChestplate")) {
mobType.ItemChestplate = new ItemStack(configFile.getInt(mobName + ".ItemChestplate"));// CraftItemStack.asNMSCopy(new itemChestplate = new ItemStack(config.getInt("itemChestplate"));
// ItemStack(configFile.getInt(mobName+".ItemChestplate"))).getItem();
} }
if (configFile.contains(mobName + ".ItemBoots")) { if (config.contains("itemBoots")) {
mobType.ItemBoots = new ItemStack(configFile.getInt(mobName + ".ItemBoots"));// CraftItemStack.asNMSCopy(new itemBoots = new ItemStack(config.getInt("itemBoots"));
// ItemStack(configFile.getInt(mobName+".ItemBoots"))).getItem();
} }
if (configFile.contains(mobName + ".ItemLeggings")) { if (config.contains("itemLeggings")) {
mobType.ItemLeggings = new ItemStack(configFile.getInt(mobName + ".ItemLeggings"));// CraftItemStack.asNMSCopy(new itemLeggings = new ItemStack(config.getInt("itemLeggings"));
// ItemStack(configFile.getInt(mobName+".ItemLeggings"))).getItem();
} }
if (configFile.contains(mobName + ".ItemHand")) { if (config.contains("itemHand")) {
mobType.ItemHand = new ItemStack(configFile.getInt(mobName + ".ItemHand"));// CraftItemStack.asNMSCopy(new itemHand = new ItemStack(config.getInt("itemHand"));
// ItemStack(configFile.getInt(mobName+".ItemHand"))).getItem();
} }
// Load different Mob options // Load different Mob options
if (configFile.contains(mobName + ".isWitherSkeleton")) { if (config.contains("isWitherSkeleton")) {
mobType.witherSkeleton = configFile.getBoolean(mobName + ".isWitherSkeleton"); witherSkeleton = config.getBoolean("isWitherSkeleton");
} }
if (configFile.contains(mobName + ".ocelotType")) { if (config.contains("ocelotType")) {
mobType.ocelotType = configFile.getString(mobName + ".ocelotType"); ocelotType = config.getString("ocelotType");
} }
// Drops // Drops
ConfigurationSection configSetion = configFile.getConfigurationSection(mobName + ".drops"); ConfigurationSection configSetion = config.getConfigurationSection("drops");
if (configSetion != null) { if (configSetion != null) {
Set<String> list = configSetion.getKeys(false); Set<String> list = configSetion.getKeys(false);
for (String dropPath : list) { for (String dropPath : list) {
@ -234,33 +178,23 @@ public class DMobType {
/* Add Item to the drops map */ /* Add Item to the drops map */
item.setItemMeta(itemMeta); item.setItemMeta(itemMeta);
mobType.getDrops().put(item, chance); getDrops().put(item, chance);
} }
} }
} }
return set; /**
} * @param name
* the name of the DMobType
// Get * @param type
public static DMobType getByName(String name, Set<DMobType> mobTypes) { * the EntityType of the mob
for (DMobType mobType : mobTypes) { */
if (mobType.name.equalsIgnoreCase(name)) { public DMobType(String name, EntityType type) {
return mobType; this.name = name;
} this.type = type;
}
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 * @return the name
*/ */
@ -309,76 +243,76 @@ public class DMobType {
/** /**
* @return the itemHand * @return the itemHand
*/ */
public ItemStack getItemHand() { public ItemStack getitemHand() {
return ItemHand; return itemHand;
} }
/** /**
* @param itemHand * @param itemHand
* the itemHand to set * the itemHand to set
*/ */
public void setItemHand(ItemStack itemHand) { public void setitemHand(ItemStack itemHand) {
ItemHand = itemHand; this.itemHand = itemHand;
} }
/** /**
* @return the itemHelmet * @return the itemHelmet
*/ */
public ItemStack getItemHelmet() { public ItemStack getitemHelmet() {
return ItemHelmet; return itemHelmet;
} }
/** /**
* @param itemHelmet * @param itemHelmet
* the itemHelmet to set * the itemHelmet to set
*/ */
public void setItemHelmet(ItemStack itemHelmet) { public void setitemHelmet(ItemStack itemHelmet) {
ItemHelmet = itemHelmet; this.itemHelmet = itemHelmet;
} }
/** /**
* @return the itemChestplate * @return the itemChestplate
*/ */
public ItemStack getItemChestplate() { public ItemStack getitemChestplate() {
return ItemChestplate; return itemChestplate;
} }
/** /**
* @param itemChestplate * @param itemChestplate
* the itemChestplate to set * the itemChestplate to set
*/ */
public void setItemChestplate(ItemStack itemChestplate) { public void setitemChestplate(ItemStack itemChestplate) {
ItemChestplate = itemChestplate; this.itemChestplate = itemChestplate;
} }
/** /**
* @return the itemLeggings * @return the itemLeggings
*/ */
public ItemStack getItemLeggings() { public ItemStack getitemLeggings() {
return ItemLeggings; return itemLeggings;
} }
/** /**
* @param itemLeggings * @param itemLeggings
* the itemLeggings to set * the itemLeggings to set
*/ */
public void setItemLeggings(ItemStack itemLeggings) { public void setitemLeggings(ItemStack itemLeggings) {
ItemLeggings = itemLeggings; this.itemLeggings = itemLeggings;
} }
/** /**
* @return the itemBoots * @return the itemBoots
*/ */
public ItemStack getItemBoots() { public ItemStack getitemBoots() {
return ItemBoots; return itemBoots;
} }
/** /**
* @param itemBoots * @param itemBoots
* the itemBoots to set * the itemBoots to set
*/ */
public void setItemBoots(ItemStack itemBoots) { public void setitemBoots(ItemStack itemBoots) {
ItemBoots = itemBoots; this.itemBoots = itemBoots;
} }
/** /**
@ -426,4 +360,52 @@ public class DMobType {
this.ocelotType = ocelotType; 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 * 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 * 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 * 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 * 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 * 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 * 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; 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; import org.bukkit.inventory.ItemStack;
/** /**
@ -24,31 +29,31 @@ import org.bukkit.inventory.ItemStack;
*/ */
public class DClass { public class DClass {
private CopyOnWriteArrayList<ItemStack> items = new CopyOnWriteArrayList<>();
private String name; private String name;
private List<ItemStack> items = new ArrayList<>();
private boolean dog; 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.items = items;
this.name = name; this.name = name;
this.dog = dog; 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 * @return the name
*/ */
@ -57,11 +62,26 @@ public class DClass {
} }
/** /**
* @param name * @return the items
* the name to set
*/ */
public void setName(String name) { public List<ItemStack> getItems() {
this.name = name; 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 * 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 * 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; return;
} }
DClass dClass = game.getRules().getClass(className); DClass dClass = plugin.getDClasses().getByName(className);
if (dClass != null) { if (dClass != null) {
if (this.dClass != dClass) { if (this.dClass != dClass) {
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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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; 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.player.DClass;
import io.github.dre2n.dungeonsxl.world.GameWorld; import io.github.dre2n.dungeonsxl.world.GameWorld;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
/** /**
@ -31,13 +29,34 @@ public class ClassesSign extends DSign {
private DSignType type = DSignTypeDefault.CLASSES; private DSignType type = DSignTypeDefault.CLASSES;
private DClass dClass;
public ClassesSign(Sign sign, GameWorld gameWorld) { public ClassesSign(Sign sign, GameWorld gameWorld) {
super(sign, 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 @Override
public boolean check() { public boolean check() {
return true; String[] lines = getSign().getLines();
dClass = plugin.getDClasses().getByName(lines[1]);
return dClass != null;
} }
@Override @Override
@ -47,45 +66,14 @@ public class ClassesSign extends DSign {
return; return;
} }
int[] direction = GroupSign.getDirection(getSign().getBlock().getData()); getSign().setLine(0, ChatColor.DARK_BLUE + "############");
int directionX = direction[0]; getSign().setLine(1, ChatColor.DARK_GREEN + dClass.getName());
int directionZ = direction[1]; getSign().setLine(2, "");
getSign().setLine(3, ChatColor.DARK_BLUE + "############");
getSign().update();
int xx = 0, zz = 0; getGameWorld().getSignClass().add(getSign());
for (DClass dclass : getGame().getRules().getClasses()) {
// Check existing signs
boolean isContinued = true;
for (Sign isusedsign : getGameWorld().getSignClass()) {
if (dclass.getName().equalsIgnoreCase(ChatColor.stripColor(isusedsign.getLine(1)))) {
isContinued = false;
}
}
if (!isContinued) {
continue;
}
Block classBlock = getSign().getBlock().getRelative(xx, 0, zz);
if (classBlock.getData() == getSign().getData().getData() && classBlock.getType() == Material.WALL_SIGN && classBlock.getState() instanceof Sign) {
Sign classSign = (Sign) classBlock.getState();
classSign.setLine(0, ChatColor.DARK_BLUE + "############");
classSign.setLine(1, ChatColor.DARK_GREEN + dclass.getName());
classSign.setLine(2, "");
classSign.setLine(3, ChatColor.DARK_BLUE + "############");
classSign.update();
getGameWorld().getSignClass().add(classSign);
} else {
break;
}
xx = xx + directionX;
zz = zz + directionZ;
}
} }
@Override @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 * 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 * 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 * 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 * 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; 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.DMob;
import io.github.dre2n.dungeonsxl.mob.DMobType; import io.github.dre2n.dungeonsxl.mob.DMobType;
import io.github.dre2n.dungeonsxl.sign.DMobSign; import io.github.dre2n.dungeonsxl.sign.DMobSign;
@ -71,7 +72,7 @@ public class MobSpawnTask extends BukkitRunnable {
} }
// Check custom mobs // Check custom mobs
DMobType mobType = DMobType.getByName(sign.getMob(), gameWorld.getGame().getRules().getMobTypes()); DMobType mobType = DungeonsXL.getInstance().getDMobTypes().getByName(sign.getMob());
if (mobType != null) { if (mobType != null) {
mobType.spawn(GameWorld.getByWorld(world), spawnLoc); 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 * 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 * 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 * 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 * 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;
}
}