Skip to content

Commit

Permalink
Added constant status permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
nickstuaw committed Oct 4, 2021
1 parent 7637f74 commit 03efe04
Show file tree
Hide file tree
Showing 11 changed files with 309 additions and 128 deletions.
27 changes: 9 additions & 18 deletions .idea/artifacts/PersonalPVP_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/artifacts/PersonalPVP_jar2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/copyright/Nick.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>xyz.nsgw.personalpvp</groupId>
<artifactId>PersonalPVP</artifactId>
<version>1.4.5</version>
<version>1.5.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>PersonalPVP</name>
Expand Down
25 changes: 12 additions & 13 deletions src/main/java/xyz/nsgw/personalpvp/Listeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.bukkit.projectiles.ProjectileSource;
import org.jetbrains.annotations.NotNull;
import xyz.nsgw.personalpvp.config.GeneralConfig;
import xyz.nsgw.personalpvp.managers.PVPManager;
import xyz.nsgw.personalpvp.managers.TaskManager;

import java.util.Arrays;
Expand Down Expand Up @@ -68,7 +67,7 @@ public void onQuit(final PlayerQuitEvent e) {
class QuitListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onQuit(final PlayerQuitEvent e) {
PVPManager.reset(e.getPlayer().getUniqueId());
PPVPPlugin.inst().pvp().reset(e.getPlayer().getUniqueId());
}
}
class DeathListener implements Listener {
Expand Down Expand Up @@ -98,7 +97,7 @@ public void onDamage(@NotNull EntityDamageByEntityEvent e) {
}
return;
}
if(PVPManager.isEitherNegative(entityUuid,damagerUuid)) {
if(PPVPPlugin.inst().pvp().isEitherNegative(entityUuid,damagerUuid)) {
e.setCancelled(true);
TaskManager.blockedAttack(entityUuid,damagerUuid);
}
Expand All @@ -110,9 +109,9 @@ private boolean shouldTameablesCancel(final Entity attacker, final Entity defend
if(attacker instanceof Tameable) {
animal = (Tameable) attacker;
if(animal.getOwner() == null || !(animal.getOwner() instanceof Player)) return false;
if(PVPManager.isPvpDisabled(animal.getOwner().getUniqueId())) return true;
if(PPVPPlugin.inst().pvp().isPvpDisabled(animal.getOwner().getUniqueId())) return true;
if(defender instanceof Player) {
if(PVPManager.isPvpDisabled(defender.getUniqueId())) return true;
if(PPVPPlugin.inst().pvp().isPvpDisabled(defender.getUniqueId())) return true;
}
}
if(defender instanceof Tameable) {
Expand All @@ -128,7 +127,7 @@ private boolean shouldTameablesCancel(final Entity attacker, final Entity defend
}
private boolean checkOwners(Tameable animal) {
if(animal.getOwner() == null || !(animal.getOwner() instanceof Player)) return false;
if(PVPManager.isPvpDisabled(animal.getOwner().getUniqueId())) return true;
if(PPVPPlugin.inst().pvp().isPvpDisabled(animal.getOwner().getUniqueId())) return true;
return false;
}
}
Expand All @@ -139,14 +138,14 @@ public void onCloud(final AreaEffectCloudApplyEvent e) {
List<UUID> list = e.getAffectedEntities().stream().filter(livingEntity -> livingEntity instanceof Player).map(LivingEntity::getUniqueId).collect(Collectors.toList());
if(Arrays.asList(Utils.BAD_EFFECTS).contains(e.getEntity().getBasePotionData().getType().getEffectType())) {
list.forEach(p -> {
if(PVPManager.pvpNegative(p)) {
if(PPVPPlugin.inst().pvp().pvpNegative(p)) {
e.getAffectedEntities().remove(Bukkit.getPlayer(p));
}
});
}
if(e.getEntity().getCustomEffects().stream().map(PotionEffect::getType).noneMatch(Arrays.asList(Utils.BAD_EFFECTS)::contains)) return;
list.forEach(p -> {
if(PVPManager.pvpNegative(p)) {
if(PPVPPlugin.inst().pvp().pvpNegative(p)) {
e.getAffectedEntities().remove(Bukkit.getPlayer(p));
}
});
Expand All @@ -158,8 +157,8 @@ public void onSplash(final PotionSplashEvent e){
e.getAffectedEntities().stream().noneMatch(entity -> entity instanceof Player))) return;
if(e.getPotion().getEffects().stream().map(PotionEffect::getType).noneMatch(Arrays.asList(Utils.BAD_EFFECTS)::contains)) return;
Stream<UUID> stream = e.getAffectedEntities().stream().filter(livingEntity -> livingEntity instanceof Player).map(LivingEntity::getUniqueId);
if(PVPManager.pvpNegative((((Player) shooter).getUniqueId()))
|| stream.noneMatch(PVPManager::pvpPositive)) {
if(PPVPPlugin.inst().pvp().pvpNegative((((Player) shooter).getUniqueId()))
|| stream.noneMatch(PPVPPlugin.inst().pvp()::pvpPositive)) {
e.setCancelled(true);
((Player) shooter).getInventory().addItem(e.getEntity().getItem());
TaskManager.blockedAttack(stream.toArray(UUID[]::new));
Expand All @@ -186,7 +185,7 @@ public void onHit(final ProjectileHitEvent e){
!(e.getHitEntity() instanceof Player)) return;
Player shooter = (Player) projectile.getShooter();
UUID shooterUuid = shooter.getUniqueId(), entityUuid = e.getHitEntity().getUniqueId();
if(PVPManager.isEitherNegative(shooterUuid,entityUuid) && !((projectile instanceof Snowball) || projectile instanceof Egg)) {
if(PPVPPlugin.inst().pvp().isEitherNegative(shooterUuid,entityUuid) && !((projectile instanceof Snowball) || projectile instanceof Egg)) {
e.setCancelled(true);
TaskManager.blockedAttack(shooterUuid,entityUuid);
if((shooter).getGameMode().equals(GameMode.CREATIVE)) return;
Expand All @@ -212,7 +211,7 @@ class FishingListener implements Listener {
public void onFish(@NotNull PlayerFishEvent e) {
if(!(e.getCaught() instanceof Player)) return;
UUID caughtUuid = e.getCaught().getUniqueId(), playerUuid = e.getPlayer().getUniqueId();
if(PVPManager.isEitherNegative(caughtUuid,playerUuid)) {
if(PPVPPlugin.inst().pvp().isEitherNegative(caughtUuid,playerUuid)) {
e.setCancelled(true);
TaskManager.blockedAttack(caughtUuid,playerUuid);
}
Expand All @@ -224,7 +223,7 @@ public void onCombust(final EntityCombustByEntityEvent e) {
if(!(e.getCombuster() instanceof Player) ||
!(e.getEntity() instanceof Player)) return;
UUID combusterUuid = e.getCombuster().getUniqueId(), entityUuid = e.getEntity().getUniqueId();
if(PVPManager.isEitherNegative(combusterUuid,entityUuid)) {
if(PPVPPlugin.inst().pvp().isEitherNegative(combusterUuid,entityUuid)) {
e.setCancelled(true);
TaskManager.blockedAttack(combusterUuid,entityUuid);
}
Expand Down
26 changes: 20 additions & 6 deletions src/main/java/xyz/nsgw/personalpvp/PPVPPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public final class PPVPPlugin extends JavaPlugin {

private static PPVPPlugin instance;

private PVPManager pvpManager;

public static PPVPPlugin inst() {
return instance;
}
Expand All @@ -42,6 +44,8 @@ private static void setInstance(final PPVPPlugin pl) {
@Override
public void onEnable() {

pvpManager = new PVPManager();

configHandler = new ConfigHandler(this.getDataFolder());

setInstance(this);
Expand All @@ -59,21 +63,25 @@ public void onEnable() {
e.printStackTrace();
}
}
if (this.data_existed) PVPManager.load();
if (this.data_existed) pvpManager.load();

new Listeners(this);

checkActionbar();

this.log.info("Default PvP setting: "+(PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.DEFAULT_PVP_STATUS)?"TRUE":"FALSE"));
this.log.info("If you are using spigot (not paper) or get actionbar errors, please disable the actionbar in config.yml by changing toggleable-actionbar.enable to false.");
this.log.info("Default PvP setting: "
+(PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.DEFAULT_PVP_STATUS)?"TRUE":"FALSE"));
this.log.info("If you are using spigot (not paper) or get actionbar errors, please disable the actionbar"
+ " in config.yml by changing toggleable-actionbar.enable to false.");
this.log.info("Personal PvP ENABLED.");
}

public ConfigHandler conf() {
return configHandler;
return this.configHandler;
}

public PVPManager pvp() {return this.pvpManager;}

public void checkActionbar() {
if(configHandler.get().getProperty(GeneralConfig.ABAR_ENABLE)) {
if(! configHandler.get().getProperty(GeneralConfig.ABAR_RESET_ON_Q)) {
Expand All @@ -98,8 +106,14 @@ public void onDisable() {
TaskManager.stop();
commandHandler.onDisable();
List<UUID> emptyList = new ArrayList<>();
if(configHandler.get().getProperty(GeneralConfig.RESET_PVP_ON_QUIT) != configHandler.get().getProperty(GeneralConfig.ABAR_RESET_ON_Q) || no_reset_for_any()) {
Utils.saveObjects(configHandler.get().getProperty(GeneralConfig.FILE), configHandler.get().getProperty(GeneralConfig.RESET_PVP_ON_QUIT) ?emptyList:PVPManager.players(), configHandler.get().getProperty(GeneralConfig.ABAR_RESET_ON_Q) ?emptyList:TaskManager.ignoredValues(), PVPManager.lockedPlayers());
if(configHandler.get().getProperty(GeneralConfig.RESET_PVP_ON_QUIT)
!= configHandler.get().getProperty(GeneralConfig.ABAR_RESET_ON_Q) || no_reset_for_any()) {
Utils.saveObjects(configHandler.get().getProperty(GeneralConfig.FILE),
configHandler.get().getProperty(GeneralConfig.RESET_PVP_ON_QUIT) ?
emptyList:
PPVPPlugin.inst().pvp().players(),
configHandler.get().getProperty(GeneralConfig.ABAR_RESET_ON_Q) ? emptyList :
TaskManager.ignoredValues(), PPVPPlugin.inst().pvp().lockedPlayers());
}
this.saveConfig();
this.log.info("Personal PvP DISABLED.");
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/xyz/nsgw/personalpvp/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import xyz.nsgw.personalpvp.config.GeneralConfig;
import xyz.nsgw.personalpvp.managers.PVPManager;

import java.io.*;
import java.util.ArrayList;
Expand Down Expand Up @@ -101,18 +100,18 @@ public static List<List<UUID>> loaded() {

public static boolean togglePersonal(final Player p) {
if(pl.conf().get().getProperty(GeneralConfig.IS_STATUS_LOCKING)) {
if (PVPManager.isLocked(p.getUniqueId())) {
if (pl.pvp().isLocked(p.getUniqueId())) {
Utils.sendText(p,Utils.parse("Oops! Your PVP status has been locked."));
return false;
}
}
if(PVPManager.coolingDown(p)) {
int remaining = PVPManager.getRemainingSeconds(p.getUniqueId());
if(pl.pvp().coolingDown(p)) {
int remaining = pl.pvp().getRemainingSeconds(p.getUniqueId());
Utils.sendText(p, Utils.parse("<red>You can do that again in <yellow><bold><seconds></bold></yellow>.","seconds",remaining+(remaining>1?" seconds":" second")));
return false;
}
PVPManager.coolDown(p);
Utils.sendText(p, PVPManager.toggle(p.getUniqueId()) ? MiniMessage.get().parse("<aqua>PVP enabled.") : MiniMessage.get().parse("<green>PVP disabled."));
pl.pvp().coolDown(p);
Utils.sendText(p, pl.pvp().toggle(p.getUniqueId()) ? MiniMessage.get().parse("<aqua>PVP enabled.") : MiniMessage.get().parse("<green>PVP disabled."));
return true;
}
}
Loading

0 comments on commit 03efe04

Please sign in to comment.