Skip to content

Commit

Permalink
Merge mob sign and external mob sign; resolves #442 and resolves #321
Browse files Browse the repository at this point in the history
  • Loading branch information
Sataniel98 committed Aug 4, 2018
1 parent a3a0651 commit bbe18fd
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 570 deletions.
2 changes: 1 addition & 1 deletion src/main/java/de/erethon/dungeonsxl/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import de.erethon.dungeonsxl.global.GameSign;
import de.erethon.dungeonsxl.player.DGroup;
import de.erethon.dungeonsxl.sign.DSign;
import de.erethon.dungeonsxl.sign.mob.MobSign;
import de.erethon.dungeonsxl.sign.MobSign;
import de.erethon.dungeonsxl.trigger.ProgressTrigger;
import de.erethon.dungeonsxl.world.DGameWorld;
import de.erethon.dungeonsxl.world.DResourceWorld;
Expand Down
28 changes: 17 additions & 11 deletions src/main/java/de/erethon/dungeonsxl/mob/CitizensMobProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
*/
public class CitizensMobProvider implements ExternalMobProvider, Listener {

private static final String IDENTIFIER = "CI";

private DNPCRegistry registry = new DNPCRegistry();
private String identifier = "CI";
private Set<NPC> spawnedNPCs = new HashSet<>();

/**
Expand Down Expand Up @@ -70,7 +71,7 @@ public void removeSpawnedNPC(NPC npc) {

@Override
public String getIdentifier() {
return identifier;
return IDENTIFIER;
}

@Override
Expand All @@ -86,19 +87,24 @@ public String getCommand(String mob, String world, double x, double y, double z)
@Override
public void summon(String mob, Location location) {
NPC source = CitizensAPI.getNPCRegistry().getById(NumberUtil.parseInt(mob));
if (!(source instanceof AbstractNPC)) {
return;
}

if (source instanceof AbstractNPC) {
NPC npc = registry.createTransientClone((AbstractNPC) source);
if (npc.isSpawned()) {
npc.despawn();
}
NPC npc = registry.createTransientClone((AbstractNPC) source);
if (npc.isSpawned()) {
npc.despawn();
}

npc.spawn(location);
spawnedNPCs.add(npc);
npc.spawn(location);
spawnedNPCs.add(npc);

DGameWorld gameWorld = DGameWorld.getByWorld(location.getWorld());
new DMob((LivingEntity) npc.getEntity(), gameWorld, mob);
DGameWorld gameWorld = DGameWorld.getByWorld(location.getWorld());
if (gameWorld == null) {
return;
}

new DMob((LivingEntity) npc.getEntity(), gameWorld, mob);
}

/* Listeners */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ public class ExternalMobProviderCache {
DungeonsXL plugin = DungeonsXL.getInstance();

private Set<ExternalMobProvider> providers = new HashSet<>();
private CitizensMobProvider citizensMobProvider;

public ExternalMobProviderCache() {
// Supported providers
providers.addAll(Arrays.asList(ExternalMobPlugin.values()));

if (Bukkit.getPluginManager().getPlugin("Citizens") != null) {
CitizensMobProvider citizens = new CitizensMobProvider();
providers.add(citizens);
Bukkit.getPluginManager().registerEvents(citizens, plugin);
citizensMobProvider = new CitizensMobProvider();
providers.add(citizensMobProvider);
Bukkit.getPluginManager().registerEvents(citizensMobProvider, plugin);
} else {
MessageUtil.log(plugin, "Could not find compatible Citizens plugin. The mob provider Citizens (\"CI\") will not get enabled...");
}
Expand Down Expand Up @@ -77,13 +79,7 @@ public Set<ExternalMobProvider> getProviders() {
* @return the Citizens provider
*/
public CitizensMobProvider getCitizensMobProvider() {
for (ExternalMobProvider provider : providers) {
if (provider instanceof CitizensMobProvider) {
return (CitizensMobProvider) provider;
}
}

return null;
return citizensMobProvider;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import de.erethon.dungeonsxl.sign.message.MessageSign;
import de.erethon.dungeonsxl.sign.message.SoundMessageSign;
import de.erethon.dungeonsxl.sign.message.TitleSign;
import de.erethon.dungeonsxl.sign.mob.DMobSign;
import de.erethon.dungeonsxl.sign.mob.ExternalMobSign;

/**
* Default implementation of DSignType.
Expand All @@ -47,18 +45,17 @@ public enum DSignTypeDefault implements DSignType {
COMMAND("CMD", "cmd", false, false, CommandSign.class),
DROP("Drop", "drop", false, false, DropSign.class),
END("End", "end", false, true, EndSign.class),
EXTERNAL_MOB("ExternalMob", "mob", false, false, ExternalMobSign.class),
@Deprecated
EXTERNAL_MOB("ExternalMob", "mob", false, false, MobSign.class),
FLAG("Flag", "flag", false, false, FlagSign.class),
FLOOR("Floor", "floor", false, true, FloorSign.class),
HOLOGRAM("Hologram", "hologram", true, false, HologramSign.class),
INTERACT("Interact", "interact", true, true, InteractSign.class),
LEAVE("Leave", "leave", true, true, LeaveSign.class),
LIVES_MODIFIER("Lives", "lives", false, false, LivesModifierSign.class),
LOBBY("Lobby", "lobby", true, false, LobbySign.class),
MOB("Mob", "mob", false, false, DMobSign.class),
MOB("Mob", "mob", false, false, MobSign.class),
MESSAGE("MSG", "msg", false, false, MessageSign.class),
@Deprecated
MYTHIC_MOBS("MythicMobs", "mob", false, false, ExternalMobSign.class),
OPEN_DOOR("Door", "door", false, false, OpenDoorSign.class),
PLACE("Place", "place", false, false, PlaceSign.class),
PROTECTION("Protection", "protection", false, false, ProtectionSign.class),
Expand Down
Loading

0 comments on commit bbe18fd

Please sign in to comment.