Skip to content

Commit

Permalink
Bug fixes and PAPI support. Tested completely and successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
nickstuaw committed Sep 20, 2021
1 parent 0a67606 commit 61a6a30
Show file tree
Hide file tree
Showing 24 changed files with 102 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

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

12 changes: 11 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>xyz.nsgw</groupId>
<artifactId>PersonalPVP</artifactId>
<version>1.4</version>
<version>1.4.2</version>
<packaging>jar</packaging>

<name>PersonalPVP</name>
Expand Down Expand Up @@ -93,6 +93,10 @@
<id>aikar</id>
<url>https://repo.aikar.co/content/groups/aikar/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -127,5 +131,11 @@
<artifactId>configme</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.10</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
52 changes: 41 additions & 11 deletions src/main/java/xyz/nsgw/personalpvp/Listeners.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.nsgw.personalpvp;

import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.*;
Expand All @@ -20,8 +21,11 @@
import xyz.nsgw.personalpvp.managers.PVPManager;
import xyz.nsgw.personalpvp.managers.TaskManager;

import java.awt.geom.Area;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Listeners implements Listener {
Expand Down Expand Up @@ -85,6 +89,13 @@ public void onDamage(@NotNull EntityDamageByEntityEvent e) {
}
if(!(defender instanceof Player) || !(attacker instanceof Player)) return;
UUID entityUuid = defender.getUniqueId(), damagerUuid = attacker.getUniqueId();
if(attacker instanceof AreaEffectCloud) {
AreaEffectCloud cloud = (AreaEffectCloud) attacker;
if(cloud.getCustomEffects().stream().map(PotionEffect::getType).anyMatch(Arrays.asList(Utils.BAD_EFFECTS)::contains)) {
e.setCancelled(true);
}
return;
}
if(PVPManager.isEitherNegative(entityUuid,damagerUuid)) {
e.setCancelled(true);
TaskManager.blockedAttack(entityUuid,damagerUuid);
Expand Down Expand Up @@ -120,22 +131,30 @@ private boolean checkOwners(Tameable animal) {
}
}
class PotionListener implements Listener {
private final PotionEffectType[] BAD_EFFECTS = new PotionEffectType[]{
PotionEffectType.BLINDNESS,
PotionEffectType.CONFUSION,
PotionEffectType.HARM,
PotionEffectType.HUNGER,
PotionEffectType.POISON,
PotionEffectType.SLOW,
PotionEffectType.SLOW_DIGGING,
PotionEffectType.WEAKNESS
};
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onCloud(final AreaEffectCloudApplyEvent e) {
if(e.getAffectedEntities().stream().noneMatch(livingEntity -> livingEntity instanceof Player)) return;
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)) {
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)) {
e.getAffectedEntities().remove(Bukkit.getPlayer(p));
}
});
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onSplash(final PotionSplashEvent e){
ProjectileSource shooter = e.getEntity().getShooter();
if((!(shooter instanceof Player) ||
e.getAffectedEntities().stream().noneMatch(entity -> entity instanceof Player))) return;
if(e.getPotion().getEffects().stream().map(PotionEffect::getType).noneMatch(Arrays.asList(this.BAD_EFFECTS)::contains)) 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)) {
Expand All @@ -144,6 +163,17 @@ public void onSplash(final PotionSplashEvent e){
TaskManager.blockedAttack(stream.toArray(UUID[]::new));
}
}
/*@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onLing(final LingeringPotionSplashEvent e){
e.getAreaEffectCloud().getBasePotionData().getType()
Stream<UUID> stream = e.getAffectedEntities().stream().filter(livingEntity -> livingEntity instanceof Player).map(LivingEntity::getUniqueId);
if(e.getEntity().getCustomEffects().stream().map(PotionEffect::getType).noneMatch(Arrays.asList(Utils.BAD_EFFECTS)::contains)) return;
stream.forEach(p -> {
if(PVPManager.pvpNegative(p)) {
e.getAffectedEntities().remove(Bukkit.getPlayer(p));e.
}
});
}*/
}
class ProjectileListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/xyz/nsgw/personalpvp/Utils.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package xyz.nsgw.personalpvp;

import me.clip.placeholderapi.PlaceholderAPI;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import xyz.nsgw.personalpvp.config.GeneralConfig;
import xyz.nsgw.personalpvp.managers.PVPManager;

Expand All @@ -16,6 +18,17 @@

