0.5.0 bis

Monster stuff
This commit is contained in:
unurled 2022-04-08 16:51:40 +02:00
parent 26cf701494
commit 0d910d3baf
12 changed files with 301 additions and 143 deletions

View file

@ -1,37 +1,49 @@
package gq.unurled.raxen.components.dungeons;
import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.components.dungeons.types.MonsterType;
import gq.unurled.raxen.components.dungeons.types.forest.ForestMonster;
import gq.unurled.raxen.components.entity.other.RaxenEntity;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static gq.unurled.raxen.utils.DungeonUtils.getRadiusFromRank;
import static gq.unurled.raxen.utils.Utils.log;
public class Dungeon {
private UUID uuid;
private String name;
private Rank rank;
private Gate gate;
private Map<UUID, RaxenEntity> monster = new HashMap();
private Map<String, RaxenEntity> monster = new HashMap();
/**
* The Type of the Dungeon
*/
private Types types;
/**
* Monster Types
*/
private MonsterType monsterType;
private Location location;
private Integer radius;
public Dungeon(UUID uuid, Rank rank, Types types) {
this.uuid = uuid;
public Dungeon(String name, Rank rank, Types types, MonsterType mType) {
this.name = name;
this.rank = rank;
this.types = types;
this.monsterType = mType;
}
/**
@ -42,17 +54,16 @@ public class Dungeon {
// -281.50 36.00 187.50
Location loc = new Location(Bukkit.getWorld("Liberty_City"), -284.0, 45.00, 187.50);
Integer radius = getRadiusFromRank(this.rank);
this.gate = new Gate(uuid, loc, radius);
this.gate = new Gate(name, loc, radius);
}
/**
* TODO: Terrain Generation of the inside of the Dungeons
*/
public void generate() {
genMonster();
}
public void genMonster() {
Raxen main = (Raxen) Bukkit.getPluginManager().getPlugin("Raxen");
main.getManager().getWorldManager().loadWorld(name);
monsterType.genMonster(Bukkit.getWorld(name), rank);
}
}

View file

@ -8,17 +8,16 @@ import java.util.UUID;
public class Gate {
private UUID uuid;
private String name;
private Location loc;
private Integer portalRadius;
public Gate(UUID uuid, Location loc, Integer portalRadius) {
public Gate(String name, Location loc, Integer portalRadius) {
this.loc = loc;
this.portalRadius = portalRadius;
this.uuid = uuid;
this.name = name;
}
public void teleport() {
@ -70,7 +69,7 @@ public class Gate {
return portalRadius;
}
public UUID getUuid() {
return uuid;
public String getName() {
return name;
}
}

View file

@ -1,69 +0,0 @@
package gq.unurled.raxen.components.dungeons;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import gq.unurled.raxen.Raxen;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static gq.unurled.raxen.utils.Utils.*;
public class WorldManagement {
private Raxen main;
MVWorldManager worldManager;
/**
* String : name
* MultiverseWorld : a world that need to be registered
*/
private Map<String, MultiverseWorld> loadedWorlds = new HashMap<>();
private List<String> worlds = new ArrayList<>();
private File pluginFolder;
private File worldFolder;
public WorldManagement(Raxen main) {
this.main = main;
this.pluginFolder = new File(main.getDataFolder() + "/worlds/");
this.worldFolder = new File("worlds/");
this.worldManager = main.getManager().getMultiverse().getWorldManager();
worlds.add("Forest");
log(pluginFolder.getAbsolutePath(), "" + pluginFolder.isDirectory());
log(worldFolder.getAbsolutePath(), "" + worldFolder.isDirectory());
}
public void load() {
if (!pluginFolder.exists()) {
pluginFolder.mkdirs();
error("Please put in the folder " + pluginFolder.getAbsolutePath() + " all the needed worlds :");
for (String s : worlds) {
error(" - " + s + ",");
}
}
}
public void loadWorld(String name) {
File world = new File(pluginFolder + name + "/");
if (!world.exists() || !world.isDirectory()) {
error("Loading world " + name + ". Folder don't exists.");
}
File newWorld = new File(worldFolder + name);
try {
copyDirectory(world.getAbsolutePath(), newWorld.getAbsolutePath());
} catch (IOException e) {
error("Error while Loading world " + name + " at coping data.");
e.printStackTrace();
}
worldManager.loadWorld(name);
}
}

View file

@ -0,0 +1,44 @@
package gq.unurled.raxen.components.dungeons.types;
import gq.unurled.raxen.components.dungeons.Rank;
import org.bukkit.World;
public interface MonsterType {
public enum type {;
private Double rate;
public String ID;
public Class clazz;
type(Double rate, String ID, Class clazz) {
this.rate = rate;
this.ID = ID;
this.clazz = clazz;
}
public static type getTypeById(String ID) {
for (type type : type.values()) {
if(type.ID.equals(ID)) {
return type;
}
}
return null;
}
public Double getRate() {
return rate;
}
public void setRate(Double rate) {
this.rate = rate;
}
public String getID() {
return ID;
}
public void setID(String ID) {
this.ID = ID;
}
}
void genMonster(World world, Rank rank);
}

View file

@ -1,6 +1,71 @@
package gq.unurled.raxen.components.dungeons.types.forest;
public enum ForestMonster {
ELF,
WOLF
import gq.unurled.raxen.components.dungeons.Rank;
import gq.unurled.raxen.components.dungeons.types.MonsterType;
import gq.unurled.raxen.components.entity.other.custom.dungeon.forest.Elf;
import gq.unurled.raxen.components.entity.other.custom.dungeon.forest.Wolf;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Zombie;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import java.util.Random;
import static gq.unurled.raxen.utils.Utils.debug;
import static org.apache.commons.lang.math.RandomUtils.nextInt;
public class ForestMonster implements MonsterType {
@Override
public void genMonster(World world, Rank rank) {
Double x = 0.0;
Double y = 100.0;
Double z = 0.0;
for (type type : type.values()) {
type.name();
Random r = new Random();
int per = r.nextInt(100);
if (per >= type.rate) {
// spawn entity
debug("Spawning Entity " + type.ID);
Entity e = world.spawnEntity(new Location(world, x, y, z), EntityType.ARROW);
e.setInvulnerable(true);
BukkitTask task = new BukkitRunnable() {
@Override
public void run() {
Location loc = new Location(e.getWorld(), e.getLocation().getX(), e.getLocation().getY()-1, e.getLocation().getZ());
if (loc.getBlock().getType() != Material.AIR) {
e.setInvulnerable(false);
this.cancel();
}
}
}.runTaskTimerAsynchronously(Bukkit.getPluginManager().getPlugin("Raxen"), 0L, 20L);
}
x = 5.0 + ( 50.0 - 5.0 ) * r.nextDouble();
z = 5.0 + ( 50.0 - 5.0 ) * r.nextDouble();
}
}
@Getter
enum type {
ELF(50.0 ,"ELF", Elf.class),
WOLF(50.0, "WOLF", Wolf.class);
private Double rate;
public String ID;
public Class clazz;
type(Double rate, String ID, Class clazz) {
this.rate = rate;
this.ID = ID;
this.clazz = clazz;
}
}
}

View file

@ -11,7 +11,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
public class RaxenEntity {
public abstract class RaxenEntity {
private final Raxen main;
@ -52,4 +52,5 @@ public class RaxenEntity {
return data.get(key.maxHealth, PersistentDataType.DOUBLE);
}
public abstract Entity createEntity(Location location);
}

View file

@ -0,0 +1,35 @@
package gq.unurled.raxen.components.entity.other.custom.dungeon.forest;
import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.components.entity.other.RaxenEntity;
import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
public class Elf extends RaxenEntity {
@Getter
private final String name;
public Elf(Raxen main, String name, Integer level, Double health, Double strength) {
super(main, name, level, health, strength);
this.name = name;
}
@Override
public Entity createEntity(Location location) {
return super.createEntity(EntityType.PLAYER, name, location);
}
/**
* Elf Default values
* @param main the main instance
* @param name
*/
public Elf(Raxen main, String name) {
super(main, "Elf", 10, 120.0, 25.0);
this.name = name;
}
}

View file

@ -0,0 +1,30 @@
package gq.unurled.raxen.components.entity.other.custom.dungeon.forest;
import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.components.entity.other.RaxenEntity;
import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
public class Wolf extends RaxenEntity {
@Getter
private final String name;
public Wolf(Raxen main, String name, Integer level, Double health, Double strength) {
super(main, name, level, health, strength);
this.name = name;
}
public Wolf(Raxen main) {
super(main, "Wolf", 5, 100.0, 20.0);
this.name = "Wolf";
}
@Override
public Entity createEntity(Location location) {
return super.createEntity(EntityType.WOLF, name, location);
}
}

View file

@ -3,6 +3,8 @@ package gq.unurled.raxen.components.entity.other.custom.hostile.low;
import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.components.entity.other.RaxenEntity;
import gq.unurled.raxen.components.entity.other.custom.Entity;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
public class Goblin extends Entity {
@ -10,7 +12,12 @@ public class Goblin extends Entity {
public Goblin(Raxen main) {
super("Goblin", 1, 100.0, 10.0, 0.0, 50.0, true);
this.goblin = new RaxenEntity(main, "Goblin", 1, 100.0, 10.0);
this.goblin = new RaxenEntity(main, "Goblin", 1, 100.0, 10.0) {
@Override
public org.bukkit.entity.Entity createEntity(Location location) {
return super.createEntity(EntityType.PLAYER, "Goblin", location);
}
};
register(main);
}

View file

@ -1,72 +1,100 @@
package gq.unurled.raxen.manager.server;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import gq.unurled.raxen.Raxen;
import gq.unurled.raxen.manager.entity.StorageManager;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.*;
import static gq.unurled.raxen.utils.Utils.*;
import static gq.unurled.raxen.utils.Utils.error;
public class WorldManager {
private Raxen main;
private static StorageManager sto;
@Getter
private HashMap<String, World> worlds = new HashMap<>();
MVWorldManager worldManager;
/**
* String : name
* MultiverseWorld : a world that need to be registered
*/
private Map<String, MultiverseWorld> loadedWorlds = new HashMap<>();
private List<String> worlds = new ArrayList<>();
private File pluginFolder;
private File worldFolder;
public WorldManager(Raxen main) {
this.main = main;
this.sto = main.getManager().getStorageManager();
if(!(new File(main.getDataFolder() + "/Worlds/").exists())) {
new File(main.getDataFolder() + "/Worlds/").mkdirs();
this.pluginFolder = new File(main.getDataFolder() + "/worlds/");
this.worldFolder = new File("worlds/");
this.worldManager = main.getManager().getMultiverse().getWorldManager();
worlds.add("Forest");
log(pluginFolder.getAbsolutePath(), "" + pluginFolder.isDirectory());
log(worldFolder.getAbsolutePath(), "" + worldFolder.isDirectory());
}
public void removeWorld(String name) {
File world = new File(worldFolder + name + "/");
if (!world.exists() || !world.isDirectory()) {
error("Saving world " + name + ". Folder don't exists.");
return;
}
worldManager.unloadWorld(name);
try {
removeDirectory(world.toPath());
} catch (IOException e) {
error("Error while Saving world " + name + " at coping data.");
e.printStackTrace();
}
}
public void save() {
String path = main.getDataFolder() + "/Worlds/";
File folder = new File(path);
List<World> worlds = Bukkit.getWorlds();
for (World world : worlds) {
File file = new File(path + world.getName() + ".yml");
FileConfiguration fileConf = sto.createYml(file);
fileConf.set("name", world.getName());
fileConf.set("uuid", world.getUID().toString());
try {
fileConf.save(file);
} catch (IOException e) {
e.printStackTrace();
public void load() {
if (!pluginFolder.exists()) {
pluginFolder.mkdirs();
error("Please put in the folder " + pluginFolder.getAbsolutePath() + " all the needed worlds :");
for (String s : worlds) {
error(" - " + s + ",");
}
return;
}
for (String s : worlds) {
File world = new File(pluginFolder + s);
File worldd = new File(worldFolder + s);
if (worldd.exists()) {
if (worldd.isDirectory()) {
worldManager.loadWorld(s);
}
} else if (world.exists() ) {
if (world.isDirectory()) {
loadWorld(s);
} else {
error("World " + s + " is not a world Folder!");
}
} else {
error("World " + s + " do not exist.");
}
}
}
public void saveWorld(String name) {
World world = Bukkit.getWorld(name);
UUID uuid = world.getUID();
String key = world.getKey().getKey();
File file = new File(main.getDataFolder() + "/Worlds/" + name + ".yml");
}
public void load() {
String path = main.getDataFolder() + "/Worlds/";
File folder = new File(path);
File[] listFile = folder.listFiles();
for (File file : listFile) {
loadWorld(file);
public void loadWorld(String name) {
File world = new File(pluginFolder + name + "/");
if (!world.exists() || !world.isDirectory()) {
error("Loading world " + name + ". Folder don't exists.");
return;
}
File newWorld = new File(worldFolder + name);
try {
copyDirectory(world.getAbsolutePath(), newWorld.getAbsolutePath());
} catch (IOException e) {
error("Error while Loading world " + name + " at coping data.");
e.printStackTrace();
}
worldManager.loadWorld(name);
}
public World loadWorld(File file) {
FileConfiguration fileConf = sto.createYml(file);
World world = Bukkit.createWorld(new WorldCreator(fileConf.getString("name")));
worlds.put(world.getName(), world);
return world;
}
}

View file

@ -18,10 +18,10 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.*;
import java.util.Comparator;
public class Utils {
@ -226,4 +226,15 @@ public class Utils {
});
}
public static void removeDirectory(Path path) throws IOException {
if (Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) {
try (DirectoryStream<Path> entries = Files.newDirectoryStream(path)) {
for (Path entry : entries) {
removeDirectory(entry);
}
}
}
Files.delete(path);
}
}

View file

@ -12,8 +12,4 @@
resource_pack_url: "https://mc-packs.net/" # recommend to use https://mc-packs.net/ => free resource pack hoster (will eventually develop one myself but not atm)
resource_pack_sha1: "sha1hallo" # sha1 hash
worlds:
forest:
enabled: true
debug: false