mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
Add friendlyFire option to GameTypes
This commit is contained in:
parent
8b35d91f75
commit
d519578dae
@ -37,6 +37,17 @@ public interface GameType {
|
||||
*/
|
||||
public void setPlayerVersusPlayer(boolean playerVersusPlayer);
|
||||
|
||||
/**
|
||||
* @return the friendlyFire
|
||||
*/
|
||||
public boolean isFriendlyFire();
|
||||
|
||||
/**
|
||||
* @param friendlyFire
|
||||
* the friendlyFire to set
|
||||
*/
|
||||
public void setFriendlyFire(boolean friendlyFire);
|
||||
|
||||
/**
|
||||
* @return the mobWaves
|
||||
*/
|
||||
|
@ -4,25 +4,26 @@ import org.bukkit.GameMode;
|
||||
|
||||
public enum GameTypeDefault implements GameType {
|
||||
|
||||
ADVENTURE("Adventure", "Adventure", false, false, true, false, true, GameMode.ADVENTURE),
|
||||
ADVENTURE_TIME_IS_RUNNING("Adventure - Time is Running", "Adventure TiR", false, false, true, true, true, GameMode.ADVENTURE),
|
||||
APOCALYPSE_LAST_MAN_STANDING("Apocalypse", "Apocalypse LMS", true, true, true, false, false, GameMode.SURVIVAL),
|
||||
APOCALYPSE_LIMITED_MOBS("Apocalypse - Limited Mobs", "Apc Limited", true, true, true, false, false, GameMode.SURVIVAL),
|
||||
APOCALYPSE_TIME_IS_RUNNING("Apocalypse - Time is Running", "Apocalypse TiR", true, true, true, true, false, GameMode.SURVIVAL),
|
||||
PVE_LAST_MAN_STANDING("Player versus Environment - Last Man Standing", "PvE LMS", false, true, true, false, false, GameMode.SURVIVAL),
|
||||
PVE_LIMITED_MOBS("Player versus Environment - Limited Mobs", "PvE Limited", false, true, true, false, false, GameMode.SURVIVAL),
|
||||
PVE_TIME_IS_RUNNING("Player versus Environment - Time is Running", "PvE TiR", false, true, true, true, false, GameMode.SURVIVAL),
|
||||
PVP_FACTIONS_BATTLEFIELD("Player versus Player - Factions Battlefield", "FactionsPvP", true, false, false, false, false, GameMode.SURVIVAL),
|
||||
PVP_LAST_MAN_STANDING("Player versus Player - Last Man Standing", "PvP LMS", true, false, false, false, false, GameMode.SURVIVAL),
|
||||
QUEST("Quest", "Quest", false, false, true, false, false, GameMode.SURVIVAL),
|
||||
QUEST_TIME_IS_RUNNING("Quest - Time is Running", "Quest TiR", false, false, true, true, false, GameMode.SURVIVAL),
|
||||
TEST("Test", "Test", false, false, false, true, true, GameMode.SURVIVAL),
|
||||
TUTORIAL("Tutorial", "Tutorial", false, false, true, false, false, GameMode.SURVIVAL),
|
||||
ADVENTURE("Adventure", "Adventure", false, false, false, true, false, true, GameMode.ADVENTURE),
|
||||
ADVENTURE_TIME_IS_RUNNING("Adventure - Time is Running", "Adventure TiR", false, false, false, true, true, true, GameMode.ADVENTURE),
|
||||
APOCALYPSE_LAST_MAN_STANDING("Apocalypse", "Apocalypse LMS", true, true, true, true, false, false, GameMode.SURVIVAL),
|
||||
APOCALYPSE_LIMITED_MOBS("Apocalypse - Limited Mobs", "Apc Limited", true, true, true, true, false, false, GameMode.SURVIVAL),
|
||||
APOCALYPSE_TIME_IS_RUNNING("Apocalypse - Time is Running", "Apocalypse TiR", true, true, true, true, true, false, GameMode.SURVIVAL),
|
||||
PVE_LAST_MAN_STANDING("Player versus Environment - Last Man Standing", "PvE LMS", false, false, true, true, false, false, GameMode.SURVIVAL),
|
||||
PVE_LIMITED_MOBS("Player versus Environment - Limited Mobs", "PvE Limited", false, false, true, true, false, false, GameMode.SURVIVAL),
|
||||
PVE_TIME_IS_RUNNING("Player versus Environment - Time is Running", "PvE TiR", false, false, true, true, true, false, GameMode.SURVIVAL),
|
||||
PVP_FACTIONS_BATTLEFIELD("Player versus Player - Factions Battlefield", "FactionsPvP", true, false, false, false, false, false, GameMode.SURVIVAL),
|
||||
PVP_LAST_MAN_STANDING("Player versus Player - Last Man Standing", "PvP LMS", true, false, false, false, false, false, GameMode.SURVIVAL),
|
||||
QUEST("Quest", "Quest", false, false, false, true, false, false, GameMode.SURVIVAL),
|
||||
QUEST_TIME_IS_RUNNING("Quest - Time is Running", "Quest TiR", false, false, false, true, true, false, GameMode.SURVIVAL),
|
||||
TEST("Test", "Test", false, false, false, false, true, true, GameMode.SURVIVAL),
|
||||
TUTORIAL("Tutorial", "Tutorial", false, false, false, true, false, false, GameMode.SURVIVAL),
|
||||
DEFAULT("Default", "Default");
|
||||
|
||||
private String displayName;
|
||||
private String signName;
|
||||
private boolean playerVersusPlayer;
|
||||
private boolean friendlyFire;
|
||||
private boolean mobWaves;
|
||||
private boolean rewards;
|
||||
private boolean showTime;
|
||||
@ -34,10 +35,11 @@ public enum GameTypeDefault implements GameType {
|
||||
this.signName = signName;
|
||||
}
|
||||
|
||||
GameTypeDefault(String displayName, String signName, boolean playerVersusPlayer, boolean mobWaves, boolean rewards, boolean showTime, boolean build, GameMode gameMode) {
|
||||
GameTypeDefault(String displayName, String signName, boolean playerVersusPlayer, boolean friendlyFire, boolean mobWaves, boolean rewards, boolean showTime, boolean build, GameMode gameMode) {
|
||||
this.displayName = displayName;
|
||||
this.signName = signName;
|
||||
this.playerVersusPlayer = playerVersusPlayer;
|
||||
this.setFriendlyFire(friendlyFire);
|
||||
this.mobWaves = mobWaves;
|
||||
this.rewards = rewards;
|
||||
this.showTime = showTime;
|
||||
@ -75,6 +77,16 @@ public enum GameTypeDefault implements GameType {
|
||||
this.playerVersusPlayer = playerVersusPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFriendlyFire() {
|
||||
return friendlyFire;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFriendlyFire(boolean friendlyFire) {
|
||||
this.friendlyFire = friendlyFire;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMobWaves() {
|
||||
return mobWaves;
|
||||
|
@ -2,6 +2,9 @@ package io.github.dre2n.dungeonsxl.listener;
|
||||
|
||||
import io.github.dre2n.dungeonsxl.config.WorldConfig;
|
||||
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
|
||||
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.game.GameWorld;
|
||||
import io.github.dre2n.dungeonsxl.global.DPortal;
|
||||
import io.github.dre2n.dungeonsxl.global.GroupSign;
|
||||
@ -62,7 +65,7 @@ public class EntityListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
public void onDeath(EntityDeathEvent event) {
|
||||
World world = event.getEntity().getWorld();
|
||||
|
||||
if (event.getEntity() instanceof LivingEntity) {
|
||||
@ -80,7 +83,7 @@ public class EntityListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
public void onDamage(EntityDamageEvent event) {
|
||||
World world = event.getEntity().getWorld();
|
||||
GameWorld gameWorld = GameWorld.getByWorld(world);
|
||||
|
||||
@ -88,21 +91,40 @@ public class EntityListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
WorldConfig config = gameWorld.getConfig();
|
||||
|
||||
// Deny all Damage in Lobby
|
||||
if ( !gameWorld.isPlaying()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
World world = event.getEntity().getWorld();
|
||||
GameWorld gameWorld = GameWorld.getByWorld(world);
|
||||
|
||||
// Deny all Damage from Players to Players
|
||||
if ( !(event instanceof EntityDamageByEntityEvent)) {
|
||||
if (gameWorld == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) event;
|
||||
Entity attackerEntity = sub.getDamager();
|
||||
Entity attackedEntity = sub.getEntity();
|
||||
Game game = gameWorld.getGame();
|
||||
|
||||
if (game == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
WorldConfig config = gameWorld.getConfig();
|
||||
GameType type = game.getType();
|
||||
|
||||
boolean pvp = config.isPlayerVersusPlayer();
|
||||
boolean friendlyFire = config.isFriendlyFire();
|
||||
|
||||
if (type != GameTypeDefault.DEFAULT) {
|
||||
pvp = type.isPlayerVersusPlayer();
|
||||
friendlyFire = type.isFriendlyFire();
|
||||
}
|
||||
|
||||
Entity attackerEntity = event.getDamager();
|
||||
Entity attackedEntity = event.getEntity();
|
||||
|
||||
if (attackerEntity instanceof Projectile) {
|
||||
attackerEntity = (Entity) ((Projectile) attackerEntity).getShooter();
|
||||
@ -121,13 +143,12 @@ public class EntityListener implements Listener {
|
||||
attackerDGroup = DGroup.getByPlayer(attackerPlayer);
|
||||
attackedDGroup = DGroup.getByPlayer(attackedPlayer);
|
||||
|
||||
if (config.isPlayerVersusPlayer()) {
|
||||
Bukkit.broadcastMessage("pvp cancel");
|
||||
if ( !pvp) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (attackerDGroup != null && attackedDGroup != null) {
|
||||
if (config.isFriendlyFire() && attackerDGroup.equals(attackedDGroup)) {
|
||||
if ( !friendlyFire && attackerDGroup.equals(attackedDGroup)) {
|
||||
Bukkit.broadcastMessage("ff cancel");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@ -185,7 +206,7 @@ public class EntityListener implements Listener {
|
||||
|
||||
// Zombie/skeleton combustion from the sun.
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onEntityCombust(EntityCombustEvent event) {
|
||||
public void onCombust(EntityCombustEvent event) {
|
||||
GameWorld gameWorld = GameWorld.getByWorld(event.getEntity().getWorld());
|
||||
if (gameWorld != null) {
|
||||
event.setCancelled(true);
|
||||
@ -194,7 +215,7 @@ public class EntityListener implements Listener {
|
||||
|
||||
// Allow Other combustion
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
|
||||
public void onCombustByEntity(EntityCombustByEntityEvent event) {
|
||||
GameWorld gameWorld = GameWorld.getByWorld(event.getEntity().getWorld());
|
||||
if (gameWorld != null) {
|
||||
if (event.isCancelled()) {
|
||||
@ -205,7 +226,7 @@ public class EntityListener implements Listener {
|
||||
|
||||
// Explosions
|
||||
@EventHandler
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
public void onExplode(EntityExplodeEvent event) {
|
||||
GameWorld gameWorld = GameWorld.getByWorld(event.getEntity().getWorld());
|
||||
|
||||
if (gameWorld != null) {
|
||||
@ -241,4 +262,5 @@ public class EntityListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user