From 5884e7b5b43f0f37efe9b9c1d75579501fcba236 Mon Sep 17 00:00:00 2001 From: RoboMWM Date: Wed, 1 Mar 2017 18:23:02 -0800 Subject: [PATCH] Strip to 1.8 compatibility (DeathSpectatingLite) No, I am not maintaining this branch, feel free to fork and maintain yourself though. --- pom.xml | 14 ++-- .../to/us/tf/DeathSpectating/CompatUtil.java | 44 ---------- .../us/tf/DeathSpectating/ConfigManager.java | 19 ----- .../tf/DeathSpectating/DeathSpectating.java | 16 +--- .../tf/DeathSpectating/features/Titles.java | 84 ------------------- .../listeners/DamageListener.java | 16 ---- 6 files changed, 8 insertions(+), 185 deletions(-) delete mode 100644 src/main/java/to/us/tf/DeathSpectating/CompatUtil.java delete mode 100644 src/main/java/to/us/tf/DeathSpectating/features/Titles.java diff --git a/pom.xml b/pom.xml index 860415c..c71f7f7 100644 --- a/pom.xml +++ b/pom.xml @@ -5,16 +5,16 @@ 4.0.0 to.us.tf - DeathSpectating - 1.1.3 + DeathSpectatingLite + 1.0 1.8 1.8 - paper-repo - https://repo.destroystokyo.com/repository/maven-public/ + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ @@ -31,9 +31,9 @@ - com.destroystokyo.paper - paper-api - 1.11.2-R0.1-SNAPSHOT + org.bukkit + bukkit + 1.8.8-R0.1-SNAPSHOT jar provided diff --git a/src/main/java/to/us/tf/DeathSpectating/CompatUtil.java b/src/main/java/to/us/tf/DeathSpectating/CompatUtil.java deleted file mode 100644 index d90d0ec..0000000 --- a/src/main/java/to/us/tf/DeathSpectating/CompatUtil.java +++ /dev/null @@ -1,44 +0,0 @@ -package to.us.tf.DeathSpectating; - -import org.bukkit.Bukkit; - -/** - * Created on 2/27/2017. - * - * @author RoboMWM - */ -public class CompatUtil -{ - private static Integer serverVersion = null; - private static int currentVersion = 11; - public static boolean isNewer() - { - return getVersion() > currentVersion; - } - - public static int getVersion() - { - if (serverVersion != null) - return serverVersion; - String version = Bukkit.getBukkitVersion(); - version = version.substring(2); - version = version.substring(0, version.indexOf(".")); - int versionNumber; - try - { - versionNumber = Integer.valueOf(version); - } - catch (Exception e) - { - Bukkit.getLogger().warning("[DeathSpectating] Was not able to determine bukkit version."); - return -1; - } - serverVersion = versionNumber; - return versionNumber; - } - - public static boolean isOlder(int version) - { - return getVersion() < version; - } -} diff --git a/src/main/java/to/us/tf/DeathSpectating/ConfigManager.java b/src/main/java/to/us/tf/DeathSpectating/ConfigManager.java index 1c1d9ee..0698f4c 100644 --- a/src/main/java/to/us/tf/DeathSpectating/ConfigManager.java +++ b/src/main/java/to/us/tf/DeathSpectating/ConfigManager.java @@ -7,7 +7,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; -import javax.annotation.Nonnull; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; @@ -98,24 +97,6 @@ public class ConfigManager if (messageSection.getString("deniedCommand") == null) messageSection.set("deniedCommand", "&cYou are not allowed to use that command while death spectating."); messages.put("deniedCommand", formatter(messageSection.getString("deniedCommand"))); - - //Title messages - ConfigurationSection titleSection = config.getConfigurationSection("titleMessages"); - if (titleSection == null) - titleSection = config.createSection("titleMessages"); - - if (titleSection.getStringList("titles").isEmpty()) - titleSection.set("titles", new ArrayList<>(Arrays.asList("&cYou died!", "&cGame over!"))); - if (titleSection.getStringList("subtitles").isEmpty()) - titleSection.set("subtitles", new ArrayList<>(Arrays.asList("Respawning in {0}", "Score: &e{1}", "Score: &e{1}&f, Respawning in {0}"))); - - instance.saveConfig(); - } - - public String getDeathTitle(@Nonnull String titleType) - { - List hi = config.getConfigurationSection("titleMessages").getStringList(titleType); - return hi.get(ThreadLocalRandom.current().nextInt(hi.size())); } public long getRespawnTicks() diff --git a/src/main/java/to/us/tf/DeathSpectating/DeathSpectating.java b/src/main/java/to/us/tf/DeathSpectating/DeathSpectating.java index f1c07c4..85063fc 100644 --- a/src/main/java/to/us/tf/DeathSpectating/DeathSpectating.java +++ b/src/main/java/to/us/tf/DeathSpectating/DeathSpectating.java @@ -1,14 +1,9 @@ package to.us.tf.DeathSpectating; -import org.bukkit.Effect; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.Particle; import org.bukkit.Statistic; -import org.bukkit.World; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Creature; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.ExperienceOrb; @@ -24,9 +19,7 @@ import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.potion.PotionEffect; -import org.bukkit.scheduler.BukkitRunnable; import to.us.tf.DeathSpectating.events.DeathSpectatingEvent; -import to.us.tf.DeathSpectating.features.Titles; import to.us.tf.DeathSpectating.listeners.DamageListener; import to.us.tf.DeathSpectating.listeners.MiscListeners; import to.us.tf.DeathSpectating.tasks.SpectateTask; @@ -49,8 +42,6 @@ public void onEnable() getServer().getPluginManager().registerEvents(this, this); getServer().getPluginManager().registerEvents(new DamageListener(this), this); getServer().getPluginManager().registerEvents(new MiscListeners(this), this); - if (!CompatUtil.isOlder(11)) //TODO: register in class, not in main(?) - getServer().getPluginManager().registerEvents(new Titles(this, configManager), this); } public ConfigManager getConfigManager() @@ -163,7 +154,7 @@ public boolean startDeathSpectating(Player player) //Compile a list of null-free/air-free items to drop for (ItemStack itemStack : player.getInventory().getContents()) { - if (itemStack != null && itemStack.getType() != Material.AIR && !itemStack.containsEnchantment(Enchantment.VANISHING_CURSE)) + if (itemStack != null && itemStack.getType() != Material.AIR) itemsToDrop.add(itemStack); } } @@ -212,11 +203,6 @@ public boolean startDeathSpectating(Player player) player.incrementStatistic(Statistic.DEATHS); player.setStatistic(Statistic.TIME_SINCE_DEATH, 0); - //TODO: Non-vanilla behavior: Player death animation (red and falling over) (Issue #13) - //Smoke effect //TODO: after 20 ticks (Issue #14) (Will implement 20 tick delay after issue #13 is resolved - if (isSpectating(player)) //TODO: does smoke effect/death animation occur if player#spigot()#respawn() is called on death? My guess is no. - player.getWorld().spawnParticle(Particle.CLOUD, player.getLocation(), 25); - //Clear potion effects for (PotionEffect potionEffect : player.getActivePotionEffects()) player.removePotionEffect(potionEffect.getType()); diff --git a/src/main/java/to/us/tf/DeathSpectating/features/Titles.java b/src/main/java/to/us/tf/DeathSpectating/features/Titles.java deleted file mode 100644 index d4dc9da..0000000 --- a/src/main/java/to/us/tf/DeathSpectating/features/Titles.java +++ /dev/null @@ -1,84 +0,0 @@ -package to.us.tf.DeathSpectating.features; - -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.scheduler.BukkitRunnable; -import to.us.tf.DeathSpectating.ConfigManager; -import to.us.tf.DeathSpectating.DeathSpectating; -import to.us.tf.DeathSpectating.events.DeathSpectatingEvent; -import to.us.tf.DeathSpectating.tasks.SpectateTask; - -import java.util.HashMap; -import java.util.Map; - -/** - * Decided to incorporate it straight into this plugin, since CB does have a basic title API - * Created on 2/26/2017. - * @author RoboMWM - */ -public class Titles implements Listener -{ - DeathSpectating instance; - - private Map scores = new HashMap<>(); - ConfigManager config; - - public Titles(DeathSpectating deathSpectating, ConfigManager config) - { - instance = deathSpectating; - this.config = config; - } - - @EventHandler(priority = EventPriority.LOWEST) - void onDeathStoreScore(PlayerDeathEvent event) - { - scores.put(event.getEntity(), event.getEntity().getTotalExperience()); - } - - @EventHandler(priority = EventPriority.HIGHEST) - void onQuitEvent(PlayerQuitEvent event) - { - //Cleanup just in case - scores.remove(event.getPlayer()); - } - - @EventHandler - void onSpectate(DeathSpectatingEvent event) - { - final String unformattedTitle = config.getDeathTitle("titles"); - final String unformattedSubTitle = config.getDeathTitle("subtitles"); - if (unformattedTitle.isEmpty() && unformattedSubTitle.isEmpty()) //Disabled - return; - new BukkitRunnable() - { - SpectateTask spectateTask = event.getSpectateTask(); - int score = scores.remove(spectateTask.getPlayer()); - - @Override - public void run() - { - if (spectateTask.getTicks() < 2 || !spectateTask.getPlayer().hasMetadata("DEAD")) - { - this.cancel(); - return; - } - int seconds = (int)spectateTask.getTicks() / 20; - String title = config.formatter(unformattedTitle, seconds, score); - String subTitle = config.formatter(unformattedSubTitle, seconds, score); - spectateTask.getPlayer().sendTitle(title, subTitle, 0, 20, 2); //Could use paper's more robust Title API - } - }.runTaskTimer(instance, 2L, 10L); - } - - @EventHandler - void onRespawn(PlayerRespawnEvent event) - { - event.getPlayer().sendTitle(" ", " ", 1, 1, 1); //resetTitle only seems to reset title, not both title and subtitle - event.getPlayer().resetTitle(); - } -} diff --git a/src/main/java/to/us/tf/DeathSpectating/listeners/DamageListener.java b/src/main/java/to/us/tf/DeathSpectating/listeners/DamageListener.java index 1215080..51a605b 100644 --- a/src/main/java/to/us/tf/DeathSpectating/listeners/DamageListener.java +++ b/src/main/java/to/us/tf/DeathSpectating/listeners/DamageListener.java @@ -1,15 +1,11 @@ package to.us.tf.DeathSpectating.listeners; -import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.PlayerInventory; -import to.us.tf.DeathSpectating.CompatUtil; import to.us.tf.DeathSpectating.DeathSpectating; /** @@ -40,18 +36,6 @@ void onPlayerBasicallyWouldBeDead(EntityDamageEvent event) if (player.getHealth() > event.getFinalDamage()) return; - //Ignore if player is holding a totem of undying - PlayerInventory inventory = player.getInventory(); - try - { - if (inventory.getItemInMainHand().getType() == Material.TOTEM || inventory.getItemInOffHand().getType() == Material.TOTEM) - return; - } - catch (NoSuchFieldError | NoSuchMethodError e) //TOTEM (not in 1.10 and below) //getItemInMainHand, etc. (not in 1.8 and below) - { - if (CompatUtil.isNewer()) throw e; - } - //Ignore if this is probably the result of the Essentials suicide command //Essentials will perform Player#setHealth(0), which does not fire a damage event, but does kill the player. This will lead to a double death message. if ((event.getCause() == EntityDamageEvent.DamageCause.CUSTOM || event.getCause() == EntityDamageEvent.DamageCause.SUICIDE)