fix 1.9 support

This commit is contained in:
Gerrygames 2018-02-27 11:07:14 +01:00
parent edf96fdbec
commit b1cef12f46
2 changed files with 40 additions and 21 deletions

View File

@ -11,6 +11,7 @@ import de.gerrygames.viarewind.legacysupport.versioninfo.VersionInformer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
public class BukkitPlugin extends JavaPlugin { public class BukkitPlugin extends JavaPlugin {
@ -23,23 +24,28 @@ public class BukkitPlugin extends JavaPlugin {
getConfig().options().copyDefaults(true); getConfig().options().copyDefaults(true);
saveConfig(); saveConfig();
final FileConfiguration config = getConfig(); final FileConfiguration config = getConfig();
Bukkit.getScheduler().runTask(this, () -> { new BukkitRunnable() {
if (ProtocolRegistry.SERVER_PROTOCOL>5 && config.getBoolean("enchanting-gui-fix")) @Override
Bukkit.getPluginManager().registerEvents(new EnchantingListener(), this); public void run() {
if (ProtocolRegistry.SERVER_PROTOCOL>78 && config.getBoolean("brewing-stand-gui-fix")) if (ProtocolRegistry.SERVER_PROTOCOL==-1) return;
Bukkit.getPluginManager().registerEvents(new BrewingListener(), this); cancel();
if (ProtocolRegistry.SERVER_PROTOCOL>84 && config.getBoolean("lily-pad-fix")) if (ProtocolRegistry.SERVER_PROTOCOL>5 && config.getBoolean("enchanting-gui-fix"))
LilyPadFixer.fix(); Bukkit.getPluginManager().registerEvents(new EnchantingListener(), BukkitPlugin.this);
if (ProtocolRegistry.SERVER_PROTOCOL>47 && config.getBoolean("sound-fix")) if (ProtocolRegistry.SERVER_PROTOCOL>78 && config.getBoolean("brewing-stand-gui-fix"))
Bukkit.getPluginManager().registerEvents(new SoundListener(), this); Bukkit.getPluginManager().registerEvents(new BrewingListener(), BukkitPlugin.this);
if (ProtocolRegistry.SERVER_PROTOCOL>5 && config.getBoolean("slime-fix")) if (ProtocolRegistry.SERVER_PROTOCOL>84 && config.getBoolean("lily-pad-fix"))
Bukkit.getPluginManager().registerEvents(new BounceListener(), this); LilyPadFixer.fix();
if (ProtocolRegistry.SERVER_PROTOCOL>76 && config.getBoolean("elytra-fix")) if (ProtocolRegistry.SERVER_PROTOCOL>47 && config.getBoolean("sound-fix"))
Bukkit.getPluginManager().registerEvents(new ElytraListener(), this); Bukkit.getPluginManager().registerEvents(new SoundListener(), BukkitPlugin.this);
if (ProtocolRegistry.SERVER_PROTOCOL>54 && config.getBoolean("area-effect-cloud-particles")) if (ProtocolRegistry.SERVER_PROTOCOL>5 && config.getBoolean("slime-fix"))
Bukkit.getPluginManager().registerEvents(new AreaEffectCloudListener(), this); Bukkit.getPluginManager().registerEvents(new BounceListener(), BukkitPlugin.this);
if (config.getBoolean("versioninfo.active")) new VersionInformer(); if (ProtocolRegistry.SERVER_PROTOCOL>76 && config.getBoolean("elytra-fix"))
}); Bukkit.getPluginManager().registerEvents(new ElytraListener(), BukkitPlugin.this);
if (ProtocolRegistry.SERVER_PROTOCOL>54 && config.getBoolean("area-effect-cloud-particles"))
Bukkit.getPluginManager().registerEvents(new AreaEffectCloudListener(), BukkitPlugin.this);
if (config.getBoolean("versioninfo.active")) new VersionInformer();
}
}.runTaskTimer(this, 1L, 1L);
} }
public static BukkitPlugin getInstance() { public static BukkitPlugin getInstance() {

View File

@ -21,6 +21,13 @@ import us.myles.ViaVersion.api.Via;
import java.lang.reflect.Method; import java.lang.reflect.Method;
public class SoundListener implements Listener { public class SoundListener implements Listener {
private static boolean isSoundCategory = false;
static {
try {
Class.forName("org.bukkit.SoundCategory");
isSoundCategory = true;
} catch (ClassNotFoundException ignored) {}
}
public SoundListener() { public SoundListener() {
try { try {
@ -58,22 +65,28 @@ public class SoundListener implements Listener {
float volume = 0.2f; float volume = 0.2f;
float pitch = (float) ((Math.random() - Math.random()) * 0.7f + 1.0f) * 2.0f; float pitch = (float) ((Math.random() - Math.random()) * 0.7f + 1.0f) * 2.0f;
Location loc = player.getLocation(); Location loc = player.getLocation();
playSound(loc, Sound.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, volume, pitch, 16, 47); playSound(loc, Sound.ENTITY_ITEM_PICKUP, "PLAYERS", volume, pitch, 16, 47);
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
private void onExperienceOrbPickup(PlayerExpChangeEvent e) { private void onExperienceOrbPickup(PlayerExpChangeEvent e) {
float volume = 0.1f; float volume = 0.1f;
float pitch = (float) (0.5f * ((Math.random() - Math.random()) * 0.7f + 1.8f)); float pitch = (float) (0.5f * ((Math.random() - Math.random()) * 0.7f + 1.8f));
playSound(e.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, volume, pitch, 16, 47); playSound(e.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, "PLAYERS", volume, pitch, 16, 47);
} }
private static void playSound(Location loc, Sound sound, SoundCategory category, float volume, float pitch, double dist, int version) { private static void playSound(Location loc, Sound sound, String category, float volume, float pitch, double dist, int version) {
Bukkit.getOnlinePlayers().stream() Bukkit.getOnlinePlayers().stream()
.filter(p -> p.getWorld()==loc.getWorld()) .filter(p -> p.getWorld()==loc.getWorld())
.filter(p -> p.getLocation().distanceSquared(loc) < dist * dist) .filter(p -> p.getLocation().distanceSquared(loc) < dist * dist)
.filter(p -> Via.getAPI().getPlayerVersion(p) <= version) .filter(p -> Via.getAPI().getPlayerVersion(p) <= version)
.forEach(p -> p.playSound(loc, sound, category, volume, pitch)); .forEach(p -> {
if (isSoundCategory) {
p.playSound(loc, sound, SoundCategory.valueOf(category), volume, pitch);
} else {
p.playSound(loc, sound, volume, pitch);
}
});
} }
private static void playBlockPlaceSound(Player player, Block block) { private static void playBlockPlaceSound(Player player, Block block) {