Added experimental support for Citizens

This commit is contained in:
Daniel Saukel 2016-05-01 00:20:44 +02:00
parent e34d5218dc
commit c0a39bc533
13 changed files with 218 additions and 34 deletions

10
pom.xml
View File

@ -74,6 +74,12 @@
<artifactId>commandsxl</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>citizensapi</artifactId>
<version>2.0.17-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
@ -88,5 +94,9 @@
<id>dre2n-repo</id>
<url>http://feuerstern.bplaced.net/repo/</url>
</repository>
<repository>
<id>citizens-repo</id>
<url>http://repo.citizensnpcs.co/</url>
</repository>
</repositories>
</project>

View File

@ -31,11 +31,7 @@ import io.github.dre2n.dungeonsxl.dungeon.Dungeons;
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.BlockListener;
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.listener.*;
import io.github.dre2n.dungeonsxl.mob.ExternalMobProviders;
import io.github.dre2n.dungeonsxl.player.DGroup;
import io.github.dre2n.dungeonsxl.player.DPermissions;
@ -143,6 +139,9 @@ public class DungeonsXL extends BRPlugin {
manager.registerEvents(new BlockListener(), this);
manager.registerEvents(new WorldListener(), this);
manager.registerEvents(new HangingListener(), this);
if (manager.getPlugin("Citizens") != null) {
manager.registerEvents(new CitizensListener(), this);
}
// Load All
loadAll();

View File

@ -16,7 +16,7 @@
*/
package io.github.dre2n.dungeonsxl.game;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.commons.util.messageutil.MessageUtil;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.block.Sign;
@ -35,7 +35,7 @@ public class GameTypes {
Class.forName("com.massivecraft.factions.Patch");
} catch (ClassNotFoundException exception) {
DungeonsXL.getInstance().getLogger().info("Could not find compatible Factions plugin. The game type PVP_FACTIONS_BATTLEFIELD will not get enabled...");
MessageUtil.log("Could not find compatible Factions plugin. The game type PVP_FACTIONS_BATTLEFIELD will not get enabled...");
continue;
}
}

View File

@ -0,0 +1,43 @@
/*
* 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.listener;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.mob.CitizensMobProvider;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCDeathEvent;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
/**
* @author Daniel Saukel
*/
public class CitizensListener implements Listener {
CitizensMobProvider provider = DungeonsXL.getInstance().getExternalMobProviders().getCitizensMobProvider();
@EventHandler
public void onNPCDeath(NPCDeathEvent event) {
NPC npc = event.getNPC();
if (provider.getSpawnedNPCs().contains(npc)) {
CitizensAPI.getNPCRegistry().deregister(npc);
provider.removeSpawnedNPC(npc);
}
}
}

View File

