mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-12-01 06:53:26 +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);
|
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
|
* @return the mobWaves
|
||||||
*/
|
*/
|
||||||
|
@ -4,25 +4,26 @@ import org.bukkit.GameMode;
|
|||||||
|
|
||||||
public enum GameTypeDefault implements GameType {
|
public enum GameTypeDefault implements GameType {
|
||||||
|
|
||||||
ADVENTURE("Adventure", "Adventure", false, false, true, false, true, GameMode.ADVENTURE),
|
ADVENTURE("Adventure", "Adventure", false, false, false, true, false, true, GameMode.ADVENTURE),
|
||||||
ADVENTURE_TIME_IS_RUNNING("Adventure - Time is Running", "Adventure TiR", false, false, true, true, 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, false, false, GameMode.SURVIVAL),
|
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, 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, 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, true, true, false, 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, 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, true, true, true, 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, 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, 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, true, 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, true, true, 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, true, true, GameMode.SURVIVAL),
|
TEST("Test", "Test", false, false, false, false, true, true, GameMode.SURVIVAL),
|
||||||
TUTORIAL("Tutorial", "Tutorial", false, false, true, false, false, GameMode.SURVIVAL),
|
TUTORIAL("Tutorial", "Tutorial", false, false, false, true, false, false, GameMode.SURVIVAL),
|
||||||
DEFAULT("Default", "Default");
|
DEFAULT("Default", "Default");
|
||||||
|
|
||||||
private String displayName;
|
private String displayName;
|
||||||
private String signName;
|
private String signName;
|
||||||
private boolean playerVersusPlayer;
|
private boolean playerVersusPlayer;
|
||||||
|
private boolean friendlyFire;
|
||||||
private boolean mobWaves;
|
private boolean mobWaves;
|
||||||
private boolean rewards;
|
private boolean rewards;
|
||||||
private boolean showTime;
|
private boolean showTime;
|
||||||
@ -34,10 +35,11 @@ public enum GameTypeDefault implements GameType {
|
|||||||
this.signName = signName;
|
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.displayName = displayName;
|
||||||
this.signName = signName;
|
this.signName = signName;
|
||||||
this.playerVersusPlayer = playerVersusPlayer;
|
this.playerVersusPlayer = playerVersusPlayer;
|
||||||
|
this.setFriendlyFire(friendlyFire);
|
||||||
this.mobWaves = mobWaves;
|
this.mobWaves = mobWaves;
|
||||||
this.rewards = rewards;
|
this.rewards = rewards;
|
||||||
this.showTime = showTime;
|
this.showTime = showTime;
|
||||||
@ -75,6 +77,16 @@ public enum GameTypeDefault implements GameType {
|
|||||||
this.playerVersusPlayer = playerVersusPlayer;
|
this.playerVersusPlayer = playerVersusPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFriendlyFire() {
|
||||||
|
return friendlyFire;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFriendlyFire(boolean friendlyFire) {
|
||||||
|
this.friendlyFire = friendlyFire;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasMobWaves() {
|
public boolean hasMobWaves() {
|
||||||
return mobWaves;
|
return mobWaves;
|
||||||
|
@ -2,6 +2,9 @@ package io.github.dre2n.dungeonsxl.listener;
|
|||||||
|
|
||||||
import io.github.dre2n.dungeonsxl.config.WorldConfig;
|
import io.github.dre2n.dungeonsxl.config.WorldConfig;
|
||||||
import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
|
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.game.GameWorld;
|
||||||
import io.github.dre2n.dungeonsxl.global.DPortal;
|
import io.github.dre2n.dungeonsxl.global.DPortal;
|
||||||
import io.github.dre2n.dungeonsxl.global.GroupSign;
|
import io.github.dre2n.dungeonsxl.global.GroupSign;
|
||||||
@ -62,7 +65,7 @@ public class EntityListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onEntityDeath(EntityDeathEvent event) {
|
public void onDeath(EntityDeathEvent event) {
|
||||||
World world = event.getEntity().getWorld();
|
World world = event.getEntity().getWorld();
|
||||||
|
|
||||||
if (event.getEntity() instanceof LivingEntity) {
|
if (event.getEntity() instanceof LivingEntity) {
|
||||||
@ -80,7 +83,7 @@ public class EntityListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onEntityDamage(EntityDamageEvent event) {
|
public void onDamage(EntityDamageEvent event) {
|
||||||
World world = event.getEntity().getWorld();
|
World world = event.getEntity().getWorld();
|
||||||
GameWorld gameWorld = GameWorld.getByWorld(world);
|
GameWorld gameWorld = GameWorld.getByWorld(world);
|
||||||
|
|
||||||
@ -88,21 +91,40 @@ public class EntityListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldConfig config = gameWorld.getConfig();
|
|
||||||
|
|
||||||
// Deny all Damage in Lobby
|
// Deny all Damage in Lobby
|
||||||
if ( !gameWorld.isPlaying()) {
|
if ( !gameWorld.isPlaying()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Deny all Damage from Players to Players
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
if ( !(event instanceof EntityDamageByEntityEvent)) {
|
public void onDamageByEntity(EntityDamageByEntityEvent event) {
|
||||||
|
World world = event.getEntity().getWorld();
|
||||||
|
GameWorld gameWorld = GameWorld.getByWorld(world);
|
||||||
|
|
||||||
|
if (gameWorld == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent) event;
|
Game game = gameWorld.getGame();
|
||||||
Entity attackerEntity = sub.getDamager();
|
|
||||||
Entity attackedEntity = sub.getEntity();
|
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) {
|
if (attackerEntity instanceof Projectile) {
|
||||||
attackerEntity = (Entity) ((Projectile) attackerEntity).getShooter();
|
attackerEntity = (Entity) ((Projectile) attackerEntity).getShooter();
|
||||||
@ -121,13 +143,12 @@ public class EntityListener implements Listener {
|
|||||||
attackerDGroup = DGroup.getByPlayer(attackerPlayer);
|
attackerDGroup = DGroup.getByPlayer(attackerPlayer);
|
||||||
attackedDGroup = DGroup.getByPlayer(attackedPlayer);
|
attackedDGroup = DGroup.getByPlayer(attackedPlayer);
|
||||||
|
|
||||||
if (config.isPlayerVersusPlayer()) {
|
if ( !pvp) {
|
||||||
Bukkit.broadcastMessage("pvp cancel");
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attackerDGroup != null && attackedDGroup != null) {
|
if (attackerDGroup != null && attackedDGroup != null) {
|
||||||
if (config.isFriendlyFire() && attackerDGroup.equals(attackedDGroup)) {
|
if ( !friendlyFire && attackerDGroup.equals(attackedDGroup)) {
|
||||||
Bukkit.broadcastMessage("ff cancel");
|
Bukkit.broadcastMessage("ff cancel");
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
@ -185,7 +206,7 @@ public class EntityListener implements Listener {
|
|||||||
|
|
||||||
// Zombie/skeleton combustion from the sun.
|
// Zombie/skeleton combustion from the sun.
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onEntityCombust(EntityCombustEvent event) {
|
public void onCombust(EntityCombustEvent event) {
|
||||||
GameWorld gameWorld = GameWorld.getByWorld(event.getEntity().getWorld());
|
GameWorld gameWorld = GameWorld.getByWorld(event.getEntity().getWorld());
|
||||||
if (gameWorld != null) {
|
if (gameWorld != null) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -194,7 +215,7 @@ public class EntityListener implements Listener {
|
|||||||
|
|
||||||
// Allow Other combustion
|
// Allow Other combustion
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
|
public void onCombustByEntity(EntityCombustByEntityEvent event) {
|
||||||
GameWorld gameWorld = GameWorld.getByWorld(event.getEntity().getWorld());
|
GameWorld gameWorld = GameWorld.getByWorld(event.getEntity().getWorld());
|
||||||
if (gameWorld != null) {
|
if (gameWorld != null) {
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
@ -205,7 +226,7 @@ public class EntityListener implements Listener {
|
|||||||
|
|
||||||
// Explosions
|
// Explosions
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityExplode(EntityExplodeEvent event) {
|
public void onExplode(EntityExplodeEvent event) {
|
||||||
GameWorld gameWorld = GameWorld.getByWorld(event.getEntity().getWorld());
|
GameWorld gameWorld = GameWorld.getByWorld(event.getEntity().getWorld());
|
||||||
|
|
||||||
if (gameWorld != null) {
|
if (gameWorld != null) {
|
||||||
@ -241,4 +262,5 @@ public class EntityListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user