Fixes quite a lot of warnings

This commit is contained in:
2022-08-05 03:42:35 +02:00
parent f8407a3692
commit 950faa7100
270 changed files with 3014 additions and 3078 deletions

View File

@@ -1,5 +1,8 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
import net.knarcraft.factions.Rel;
import net.knarcraft.factions.entity.BoardColl;
import net.knarcraft.factions.entity.Faction;
@@ -7,9 +10,6 @@ import net.knarcraft.factions.entity.MConf;
import net.knarcraft.factions.entity.MFlag;
import net.knarcraft.factions.entity.MPlayer;
import net.knarcraft.factions.event.EventFactionsPvpDisallowed;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
@@ -32,7 +32,7 @@ public class EngineCanCombatHappen extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineCanCombatHappen i = new EngineCanCombatHappen();
private static final EngineCanCombatHappen i = new EngineCanCombatHappen();
public static EngineCanCombatHappen get() {
return i;
@@ -44,9 +44,9 @@ public class EngineCanCombatHappen extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void canCombatDamageHappen(EntityDamageByEntityEvent event) {
if (this.canCombatDamageHappen(event, true)) {
return;
}
if (this.canCombatDamageHappen(event, true)) {
return;
}
event.setCancelled(true);
Entity damager = event.getDamager();
@@ -61,32 +61,30 @@ public class EngineCanCombatHappen extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void canCombatDamageHappen(EntityCombustByEntityEvent event) {
EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), EntityDamageEvent.DamageCause.FIRE, 0D);
if (this.canCombatDamageHappen(sub, false)) {
return;
}
if (this.canCombatDamageHappen(sub, false)) {
return;
}
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void canCombatDamageHappen(PotionSplashEvent event) {
// If a harmful potion is splashing ...
if (!MUtil.isHarmfulPotion(event.getPotion())) {
return;
}
if (!MUtil.isHarmfulPotion(event.getPotion())) {
return;
}
ProjectileSource projectileSource = event.getPotion().getShooter();
if (!(projectileSource instanceof Entity)) {
return;
}
Entity thrower = (Entity) projectileSource;
if (!(projectileSource instanceof Entity thrower)) {
return;
}
// ... scan through affected entities to make sure they're all valid targets.
for (LivingEntity affectedEntity : event.getAffectedEntities()) {
EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(thrower, affectedEntity, EntityDamageEvent.DamageCause.CUSTOM, 0D);
if (this.canCombatDamageHappen(sub, true)) {
continue;
}
if (this.canCombatDamageHappen(sub, true)) {
continue;
}
// affected entity list doesn't accept modification (iter.remove() is a no-go), but this works
event.setIntensity(affectedEntity, 0.0);
@@ -96,16 +94,14 @@ public class EngineCanCombatHappen extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void canCombatDamageHappen(AreaEffectCloudApplyEvent event) {
// If a harmful potion effect cloud is present ...
if (!MUtil.isHarmfulPotion(event.getEntity().getBasePotionData().getType().getEffectType())) {
return;
}
if (!MUtil.isHarmfulPotion(event.getEntity().getBasePotionData().getType().getEffectType())) {
return;
}
ProjectileSource projectileSource = event.getEntity().getSource();
if (!(projectileSource instanceof Entity)) {
return;
}
Entity thrower = (Entity) projectileSource;
if (!(projectileSource instanceof Entity thrower)) {
return;
}
// ... create a dummy list to avoid ConcurrentModificationException ...
List<LivingEntity> affectedList = new ArrayList<>();
@@ -114,9 +110,9 @@ public class EngineCanCombatHappen extends Engine {
for (LivingEntity affectedEntity : event.getAffectedEntities()) {
EntityDamageByEntityEvent sub = new EntityDamageByEntityEvent(thrower, affectedEntity, EntityDamageEvent.DamageCause.CUSTOM, 0D);
// Notification disabled due to the iterating nature of effect clouds.
if (EngineCanCombatHappen.get().canCombatDamageHappen(sub, false)) {
continue;
}
if (EngineCanCombatHappen.get().canCombatDamageHappen(sub, false)) {
continue;
}
affectedList.add(affectedEntity);
}
@@ -137,9 +133,9 @@ public class EngineCanCombatHappen extends Engine {
// If the defender is a player ...
Entity edefender = event.getEntity();
if (MUtil.isntPlayer(edefender)) {
return true;
}
if (MUtil.isntPlayer(edefender)) {
return true;
}
Player defender = (Player) edefender;
MPlayer mdefender = MPlayer.get(edefender);
@@ -148,9 +144,9 @@ public class EngineCanCombatHappen extends Engine {
// (we check null here since there may not be an attacker)
// (lack of attacker situations can be caused by other bukkit plugins)
if (eattacker != null && eattacker.equals(edefender)) {
return true;
}
if (eattacker != null && eattacker.equals(edefender)) {
return true;
}
// ... gather defender PS and faction information ...
PS defenderPs = PS.valueOf(defender.getLocation());
@@ -160,13 +156,13 @@ public class EngineCanCombatHappen extends Engine {
if (MUtil.isPlayer(eattacker)) {
MPlayer mplayer = MPlayer.get(eattacker);
if (mplayer != null && mplayer.isOverriding()) {
return true;
}
if (mplayer != null && mplayer.isOverriding()) {
return true;
}
}
// ... PVP flag may cause a damage block ...
if (defenderPsFaction.getFlag(MFlag.getFlagPvp()) == false) {
if (!defenderPsFaction.getFlag(MFlag.getFlagPvp())) {
if (eattacker == null) {
// No attacker?
// Let's behave as if it were a player
@@ -184,16 +180,16 @@ public class EngineCanCombatHappen extends Engine {
}
// ... and if the attacker is a player ...
if (MUtil.isntPlayer(eattacker)) {
return true;
}
if (MUtil.isntPlayer(eattacker)) {
return true;
}
Player attacker = (Player) eattacker;
MPlayer uattacker = MPlayer.get(attacker);
// ... does this player bypass all protection? ...
if (MConf.get().playersWhoBypassAllProtection.contains(attacker.getName())) {
return true;
}
if (MConf.get().playersWhoBypassAllProtection.contains(attacker.getName())) {
return true;
}
// ... gather attacker PS and faction information ...
PS attackerPs = PS.valueOf(attacker.getLocation());
@@ -202,27 +198,27 @@ public class EngineCanCombatHappen extends Engine {
// ... PVP flag may cause a damage block ...
// (just checking the defender as above isn't enough. What about the attacker? It could be in a no-pvp area)
// NOTE: This check is probably not that important but we could keep it anyways.
if (attackerPsFaction.getFlag(MFlag.getFlagPvp()) == false) {
if (!attackerPsFaction.getFlag(MFlag.getFlagPvp())) {
ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.PEACEFUL_LAND, event);
if (!ret && notify) {
uattacker.msg("<i>PVP is disabled in %s.", attackerPsFaction.describeTo(uattacker));
}
if (!ret && notify) {
uattacker.msg("<i>PVP is disabled in %s.", attackerPsFaction.describeTo(uattacker));
}
return ret;
}
// ... are PVP rules completely ignored in this world? ...
if (!MConf.get().worldsPvpRulesEnabled.contains(defenderPs.getWorld())) {
return true;
}
if (!MConf.get().worldsPvpRulesEnabled.contains(defenderPs.getWorld())) {
return true;
}
Faction defendFaction = mdefender.getFaction();
Faction attackFaction = uattacker.getFaction();
if (attackFaction.isNone() && MConf.get().disablePVPForFactionlessPlayers) {
ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.FACTIONLESS, event);
if (!ret && notify) {
uattacker.msg("<i>You can't hurt other players until you join a faction.");
}
if (!ret && notify) {
uattacker.msg("<i>You can't hurt other players until you join a faction.");
}
return ret;
} else if (defendFaction.isNone()) {
if (defenderPsFaction == attackFaction && MConf.get().enablePVPAgainstFactionlessInAttackersLand) {
@@ -230,9 +226,9 @@ public class EngineCanCombatHappen extends Engine {
return true;
} else if (MConf.get().disablePVPForFactionlessPlayers) {
ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.FACTIONLESS, event);
if (!ret && notify) {
uattacker.msg("<i>You can't hurt players who are not currently in a faction.");
}
if (!ret && notify) {
uattacker.msg("<i>You can't hurt players who are not currently in a faction.");
}
return ret;
} else if (attackFaction.isNone() && MConf.get().enablePVPBetweenFactionlessPlayers) {
// Allow factionless vs factionless
@@ -243,11 +239,11 @@ public class EngineCanCombatHappen extends Engine {
Rel relation = defendFaction.getRelationTo(attackFaction);
// Check the relation
if (relation.isFriend() && defenderPsFaction.getFlag(MFlag.getFlagFriendlyire()) == false) {
if (relation.isFriend() && !defenderPsFaction.getFlag(MFlag.getFlagFriendlyire())) {
ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, DisallowCause.FRIENDLYFIRE, event);
if (!ret && notify) {
uattacker.msg("<i>You can't hurt %s<i>.", relation.getDescPlayerMany());
}
if (!ret && notify) {
uattacker.msg("<i>You can't hurt %s<i>.", relation.getDescPlayerMany());
}
return ret;
}

View File

@@ -1,5 +1,8 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat;
import com.massivecraft.massivecore.util.MUtil;
import net.knarcraft.factions.Factions;
import net.knarcraft.factions.Rel;
import net.knarcraft.factions.RelationParticipator;
@@ -7,9 +10,6 @@ import net.knarcraft.factions.chat.ChatFormatter;
import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.entity.MConf;
import net.knarcraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat;
import com.massivecraft.massivecore.util.MUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
@@ -18,6 +18,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.EventExecutor;
import org.jetbrains.annotations.NotNull;
import java.util.Iterator;
import java.util.function.Predicate;
@@ -27,7 +28,7 @@ public class EngineChat extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineChat i = new EngineChat();
private static final EngineChat i = new EngineChat();
public static EngineChat get() {
return i;
@@ -64,9 +65,9 @@ public class EngineChat extends Engine {
// SET FORMAT
// -------------------------------------------- //
private class SetFormatEventExecutor implements EventExecutor {
private static class SetFormatEventExecutor implements EventExecutor {
@Override
public void execute(Listener listener, Event event) throws EventException {
public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException {
try {
if (!(event instanceof AsyncPlayerChatEvent)) {
return;
@@ -86,9 +87,9 @@ public class EngineChat extends Engine {
// PARSE TAGS
// -------------------------------------------- //
private class ParseTagsEventExecutor implements EventExecutor {
private static class ParseTagsEventExecutor implements EventExecutor {
@Override
public void execute(Listener listener, Event event) throws EventException {
public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException {
try {
if (!(event instanceof AsyncPlayerChatEvent)) {
return;
@@ -115,9 +116,9 @@ public class EngineChat extends Engine {
// PARSE RELCOLOR
// -------------------------------------------- //
private class ParseRelcolorEventExecutor implements EventExecutor {
private static class ParseRelcolorEventExecutor implements EventExecutor {
@Override
public void execute(Listener listener, Event event) throws EventException {
public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException {
try {
if (!(event instanceof EventMassiveCorePlayerToRecipientChat)) {
return;

View File

@@ -1,5 +1,11 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.collections.MassiveSet;
import com.massivecraft.massivecore.mixin.MixinWorld;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.Txt;
import net.knarcraft.factions.Rel;
import net.knarcraft.factions.entity.BoardColl;
import net.knarcraft.factions.entity.Faction;
@@ -9,12 +15,6 @@ import net.knarcraft.factions.entity.MFlag;
import net.knarcraft.factions.entity.MPerm;
import net.knarcraft.factions.entity.MPlayer;
import net.knarcraft.factions.event.EventFactionsChunksChange;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.collections.MassiveSet;
import com.massivecraft.massivecore.mixin.MixinWorld;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.Txt;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -30,7 +30,7 @@ public class EngineChunkChange extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineChunkChange i = new EngineChunkChange();
private static final EngineChunkChange i = new EngineChunkChange();
public static EngineChunkChange get() {
return i;
@@ -60,9 +60,9 @@ public class EngineChunkChange extends Engine {
final Set<PS> chunks = event.getChunks();
// Override Mode? Sure!
if (mplayer.isOverriding()) {
return;
}
if (mplayer.isOverriding()) {
return;
}
// CALC: Is there at least one normal faction among the current ones?
boolean currentFactionsContainsAtLeastOneNormal = false;
@@ -156,9 +156,9 @@ public class EngineChunkChange extends Engine {
// HOW: Next we check if the new faction has permission to claim nearby the nearby factions.
MPerm claimnear = MPerm.getPermClaimnear();
for (Faction nearbyFaction : nearbyFactions) {
if (claimnear.has(mplayer, nearbyFaction, true)) {
continue;
}
if (claimnear.has(mplayer, nearbyFaction, true)) {
continue;
}
event.setCancelled(true);
return;
}
@@ -217,14 +217,14 @@ public class EngineChunkChange extends Engine {
Set<PS> oldChunks = entry.getValue();
// ... that is an actual faction ...
if (oldFaction.isNone()) {
continue;
}
if (oldFaction.isNone()) {
continue;
}
// ... for which the mplayer lacks permission ...
if (MPerm.getPermTerritory().has(mplayer, oldFaction, false)) {
continue;
}
if (MPerm.getPermTerritory().has(mplayer, oldFaction, false)) {
continue;
}
// ... consider all reasons to forbid "overclaiming/warclaiming" ...

View File

@@ -1,11 +1,11 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerCleanInactivityToleranceMillis;
import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.entity.MConf;
import net.knarcraft.factions.entity.MPlayer;
import net.knarcraft.factions.entity.MPlayerColl;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerCleanInactivityToleranceMillis;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -17,7 +17,7 @@ public class EngineCleanInactivity extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineCleanInactivity i = new EngineCleanInactivity();
private static final EngineCleanInactivity i = new EngineCleanInactivity();
public static EngineCleanInactivity get() {
return i;
@@ -29,9 +29,9 @@ public class EngineCleanInactivity extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void ageBonus(EventMassiveCorePlayerCleanInactivityToleranceMillis event) {
if (event.getColl() != MPlayerColl.get()) {
return;
}
if (event.getColl() != MPlayerColl.get()) {
return;
}
applyPlayerAgeBonus(event);
applyFactionAgeBonus(event);
@@ -40,16 +40,16 @@ public class EngineCleanInactivity extends Engine {
public void applyPlayerAgeBonus(EventMassiveCorePlayerCleanInactivityToleranceMillis event) {
// Calculate First Played
Long firstPlayed = event.getEntity().getFirstPlayed();
Long age = 0L;
long age = 0L;
if (firstPlayed != null) {
age = System.currentTimeMillis() - firstPlayed;
}
// Calculate the Bonus!
Long bonus = calculateBonus(age, MConf.get().cleanInactivityToleranceMillisPlayerAgeToBonus);
if (bonus == null) {
return;
}
if (bonus == null) {
return;
}
// Apply
event.getToleranceCauseMillis().put("Player Age Bonus", bonus);
@@ -65,30 +65,30 @@ public class EngineCleanInactivity extends Engine {
// Calculate the Bonus!
Long bonus = calculateBonus(age, MConf.get().cleanInactivityToleranceMillisFactionAgeToBonus);
if (bonus == null) {
return;
}
if (bonus == null) {
return;
}
// Apply
event.getToleranceCauseMillis().put("Faction Age Bonus", bonus);
}
private Long calculateBonus(long age, Map<Long, Long> ageToBonus) {
if (ageToBonus.isEmpty()) {
return null;
}
if (ageToBonus.isEmpty()) {
return null;
}
Long bonus = 0L;
long bonus = 0L;
for (Entry<Long, Long> entry : ageToBonus.entrySet()) {
Long key = entry.getKey();
if (key == null) {
continue;
}
if (key == null) {
continue;
}
Long value = entry.getValue();
if (value == null) {
continue;
}
if (value == null) {
continue;
}
if (age >= key) {
bonus = value;

View File

@@ -1,15 +1,15 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt;
import net.knarcraft.factions.Rel;
import net.knarcraft.factions.entity.BoardColl;
import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.entity.MConf;
import net.knarcraft.factions.entity.MFlag;
import net.knarcraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -22,7 +22,7 @@ public class EngineDenyCommands extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineDenyCommands i = new EngineDenyCommands();
private static final EngineDenyCommands i = new EngineDenyCommands();
public static EngineDenyCommands get() {
return i;
@@ -36,15 +36,15 @@ public class EngineDenyCommands extends Engine {
public void denyCommands(PlayerCommandPreprocessEvent event) {
// If a player is trying to run a command ...
Player player = event.getPlayer();
if (MUtil.isntPlayer(player)) {
return;
}
if (MUtil.isntPlayer(player)) {
return;
}
MPlayer mplayer = MPlayer.get(player);
// ... and the player is not overriding ...
if (mplayer.isOverriding()) {
return;
}
if (mplayer.isOverriding()) {
return;
}
// ... clean up the command ...
String command = event.getMessage();
@@ -72,19 +72,19 @@ public class EngineDenyCommands extends Engine {
if (MConf.get().denyCommandsDistance > -1 && !MConf.get().denyCommandsDistanceBypassIn.contains(factionAtRel)) {
for (Player otherplayer : player.getWorld().getPlayers()) {
MPlayer othermplayer = MPlayer.get(otherplayer);
if (othermplayer == mplayer) {
continue;
}
if (othermplayer == mplayer) {
continue;
}
double distance = player.getLocation().distance(otherplayer.getLocation());
if (MConf.get().denyCommandsDistance > distance) {
continue;
}
if (MConf.get().denyCommandsDistance > distance) {
continue;
}
Rel playerRel = mplayer.getRelationTo(othermplayer);
if (!MConf.get().denyCommandsDistanceRelation.containsKey(playerRel)) {
continue;
}
if (!MConf.get().denyCommandsDistanceRelation.containsKey(playerRel)) {
continue;
}
String desc = playerRel.getDescPlayerOne();
@@ -95,17 +95,17 @@ public class EngineDenyCommands extends Engine {
}
// ... if there is no relation here then there are no further checks ...
if (factionAtRel == null) {
return;
}
if (factionAtRel == null) {
return;
}
List<String> deniedCommands = MConf.get().denyCommandsTerritoryRelation.get(factionAtRel);
if (deniedCommands == null) {
return;
}
if (!MUtil.containsCommand(command, deniedCommands)) {
return;
}
if (deniedCommands == null) {
return;
}
if (!MUtil.containsCommand(command, deniedCommands)) {
return;
}
mplayer.msg("<b>You can't use \"<h>/%s<b>\" in %s territory.", command, Txt.getNicedEnum(factionAtRel));
event.setCancelled(true);

View File

@@ -1,16 +1,16 @@
package net.knarcraft.factions.engine;
import net.knarcraft.factions.Rel;
import net.knarcraft.factions.entity.BoardColl;
import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.entity.MConf;
import net.knarcraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.Couple;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.mixin.MixinMessage;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt;
import net.knarcraft.factions.Rel;
import net.knarcraft.factions.entity.BoardColl;
import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.entity.MConf;
import net.knarcraft.factions.entity.MPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -25,7 +25,7 @@ public class EngineDenyTeleport extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineDenyTeleport i = new EngineDenyTeleport();
private static final EngineDenyTeleport i = new EngineDenyTeleport();
public static EngineDenyTeleport get() {
return i;
@@ -45,9 +45,9 @@ public class EngineDenyTeleport extends Engine {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void canTeleportHappen(PlayerTeleportEvent event) {
Entry<TeleportCause, TerritoryType> entry = shouldBeCancelled(event);
if (entry == null) {
return;
}
if (entry == null) {
return;
}
event.setCancelled(true);
@@ -56,18 +56,18 @@ public class EngineDenyTeleport extends Engine {
String teleportDesc = Txt.getNicedEnum(cause);
String denyDesc = "";
if (deny == TerritoryType.ENEMY) {
denyDesc = "enemy";
}
if (deny == TerritoryType.WILDERNESS) {
denyDesc = "wilderness";
}
if (deny == TerritoryType.OWN) {
denyDesc = "your own";
}
if (deny == TerritoryType.OTHER) {
denyDesc = "other faction's";
}
if (deny == TerritoryType.ENEMY) {
denyDesc = "enemy";
}
if (deny == TerritoryType.WILDERNESS) {
denyDesc = "wilderness";
}
if (deny == TerritoryType.OWN) {
denyDesc = "your own";
}
if (deny == TerritoryType.OTHER) {
denyDesc = "other faction's";
}
Player player = event.getPlayer();
MixinMessage.get().msgOne(player, "<b>Teleportation with %s is not allowed in %s territory.", teleportDesc, denyDesc);
@@ -75,9 +75,9 @@ public class EngineDenyTeleport extends Engine {
private Entry<TeleportCause, TerritoryType> shouldBeCancelled(PlayerTeleportEvent event) {
Player player = event.getPlayer();
if (MUtil.isntPlayer(player)) {
return null;
}
if (MUtil.isntPlayer(player)) {
return null;
}
MPlayer mplayer = MPlayer.get(player);
@@ -92,40 +92,39 @@ public class EngineDenyTeleport extends Engine {
MConf mconf = MConf.get();
if (cause == TeleportCause.CHORUS_FRUIT) {
if (!mconf.allowChorusFruitInEnemyTerritory && types.contains(TerritoryType.ENEMY)) {
return Couple.valueOf(cause, TerritoryType.ENEMY);
}
if (!mconf.allowChorusFruitInEnemyTerritory && types.contains(TerritoryType.ENEMY)) {
return Couple.valueOf(cause, TerritoryType.ENEMY);
}
if (!mconf.allowChorusFruitInWildernessTerritory && types.contains(TerritoryType.WILDERNESS)) {
return Couple.valueOf(cause, TerritoryType.WILDERNESS);
}
if (!mconf.allowChorusFruitInWildernessTerritory && types.contains(TerritoryType.WILDERNESS)) {
return Couple.valueOf(cause, TerritoryType.WILDERNESS);
}
if (!mconf.allowChorusFruitInOwnTerritory && types.contains(TerritoryType.OWN)) {
return Couple.valueOf(cause, TerritoryType.OWN);
}
if (!mconf.allowChorusFruitInOwnTerritory && types.contains(TerritoryType.OWN)) {
return Couple.valueOf(cause, TerritoryType.OWN);
}
if (!mconf.allowChorusFruitInOtherTerritory && types.contains(TerritoryType.OTHER)) {
return Couple.valueOf(cause, TerritoryType.OTHER);
}
if (!mconf.allowChorusFruitInOtherTerritory && types.contains(TerritoryType.OTHER)) {
return Couple.valueOf(cause, TerritoryType.OTHER);
}
} else if (cause == TeleportCause.ENDER_PEARL) {
if (!mconf.allowEnderPearlInEnemyTerritory && types.contains(TerritoryType.ENEMY)) {
return Couple.valueOf(cause, TerritoryType.ENEMY);
}
if (!mconf.allowEnderPearlInEnemyTerritory && types.contains(TerritoryType.ENEMY)) {
return Couple.valueOf(cause, TerritoryType.ENEMY);
}
if (!mconf.allowEnderPearlInWildernessTerritory && types.contains(TerritoryType.WILDERNESS)) {
return Couple.valueOf(cause, TerritoryType.WILDERNESS);
}
if (!mconf.allowEnderPearlInWildernessTerritory && types.contains(TerritoryType.WILDERNESS)) {
return Couple.valueOf(cause, TerritoryType.WILDERNESS);
}
if (!mconf.allowEnderPearlInOwnTerritory && types.contains(TerritoryType.OWN)) {
return Couple.valueOf(cause, TerritoryType.OWN);
}
if (!mconf.allowEnderPearlInOwnTerritory && types.contains(TerritoryType.OWN)) {
return Couple.valueOf(cause, TerritoryType.OWN);
}
if (!mconf.allowEnderPearlInOtherTerritory && types.contains(TerritoryType.OTHER)) {
return Couple.valueOf(cause, TerritoryType.OTHER);
}
} // Don't cancel other kinds of teleports
if (!mconf.allowEnderPearlInOtherTerritory && types.contains(TerritoryType.OTHER)) {
return Couple.valueOf(cause, TerritoryType.OTHER);
}
} else {
// Don't cancel other kinds of teleports
}
return null;
}
@@ -134,15 +133,15 @@ public class EngineDenyTeleport extends Engine {
Faction territoryFaction = BoardColl.get().getFactionAt(territory);
Rel relation = territoryFaction.getRelationTo(mplayer);
if (territoryFaction.isNone()) {
return TerritoryType.WILDERNESS;
}
if (relation == Rel.ENEMY) {
return TerritoryType.ENEMY;
}
if (relation == Rel.FACTION) {
return TerritoryType.OWN;
}
if (territoryFaction.isNone()) {
return TerritoryType.WILDERNESS;
}
if (relation == Rel.ENEMY) {
return TerritoryType.ENEMY;
}
if (relation == Rel.FACTION) {
return TerritoryType.OWN;
}
return TerritoryType.OTHER;
}

View File

@@ -1,5 +1,9 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.money.Money;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.Txt;
import net.knarcraft.factions.Factions;
import net.knarcraft.factions.cmd.CmdFactions;
import net.knarcraft.factions.entity.Faction;
@@ -22,10 +26,6 @@ import net.knarcraft.factions.event.EventFactionsWarpAdd;
import net.knarcraft.factions.event.EventFactionsWarpRemove;
import net.knarcraft.factions.event.EventFactionsWarpTeleport;
import net.knarcraft.factions.integration.Econ;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.money.Money;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.Txt;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -39,7 +39,7 @@ public class EngineEcon extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineEcon i = new EngineEcon();
private static final EngineEcon i = new EngineEcon();
public static EngineEcon get() {
return i;

View File

@@ -1,10 +1,10 @@
package net.knarcraft.factions.engine;
import net.knarcraft.factions.entity.MConf;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
import net.knarcraft.factions.entity.MConf;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@@ -26,7 +26,7 @@ public class EngineExploit extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineExploit i = new EngineExploit();
private static final EngineExploit i = new EngineExploit();
public static EngineExploit get() {
return i;
@@ -38,9 +38,9 @@ public class EngineExploit extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void obsidianGenerators(BlockFromToEvent event) {
if (!MConf.get().handleExploitObsidianGenerators) {
return;
}
if (!MConf.get().handleExploitObsidianGenerators) {
return;
}
// thanks to ObGenBlocker and WorldGuard for this method
Block block = event.getToBlock();
@@ -57,12 +57,12 @@ public class EngineExploit extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void enderPearlClipping(PlayerTeleportEvent event) {
if (!MConf.get().handleExploitEnderPearlClipping) {
return;
}
if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) {
return;
}
if (!MConf.get().handleExploitEnderPearlClipping) {
return;
}
if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) {
return;
}
// this exploit works when the target location is within 0.31 blocks or so of a door or glass block or similar...
Location target = event.getTo();
@@ -104,31 +104,31 @@ public class EngineExploit extends Engine {
private static final int NETHER_TRAP_RADIUS_CHECK = 5;
private static final int NETHER_TRAP_RESET_RADIUS_SQUARED = 9;
private HashMap<UUID, List<Block>> portalTraps = new HashMap<>();
private final HashMap<UUID, List<Block>> portalTraps = new HashMap<>();
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void portalTrapRemoveAnimation(PlayerTeleportEvent event) {
// If there is a teleport caused by a nether portal ...
if (!MConf.get().handleNetherPortalTrap || event.getCause() != TeleportCause.NETHER_PORTAL) {
return;
}
if (!MConf.get().handleNetherPortalTrap || event.getCause() != TeleportCause.NETHER_PORTAL) {
return;
}
Player player = event.getPlayer();
Block from = event.getTo().getBlock();
// ... and the player can't build at the destination ...
if (EnginePermBuild.canPlayerBuildAt(player, PS.valueOf(from), false)) {
return;
}
if (EnginePermBuild.canPlayerBuildAt(player, PS.valueOf(from), false)) {
return;
}
// ... reset the old portal blocks stored ...
this.portalReset(player);
// ... get all the portal blocks belonging to the new portal at the destination ...
List<Block> portalTrap = getPortal(from);
if (portalTrap.isEmpty()) {
return;
}
if (portalTrap.isEmpty()) {
return;
}
// ... and then store those blocks and send an update as if they were air.
this.portalTraps.put(player.getUniqueId(), portalTrap);
@@ -138,18 +138,18 @@ public class EngineExploit extends Engine {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void portalUpdate(PlayerMoveEvent event) {
// If a player moves ...
if (!MConf.get().handleNetherPortalTrap || MUtil.isSameBlock(event)) {
return;
}
if (!MConf.get().handleNetherPortalTrap || MUtil.isSameBlock(event)) {
return;
}
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
// ... and he recently used a portal ...
List<Block> portalTrap = this.portalTraps.get(uuid);
if (portalTrap == null) {
return;
}
if (portalTrap == null) {
return;
}
Location locationTo = event.getTo();
Location locationFrom = portalTrap.get(0).getLocation();
@@ -172,17 +172,17 @@ public class EngineExploit extends Engine {
// If a player has already a portal registered to him ...
List<Block> portalTrap = this.portalTraps.get(uuid);
if (portalTrap == null) {
return;
}
if (portalTrap == null) {
return;
}
// ... remove them from the registry ...
this.portalTraps.remove(uuid);
// ... and send updates if the player and portal are in the same world.
if (!player.getWorld().equals(portalTrap.get(0).getWorld())) {
return;
}
if (!player.getWorld().equals(portalTrap.get(0).getWorld())) {
return;
}
portalUpdateReset(player, portalTrap);
}
@@ -212,9 +212,9 @@ public class EngineExploit extends Engine {
for (int x = -(NETHER_TRAP_RADIUS_CHECK); x <= NETHER_TRAP_RADIUS_CHECK; x++) {
for (int y = -(NETHER_TRAP_RADIUS_CHECK); y <= NETHER_TRAP_RADIUS_CHECK; y++) {
for (int z = -(NETHER_TRAP_RADIUS_CHECK); z <= NETHER_TRAP_RADIUS_CHECK; z++) {
if (from.getRelative(x, y, z).getType() == Material.NETHER_PORTAL) {
ret.add(from.getRelative(x, y, z));
}
if (from.getRelative(x, y, z).getType() == Material.NETHER_PORTAL) {
ret.add(from.getRelative(x, y, z));
}
}
}
}

View File

@@ -1,10 +1,10 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import net.knarcraft.factions.entity.BoardColl;
import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.entity.MFlag;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import org.bukkit.entity.Enderman;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
@@ -16,7 +16,7 @@ public class EngineFlagEndergrief extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineFlagEndergrief i = new EngineFlagEndergrief();
private static final EngineFlagEndergrief i = new EngineFlagEndergrief();
public static EngineFlagEndergrief get() {
return i;
@@ -30,16 +30,16 @@ public class EngineFlagEndergrief extends Engine {
public void blockEndergrief(EntityChangeBlockEvent event) {
// If an enderman is changing a block ...
Entity entity = event.getEntity();
if (!(entity instanceof Enderman)) {
return;
}
if (!(entity instanceof Enderman)) {
return;
}
// ... and the faction there has endergrief disabled ...
PS ps = PS.valueOf(event.getBlock());
Faction faction = BoardColl.get().getFactionAt(ps);
if (faction.getFlag(MFlag.getFlagEndergrief())) {
return;
}
if (faction.getFlag(MFlag.getFlagEndergrief())) {
return;
}
// ... stop the block alteration.
event.setCancelled(true);

View File

@@ -1,10 +1,10 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import net.knarcraft.factions.entity.BoardColl;
import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.util.EnumerationUtil;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
@@ -32,7 +32,7 @@ public class EngineFlagExplosion extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineFlagExplosion i = new EngineFlagExplosion();
private static final EngineFlagExplosion i = new EngineFlagExplosion();
public static EngineFlagExplosion get() {
return i;
@@ -42,21 +42,21 @@ public class EngineFlagExplosion extends Engine {
// FLAG: EXPLOSIONS
// -------------------------------------------- //
protected Set<DamageCause> DAMAGE_CAUSE_EXPLOSIONS = EnumSet.of(DamageCause.BLOCK_EXPLOSION, DamageCause.ENTITY_EXPLOSION);
protected final Set<DamageCause> DAMAGE_CAUSE_EXPLOSIONS = EnumSet.of(DamageCause.BLOCK_EXPLOSION, DamageCause.ENTITY_EXPLOSION);
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockExplosion(HangingBreakEvent event) {
// If a hanging entity was broken by an explosion ...
if (event.getCause() != RemoveCause.EXPLOSION) {
return;
}
if (event.getCause() != RemoveCause.EXPLOSION) {
return;
}
Entity entity = event.getEntity();
// ... and the faction there has explosions disabled ...
Faction faction = BoardColl.get().getFactionAt(PS.valueOf(entity.getLocation()));
if (faction.isExplosionsAllowed()) {
return;
}
if (faction.isExplosionsAllowed()) {
return;
}
// ... then cancel.
event.setCancelled(true);
@@ -65,19 +65,19 @@ public class EngineFlagExplosion extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockExplosion(EntityDamageEvent event) {
// If an explosion damages ...
if (!DAMAGE_CAUSE_EXPLOSIONS.contains(event.getCause())) {
return;
}
if (!DAMAGE_CAUSE_EXPLOSIONS.contains(event.getCause())) {
return;
}
// ... an entity that is modified on damage ...
if (!EnumerationUtil.isEntityTypeEditOnDamage(event.getEntityType())) {
return;
}
if (!EnumerationUtil.isEntityTypeEditOnDamage(event.getEntityType())) {
return;
}
// ... and the faction has explosions disabled ...
if (BoardColl.get().getFactionAt(PS.valueOf(event.getEntity())).isExplosionsAllowed()) {
return;
}
if (BoardColl.get().getFactionAt(PS.valueOf(event.getEntity())).isExplosionsAllowed()) {
return;
}
// ... then cancel!
event.setCancelled(true);
@@ -86,10 +86,9 @@ public class EngineFlagExplosion extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockExplosion(EntityExplodeEvent event) {
Location location = event.getLocation();
Cancellable cancellable = event;
Collection<Block> blocks = event.blockList();
blockExplosion(location, cancellable, blocks);
blockExplosion(location, event, blocks);
}
// Note that this method is used by EngineV18 for the BlockExplodeEvent
@@ -117,9 +116,9 @@ public class EngineFlagExplosion extends Engine {
faction2allowed.put(faction, allowed);
}
if (!allowed) {
iterator.remove();
}
if (!allowed) {
iterator.remove();
}
}
}
@@ -127,17 +126,17 @@ public class EngineFlagExplosion extends Engine {
public void blockExplosion(EntityChangeBlockEvent event) {
// If a wither is changing a block ...
Entity entity = event.getEntity();
if (!(entity instanceof Wither)) {
return;
}
if (!(entity instanceof Wither)) {
return;
}
// ... and the faction there has explosions disabled ...
PS ps = PS.valueOf(event.getBlock());
Faction faction = BoardColl.get().getFactionAt(ps);
if (faction.isExplosionsAllowed()) {
return;
}
if (faction.isExplosionsAllowed()) {
return;
}
// ... stop the block alteration.
event.setCancelled(true);
@@ -146,10 +145,9 @@ public class EngineFlagExplosion extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockExplosion(BlockExplodeEvent event) {
Location location = event.getBlock().getLocation();
Cancellable cancellable = event;
Collection<Block> blocks = event.blockList();
EngineFlagExplosion.get().blockExplosion(location, cancellable, blocks);
EngineFlagExplosion.get().blockExplosion(location, event, blocks);
}
}

View File

@@ -1,10 +1,10 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import net.knarcraft.factions.entity.BoardColl;
import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.entity.MFlag;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.Cancellable;
@@ -20,7 +20,7 @@ public class EngineFlagFireSpread extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineFlagFireSpread i = new EngineFlagFireSpread();
private static final EngineFlagFireSpread i = new EngineFlagFireSpread();
public static EngineFlagFireSpread get() {
return i;
@@ -35,9 +35,9 @@ public class EngineFlagFireSpread extends Engine {
PS ps = PS.valueOf(block);
Faction faction = BoardColl.get().getFactionAt(ps);
if (faction.getFlag(MFlag.getFlagFirespread())) {
return;
}
if (faction.getFlag(MFlag.getFlagFirespread())) {
return;
}
// then cancel the event.
cancellable.setCancelled(true);
@@ -46,9 +46,9 @@ public class EngineFlagFireSpread extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockFireSpread(BlockIgniteEvent event) {
// If fire is spreading ...
if (event.getCause() != IgniteCause.SPREAD && event.getCause() != IgniteCause.LAVA) {
return;
}
if (event.getCause() != IgniteCause.SPREAD && event.getCause() != IgniteCause.LAVA) {
return;
}
// ... consider blocking it.
blockFireSpread(event.getBlock(), event);
@@ -58,9 +58,9 @@ public class EngineFlagFireSpread extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockFireSpread(BlockSpreadEvent event) {
// If fire is spreading ...
if (event.getNewState().getType() != Material.FIRE) {
return;
}
if (event.getNewState().getType() != Material.FIRE) {
return;
}
// ... consider blocking it.
blockFireSpread(event.getBlock(), event);

View File

@@ -1,12 +1,12 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.collections.BackstringSet;
import com.massivecraft.massivecore.ps.PS;
import net.knarcraft.factions.entity.BoardColl;
import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.entity.MFlag;
import net.knarcraft.factions.util.EnumerationUtil;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.collections.BackstringSet;
import com.massivecraft.massivecore.ps.PS;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
@@ -21,7 +21,7 @@ public class EngineFlagSpawn extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineFlagSpawn i = new EngineFlagSpawn();
private static final EngineFlagSpawn i = new EngineFlagSpawn();
public static EngineFlagSpawn get() {
return i;
@@ -52,9 +52,9 @@ public class EngineFlagSpawn extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockMonstersAndAnimals(CreatureSpawnEvent event) {
// If this is a natural spawn ..
if (!NATURAL_SPAWN_REASONS.contains(event.getSpawnReason())) {
return;
}
if (!NATURAL_SPAWN_REASONS.contains(event.getSpawnReason())) {
return;
}
// ... get the spawn location ...
Location location = event.getLocation();
@@ -62,17 +62,17 @@ public class EngineFlagSpawn extends Engine {
// ... get the faction there ...
Faction faction = BoardColl.get().getFactionAt(ps);
if (faction == null) {
return;
}
if (faction == null) {
return;
}
// ... get the entity type ...
EntityType type = event.getEntityType();
// ... and if this type can't spawn in the faction ...
if (canSpawn(faction, type)) {
return;
}
if (canSpawn(faction, type)) {
return;
}
// ... then cancel.
event.setCancelled(true);

View File

@@ -1,10 +1,10 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import net.knarcraft.factions.entity.BoardColl;
import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.entity.MFlag;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Zombie;
import org.bukkit.event.EventHandler;
@@ -16,7 +16,7 @@ public class EngineFlagZombiegrief extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineFlagZombiegrief i = new EngineFlagZombiegrief();
private static final EngineFlagZombiegrief i = new EngineFlagZombiegrief();
public static EngineFlagZombiegrief get() {
return i;
@@ -30,16 +30,16 @@ public class EngineFlagZombiegrief extends Engine {
public void denyZombieGrief(EntityBreakDoorEvent event) {
// If a zombie is breaking a door ...
Entity entity = event.getEntity();
if (!(entity instanceof Zombie)) {
return;
}
if (!(entity instanceof Zombie)) {
return;
}
// ... and the faction there has zombiegrief disabled ...
PS ps = PS.valueOf(event.getBlock());
Faction faction = BoardColl.get().getFactionAt(ps);
if (faction.getFlag(MFlag.getFlagZombiegrief())) {
return;
}
if (faction.getFlag(MFlag.getFlagZombiegrief())) {
return;
}
// ... stop the door breakage.
event.setCancelled(true);

View File

@@ -1,5 +1,11 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerUpdate;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.store.DriverFlatfile;
import com.massivecraft.massivecore.util.MUtil;
import net.knarcraft.factions.Perm;
import net.knarcraft.factions.cmd.CmdFactions;
import net.knarcraft.factions.entity.BoardColl;
@@ -10,12 +16,6 @@ import net.knarcraft.factions.entity.MFlagColl;
import net.knarcraft.factions.entity.MPerm;
import net.knarcraft.factions.entity.MPlayer;
import net.knarcraft.factions.event.EventFactionsFlagChange;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerUpdate;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.store.DriverFlatfile;
import com.massivecraft.massivecore.util.MUtil;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -30,7 +30,7 @@ public class EngineFly extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineFly i = new EngineFly();
private static final EngineFly i = new EngineFly();
public static EngineFly get() {
return i;
@@ -44,31 +44,31 @@ public class EngineFly extends Engine {
public void onMassiveCorePlayerUpdate(EventMassiveCorePlayerUpdate event) {
// If we are updating a player ...
Player player = event.getPlayer();
if (MUtil.isntPlayer(player)) {
return;
}
if (MUtil.isntPlayer(player)) {
return;
}
// ... and that player isn't in creative or spectator mode ...
if (EventMassiveCorePlayerUpdate.isFlyAllowed(player, false)) {
return;
}
if (EventMassiveCorePlayerUpdate.isFlyAllowed(player, false)) {
return;
}
// ... and the player is alive ...
if (player.isDead()) {
return;
}
if (player.isDead()) {
return;
}
MPlayer mplayer = MPlayer.get(player);
// ... and the player enables flying ...
if (!mplayer.isFlying()) {
return;
}
if (!mplayer.isFlying()) {
return;
}
// ... and the player can fly here...
if (!canFlyInTerritory(mplayer, PS.valueOf(player))) {
return;
}
if (!canFlyInTerritory(mplayer, PS.valueOf(player))) {
return;
}
// ... set allowed ...
event.setAllowed(true);
@@ -80,27 +80,27 @@ public class EngineFly extends Engine {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void moveChunkDetect(PlayerMoveEvent event) {
// If the player is moving from one chunk to another ...
if (MUtil.isSameChunk(event)) {
return;
}
if (MUtil.isSameChunk(event)) {
return;
}
Player player = event.getPlayer();
if (MUtil.isntPlayer(player)) {
return;
}
if (MUtil.isntPlayer(player)) {
return;
}
// ... gather info on the player and the move ...
MPlayer mplayer = MPlayer.get(player);
PS chunkTo = PS.valueOf(event.getTo()).getChunk(true);
// ... and they are currently flying ...
if (!mplayer.isFlying()) {
return;
}
if (!mplayer.isFlying()) {
return;
}
// ... but can't fly at the new place ...
if (canFlyInTerritory(mplayer, chunkTo)) {
return;
}
if (canFlyInTerritory(mplayer, chunkTo)) {
return;
}
// ... then perhaps they should not be
mplayer.setFlying(false);
@@ -109,12 +109,12 @@ public class EngineFly extends Engine {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void flagUpdate(EventFactionsFlagChange event) {
if (event.getFlag() != MFlag.getFlagFly()) {
return;
}
if (event.isNewValue() == true) {
return;
}
if (event.getFlag() != MFlag.getFlagFly()) {
return;
}
if (event.isNewValue()) {
return;
}
// Disable for all players when disabled
event.getFaction().getOnlinePlayers().forEach(EngineFly::deactivateForPlayer);
@@ -123,24 +123,23 @@ public class EngineFly extends Engine {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void territoryShield(EntityDamageByEntityEvent event) {
// If flying is diabled on PVP ...
if (!MConf.get().flyDisableOnPvp) {
return;
}
if (!MConf.get().flyDisableOnPvp) {
return;
}
// ... and the defender is a player ...
Entity entity = event.getEntity();
if (MUtil.isntPlayer(entity)) {
return;
}
if (MUtil.isntPlayer(entity)) {
return;
}
Player defender = (Player) entity;
MPlayer mdefender = MPlayer.get(defender);
// ... and the attacker is a player ...
Entity eattacker = MUtil.getLiableDamager(event);
if (!(eattacker instanceof Player)) {
return;
}
Player attacker = (Player) eattacker;
if (!(eattacker instanceof Player attacker)) {
return;
}
MPlayer mattacker = MPlayer.get(attacker);
// ... disable flying for both
@@ -206,12 +205,12 @@ public class EngineFly extends Engine {
if (isAdmin) {
boolean overriding = mplayer.isOverriding();
ex.addMsg("<i>You can change the flag if you are overriding.");
if (overriding) {
ex.addMsg("<i>You are already overriding.");
} else {
ex.addMsg("<i>You can enable override with:");
ex.addMessage(CmdFactions.get().cmdFactionsOverride.getTemplate(false, true, mplayer.getSender()));
}
if (overriding) {
ex.addMsg("<i>You are already overriding.");
} else {
ex.addMsg("<i>You can enable override with:");
ex.addMessage(CmdFactions.get().cmdFactionsOverride.getTemplate(false, true, mplayer.getSender()));
}
if (!isDefault) {
ex.addMsg("<i>You can also ask someone with access to the configuration files to make flying enabled by default.");

View File

@@ -1,10 +1,10 @@
package net.knarcraft.factions.engine;
import net.knarcraft.factions.Factions;
import net.knarcraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave;
import com.massivecraft.massivecore.util.MUtil;
import net.knarcraft.factions.Factions;
import net.knarcraft.factions.entity.MPlayer;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler;
@@ -16,7 +16,7 @@ public class EngineLastActivity extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineLastActivity i = new EngineLastActivity();
private static final EngineLastActivity i = new EngineLastActivity();
public static EngineLastActivity get() {
return i;
@@ -27,21 +27,21 @@ public class EngineLastActivity extends Engine {
// -------------------------------------------- //
public static void updateLastActivity(CommandSender sender) {
if (sender == null) {
throw new RuntimeException("sender");
}
if (MUtil.isntSender(sender)) {
return;
}
if (sender == null) {
throw new RuntimeException("sender");
}
if (MUtil.isntSender(sender)) {
return;
}
MPlayer mplayer = MPlayer.get(sender);
mplayer.setLastActivityMillis();
}
public static void updateLastActivitySoon(final CommandSender sender) {
if (sender == null) {
throw new RuntimeException("sender");
}
if (sender == null) {
throw new RuntimeException("sender");
}
Bukkit.getScheduler().scheduleSyncDelayedTask(Factions.get(), () -> updateLastActivity(sender));
}

View File

@@ -1,13 +1,13 @@
package net.knarcraft.factions.engine;
import net.knarcraft.factions.Factions;
import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.entity.MConf;
import net.knarcraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.mixin.MixinActual;
import com.massivecraft.massivecore.mixin.MixinMessage;
import com.massivecraft.massivecore.util.MUtil;
import net.knarcraft.factions.Factions;
import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.entity.MConf;
import net.knarcraft.factions.entity.MPlayer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -21,7 +21,7 @@ public class EngineMotd extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineMotd i = new EngineMotd();
private static final EngineMotd i = new EngineMotd();
public static EngineMotd get() {
return i;

View File

@@ -1,5 +1,10 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.mixin.MixinTitle;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt;
import net.knarcraft.factions.AccessStatus;
import net.knarcraft.factions.TerritoryAccess;
import net.knarcraft.factions.entity.BoardColl;
@@ -7,11 +12,6 @@ import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.entity.MConf;
import net.knarcraft.factions.entity.MPlayer;
import net.knarcraft.factions.util.AsciiMap;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.mixin.MixinTitle;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -24,7 +24,7 @@ public class EngineMoveChunk extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineMoveChunk i = new EngineMoveChunk();
private static final EngineMoveChunk i = new EngineMoveChunk();
public static EngineMoveChunk get() {
return i;
@@ -37,13 +37,13 @@ public class EngineMoveChunk extends Engine {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void moveChunkDetect(PlayerMoveEvent event) {
// If the player is moving from one chunk to another ...
if (MUtil.isSameChunk(event)) {
return;
}
if (MUtil.isSameChunk(event)) {
return;
}
Player player = event.getPlayer();
if (MUtil.isntPlayer(player)) {
return;
}
if (MUtil.isntPlayer(player)) {
return;
}
// ... gather info on the player and the move ...
MPlayer mplayer = MPlayer.get(player);
@@ -67,9 +67,9 @@ public class EngineMoveChunk extends Engine {
}
private static void sendAutoMapUpdate(MPlayer mplayer, PS ps) {
if (!mplayer.isMapAutoUpdating()) {
return;
}
if (!mplayer.isMapAutoUpdating()) {
return;
}
AsciiMap map = new AsciiMap(mplayer, ps, false);
mplayer.message(map.render());
}
@@ -78,9 +78,9 @@ public class EngineMoveChunk extends Engine {
Faction factionFrom = BoardColl.get().getFactionAt(psFrom);
Faction factionTo = BoardColl.get().getFactionAt(psTo);
if (factionFrom == factionTo) {
return;
}
if (factionFrom == factionTo) {
return;
}
if (mplayer.isTerritoryInfoTitles()) {
String titleMain = parseTerritoryInfo(MConf.get().territoryInfoTitlesMain, mplayer, factionTo);
@@ -96,12 +96,12 @@ public class EngineMoveChunk extends Engine {
}
private static String parseTerritoryInfo(String string, MPlayer mplayer, Faction faction) {
if (string == null) {
throw new NullPointerException("string");
}
if (faction == null) {
throw new NullPointerException("faction");
}
if (string == null) {
throw new NullPointerException("string");
}
if (faction == null) {
throw new NullPointerException("faction");
}
string = Txt.parse(string);
string = string.replace("{name}", faction.getName());
@@ -112,9 +112,9 @@ public class EngineMoveChunk extends Engine {
}
private static void sendTerritoryAccessMessage(MPlayer mplayer, PS psFrom, PS psTo) {
if (!MConf.get().territoryAccessShowMessage) {
return;
}
if (!MConf.get().territoryAccessShowMessage) {
return;
}
// Get TerritoryAccess for from & to chunks
TerritoryAccess accessFrom = BoardColl.get().getTerritoryAccessAt(psFrom);
@@ -123,9 +123,9 @@ public class EngineMoveChunk extends Engine {
// See if the status has changed
AccessStatus statusFrom = accessFrom.getTerritoryAccess(mplayer);
AccessStatus statusTo = accessTo.getTerritoryAccess(mplayer);
if (statusFrom == statusTo) {
return;
}
if (statusFrom == statusTo) {
return;
}
// Inform
mplayer.message(statusTo.getStatusMessage());
@@ -138,9 +138,9 @@ public class EngineMoveChunk extends Engine {
private static void tryAutoClaim(MPlayer mplayer, PS chunkTo) {
// If the player is auto claiming ...
Faction autoClaimFaction = mplayer.getAutoClaimFaction();
if (autoClaimFaction == null) {
return;
}
if (autoClaimFaction == null) {
return;
}
// ... try claim.
mplayer.tryClaim(autoClaimFaction, Collections.singletonList(chunkTo));

View File

@@ -1,5 +1,8 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
import net.knarcraft.factions.Factions;
import net.knarcraft.factions.TerritoryAccess;
import net.knarcraft.factions.entity.Board;
@@ -10,9 +13,6 @@ import net.knarcraft.factions.entity.MConf;
import net.knarcraft.factions.entity.MPerm;
import net.knarcraft.factions.entity.MPlayer;
import net.knarcraft.factions.util.EnumerationUtil;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@@ -51,7 +51,7 @@ public class EnginePermBuild extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EnginePermBuild i = new EnginePermBuild();
private static final EnginePermBuild i = new EnginePermBuild();
public static EnginePermBuild get() {
return i;
@@ -62,39 +62,39 @@ public class EnginePermBuild extends Engine {
// -------------------------------------------- //
public static Boolean isProtected(ProtectCase protectCase, boolean verboose, MPlayer mplayer, PS ps, Object object) {
if (mplayer == null) {
return null;
}
if (protectCase == null) {
return null;
}
if (mplayer == null) {
return null;
}
if (protectCase == null) {
return null;
}
String name = mplayer.getName();
if (MConf.get().playersWhoBypassAllProtection.contains(name)) {
return false;
}
if (mplayer.isOverriding()) {
return false;
}
if (MConf.get().playersWhoBypassAllProtection.contains(name)) {
return false;
}
if (mplayer.isOverriding()) {
return false;
}
MPerm perm = protectCase.getPerm(object);
if (perm == null) {
return null;
}
if (protectCase != ProtectCase.BUILD) {
return !perm.has(mplayer, ps, verboose);
}
if (perm == null) {
return null;
}
if (protectCase != ProtectCase.BUILD) {
return !perm.has(mplayer, ps, verboose);
}
if (!perm.has(mplayer, ps, false) && MPerm.getPermPainbuild().has(mplayer, ps, false)) {
if (!verboose) {
return false;
}
if (!verboose) {
return false;
}
Faction hostFaction = BoardColl.get().getFactionAt(ps);
mplayer.msg("<b>It is painful to build in the territory of %s<b>.", hostFaction.describeTo(mplayer));
Player player = mplayer.getPlayer();
if (player != null) {
player.damage(MConf.get().actionDeniedPainAmount);
}
if (player != null) {
player.damage(MConf.get().actionDeniedPainAmount);
}
}
return !perm.has(mplayer, ps, verboose);
@@ -102,20 +102,20 @@ public class EnginePermBuild extends Engine {
public static Boolean protect(ProtectCase protectCase, boolean verboose, Player player, PS ps, Object object, Cancellable cancellable) {
Boolean ret = isProtected(protectCase, verboose, MPlayer.get(player), ps, object);
if (Boolean.TRUE.equals(ret) && cancellable != null) {
cancellable.setCancelled(true);
}
if (Boolean.TRUE.equals(ret) && cancellable != null) {
cancellable.setCancelled(true);
}
return ret;
}
public static Boolean build(Entity entity, Block block, Event event) {
if (!(event instanceof Cancellable)) {
return true;
}
if (MUtil.isntPlayer(entity)) {
return false;
}
if (!(event instanceof Cancellable)) {
return true;
}
if (MUtil.isntPlayer(entity)) {
return false;
}
Player player = (Player) entity;
boolean verboose = !isFake(event);
return protect(ProtectCase.BUILD, verboose, player, PS.valueOf(block), block, (Cancellable) event);
@@ -139,9 +139,9 @@ public class EnginePermBuild extends Engine {
public static boolean canPlayerBuildAt(Object senderObject, PS ps, boolean verboose) {
MPlayer mplayer = MPlayer.get(senderObject);
if (mplayer == null) {
return false;
}
if (mplayer == null) {
return false;
}
Boolean ret = isProtected(ProtectCase.BUILD, verboose, mplayer, ps, null);
return !Boolean.TRUE.equals(ret);
@@ -180,9 +180,9 @@ public class EnginePermBuild extends Engine {
public void build(EntityChangeBlockEvent event) {
// Handling lilypads being broken by boats
Entity entity = event.getEntity();
if (entity.getType() != EntityType.BOAT || entity.getPassengers().size() <= 0) {
return;
}
if (entity.getType() != EntityType.BOAT || entity.getPassengers().size() <= 0) {
return;
}
Entity player = entity.getPassengers().stream().filter(MUtil::isPlayer).findAny().orElse(entity);
build(player, event.getBlock(), event);
@@ -196,26 +196,26 @@ public class EnginePermBuild extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void useBlockItem(PlayerInteractEvent event) {
// If the player right clicks (or is physical with) a block ...
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) {
return;
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) {
return;
}
Block block = event.getClickedBlock();
Player player = event.getPlayer();
if (block == null) {
return;
}
if (block == null) {
return;
}
// ... and we are either allowed to use this block ...
Boolean ret = useBlock(player, block, true, event);
if (Boolean.TRUE.equals(ret)) {
return;
}
if (Boolean.TRUE.equals(ret)) {
return;
}
// ... or are allowed to right click with the item, this event is safe to perform.
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
useItem(player, block, event.getMaterial(), event);
}
@@ -241,9 +241,9 @@ public class EnginePermBuild extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void useEntity(PlayerInteractEntityEvent event) {
// Ignore Off Hand
if (isOffHand(event)) {
return;
}
if (isOffHand(event)) {
return;
}
useEntity(event.getPlayer(), event.getRightClicked(), true, event);
}
@@ -254,22 +254,22 @@ public class EnginePermBuild extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void handleArmorStand(PlayerInteractAtEntityEvent event) {
// Ignore Off Hand
if (isOffHand(event)) {
return;
}
if (isOffHand(event)) {
return;
}
// Gather Info
final Player player = event.getPlayer();
if (MUtil.isntPlayer(player)) {
return;
}
if (MUtil.isntPlayer(player)) {
return;
}
final Entity entity = event.getRightClicked();
final boolean verboose = true;
// Only care for armor stands.
if (entity.getType() != EntityType.ARMOR_STAND) {
return;
}
if (entity.getType() != EntityType.ARMOR_STAND) {
return;
}
// If we can't use, block it
EnginePermBuild.useEntity(player, entity, verboose, event);
@@ -283,16 +283,16 @@ public class EnginePermBuild extends Engine {
public void buildEntity(EntityDamageByEntityEvent event) {
// If a player ...
Entity damager = MUtil.getLiableDamager(event);
if (MUtil.isntPlayer(damager)) {
return;
}
if (MUtil.isntPlayer(damager)) {
return;
}
Player player = (Player) damager;
// ... damages an entity which is edited on damage ...
Entity entity = event.getEntity();
if (entity == null || !EnumerationUtil.isEntityTypeEditOnDamage(entity.getType())) {
return;
}
if (entity == null || !EnumerationUtil.isEntityTypeEditOnDamage(entity.getType())) {
return;
}
// ... and the player can't build there, cancel the event
build(player, entity.getLocation().getBlock(), event);
@@ -302,23 +302,22 @@ public class EnginePermBuild extends Engine {
public void combustEntity(EntityCombustByEntityEvent event) {
// If a burning projectile ...
if (!(event.getCombuster() instanceof Projectile)) {
return;
}
Projectile entityProjectile = (Projectile) event.getCombuster();
if (!(event.getCombuster() instanceof Projectile entityProjectile)) {
return;
}
// ... fired by a player ...
ProjectileSource projectileSource = entityProjectile.getShooter();
if (MUtil.isntPlayer(projectileSource)) {
return;
}
if (MUtil.isntPlayer(projectileSource)) {
return;
}
Player player = (Player) projectileSource;
// ... and hits an entity which is edited on damage (and thus likely to burn) ...
Entity entityTarget = event.getEntity();
if (entityTarget == null || !EnumerationUtil.isEntityTypeEditOnDamage(entityTarget.getType())) {
return;
}
if (entityTarget == null || !EnumerationUtil.isEntityTypeEditOnDamage(entityTarget.getType())) {
return;
}
// ... and the player can't build there, cancel the event
Block block = entityTarget.getLocation().getBlock();
@@ -339,9 +338,9 @@ public class EnginePermBuild extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockBuild(BlockPistonExtendEvent event) {
// Is checking deactivated by MConf?
if (!MConf.get().handlePistonProtectionThroughDenyBuild) {
return;
}
if (!MConf.get().handlePistonProtectionThroughDenyBuild) {
return;
}
Faction pistonFaction = BoardColl.get().getFactionAt(PS.valueOf(event.getBlock()));
@@ -354,14 +353,14 @@ public class EnginePermBuild extends Engine {
// Members of a faction might not have build rights in their own territory, but pistons should still work regardless
Faction targetFaction = BoardColl.get().getFactionAt(PS.valueOf(targetBlock));
if (targetFaction == pistonFaction) {
continue;
}
if (targetFaction == pistonFaction) {
continue;
}
// Perm check
if (MPerm.getPermBuild().has(pistonFaction, targetFaction)) {
continue;
}
if (MPerm.getPermBuild().has(pistonFaction, targetFaction)) {
continue;
}
event.setCancelled(true);
return;
@@ -371,9 +370,9 @@ public class EnginePermBuild extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void blockBuild(BlockPistonRetractEvent event) {
// Is checking deactivated by MConf?
if (!MConf.get().handlePistonProtectionThroughDenyBuild) {
return;
}
if (!MConf.get().handlePistonProtectionThroughDenyBuild) {
return;
}
Faction pistonFaction = BoardColl.get().getFactionAt(PS.valueOf(event.getBlock()));
@@ -382,20 +381,20 @@ public class EnginePermBuild extends Engine {
// Check for all retracted blocks
for (Block block : blocks) {
// Is the retracted block air/water/lava? Don't worry about it
if (block.isEmpty() || block.isLiquid()) {
return;
}
if (block.isEmpty() || block.isLiquid()) {
return;
}
// Members of a faction might not have build rights in their own territory, but pistons should still work regardless
Faction targetFaction = BoardColl.get().getFactionAt(PS.valueOf(block));
if (targetFaction == pistonFaction) {
continue;
}
if (targetFaction == pistonFaction) {
continue;
}
// Perm check
if (MPerm.getPermBuild().has(pistonFaction, targetFaction)) {
continue;
}
if (MPerm.getPermBuild().has(pistonFaction, targetFaction)) {
continue;
}
event.setCancelled(true);
return;
@@ -410,27 +409,27 @@ public class EnginePermBuild extends Engine {
@EventHandler(priority = EventPriority.NORMAL)
public void buildFire(PlayerInteractEvent event) {
// If it is a left click on block and the clicked block is not null...
if (event.getAction() != Action.LEFT_CLICK_BLOCK || event.getClickedBlock() == null) {
return;
}
if (event.getAction() != Action.LEFT_CLICK_BLOCK || event.getClickedBlock() == null) {
return;
}
// ... and the potential block is not null either ...
Block potentialBlock = event.getClickedBlock().getRelative(BlockFace.UP, 1);
if (potentialBlock == null) {
return;
}
if (potentialBlock == null) {
return;
}
Material blockType = potentialBlock.getType();
// ... and we're only going to check for fire ... (checking everything else would be bad performance wise)
if (blockType != Material.FIRE) {
return;
}
if (blockType != Material.FIRE) {
return;
}
// ... check if they can't build, cancel the event ...
if (!Boolean.FALSE.equals(build(event.getPlayer(), potentialBlock, event))) {
return;
}
if (!Boolean.FALSE.equals(build(event.getPlayer(), potentialBlock, event))) {
return;
}
// ... and compensate for client side prediction
event.getPlayer().sendBlockChange(potentialBlock.getLocation(), blockType, potentialBlock.getState().getRawData());
@@ -442,9 +441,9 @@ public class EnginePermBuild extends Engine {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void buildMove(BlockFromToEvent event) {
if (!MConf.get().protectionLiquidFlowEnabled) {
return;
}
if (!MConf.get().protectionLiquidFlowEnabled) {
return;
}
// Prepare fields
Block fromBlock = event.getBlock();
@@ -455,21 +454,21 @@ public class EnginePermBuild extends Engine {
int chunkToZ = (fromBlock.getZ() + face.getModZ()) >> 4;
// If a liquid (or dragon egg) moves from one chunk to another ...
if (chunkToX == chunkFromX && chunkToZ == chunkFromZ) {
return;
}
if (chunkToX == chunkFromX && chunkToZ == chunkFromZ) {
return;
}
// ... get the correct board for this block ...
Board board = BoardColl.get().getFixed(fromBlock.getWorld().getName().toLowerCase(), false);
if (board == null) {
return;
}
if (board == null) {
return;
}
// ... get the access map ...
Map<PS, TerritoryAccess> map = board.getMapRaw();
if (map.isEmpty()) {
return;
}
if (map.isEmpty()) {
return;
}
// ... get the faction ids from and to ...
PS fromPs = PS.valueOf(chunkFromX, chunkFromZ);
@@ -482,22 +481,22 @@ public class EnginePermBuild extends Engine {
String toId = toTa != null ? toTa.getHostFactionId() : Factions.ID_NONE;
// ... and the chunks belong to different factions ...
if (toId.equals(fromId)) {
return;
}
if (toId.equals(fromId)) {
return;
}
// ... and the faction "from" can not build at "to" ...
Faction fromFac = FactionColl.get().getFixed(fromId);
if (fromFac == null) {
fromFac = FactionColl.get().getNone();
}
if (fromFac == null) {
fromFac = FactionColl.get().getNone();
}
Faction toFac = FactionColl.get().getFixed(toId);
if (toFac == null) {
toFac = FactionColl.get().getNone();
}
if (MPerm.getPermBuild().has(fromFac, toFac)) {
return;
}
if (toFac == null) {
toFac = FactionColl.get().getNone();
}
if (MPerm.getPermBuild().has(fromFac, toFac)) {
return;
}
// ... cancel the event!
event.setCancelled(true);

View File

@@ -1,9 +1,9 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import net.knarcraft.factions.entity.MConf;
import net.knarcraft.factions.entity.MPlayer;
import net.knarcraft.factions.entity.MPlayerColl;
import com.massivecraft.massivecore.Engine;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -14,7 +14,7 @@ public class EnginePlayerData extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EnginePlayerData i = new EnginePlayerData();
private static final EnginePlayerData i = new EnginePlayerData();
public static EnginePlayerData get() {
return i;
@@ -31,20 +31,20 @@ public class EnginePlayerData extends Engine {
// ... and if the if player was banned (not just kicked) ...
//if (!event.getReason().equals("Banned by admin.")) return;
if (!player.isBanned()) {
return;
}
if (!player.isBanned()) {
return;
}
// ... and we remove player data when banned ...
if (!MConf.get().removePlayerWhenBanned) {
return;
}
if (!MConf.get().removePlayerWhenBanned) {
return;
}
// ... get rid of their stored info.
MPlayer mplayer = MPlayerColl.get().get(player, false);
if (mplayer == null) {
return;
}
if (mplayer == null) {
return;
}
if (mplayer.getRank().isLeader()) {
mplayer.getFaction().promoteNewLeader();

View File

@@ -1,5 +1,9 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.PlayerUtil;
import net.knarcraft.factions.entity.BoardColl;
import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.entity.MConf;
@@ -7,10 +11,6 @@ import net.knarcraft.factions.entity.MFlag;
import net.knarcraft.factions.entity.MPlayer;
import net.knarcraft.factions.event.EventFactionsPowerChange;
import net.knarcraft.factions.event.EventFactionsPowerChange.PowerChangeReason;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.PlayerUtil;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -21,7 +21,7 @@ public class EnginePower extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EnginePower i = new EnginePower();
private static final EnginePower i = new EnginePower();
public static EnginePower get() {
return i;
@@ -35,15 +35,15 @@ public class EnginePower extends Engine {
public void powerLossOnDeath(PlayerDeathEvent event) {
// If a player dies ...
Player player = event.getEntity();
if (MUtil.isntPlayer(player)) {
return;
}
if (MUtil.isntPlayer(player)) {
return;
}
// ... and this is the first death event this tick ...
// (yeah other plugins can case death event to fire twice the same tick)
if (PlayerUtil.isDuplicateDeathEvent(event)) {
return;
}
if (PlayerUtil.isDuplicateDeathEvent(event)) {
return;
}
MPlayer mplayer = MPlayer.get(player);
@@ -65,9 +65,9 @@ public class EnginePower extends Engine {
EventFactionsPowerChange powerChangeEvent = new EventFactionsPowerChange(null, mplayer, PowerChangeReason.DEATH, newPower);
powerChangeEvent.run();
if (powerChangeEvent.isCancelled()) {
return;
}
if (powerChangeEvent.isCancelled()) {
return;
}
newPower = powerChangeEvent.getNewPower();
mplayer.setPower(newPower);

View File

@@ -1,11 +1,11 @@
package net.knarcraft.factions.engine;
import net.knarcraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.PeriodUtil;
import net.knarcraft.factions.entity.MPlayer;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Particle;
@@ -24,7 +24,7 @@ public class EngineSeeChunk extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineSeeChunk i = new EngineSeeChunk();
private static final EngineSeeChunk i = new EngineSeeChunk();
public static EngineSeeChunk get() {
return i;
@@ -39,9 +39,9 @@ public class EngineSeeChunk extends Engine {
// -------------------------------------------- //
public static void leaveAndWorldChangeRemoval(Player player) {
if (MUtil.isntPlayer(player)) {
return;
}
if (MUtil.isntPlayer(player)) {
return;
}
final MPlayer mplayer = MPlayer.get(player);
mplayer.setSeeingChunk(false);
@@ -68,9 +68,9 @@ public class EngineSeeChunk extends Engine {
// Do we have a new period?
final long now = System.currentTimeMillis();
final long length = 500;
if (!PeriodUtil.isNewPeriod(this, length, now)) {
return;
}
if (!PeriodUtil.isNewPeriod(this, length, now)) {
return;
}
// Get the period number
final long period = PeriodUtil.getPeriod(length, now);
@@ -89,15 +89,15 @@ public class EngineSeeChunk extends Engine {
// For each player
for (Player player : Bukkit.getOnlinePlayers()) {
// Hide for dead players since the death screen looks better without.
if (player.isDead()) {
continue;
}
if (player.isDead()) {
continue;
}
// The player must obviously have the feature activated.
MPlayer mplayer = MPlayer.get(player);
if (!mplayer.isSeeingChunk()) {
continue;
}
if (!mplayer.isSeeingChunk()) {
continue;
}
// Calculate locations and play the effect there.
List<Location> locations = getLocations(player, steps, step);
@@ -110,18 +110,18 @@ public class EngineSeeChunk extends Engine {
public static List<Location> getLocations(Player player, int steps, int step) {
// Clean Args
if (player == null) {
throw new NullPointerException("player");
}
if (steps < 1) {
throw new InvalidParameterException("steps must be larger than 0");
}
if (step < 0) {
throw new InvalidParameterException("step must at least be 0");
}
if (step >= steps) {
throw new InvalidParameterException("step must be less than steps");
}
if (player == null) {
throw new NullPointerException("player");
}
if (steps < 1) {
throw new InvalidParameterException("steps must be larger than 0");
}
if (step < 0) {
throw new InvalidParameterException("step must at least be 0");
}
if (step >= steps) {
throw new InvalidParameterException("step must be less than steps");
}
// Create Ret
List<Location> ret = new ArrayList<>();
@@ -137,14 +137,14 @@ public class EngineSeeChunk extends Engine {
final int zmax = zmin + 15;
int keepEvery = 5;
if (keepEvery <= 0) {
keepEvery = Integer.MAX_VALUE;
}
if (keepEvery <= 0) {
keepEvery = Integer.MAX_VALUE;
}
int skipEvery = 0;
if (skipEvery <= 0) {
skipEvery = Integer.MAX_VALUE;
}
if (skipEvery <= 0) {
skipEvery = Integer.MAX_VALUE;
}
int x = xmin;
int z = zmin;
@@ -154,36 +154,36 @@ public class EngineSeeChunk extends Engine {
while (x + 1 <= xmax) {
x++;
i++;
if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) {
ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5));
}
if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) {
ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5));
}
}
// Add #2
while (z + 1 <= zmax) {
z++;
i++;
if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) {
ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5));
}
if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) {
ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5));
}
}
// Add #3
while (x - 1 >= xmin) {
x--;
i++;
if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) {
ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5));
}
if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) {
ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5));
}
}
// Add #4
while (z - 1 >= zmin) {
z--;
i++;
if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) {
ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5));
}
if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) {
ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5));
}
}
// Return Ret

View File

@@ -1,5 +1,11 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.PriorityLines;
import com.massivecraft.massivecore.money.Money;
import com.massivecraft.massivecore.util.TimeDiffUtil;
import com.massivecraft.massivecore.util.TimeUnit;
import com.massivecraft.massivecore.util.Txt;
import net.knarcraft.factions.comparator.ComparatorMPlayerRole;
import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.entity.MConf;
@@ -8,12 +14,6 @@ import net.knarcraft.factions.entity.MPlayer;
import net.knarcraft.factions.event.EventFactionsChunkChangeType;
import net.knarcraft.factions.event.EventFactionsFactionShowAsync;
import net.knarcraft.factions.integration.Econ;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.PriorityLines;
import com.massivecraft.massivecore.money.Money;
import com.massivecraft.massivecore.util.TimeDiffUtil;
import com.massivecraft.massivecore.util.TimeUnit;
import com.massivecraft.massivecore.util.Txt;
import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -56,7 +56,7 @@ public class EngineShow extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineShow i = new EngineShow();
private static final EngineShow i = new EngineShow();
public static EngineShow get() {
return i;

View File

@@ -1,11 +1,11 @@
package net.knarcraft.factions.engine;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.util.MUtil;
import net.knarcraft.factions.entity.Faction;
import net.knarcraft.factions.entity.MConf;
import net.knarcraft.factions.entity.MPlayer;
import net.knarcraft.factions.entity.Warp;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.util.MUtil;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -19,7 +19,7 @@ public class EngineTeleportHomeOnDeath extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineTeleportHomeOnDeath i = new EngineTeleportHomeOnDeath();
private static final EngineTeleportHomeOnDeath i = new EngineTeleportHomeOnDeath();
public static EngineTeleportHomeOnDeath get() {
return i;
@@ -32,33 +32,33 @@ public class EngineTeleportHomeOnDeath extends Engine {
public void teleportToHomeOnDeath(PlayerRespawnEvent event, EventPriority priority) {
// If a player is respawning ...
final Player player = event.getPlayer();
if (MUtil.isntPlayer(player)) {
return;
}
if (MUtil.isntPlayer(player)) {
return;
}
final MPlayer mplayer = MPlayer.get(player);
// ... homes are enabled, active and at this priority ...
if (!MConf.get().warpsEnabled) {
return;
}
if (!MConf.get().warpsTeleportToOnDeathActive) {
return;
}
if (MConf.get().warpsTeleportToOnDeathPriority != priority) {
return;
}
if (!MConf.get().warpsEnabled) {
return;
}
if (!MConf.get().warpsTeleportToOnDeathActive) {
return;
}
if (MConf.get().warpsTeleportToOnDeathPriority != priority) {
return;
}
// ... and the player has a faction ...
final Faction faction = mplayer.getFaction();
if (faction.isNone()) {
return;
}
if (faction.isNone()) {
return;
}
// ... and the faction has a home ...
List<Warp> warps = faction.getWarps().getAll((java.util.function.Predicate<Warp>) (warp -> warp.getName().equalsIgnoreCase(MConf.get().warpsTeleportToOnDeathName)));
if (warps.isEmpty()) {
return;
}
List<Warp> warps = faction.getWarps().getAll(warp -> warp.getName().equalsIgnoreCase(MConf.get().warpsTeleportToOnDeathName));
if (warps.isEmpty()) {
return;
}
Warp warp = warps.get(0);

View File

@@ -1,9 +1,9 @@
package net.knarcraft.factions.engine;
import net.knarcraft.factions.entity.MConf;
import net.knarcraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.util.MUtil;
import net.knarcraft.factions.entity.MConf;
import net.knarcraft.factions.entity.MPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -17,7 +17,7 @@ public class EngineTerritoryShield extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineTerritoryShield i = new EngineTerritoryShield();
private static final EngineTerritoryShield i = new EngineTerritoryShield();
public static EngineTerritoryShield get() {
return i;
@@ -31,32 +31,32 @@ public class EngineTerritoryShield extends Engine {
public void territoryShield(EntityDamageByEntityEvent event) {
// If the entity is a player ...
Entity entity = event.getEntity();
if (MUtil.isntPlayer(entity)) {
return;
}
if (MUtil.isntPlayer(entity)) {
return;
}
Player player = (Player) entity;
MPlayer mplayer = MPlayer.get(player);
// ... and the attacker is a player ...
Entity attacker = MUtil.getLiableDamager(event);
if (!(attacker instanceof Player)) {
return;
}
if (!(attacker instanceof Player)) {
return;
}
// ... and that player has a faction ...
if (!mplayer.hasFaction()) {
return;
}
if (!mplayer.hasFaction()) {
return;
}
// ... and that player is in their own territory ...
if (!mplayer.isInOwnTerritory()) {
return;
}
if (!mplayer.isInOwnTerritory()) {
return;
}
// ... and a territoryShieldFactor is configured ...
if (MConf.get().territoryShieldFactor <= 0) {
return;
}
if (MConf.get().territoryShieldFactor <= 0) {
return;
}
// ... then scale the damage ...
double factor = 1D - MConf.get().territoryShieldFactor;

View File

@@ -1,8 +1,8 @@
package net.knarcraft.factions.engine;
import net.knarcraft.factions.util.VisualizeUtil;
import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.util.MUtil;
import net.knarcraft.factions.util.VisualizeUtil;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerMoveEvent;
@@ -12,7 +12,7 @@ public class EngineVisualizations extends Engine {
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EngineVisualizations i = new EngineVisualizations();
private static final EngineVisualizations i = new EngineVisualizations();
public static EngineVisualizations get() {
return i;
@@ -24,9 +24,9 @@ public class EngineVisualizations extends Engine {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMoveClearVisualizations(PlayerMoveEvent event) {
if (MUtil.isSameBlock(event)) {
return;
}
if (MUtil.isSameBlock(event)) {
return;
}
VisualizeUtil.clear(event.getPlayer());
}

View File

@@ -38,10 +38,9 @@ public enum ProtectCase {
return MPerm.getPermBuild();
case USE_ENTITY:
if (!(object instanceof Entity)) {
if (!(object instanceof Entity entity)) {
return null;
}
Entity entity = (Entity) object;
EntityType type = entity.getType();
if (EnumerationUtil.isEntityTypeContainer(type)) {
return MPerm.getPermContainer();
@@ -51,10 +50,9 @@ public enum ProtectCase {
}
case USE_BLOCK:
if (!(object instanceof Material)) {
if (!(object instanceof Material material)) {
return null;
}
Material material = (Material) object;
if (EnumerationUtil.isMaterialEditOnInteract(material)) {
return MPerm.getPermBuild();
}