@ -31,7 +31,6 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
@ -88,13 +87,10 @@ public class EntityListener implements Listener {
GameWorld gameWorld = GameWorld.getByWorld(world);
if (gameWorld != null) {
if (gameWorld.isPlaying()) {
if (entity.getType() != EntityType.PLAYER) {
DMob dMob = DMob.getByEntity(entity);
if (dMob != null) {
event.getDrops().clear();
DMob dMob = DMob.getByEntity(entity);
if (dMob != null) {
dMob.onDeath(event);
}
dMob.onDeath(event);
}
}
}

View File

@ -0,0 +1,92 @@
/*
* 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.commons.util.NumberUtil;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import java.util.HashSet;
import java.util.Set;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
/**
* @author Daniel Saukel
*/
public class CitizensMobProvider implements ExternalMobProvider {
private String identifier = "CI";
private Set<NPC> spawnedNPCs = new HashSet<>();
/**
* @return the spawned Citizens NPCs
*/
public Set<NPC> getSpawnedNPCs() {
return spawnedNPCs;
}
/**
* @param npc
* the NPC to add
*/
public void addSpawnedNPC(NPC npc) {
spawnedNPCs.add(npc);
}
/**
* @param npc
* the NPC to remove
*/
public void removeSpawnedNPC(NPC npc) {
spawnedNPCs.remove(npc);
}
@Override
public String getIdentifier() {
return identifier;
}
@Override
public String getRawCommand() {
return null;
}
@Override
public String getCommand(String mob, String world, double x, double y, double z) {
return null;
}
@Override
public void summon(String mob, Location location) {
NPC npc = CitizensAPI.getNPCRegistry().getById(NumberUtil.parseInt(mob));
if (npc != null) {
npc = npc.clone();
if (npc.isSpawned()) {
npc.despawn();
}
npc.spawn(location);
spawnedNPCs.add(npc);
GameWorld gameWorld = GameWorld.getByWorld(location.getWorld());
new DMob((LivingEntity) npc.getEntity(), gameWorld, null, mob);
}
}
}

View File

@ -17,6 +17,8 @@
package io.github.dre2n.dungeonsxl.mob;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.Location;
/**
* @author Daniel Saukel
@ -54,4 +56,9 @@ public class CustomExternalMobProvider implements ExternalMobProvider {
return command.replaceAll("%mob%", mob).replaceAll("%world%", world).replaceAll("%x%", String.valueOf(x)).replaceAll("%y%", String.valueOf(y)).replaceAll("%z%", String.valueOf(z));
}
@Override
public void summon(String mob, Location location) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), getCommand(mob, location.getWorld().getName(), location.getX(), location.getY(), location.getZ()));
}
}

View File

@ -46,11 +46,14 @@ public class DMob {
this.type = type;
/* Remove DropChance of equipment */
this.entity.getEquipment().setHelmetDropChance(0);
this.entity.getEquipment().setChestplateDropChance(0);
this.entity.getEquipment().setLeggingsDropChance(0);
this.entity.getEquipment().setBootsDropChance(0);
this.entity.getEquipment().setItemInHandDropChance(0);
try {
this.entity.getEquipment().setHelmetDropChance(0);
this.entity.getEquipment().setChestplateDropChance(0);
this.entity.getEquipment().setLeggingsDropChance(0);
this.entity.getEquipment().setBootsDropChance(0);
this.entity.getEquipment().setItemInHandDropChance(0);
} catch (UnsupportedOperationException exception) {
}
}
public DMob(LivingEntity entity, GameWorld gameWorld, DMobType type, String trigger) {
@ -59,10 +62,6 @@ public class DMob {
}
public void onDeath(EntityDeathEvent event) {
if (!(event.getEntity() instanceof LivingEntity)) {
return;
}
LivingEntity victim = event.getEntity();
GameWorld gameWorld = GameWorld.getByWorld(victim.getWorld());
String name = null;
@ -95,9 +94,9 @@ public class DMob {
name = victim.getType().getName();
}
MobTrigger mobTriger = MobTrigger.get(name, gameWorld);
if (mobTriger != null) {
mobTriger.onTrigger();
MobTrigger mobTrigger = MobTrigger.get(name, gameWorld);
if (mobTrigger != null) {
mobTrigger.onTrigger();
}
Set<WaveTrigger> waveTriggers = WaveTrigger.getByGameWorld(gameWorld);

View File

@ -16,6 +16,9 @@
*/
package io.github.dre2n.dungeonsxl.mob;
import org.bukkit.Bukkit;
import org.bukkit.Location;
/**
* @author Daniel Saukel
*/
@ -48,4 +51,9 @@ public enum ExternalMobPlugin implements ExternalMobProvider {
return command.replaceAll("%mob%", mob).replaceAll("%world%", world).replaceAll("%x%", String.valueOf(x)).replaceAll("%y%", String.valueOf(y)).replaceAll("%z%", String.valueOf(z));
}
@Override
public void summon(String mob, Location location) {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), getCommand(mob, location.getWorld().getName(), location.getX(), location.getY(), location.getZ()));
}
}

View File

@ -16,6 +16,8 @@
*/
package io.github.dre2n.dungeonsxl.mob;
import org.bukkit.Location;
/**
* @author Daniel Saukel
*/
@ -46,4 +48,12 @@ public interface ExternalMobProvider {
*/
public String getCommand(String mob, String world, double x, double y, double z);
/**
* @param mob
* the mob identifier
* @param location
* the location where the mob will be spawned
*/
public void summon(String mob, Location location);
}

View File

@ -16,11 +16,13 @@
*/
package io.github.dre2n.dungeonsxl.mob;
import io.github.dre2n.commons.util.messageutil.MessageUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.Bukkit;
/**
* @author Daniel Saukel
@ -32,6 +34,11 @@ public class ExternalMobProviders {
public ExternalMobProviders() {
// Supported providers
providers.addAll(Arrays.asList(ExternalMobPlugin.values()));
if (Bukkit.getPluginManager().getPlugin("Citizens") != null) {
providers.add(new CitizensMobProvider());
} else {
MessageUtil.log("Could not find compatible Citizens plugin. The mob provider Citizens (\"CI\") will not get enabled...");
}
// Custom providers
for (Entry<String, Object> customExternalMobProvider : DungeonsXL.getInstance().getMainConfig().getExternalMobProviders().entrySet()) {
@ -60,6 +67,19 @@ public class ExternalMobProviders {
return providers;
}
/**
* @return the Citizens provider
*/
public CitizensMobProvider getCitizensMobProvider() {
for (ExternalMobProvider provider : providers) {
if (provider instanceof CitizensMobProvider) {
return (CitizensMobProvider) provider;
}
}
return null;
}
/**
* @param provider
* the provider to register

View File

@ -33,6 +33,7 @@ import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerUpdateEvent;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.game.GameType;
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
import io.github.dre2n.dungeonsxl.mob.DMob;
import io.github.dre2n.dungeonsxl.reward.DLootInventory;
import io.github.dre2n.dungeonsxl.reward.Reward;
import io.github.dre2n.dungeonsxl.trigger.DistanceTrigger;
@ -898,8 +899,7 @@ public class DPlayer extends DGlobalPlayer {
}
}
} else if (gameWorld
!= null) {
} else if (gameWorld != null) {
// Update Wolf
if (getWolf() != null) {
if (getWolf().isDead()) {
@ -911,6 +911,11 @@ public class DPlayer extends DGlobalPlayer {
}
wolfRespawnTime--;
}
DMob dMob = DMob.getByEntity(getWolf());
if (dMob != null) {
gameWorld.removeDMob(dMob);
}
}
// Kick offline plugin.getDPlayers()

View File

@ -20,7 +20,6 @@ import io.github.dre2n.dungeonsxl.mob.DMob;
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;
import org.bukkit.scheduler.BukkitRunnable;
@ -45,12 +44,8 @@ public class ExternalMobSpawnTask extends BukkitRunnable {
if (gameWorld != null) {
sign.setSpawnLocation(sign.getSign().getLocation().add(0.5, 0, 0.5));
double x = sign.getSpawnLocation().getX();
double y = sign.getSpawnLocation().getY();
double z = sign.getSpawnLocation().getZ();
String command = provider.getCommand(sign.getMob(), "DXL_Game_" + gameWorld.getId(), x, y, z);
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command);
provider.summon(sign.getMob(), sign.getSpawnLocation());
sign.setExternalMobs();
if (sign.getExternalMob() != null) {