Fixed some code smells

This commit is contained in:
Florian CUNY 2018-08-15 11:01:07 +02:00
parent 7815c837dd
commit 6358f72986
8 changed files with 32 additions and 37 deletions

View File

@ -319,7 +319,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
for (Field field : dataObject.getDeclaredFields()) { for (Field field : dataObject.getDeclaredFields()) {
// Get the property descriptor for this field // Get the property descriptor for this field
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), dataObject); PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), dataObject);
// Get the read method, i.e., getXXXX(); // Get the read method
Method method = propertyDescriptor.getReadMethod(); Method method = propertyDescriptor.getReadMethod();
// Invoke the read method to get the value. We have no idea what type of value it is. // Invoke the read method to get the value. We have no idea what type of value it is.
Object value = method.invoke(instance); Object value = method.invoke(instance);

View File

@ -33,7 +33,7 @@ public class GeoLimitMobsListener extends AbstractFlagListener {
* Start the tracker when the plugin is loaded * Start the tracker when the plugin is loaded
*/ */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void pluginReady(BentoBoxReadyEvent event) { public void onPluginReady(BentoBoxReadyEvent event) {
// Kick off the task to remove entities that go outside island boundaries // Kick off the task to remove entities that go outside island boundaries
Bukkit.getScheduler().runTaskTimer(getPlugin(), () -> { Bukkit.getScheduler().runTaskTimer(getPlugin(), () -> {
mobSpawnTracker.entrySet().stream() mobSpawnTracker.entrySet().stream()
@ -49,7 +49,7 @@ public class GeoLimitMobsListener extends AbstractFlagListener {
* @param e - event * @param e - event
*/ */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void mobSpawn(CreatureSpawnEvent e) { public void onMobSpawn(CreatureSpawnEvent e) {
if (getIWM().inWorld(e.getLocation()) if (getIWM().inWorld(e.getLocation())
&& getIWM().getGeoLimitSettings(e.getLocation().getWorld()).contains(e.getEntityType().name())) { && getIWM().getGeoLimitSettings(e.getLocation().getWorld()).contains(e.getEntityType().name())) {
getIslands().getIslandAt(e.getLocation()).ifPresent(i -> mobSpawnTracker.put(e.getEntity(), i)); getIslands().getIslandAt(e.getLocation()).ifPresent(i -> mobSpawnTracker.put(e.getEntity(), i));
@ -60,7 +60,7 @@ public class GeoLimitMobsListener extends AbstractFlagListener {
* Clean up the map when entity dies (does not handle entity removal) * Clean up the map when entity dies (does not handle entity removal)
*/ */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void MobDeath(final EntityDeathEvent e) { public void onMobDeath(final EntityDeathEvent e) {
mobSpawnTracker.remove(e.getEntity()); mobSpawnTracker.remove(e.getEntity());
} }
@ -69,7 +69,7 @@ public class GeoLimitMobsListener extends AbstractFlagListener {
* @param e - event * @param e - event
*/ */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void ProjectileExplode(final ExplosionPrimeEvent e) { public void onProjectileExplode(final ExplosionPrimeEvent e) {
if (e.getEntity() instanceof Projectile && getIWM().inWorld(e.getEntity().getLocation())) { if (e.getEntity() instanceof Projectile && getIWM().inWorld(e.getEntity().getLocation())) {
ProjectileSource source = ((Projectile)e.getEntity()).getShooter(); ProjectileSource source = ((Projectile)e.getEntity()).getShooter();
if (source instanceof Entity) { if (source instanceof Entity) {

View File

@ -71,11 +71,9 @@ public class HurtingListener extends AbstractFlagListener {
} else if (damager instanceof Projectile) { } else if (damager instanceof Projectile) {
// Find out who fired the projectile // Find out who fired the projectile
Projectile p = (Projectile) damager; Projectile p = (Projectile) damager;
if (p.getShooter() instanceof Player) { if (p.getShooter() instanceof Player && !setUser(User.getInstance((Player)p.getShooter())).checkIsland(e, damager.getLocation(), flag)) {
if (!setUser(User.getInstance((Player)p.getShooter())).checkIsland(e, damager.getLocation(), flag)) { e.getEntity().setFireTicks(0);
e.getEntity().setFireTicks(0); damager.remove();
damager.remove();
}
} }
} }
} }
@ -103,11 +101,10 @@ public class HurtingListener extends AbstractFlagListener {
*/ */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerFeedParrots(PlayerInteractEntityEvent e) { public void onPlayerFeedParrots(PlayerInteractEntityEvent e) {
if (e.getRightClicked() instanceof Parrot) { if (e.getRightClicked() instanceof Parrot
if ((e.getHand().equals(EquipmentSlot.HAND) && e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.COOKIE)) && (e.getHand().equals(EquipmentSlot.HAND) && e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.COOKIE))
|| (e.getHand().equals(EquipmentSlot.OFF_HAND) && e.getPlayer().getInventory().getItemInOffHand().getType().equals(Material.COOKIE))) { || (e.getHand().equals(EquipmentSlot.OFF_HAND) && e.getPlayer().getInventory().getItemInOffHand().getType().equals(Material.COOKIE))) {
checkIsland(e, e.getRightClicked().getLocation(), Flags.HURT_ANIMALS); checkIsland(e, e.getRightClicked().getLocation(), Flags.HURT_ANIMALS);
}
} }
} }
@ -128,20 +125,18 @@ public class HurtingListener extends AbstractFlagListener {
continue; continue;
} }
// Monsters being hurt // Monsters being hurt
if (entity instanceof Monster || entity instanceof Slime || entity instanceof Squid) { if ((entity instanceof Monster || entity instanceof Slime || entity instanceof Squid)
if (!setUser(User.getInstance(attacker)).checkIsland(e, entity.getLocation(), Flags.HURT_MONSTERS)) { && !setUser(User.getInstance(attacker)).checkIsland(e, entity.getLocation(), Flags.HURT_MONSTERS)) {
for (PotionEffect effect : e.getPotion().getEffects()) { for (PotionEffect effect : e.getPotion().getEffects()) {
entity.removePotionEffect(effect.getType()); entity.removePotionEffect(effect.getType());
}
} }
} }
// Mobs being hurt // Mobs being hurt
if (entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman) { if ((entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman)
if (!checkIsland(e, entity.getLocation(), Flags.HURT_ANIMALS)) { && !checkIsland(e, entity.getLocation(), Flags.HURT_ANIMALS)) {
for (PotionEffect effect : e.getPotion().getEffects()) { for (PotionEffect effect : e.getPotion().getEffects()) {
entity.removePotionEffect(effect.getType()); entity.removePotionEffect(effect.getType());
}
} }
} }
@ -172,7 +167,7 @@ public class HurtingListener extends AbstractFlagListener {
} }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onLingeringPotionDamage(final EntityDamageByEntityEvent e) { //FIXME No need of #setCancelled() there? public void onLingeringPotionDamage(final EntityDamageByEntityEvent e) {
if (e.getEntity() == null || e.getEntity().getUniqueId() == null) { if (e.getEntity() == null || e.getEntity().getUniqueId() == null) {
return; return;
} }

View File

@ -16,21 +16,20 @@ import world.bentobox.bentobox.lists.Flags;
public class ItemDropPickUpListener extends AbstractFlagListener { public class ItemDropPickUpListener extends AbstractFlagListener {
/* /*
* Handle item drop by visitors * Handle item drop
*/ */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVisitorDrop(PlayerDropItemEvent e) { public void onDrop(PlayerDropItemEvent e) {
checkIsland(e, e.getItemDrop().getLocation(), Flags.ITEM_DROP); checkIsland(e, e.getItemDrop().getLocation(), Flags.ITEM_DROP);
} }
/* /*
* Handle item pickup by visitors * Handle item pickup
*/ */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVisitorPickup(EntityPickupItemEvent e) { public void onPickup(EntityPickupItemEvent e) {
if (e.getEntity() instanceof Player) { if (e.getEntity() instanceof Player) {
// Disallow, but don't tell the player an error setUser(User.getInstance(e.getEntity())).checkIsland(e, e.getItem().getLocation(), Flags.ITEM_PICKUP);
setUser(User.getInstance(e.getEntity())).checkIsland(e, e.getItem().getLocation(), Flags.ITEM_PICKUP, false);
} }
} }
} }

View File

@ -22,6 +22,7 @@ import world.bentobox.bentobox.lists.Flags;
* *
*/ */
public class ItemFrameListener extends AbstractFlagListener { public class ItemFrameListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onItemFrameDamage(final EntityDamageByEntityEvent e) { public void onItemFrameDamage(final EntityDamageByEntityEvent e) {
check(e, e.getEntity(), e.getDamager()); check(e, e.getEntity(), e.getDamager());

View File

@ -22,18 +22,17 @@ public class LeashListener extends AbstractFlagListener {
* @param e - event * @param e - event
*/ */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onLeashUse(PlayerLeashEntityEvent e) { public void onLeash(PlayerLeashEntityEvent e) {
checkIsland(e, e.getEntity().getLocation(), Flags.LEASH); checkIsland(e, e.getEntity().getLocation(), Flags.LEASH);
} }
/** /**
* Prevents unleashing * Prevents unleashing
* *
* @param e - event * @param e - event
*/ */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onLeashUse(PlayerUnleashEntityEvent e) { public void onUnleash(PlayerUnleashEntityEvent e) {
checkIsland(e, e.getEntity().getLocation(), Flags.LEASH); checkIsland(e, e.getEntity().getLocation(), Flags.LEASH);
} }

View File

@ -11,6 +11,7 @@ import world.bentobox.bentobox.api.flags.AbstractFlagListener;
import world.bentobox.bentobox.lists.Flags; import world.bentobox.bentobox.lists.Flags;
public class OfflineRedstoneListener extends AbstractFlagListener { public class OfflineRedstoneListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockRedstone(BlockRedstoneEvent e) { public void onBlockRedstone(BlockRedstoneEvent e) {
// If offline redstone is allowed then return // If offline redstone is allowed then return

View File

@ -53,11 +53,11 @@ public class PhysicalInteractionListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onProjectileHit(EntityInteractEvent e) { public void onProjectileHit(EntityInteractEvent e) {
if (e.getEntity() == null || !(e.getEntity() instanceof Projectile)) { if (!(e.getEntity() instanceof Projectile)) {
return; return;
} }
Projectile p = (Projectile)e.getEntity(); Projectile p = (Projectile)e.getEntity();
if (p.getShooter() != null && p.getShooter() instanceof Player && e.getBlock() != null) { if (p.getShooter() instanceof Player && e.getBlock() != null) {
// Set the user to the shooter // Set the user to the shooter
setUser(User.getInstance((Player)p.getShooter())); setUser(User.getInstance((Player)p.getShooter()));