Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
lRENyaaa committed May 4, 2024
2 parents cc72fe0 + cc62d59 commit a0641e6
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 89 deletions.
5 changes: 5 additions & 0 deletions src/com/bekvon/bukkit/residence/ResidenceCommandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ public void sendUsage(CommandSender sender, String command) {
}

private boolean commandHelp(String[] args, boolean resadmin, CommandSender sender, Command command) {


if (plugin.getHelpPages() == null)
return false;

Expand All @@ -333,9 +335,12 @@ private boolean commandHelp(String[] args, boolean resadmin, CommandSender sende
if (command.getName().equalsIgnoreCase("res"))
resadmin = false;

CMIDebug.d("on commands ", 1, helppath);
if (plugin.getHelpPages().containesEntry(helppath)) {
CMIDebug.d("on commands ", 0);
plugin.getHelpPages().printHelp(sender, page, helppath, resadmin);
}
CMIDebug.d("on commands ", 2);
return true;
}

Expand Down
145 changes: 85 additions & 60 deletions src/com/bekvon/bukkit/residence/allNms/v1_9Events.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bekvon.bukkit.residence.allNms;

import java.lang.reflect.Method;
import java.util.Iterator;

import org.bukkit.entity.Entity;
Expand All @@ -18,74 +19,98 @@
import com.bekvon.bukkit.residence.containers.Flags;
import com.bekvon.bukkit.residence.protection.FlagPermissions.FlagCombo;

import net.Zrips.CMILib.Version.Version;

public class v1_9Events implements Listener {

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onLingeringSplashPotion(LingeringPotionSplashEvent event) {
ProjectileHitEvent ev = event;
ThrownPotion potion = (ThrownPotion) ev.getEntity();

// disabling event on world
if (Residence.getInstance().isDisabledWorldListener(potion.getWorld()))
return;
if (event.isCancelled())
return;

boolean harmfull = false;
mein: for (PotionEffect one : potion.getEffects()) {
for (String oneHarm : Residence.getInstance().getConfigManager().getNegativePotionEffects()) {
if (oneHarm.equalsIgnoreCase(one.getType().getName())) {
harmfull = true;
break mein;
}
}
}
if (!harmfull)
return;

Entity ent = potion;
boolean srcpvp = Residence.getInstance().getPermsByLoc(ent.getLocation()).has(Flags.pvp, FlagCombo.TrueOrNone);
if (!srcpvp)
event.setCancelled(true);
ProjectileHitEvent ev = event;
ThrownPotion potion = (ThrownPotion) ev.getEntity();

// disabling event on world
if (Residence.getInstance().isDisabledWorldListener(potion.getWorld()))
return;
if (event.isCancelled())
return;

boolean harmfull = false;
mein: for (PotionEffect one : potion.getEffects()) {
for (String oneHarm : Residence.getInstance().getConfigManager().getNegativePotionEffects()) {
if (oneHarm.equalsIgnoreCase(one.getType().getName())) {
harmfull = true;
break mein;
}
}
}
if (!harmfull)
return;

Entity ent = potion;
boolean srcpvp = Residence.getInstance().getPermsByLoc(ent.getLocation()).has(Flags.pvp, FlagCombo.TrueOrNone);
if (!srcpvp)
event.setCancelled(true);
}

Method basePotionData = null;

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onLingeringEffectApply(AreaEffectCloudApplyEvent event) {

// disabling event on world
if (Residence.getInstance().isDisabledWorldListener(event.getEntity().getWorld()))
return;

boolean harmfull = false;

// Temporally fail safe to avoid console spam for getting base potion data until fix roles out
try {
for (String oneHarm : Residence.getInstance().getConfigManager().getNegativeLingeringPotionEffects()) {
if (event.getEntity().getBasePotionData().getType().name().equalsIgnoreCase(oneHarm)) {
harmfull = true;
break;
}
}
} catch (Exception e) {
return;
}

if (!harmfull)
return;

Entity ent = event.getEntity();
boolean srcpvp = Residence.getInstance().getPermsByLoc(ent.getLocation()).has(Flags.pvp, true);
Iterator<LivingEntity> it = event.getAffectedEntities().iterator();
while (it.hasNext()) {
LivingEntity target = it.next();
if (!(target instanceof Player))
continue;
Boolean tgtpvp = Residence.getInstance().getPermsByLoc(target.getLocation()).has(Flags.pvp, true);
if (!srcpvp || !tgtpvp) {
event.getAffectedEntities().remove(target);
event.getEntity().remove();
break;
}
}
// disabling event on world
if (Residence.getInstance().isDisabledWorldListener(event.getEntity().getWorld()))
return;

boolean harmfull = false;

// Temporally fail safe to avoid console spam for getting base potion data until fix roles out
try {

if (Version.isCurrentEqualOrHigher(Version.v1_20_R4)) {
for (String oneHarm : Residence.getInstance().getConfigManager().getNegativeLingeringPotionEffects()) {
if (!event.getEntity().getBasePotionType().name().equalsIgnoreCase(oneHarm))
continue;
harmfull = true;
break;
}
} else {
try {
if (basePotionData == null) {
Method tempMethod = event.getEntity().getClass().getMethod("getBasePotionData");
basePotionData = tempMethod.invoke(event.getEntity()).getClass().getMethod("getType");
}

for (String oneHarm : Residence.getInstance().getConfigManager().getNegativeLingeringPotionEffects()) {
org.bukkit.potion.PotionType type = (org.bukkit.potion.PotionType) basePotionData.invoke(event.getEntity());
if (type.name().equalsIgnoreCase(oneHarm)) {
harmfull = true;
break;
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
} catch (Exception e) {
return;
}

if (!harmfull)
return;

Entity ent = event.getEntity();
boolean srcpvp = Residence.getInstance().getPermsByLoc(ent.getLocation()).has(Flags.pvp, true);
Iterator<LivingEntity> it = event.getAffectedEntities().iterator();
while (it.hasNext()) {
LivingEntity target = it.next();
if (!(target instanceof Player))
continue;
Boolean tgtpvp = Residence.getInstance().getPermsByLoc(target.getLocation()).has(Flags.pvp, true);
if (!srcpvp || !tgtpvp) {
event.getAffectedEntities().remove(target);
event.getEntity().remove();
break;
}
}
}
}
6 changes: 3 additions & 3 deletions src/com/bekvon/bukkit/residence/gui/setFlagInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
Expand All @@ -24,6 +23,7 @@
import com.bekvon.bukkit.residence.protection.FlagPermissions.FlagState;
import com.bekvon.bukkit.residence.protection.ResidencePermissions;

import net.Zrips.CMILib.Enchants.CMIEnchantEnum;
import net.Zrips.CMILib.GUI.CMIGuiButton;
import net.Zrips.CMILib.GUI.GUIManager.GUIClickType;

Expand Down Expand Up @@ -323,11 +323,11 @@ else if (fp.has(flagName, FlagCombo.OnlyFalse))
if (state == FlagState.TRUE) {
ItemMeta im = miscInfo.getItemMeta();
if (im != null) {
im.addEnchant(Enchantment.LUCK, 1, true);
im.addEnchant(CMIEnchantEnum.LUCK_OF_THE_SEA.getEnchantment(), 1, true);
miscInfo.setItemMeta(im);
}
} else
miscInfo.removeEnchantment(Enchantment.LUCK);
miscInfo.removeEnchantment(CMIEnchantEnum.LUCK_OF_THE_SEA.getEnchantment());

Flags flag = Flags.getFlag(flagName);
if (flag != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.bukkit.event.entity.PlayerLeashEntityEvent;
import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.entity.SpawnerSpawnEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause;
Expand Down Expand Up @@ -476,7 +475,7 @@ public void onFenceLeashInteract(PlayerInteractEntityEvent event) {

Entity entity = event.getRightClicked();

if (entity.getType() != EntityType.LEASH_HITCH)
if (CMIEntityType.get(entity.getType()) != CMIEntityType.LEASH_KNOT)
return;

if (plugin.isResAdminOn(player))
Expand Down Expand Up @@ -540,11 +539,6 @@ public void onPhantomSpawn(CreatureSpawnEvent event) {
}
}

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onItemSpawnEvent(SpawnerSpawnEvent event) {

}

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent event) {
// disabling event on world
Expand Down Expand Up @@ -670,7 +664,7 @@ public void onProjectileLaunch(ProjectileLaunchEvent event) {
if (plugin.isDisabledWorldListener(event.getEntity().getWorld()))
return;

if (event.getEntityType().equals(EntityType.THROWN_EXP_BOTTLE))
if (CMIEntityType.get(event.getEntity()) == CMIEntityType.EXPERIENCE_BOTTLE)
return;

if (event.getEntity().getShooter() instanceof Player) {
Expand Down Expand Up @@ -737,8 +731,8 @@ public void onHangingBreakEvent(HangingBreakEvent event) {
return;
if (plugin.isDisabledWorldListener(ent.getWorld()))
return;
CMIEntityType type = CMIEntityType.getByType(event.getEntity().getType());

CMIEntityType type = CMIEntityType.get(event.getEntity().getType());

if (!type.equals(CMIEntityType.ITEM_FRAME) && !type.equals(CMIEntityType.GLOW_ITEM_FRAME))
return;
Expand Down Expand Up @@ -798,7 +792,7 @@ public void onExplosionPrime(ExplosionPrimeEvent event) {
EntityType entity = event.getEntityType();
FlagPermissions perms = plugin.getPermsByLoc(ent.getLocation());

switch (entity) {
switch (CMIEntityType.get(entity)) {
case CREEPER:

// Disabling listener if flag disabled globally
Expand All @@ -822,8 +816,8 @@ public void onExplosionPrime(ExplosionPrimeEvent event) {
}
}
break;
case PRIMED_TNT:
case MINECART_TNT:
case TNT:
case TNT_MINECART:

// Disabling listener if flag disabled globally
if (!Flags.tnt.isGlobalyEnabled())
Expand Down Expand Up @@ -895,7 +889,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
FlagPermissions world = plugin.getWorldFlags().getPerms(loc.getWorld().getName());

if (ent != null) {
switch (event.getEntityType()) {
switch (CMIEntityType.get(event.getEntityType())) {
case CREEPER:
// Disabling listener if flag disabled globally
if (!Flags.creeper.isGlobalyEnabled())
Expand All @@ -912,8 +906,8 @@ public void onEntityExplode(EntityExplodeEvent event) {
} else
cancel = true;
break;
case PRIMED_TNT:
case MINECART_TNT:
case TNT:
case TNT_MINECART:
// Disabling listener if flag disabled globally
if (!Flags.tnt.isGlobalyEnabled())
break;
Expand Down Expand Up @@ -974,7 +968,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
FlagPermissions blockperms = plugin.getPermsByLoc(block.getLocation());

if (ent != null) {
switch (event.getEntityType()) {
switch (CMIEntityType.get(event.getEntityType())) {
case CREEPER:
// Disabling listener if flag disabled globally
if (!Flags.creeper.isGlobalyEnabled())
Expand All @@ -991,8 +985,8 @@ public void onEntityExplode(EntityExplodeEvent event) {
} else
preserve.add(block);
continue;
case PRIMED_TNT:
case MINECART_TNT:
case TNT:
case TNT_MINECART:
// Disabling listener if flag disabled globally
if (!Flags.tnt.isGlobalyEnabled())
continue;
Expand Down Expand Up @@ -1359,12 +1353,15 @@ public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
if (event.isCancelled())
return;

if (event.getEntityType() != EntityType.ENDER_CRYSTAL && !CMIEntity.isItemFrame(event.getEntity()) && !Utils.isArmorStandEntity(event.getEntityType()))
if (CMIEntityType.get(event.getEntityType()) != CMIEntityType.ENDER_CRYSTAL && !CMIEntity.isItemFrame(event.getEntity()) && !Utils.isArmorStandEntity(event.getEntityType()))
return;

Entity dmgr = event.getDamager();

Player player = null;

CMIEntityType type = CMIEntityType.get(event.getEntityType());

if (dmgr instanceof Player) {
player = (Player) event.getDamager();
} else if (dmgr instanceof Projectile && ((Projectile) dmgr).getShooter() instanceof Player) {
Expand All @@ -1375,7 +1372,7 @@ public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
if (perm.has(Flags.destroy, FlagCombo.OnlyFalse))
event.setCancelled(true);
return;
} else if (dmgr.getType() == EntityType.PRIMED_TNT || dmgr.getType() == EntityType.MINECART_TNT) {
} else if (type == CMIEntityType.TNT || type == CMIEntityType.TNT_MINECART) {

// Disabling listener if flag disabled globally
if (Flags.explode.isGlobalyEnabled()) {
Expand All @@ -1385,7 +1382,7 @@ public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
return;
}
}
} else if (dmgr.getType() == EntityType.WITHER_SKULL || dmgr.getType() == EntityType.WITHER) {
} else if (type == CMIEntityType.WITHER_SKULL || type == CMIEntityType.WITHER) {

// Disabling listener if flag disabled globally
if (Flags.witherdamage.isGlobalyEnabled()) {
Expand Down Expand Up @@ -1455,7 +1452,7 @@ public void onEntityShootBowEvent(EntityShootBowEvent event) {
if (!(event.getEntity() instanceof Player))
return;

if (event.getProjectile().getType() == EntityType.FIREWORK)
if (CMIEntityType.get(event.getProjectile()) == CMIEntityType.FIREWORK_ROCKET)
event.getProjectile().setMetadata(CrossbowShooter, new FixedMetadataValue(plugin, event.getEntity().getUniqueId()));
}

Expand Down
Loading

0 comments on commit a0641e6

Please sign in to comment.