mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
Added simple PvP rules
This commit is contained in:
parent
2ac0ad1b5c
commit
e013d5fd3a
@ -46,6 +46,9 @@ public class WorldConfig {
|
||||
private GameMode gameMode = GameMode.SURVIVAL;
|
||||
private boolean build = false;
|
||||
|
||||
private boolean playerVersusPlayer = false;
|
||||
private boolean friendlyFire = false;
|
||||
|
||||
private List<DClass> dClasses = new ArrayList<DClass>();
|
||||
private Map<Integer, String> msgs = new HashMap<Integer, String>();
|
||||
|
||||
@ -232,6 +235,20 @@ public class WorldConfig {
|
||||
gameMode = plugin.getDefaultConfig().gameMode;
|
||||
}
|
||||
|
||||
/* PvP */
|
||||
if (configFile.contains("playerVersusPlayer")) {
|
||||
playerVersusPlayer = configFile.getBoolean("playerVersusPlayer");
|
||||
} else {
|
||||
playerVersusPlayer = plugin.getDefaultConfig().playerVersusPlayer;
|
||||
}
|
||||
|
||||
/* Friendly fire */
|
||||
if (configFile.contains("friendlyFire")) {
|
||||
friendlyFire = configFile.getBoolean("friendlyFire");
|
||||
} else {
|
||||
friendlyFire = plugin.getDefaultConfig().friendlyFire;
|
||||
}
|
||||
|
||||
/* Lives */
|
||||
if (configFile.contains("initialLives")) {
|
||||
initialLives = configFile.getInt("initialLives");
|
||||
@ -481,6 +498,20 @@ public class WorldConfig {
|
||||
return build;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if players may attack each other
|
||||
*/
|
||||
public boolean isPlayerVersusPlayer() {
|
||||
return playerVersusPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if players may attack group members
|
||||
*/
|
||||
public boolean isFriendlyFire() {
|
||||
return friendlyFire;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the initial amount of lives
|
||||
*/
|
||||
|
@ -1,10 +1,12 @@
|
||||
package io.github.dre2n.dungeonsxl.listener;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
|
||||
import io.github.dre2n.dungeonsxl.dungeon.WorldConfig;
|
||||
import io.github.dre2n.dungeonsxl.dungeon.game.GameWorld;
|
||||
import io.github.dre2n.dungeonsxl.global.DPortal;
|
||||
import io.github.dre2n.dungeonsxl.global.GroupSign;
|
||||
import io.github.dre2n.dungeonsxl.mob.DMob;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.player.DPlayer;
|
||||
|
||||
import java.util.List;
|
||||
@ -80,56 +82,84 @@ public class EntityListener implements Listener {
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
World world = event.getEntity().getWorld();
|
||||
GameWorld gameWorld = GameWorld.getByWorld(world);
|
||||
if (gameWorld != null) {
|
||||
// Deny all Damage in Lobby
|
||||
if ( !gameWorld.isPlaying()) {
|
||||
|
||||
if (gameWorld == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
WorldConfig config = gameWorld.getConfig();
|
||||
|
||||
// Deny all Damage in Lobby
|
||||
if ( !gameWorld.isPlaying()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// Deny all Damage from Players to Players
|
||||
if ( !(event instanceof EntityDamageByEntityEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) event;
|
||||
Entity attackerEntity = sub.getDamager();
|
||||
Entity attackedEntity = sub.getEntity();
|
||||
|
||||
if (attackerEntity instanceof Projectile) {
|
||||
attackerEntity = (Entity) ((Projectile) attackerEntity).getShooter();
|
||||
}
|
||||
|
||||
Player attackerPlayer = null;
|
||||
Player attackedPlayer = null;
|
||||
|
||||
DGroup attackerDGroup = null;
|
||||
DGroup attackedDGroup = null;
|
||||
|
||||
if (attackerEntity instanceof Player && attackedEntity instanceof Player) {
|
||||
attackerPlayer = (Player) attackerEntity;
|
||||
attackedPlayer = (Player) attackedEntity;
|
||||
|
||||
attackerDGroup = DGroup.getByPlayer(attackerPlayer);
|
||||
attackedDGroup = DGroup.getByPlayer(attackedPlayer);
|
||||
|
||||
if (config.isPlayerVersusPlayer()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
// Deny all Damage from Players to Players
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) event;
|
||||
Entity entity = sub.getDamager();
|
||||
Entity entity2 = sub.getEntity();
|
||||
|
||||
if (entity instanceof Projectile) {
|
||||
entity = (Entity) ((Projectile) entity).getShooter();
|
||||
}
|
||||
|
||||
if (entity instanceof Player && entity2 instanceof Player) {
|
||||
|
||||
if (attackerDGroup != null && attackedDGroup != null) {
|
||||
if (config.isFriendlyFire() && attackerDGroup.equals(attackedDGroup)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (entity instanceof LivingEntity && entity2 instanceof LivingEntity) {
|
||||
if ( !(entity instanceof Player) && !(entity2 instanceof Player)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// Check Dogs
|
||||
if (entity instanceof Player || entity2 instanceof Player) {
|
||||
for (DPlayer dPlayer : DPlayer.getByWorld(gameWorld.getWorld())) {
|
||||
if (dPlayer.getWolf() != null) {
|
||||
if (entity == dPlayer.getWolf() || entity2 == dPlayer.getWolf()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (attackerEntity instanceof LivingEntity && attackedEntity instanceof LivingEntity) {
|
||||
if ( !(attackerEntity instanceof Player) && !(attackedEntity instanceof Player)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
// Check Dogs
|
||||
if (attackerEntity instanceof Player || attackedEntity instanceof Player) {
|
||||
for (DPlayer dPlayer : DPlayer.getByWorld(gameWorld.getWorld())) {
|
||||
if (dPlayer.getWolf() != null) {
|
||||
if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (DPlayer dPlayer : DPlayer.getByWorld(gameWorld.getWorld())) {
|
||||
if (dPlayer.getWolf() != null) {
|
||||
if (entity instanceof Player || entity2 instanceof Player) {
|
||||
if (entity == dPlayer.getWolf() || entity2 == dPlayer.getWolf()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (entity == dPlayer.getWolf() || entity2 == dPlayer.getWolf()) {
|
||||
event.setCancelled(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (DPlayer dPlayer : DPlayer.getByWorld(gameWorld.getWorld())) {
|
||||
if (dPlayer.getWolf() != null) {
|
||||
if (attackerEntity instanceof Player || attackedEntity instanceof Player) {
|
||||
if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) {
|
||||
event.setCancelled(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ public class DGroup {
|
||||
|
||||
static DungeonsXL plugin = DungeonsXL.getPlugin();
|
||||
|
||||
private String name;
|
||||
private CopyOnWriteArrayList<Player> players = new CopyOnWriteArrayList<Player>();
|
||||
private String dungeonName;
|
||||
private String mapName;
|
||||
@ -31,8 +32,28 @@ public class DGroup {
|
||||
private int floorCount;
|
||||
private List<Reward> rewards = new ArrayList<Reward>();
|
||||
|
||||
public DGroup(String name, Player player, String identifier, boolean multiFloor) {
|
||||
plugin.getDGroups().add(this);
|
||||
this.name = name;
|
||||
|
||||
this.players.add(player);
|
||||
|
||||
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
|
||||
if (multiFloor && dungeon != null) {
|
||||
this.dungeonName = identifier;
|
||||
this.mapName = dungeon.getConfig().getStartFloor();
|
||||
this.unplayedFloors = dungeon.getConfig().getFloors();
|
||||
|
||||
} else {
|
||||
this.mapName = identifier;
|
||||
}
|
||||
this.playing = false;
|
||||
this.floorCount = 0;
|
||||
}
|
||||
|
||||
public DGroup(Player player, String identifier, boolean multiFloor) {
|
||||
plugin.getDGroups().add(this);
|
||||
this.name = "Group_" + plugin.getDGroups().size();
|
||||
|
||||
this.players.add(player);
|
||||
|
||||
@ -51,6 +72,21 @@ public class DGroup {
|
||||
|
||||
// Getters and setters
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the players
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user