New external mob system

This commit is contained in:
Daniel Saukel 2016-04-30 01:28:11 +02:00
parent 02317cc208
commit e34d5218dc
10 changed files with 340 additions and 47 deletions

View File

@ -36,6 +36,7 @@ import io.github.dre2n.dungeonsxl.listener.EntityListener;
import io.github.dre2n.dungeonsxl.listener.HangingListener;
import io.github.dre2n.dungeonsxl.listener.PlayerListener;
import io.github.dre2n.dungeonsxl.listener.WorldListener;
import io.github.dre2n.dungeonsxl.mob.ExternalMobProviders;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPermissions;
import io.github.dre2n.dungeonsxl.player.DPlayer;
@ -78,6 +79,7 @@ public class DungeonsXL extends BRPlugin {
private Triggers triggers;
private Dungeons dungeons;
private GlobalProtections protections;
private ExternalMobProviders dMobProviders;
private DPlayers dPlayers;
private BukkitTask worldUnloadTask;
@ -133,6 +135,7 @@ public class DungeonsXL extends BRPlugin {
loadDSigns();
loadDungeons();
loadGlobalProtections();
loadExternalMobProviders();
loadDPlayers();
manager.registerEvents(new EntityListener(), this);
@ -431,6 +434,20 @@ public class DungeonsXL extends BRPlugin {
protections = new GlobalProtections();
}
/**
* @return the loaded instance of ExternalMobProviders
*/
public ExternalMobProviders getExternalMobProviders() {
return dMobProviders;
}
/**
* load / reload a new instance of ExternalMobProviders
*/
public void loadExternalMobProviders() {
dMobProviders = new ExternalMobProviders();
}
/**
* @return the loaded instance of DPlayers
*/

View File

@ -19,7 +19,9 @@ package io.github.dre2n.dungeonsxl.config;
import io.github.dre2n.commons.config.BRConfig;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.configuration.ConfigurationSection;
/**
@ -27,7 +29,7 @@ import org.bukkit.configuration.ConfigurationSection;
*/
public class MainConfig extends BRConfig {
public static final int CONFIG_VERSION = 4;
public static final int CONFIG_VERSION = 5;
private String language = "en";
private boolean enableEconomy = false;
@ -40,6 +42,7 @@ public class MainConfig extends BRConfig {
/* Misc */
private boolean sendFloorTitle = true;
private Map<String, Object> externalMobProviders = new HashMap<>();
/* Secure Mode*/
private boolean secureModeEnabled = false;
@ -102,6 +105,13 @@ public class MainConfig extends BRConfig {
return sendFloorTitle;
}
/**
* @return the custom external mob providers
*/
public Map<String, Object> getExternalMobProviders() {
return externalMobProviders;
}
/**
* @return the tutorialEndGroup
*/
@ -182,6 +192,10 @@ public class MainConfig extends BRConfig {
config.set("sendFloorTitle", sendFloorTitle);
}
if (!config.contains("externalMobProviders")) {
config.createSection("externalMobProviders");
}
if (!config.contains("secureMode.enabled")) {
config.set("secureMode.enabled", secureModeEnabled);
}
@ -241,6 +255,10 @@ public class MainConfig extends BRConfig {
sendFloorTitle = config.getBoolean("sendFloorTitle");
}
if (config.contains("externalMobProviders")) {
externalMobProviders = config.getConfigurationSection("externalMobProviders").getValues(false);
}
if (config.contains("secureMode.enabled")) {
secureModeEnabled = config.getBoolean("secureMode.enabled");
}

View File

@ -0,0 +1,57 @@
/*
* Copyright (C) 2016 Daniel Saukel
*
* 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 java.util.Map.Entry;
/**
* @author Daniel Saukel
*/
public class CustomExternalMobProvider implements ExternalMobProvider {
private String identifier;
private String command;
public CustomExternalMobProvider(String identifier, String command) {
this.identifier = identifier;
if (command.startsWith("/")) {
command = command.replaceFirst("/", "");
}
this.command = command;
}
public CustomExternalMobProvider(Entry<String, Object> entry) {
this(entry.getKey(), (String) entry.getValue());
}
@Override
public String getIdentifier() {
return identifier;
}
@Override
public String getRawCommand() {
return command;
}
@Override
public String getCommand(String mob, String world, double x, double y, double z) {
return command.replaceAll("%mob%", mob).replaceAll("%world%", world).replaceAll("%x%", String.valueOf(x)).replaceAll("%y%", String.valueOf(y)).replaceAll("%z%", String.valueOf(z));
}
}

View File

@ -0,0 +1,51 @@
/*
* Copyright (C) 2016 Daniel Saukel
*
* 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;
/**
* @author Daniel Saukel
*/
public enum ExternalMobPlugin implements ExternalMobProvider {
CUSTOM_MOBS("CM", "ccmob spawn %mob% %world% %x% %y% %z%"),
INSANE_MOBS("IM", "insanemobs %mob% %x% %y% %z% %world%"),
MYTHIC_MOBS("MM", "mythicmobs mobs spawn %mob% 1 %world%,%x%,%y%,%z%");
private String identifier;
private String command;
ExternalMobPlugin(String identifier, String command) {
this.identifier = identifier;
this.command = command;
}
@Override
public String getIdentifier() {
return identifier;
}
@Override
public String getRawCommand() {
return command;
}
@Override
public String getCommand(String mob, String world, double x, double y, double z) {
return command.replaceAll("%mob%", mob).replaceAll("%world%", world).replaceAll("%x%", String.valueOf(x)).replaceAll("%y%", String.valueOf(y)).replaceAll("%z%", String.valueOf(z));
}
}

View File

@ -0,0 +1,49 @@
/*
* Copyright (C) 2016 Daniel Saukel
*
* 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;
/**
* @author Daniel Saukel
*/
public interface ExternalMobProvider {
/**
* @return the name of the provider plugin
*/
public String getIdentifier();
/**
* @return the raw command without replaced variables
*/
public String getRawCommand();
/**
* @param mob
* the mob identifier
* @param world
* the game world
* @param x
* the x coordinate
* @param y
* the y coordinate
* @param z
* the z coordinate
* @return the command with replaced variables
*/
public String getCommand(String mob, String world, double x, double y, double z);
}

View File

@ -0,0 +1,79 @@
/*
* Copyright (C) 2016 Daniel Saukel
*
* 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.dungeonsxl.DungeonsXL;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set;
/**
* @author Daniel Saukel
*/
public class ExternalMobProviders {
private Set<ExternalMobProvider> providers = new HashSet<>();
public ExternalMobProviders() {
// Supported providers
providers.addAll(Arrays.asList(ExternalMobPlugin.values()));
// Custom providers
for (Entry<String, Object> customExternalMobProvider : DungeonsXL.getInstance().getMainConfig().getExternalMobProviders().entrySet()) {
providers.add(new CustomExternalMobProvider(customExternalMobProvider));
}
}
/**
* @param identifier
* the identifier for ExternalMob signs
*/
public ExternalMobProvider getByIdentifier(String identifier) {
for (ExternalMobProvider provider : providers) {
if (provider.getIdentifier().equals(identifier)) {
return provider;
}
}
return null;
}
/**
* @return the loaded ExternalMobProviders
*/
public Set<ExternalMobProvider> getProviders() {
return providers;
}
/**
* @param provider
* the provider to register
*/
public void addExternalMobProvider(ExternalMobProvider provider) {
providers.add(provider);
}
/**
* @param provider
* the provider to unregister
*/
public void removeExternalMobProvider(ExternalMobProvider provider) {
providers.remove(provider);
}
}

View File

@ -30,13 +30,15 @@ public enum DSignTypeDefault implements DSignType {
CLASSES("Classes", "classes", true, ClassesSign.class),
COMMAND("CMD", "cmd", false, CommandSign.class),
END("End", "end", false, EndSign.class),
EXTERNAL_MOB("ExternalMob", "mob", false, ExternalMobSign.class),
FLOOR("Floor", "floor", false, FloorSign.class),
INTERACT("Interact", "interact", true, InteractSign.class),
LEAVE("Leave", "leave", true, LeaveSign.class),
LOBBY("Lobby", "lobby", true, LobbySign.class),
MOB("Mob", "mob", false, DMobSign.class),
MESSAGE("MSG", "msg", false, MessageSign.class),
MYTHIC_MOBS("MythicMobs", "mob", false, MythicMobsSign.class),
@Deprecated
MYTHIC_MOBS("MythicMobs", "mob", false, ExternalMobSign.class),
PLACE("Place", "place", false, PlaceSign.class),
READY("Ready", "ready", true, ReadySign.class),
REDSTONE("Redstone", "redstone", false, RedstoneSign.class),

View File

@ -17,9 +17,12 @@
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.commons.util.NumberUtil;
import io.github.dre2n.dungeonsxl.task.MythicMobSpawnTask;
import io.github.dre2n.dungeonsxl.mob.ExternalMobPlugin;
import io.github.dre2n.dungeonsxl.mob.ExternalMobProvider;
import io.github.dre2n.dungeonsxl.task.ExternalMobSpawnTask;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Sign;
@ -31,24 +34,25 @@ import org.bukkit.scheduler.BukkitTask;
/**
* @author Frank Baumann, Milan Albrecht, Daniel Saukel
*/
public class MythicMobsSign extends DSign implements MobSign {
public class ExternalMobSign extends DSign implements MobSign {
private DSignType type = DSignTypeDefault.MYTHIC_MOBS;
private DSignType type = DSignTypeDefault.EXTERNAL_MOB;
// Variables
private String mob;
private int maxInterval = 1;
private int interval = 0;
private int amount = 1;
private ExternalMobProvider provider;
private int initialAmount = 1;
private boolean initialized;
private boolean active;
private BukkitTask task;
private Location spawnLocation;
private LivingEntity mythicMob;
private ArrayList<Entity> mythicMobs = new ArrayList<>();
private LivingEntity externalMob;
private List<Entity> externalMobs = new ArrayList<>();
public MythicMobsSign(Sign sign, GameWorld gameWorld) {
public ExternalMobSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
}
@ -134,7 +138,7 @@ public class MythicMobsSign extends DSign implements MobSign {
@Override
public void initializeTask() {
task = new MythicMobSpawnTask(this).runTaskTimer(plugin, 0L, 20L);
task = new ExternalMobSpawnTask(this, provider).runTaskTimer(plugin, 0L, 20L);
}
/**
@ -153,33 +157,41 @@ public class MythicMobsSign extends DSign implements MobSign {
}
/**
* @return the mythicMob
* @return the external mob
*/
public LivingEntity getMythicMob() {
return mythicMob;
public LivingEntity getExternalMob() {
return externalMob;
}
/**
* @param mythicMob
* the mythicMob to set
* @param externalMob
* the external mob to set
*/
public void setMythicMob(LivingEntity mythicMob) {
this.mythicMob = mythicMob;
public void setExternalMob(LivingEntity externalMob) {
this.externalMob = externalMob;
}
/**
* @return the mythicMobs
* @return the externalMobs
*/
public ArrayList<Entity> getMythicMobs() {
return mythicMobs;
public List<Entity> getExternalMobs() {
return externalMobs;
}
/**
* @param mythicMobs
* the mythicMobs to set
* @param externalMob
* the externalMob to add
*/
public void setMythicMobs(ArrayList<Entity> mythicMobs) {
this.mythicMobs = mythicMobs;
public void addExternalMob(Entity externalMob) {
externalMobs.add(externalMob);
}
/**
* @param externalMob
* the external mob to remove
*/
public void removeExternalMob(Entity externalMob) {
externalMobs.remove(externalMob);
}
@Override
@ -194,7 +206,7 @@ public class MythicMobsSign extends DSign implements MobSign {
}
String[] atributes = lines[2].split(",");
if (atributes.length == 2) {
if (atributes.length == 2 || atributes.length == 3) {
return true;
} else {
@ -205,19 +217,24 @@ public class MythicMobsSign extends DSign implements MobSign {
@Override
public void onInit() {
String lines[] = getSign().getLines();
if (lines[1].isEmpty() || lines[2].isEmpty()) {
} else {
String mob = lines[1];
if (mob != null) {
String[] attributes = lines[2].split(",");
if (attributes.length == 2) {
this.setMob(mob);
setMaxInterval(NumberUtil.parseInt(attributes[0]));
setAmount(NumberUtil.parseInt(attributes[1]));
initialAmount = amount;
String mob = lines[1];
if (mob != null) {
String[] attributes = lines[2].split(",");
if (attributes.length >= 2) {
this.setMob(mob);
setMaxInterval(NumberUtil.parseInt(attributes[0]));
setAmount(NumberUtil.parseInt(attributes[1]));
initialAmount = amount;
if (attributes.length == 3) {
provider = plugin.getExternalMobProviders().getByIdentifier(attributes[2]);
} else {
provider = ExternalMobPlugin.MYTHIC_MOBS;
}
}
}
getSign().getBlock().setType(Material.AIR);
initialized = true;
@ -256,13 +273,13 @@ public class MythicMobsSign extends DSign implements MobSign {
}
}
public void setMythicMobs() {
public void setExternalMobs() {
for (Entity entity : spawnLocation.getChunk().getEntities()) {
if (entity.getLocation().getX() >= spawnLocation.getX() - 1 && entity.getLocation().getX() <= spawnLocation.getX() + 1 && entity.getLocation().getY() >= spawnLocation.getY() - 1
&& entity.getLocation().getY() <= spawnLocation.getY() + 1 && entity.getLocation().getZ() >= spawnLocation.getZ() - 1 && entity.getLocation().getZ() <= spawnLocation.getZ() + 1
&& !mythicMobs.contains(entity) && !(entity instanceof Player)) {
setMythicMob((LivingEntity) entity);
mythicMobs.add(entity);
&& !externalMobs.contains(entity) && !(entity instanceof Player)) {
setExternalMob((LivingEntity) entity);
externalMobs.add(entity);
return;
}
}

View File

@ -17,7 +17,8 @@
package io.github.dre2n.dungeonsxl.task;
import io.github.dre2n.dungeonsxl.mob.DMob;
import io.github.dre2n.dungeonsxl.sign.MythicMobsSign;
import io.github.dre2n.dungeonsxl.mob.ExternalMobProvider;
import io.github.dre2n.dungeonsxl.sign.ExternalMobSign;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import org.bukkit.Bukkit;
import org.bukkit.World;
@ -26,12 +27,14 @@ import org.bukkit.scheduler.BukkitRunnable;
/**
* @author Frank Baumann, Daniel Saukel
*/
public class MythicMobSpawnTask extends BukkitRunnable {
public class ExternalMobSpawnTask extends BukkitRunnable {
private MythicMobsSign sign;
private ExternalMobSign sign;
private ExternalMobProvider provider;
public MythicMobSpawnTask(MythicMobsSign sign) {
public ExternalMobSpawnTask(ExternalMobSign sign, ExternalMobProvider provider) {
this.sign = sign;
this.provider = provider;
}
@Override
@ -46,12 +49,12 @@ public class MythicMobSpawnTask extends BukkitRunnable {
double y = sign.getSpawnLocation().getY();
double z = sign.getSpawnLocation().getZ();
String command = "mythicmobs mobs spawn " + sign.getMob() + " 1 DXL_Game_" + gameWorld.getId() + "," + x + "," + y + "," + z;
String command = provider.getCommand(sign.getMob(), "DXL_Game_" + gameWorld.getId(), x, y, z);
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command);
sign.setMythicMobs();
if (sign.getMythicMob() != null) {
new DMob(sign.getMythicMob(), sign.getGameWorld(), null, sign.getMob());
sign.setExternalMobs();
if (sign.getExternalMob() != null) {
new DMob(sign.getExternalMob(), sign.getGameWorld(), null, sign.getMob());
}
// Set the amount

View File

@ -4,7 +4,7 @@ version: ${project.version}
authors: [Frank Baumann, Milan Albrecht, Tobias Schmitz, Daniel Saukel]
description: ${project.description}
website: ${project.url}
softdepend: [BlueRoseCommons, CommandsXL, Vault, MythicMobs]
softdepend: [BlueRoseCommons, CommandsXL, Vault, CustomMobs, InsaneMobs, MythicMobs]
commands:
dungeonsxl:
description: Reference command for DungeonsXL.