public class Utils {

public static final PotionEffectType[] BAD_EFFECTS = new PotionEffectType[]{
PotionEffectType.BLINDNESS,
PotionEffectType.CONFUSION,
PotionEffectType.HARM,
PotionEffectType.HUNGER,
PotionEffectType.POISON,
PotionEffectType.SLOW,
PotionEffectType.SLOW_DIGGING,
PotionEffectType.WEAKNESS
};

private static PPVPPlugin pl;

private static List<List<UUID>> loaded = new ArrayList<>(Arrays.asList(new ArrayList<>(),new ArrayList<>(),new ArrayList<>()));
Expand All @@ -40,6 +53,13 @@ public static void send(final Component component) {
Bukkit.getConsoleSender().sendMessage(component);
}

public static Component parse(Player p, String text, final String... placeholders) {
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
PlaceholderAPI.setPlaceholders(p, text);
}
return MiniMessage.get().parse(text, placeholders);
}

public static Component parse(String text, final String... placeholders) {
return MiniMessage.get().parse(text, placeholders);
}
Expand Down Expand Up @@ -78,13 +98,13 @@ 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())) {
Utils.sendText(p,MiniMessage.get().parse("Oops! Your PVP status has been locked."));
Utils.sendText(p,Utils.parse("Oops! Your PVP status has been locked."));
return false;
}
}
if(PVPManager.coolingDown(p)) {
int remaining = PVPManager.getRemainingSeconds(p.getUniqueId());
Utils.sendText(p, MiniMessage.get().parse("<red>You can do that again in <yellow><bold><seconds></bold></yellow>.","<seconds>",remaining+(remaining>1?" seconds":" second")));
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);
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/xyz/nsgw/personalpvp/commands/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class PVPCommand extends BaseCommand {

@Default
public void onPvp(Player p) {
if(Utils.togglePersonal(p)) notifyConsole(p.getName(), PVPManager.isPvpEnabled(p.getUniqueId()));
if(Utils.togglePersonal(p)) notifyConsole( PVPManager.isPvpEnabled(p.getUniqueId()), p);
}

private void notifyConsole(final String tName, final boolean setTo) {
if(PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.CMD_PVPTOGGLE_LOG_EVENTS_TO_CONSOLE)) Utils.send(Utils.parse(PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.CMD_PVPTOGGLELOG_CONSOLE_FORMAT),"name",tName,"pvpstatus", setTo?PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.CMD_PVPTOGGLELOG_CONSOLE__PVP_ENABLED_PFX):PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.CMD_PVPTOGGLELOG_CONSOLE__PVP_DISABLED_PFX)));
private void notifyConsole(final boolean setTo, Player p) {
if(PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.CMD_PVPTOGGLE_LOG_EVENTS_TO_CONSOLE)) Utils.send(Utils.parse(p,PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.CMD_PVPTOGGLELOG_CONSOLE_FORMAT),"name",p.getName(),"pvpstatus", setTo?PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.CMD_PVPTOGGLELOG_CONSOLE__PVP_ENABLED_PFX):PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.CMD_PVPTOGGLELOG_CONSOLE__PVP_DISABLED_PFX)));
}

@Subcommand("control")
Expand All @@ -59,7 +59,9 @@ public class onPvpCtrlr extends BaseCommand {

@Default
public void onControl(final CommandSender s) {
Utils.send(s, Utils.parse(this.title+"\n" + PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.CMD_PVPCTRL_PERSONAL_LINES) +(s.hasPermission("personalpvp.control.admin")?"\n<green><underlined>Admin</underlined>\n"+PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.CMD_PVPCTRL_LINES)+"\n":"\n")+this.title), true, false);
if(s instanceof Player) {
Utils.send(s, Utils.parse((Player) s, this.title + "\n" + PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.CMD_PVPCTRL_PERSONAL_LINES) + (s.hasPermission("personalpvp.control.admin") ? "\n<green><underlined>Admin</underlined>\n" + PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.CMD_PVPCTRL_LINES) + "\n" : "\n") + this.title), true, false);
}
}

@Subcommand("resetglobal")
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/xyz/nsgw/personalpvp/config/GeneralConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,6 @@ public class GeneralConfig implements SettingsHolder {
newListProperty(PFX_CMD_SETTINGS + PFX_PVP_CONTROL + "lines", List.of(
"<green>[<click:suggest_command:/pvp ontrol resetglobal><hover:show_text:'<aqua>Reset offline players as well as online players.'><gradient:green:aqua><bold>FULL</gradient> <gradient:aqua:green>RESET</gradient></bold></hover></click><green>]"));

public static final Property<Boolean> ENABLE_PVP_ALERT =
newProperty("notifications.enable-pvp-alert", true);
}
28 changes: 12 additions & 16 deletions src/main/java/xyz/nsgw/personalpvp/managers/TaskManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.bukkit.Bukkit;
import xyz.nsgw.personalpvp.PPVPPlugin;
import xyz.nsgw.personalpvp.Utils;
import xyz.nsgw.personalpvp.config.ConfigHandler;
import xyz.nsgw.personalpvp.config.GeneralConfig;

