|
| 1 | +/** |
| 2 | + * The MIT License |
| 3 | + * Copyright (c) 2015 Techcable |
| 4 | + * |
| 5 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | + * of this software and associated documentation files (the "Software"), to deal |
| 7 | + * in the Software without restriction, including without limitation the rights |
| 8 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | + * copies of the Software, and to permit persons to whom the Software is |
| 10 | + * furnished to do so, subject to the following conditions: |
| 11 | + * |
| 12 | + * The above copyright notice and this permission notice shall be included in |
| 13 | + * all copies or substantial portions of the Software. |
| 14 | + * |
| 15 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 21 | + * THE SOFTWARE. |
| 22 | + */ |
| 23 | +package net.techcable.spawnshield.combattag.heroes; |
| 24 | + |
| 25 | +import lombok.*; |
| 26 | + |
| 27 | +import com.herocraftonline.heroes.Heroes; |
| 28 | +import com.herocraftonline.heroes.characters.effects.CombatEffect; |
| 29 | + |
| 30 | +import net.techcable.spawnshield.combattag.CombatTagPlugin; |
| 31 | + |
| 32 | +import org.bukkit.Bukkit; |
| 33 | +import org.bukkit.entity.Entity; |
| 34 | +import org.bukkit.entity.Player; |
| 35 | +import org.bukkit.plugin.Plugin; |
| 36 | + |
| 37 | +public class HeroesSupport implements CombatTagPlugin { |
| 38 | + public static final String PLUGIN_NAME = "Heroes"; |
| 39 | + @Getter |
| 40 | + private final Heroes plugin; |
| 41 | + |
| 42 | + public HeroesSupport() { |
| 43 | + Plugin rawPlugin = Bukkit.getPluginManager().getPlugin(PLUGIN_NAME); |
| 44 | + this.plugin = rawPlugin instanceof Heroes ? (Heroes) rawPlugin : null; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public boolean isTagged(Player player) { |
| 49 | + assertInstalled(); |
| 50 | + return plugin.getCharacterManager().getHero(player).isInCombat(); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public long getRemainingTagTime(Player player) { |
| 55 | + assertInstalled(); |
| 56 | + long time = plugin.getCharacterManager().getHero(player).getCombatEffect().getTimeLeft(); |
| 57 | + if (time <= 0) return -1; |
| 58 | + return time; |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public boolean isNPC(Entity entity) { |
| 63 | + assertInstalled(); |
| 64 | + return false; |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public void tag(Player player) { |
| 69 | + assertInstalled(); |
| 70 | + throw new UnsupportedOperationException(); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public void unTag(Player player) { |
| 75 | + assertInstalled(); |
| 76 | + plugin.getCharacterManager().getHero(player).leaveCombat(CombatEffect.LeaveCombatReason.CUSTOM); |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + public boolean isInstalled() { |
| 81 | + return plugin != null; |
| 82 | + } |
| 83 | + |
| 84 | + private void assertInstalled() { |
| 85 | + if (!isInstalled()) throw new UnsupportedOperationException("Not installed"); |
| 86 | + } |
| 87 | +} |
0 commit comments