import java.util.ArrayList;
Expand Down Expand Up @@ -79,14 +80,14 @@ public static void sendInstantUpdate(final UUID u) {
false, true);
}
public static void sendInstantUpdate(final UUID u, final String msg) {
Utils.sendText(Bukkit.getPlayer(u), MiniMessage.get().parse(msg,"pvpprefix",
PVPManager.pvpPositive(u) ?
PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.ABAR_PVP_ENABLED_PFX) :
PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.ABAR_PVP_DISABLED_PFX),
"pvpstatus", PVPManager.pvpPositive(u) ?
PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.ABAR_PVP_ENABLED) :
PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.ABAR_PVP_DISABLED),
"worldtime", (hours < 10 ? "0" : "") + hours + ":" + (minutes < 10 ? "0" : "") + minutes + suffix));
Utils.sendText(Bukkit.getPlayer(u), MiniMessage.get().parse(msg, "pvpprefix",
PVPManager.pvpPositive(u) ?
PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.ABAR_PVP_ENABLED_PFX) :
PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.ABAR_PVP_DISABLED_PFX),
"pvpstatus", PVPManager.pvpPositive(u) ?
PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.ABAR_PVP_ENABLED) :
PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.ABAR_PVP_DISABLED),
"worldtime", (hours < 10 ? "0" : "") + hours + ":" + (minutes < 10 ? "0" : "") + minutes + suffix));
}

public static boolean toggleHidden(final UUID uuid) {
Expand All @@ -103,17 +104,12 @@ public static void sendJoinDuration(final UUID u, final PPVPPlugin pl) {
}

public static void blockedAttack(final UUID... us) {
if(PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.ABAR_ATTACK_VISIBILITY_DURATION)<1) return;
if(!PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.ENABLE_PVP_ALERT)) return;
PPVPPlugin pl = PPVPPlugin.inst();
for(UUID u : us) {
if (ignoredPositive(u) && !PVPManager.isPvpEnabled(u)) {
for (int i = 0;
i < PPVPPlugin.inst().conf().get().getProperty(GeneralConfig.ABAR_ATTACK_VISIBILITY_DURATION)+1;
i++) {
pl.getServer().getScheduler().scheduleSyncDelayedTask(pl, () ->
TaskManager.sendInstantUpdate(u, "<#ed4213>Use <red><bold>/pvp<#ed4213> to " +
"enable pvp."), i * 20L);
}
TaskManager.sendInstantUpdate(u, "<#ed4213>Use <red><bold>/pvp<#ed4213> to " +
"enable pvp.");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ main: xyz.nsgw.personalpvp.PPVPPlugin
api-version: 1.17
authors: [ CosmicSilence ]
website: https://github.com/Nebula-O
softdepend: [PlaceholderAPI]
permissions:
personalpvp.player:
children:
Expand Down
3 changes: 2 additions & 1 deletion target/classes/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: PersonalPVP
version: 1.4
version: 1.4.2
main: xyz.nsgw.personalpvp.PPVPPlugin
api-version: 1.17
authors: [ CosmicSilence ]
website: https://github.com/Nebula-O
softdepend: [PlaceholderAPI]
permissions:
personalpvp.player:
children:
Expand Down
Binary file modified target/classes/xyz/nsgw/personalpvp/CombustionListener.class
Binary file not shown.
Binary file modified target/classes/xyz/nsgw/personalpvp/DamageByEntityListener.class
Binary file not shown.
Binary file modified target/classes/xyz/nsgw/personalpvp/DeathListener.class
Binary file not shown.
Binary file modified target/classes/xyz/nsgw/personalpvp/FishingListener.class
Binary file not shown.
Binary file modified target/classes/xyz/nsgw/personalpvp/Listeners.class
Binary file not shown.
Binary file modified target/classes/xyz/nsgw/personalpvp/PotionListener.class
Binary file not shown.
Binary file modified target/classes/xyz/nsgw/personalpvp/ProjectileListener.class
Binary file not shown.
Binary file modified target/classes/xyz/nsgw/personalpvp/QuitListener.class
Binary file not shown.
Binary file modified target/classes/xyz/nsgw/personalpvp/Utils.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified target/classes/xyz/nsgw/personalpvp/commands/PVPCommand.class
Binary file not shown.
Binary file modified target/classes/xyz/nsgw/personalpvp/config/GeneralConfig.class
Binary file not shown.
Binary file modified target/classes/xyz/nsgw/personalpvp/managers/TaskManager.class
Binary file not shown.

0 comments on commit 61a6a30

Please sign in to comment.