Skip to content

Commit

Permalink
Fix some 1.8 things
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Sep 26, 2016
1 parent 844b060 commit 28fc595
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 58 deletions.
Expand Up @@ -95,6 +95,8 @@ public static JavaPlugin getJavaPlugin() {

public abstract ItemHelper getItemHelper();

public abstract SoundHelper getSoundHelper();

public abstract PacketHelper getPacketHelper();

public abstract ParticleHelper getParticleHelper();
Expand Down
@@ -0,0 +1,35 @@
package net.aufdemrand.denizen.nms.interfaces;

import org.bukkit.Sound;

public interface SoundHelper {

// provided by github.com/sk89q/craftbook
int[] instruments = {
0, 0, 0, 0, 0, 0, 0, 5, // 8
6, 0, 0, 0, 0, 0, 0, 0, // 16
0, 0, 0, 0, 0, 0, 0, 5, // 24
5, 5, 5, 5, 5, 5, 5, 5, // 32
6, 6, 6, 6, 6, 6, 6, 6, // 40
5, 5, 5, 5, 5, 5, 5, 2, // 48
5, 5, 5, 5, 0, 0, 0, 0, // 56
0, 0, 0, 0, 0, 0, 0, 0, // 64
0, 0, 0, 0, 0, 0, 0, 0, // 72
0, 0, 0, 0, 0, 0, 0, 0, // 80
0, 0, 0, 0, 0, 0, 0, 0, // 88
0, 0, 0, 0, 0, 0, 0, 0, // 96
0, 0, 0, 0, 0, 0, 0, 0, // 104
0, 0, 0, 0, 0, 0, 0, 0, // 112
1, 1, 1, 3, 1, 1, 1, 5, // 120
1, 1, 1, 1, 1, 2, 4, 3, // 128
};


Sound getMidiInstrumentFromPatch(int patch);

Sound getDefaultMidiInstrument();

Sound getChestOpen();

Sound getChestClose();
}
14 changes: 8 additions & 6 deletions plugin/src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -692,17 +692,17 @@ public void onEnable() {
ScriptEvent.registerScriptEvent(new PlayerQuitsScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerReceivesMessageScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerRespawnsScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerRightClicksAtEntityScriptEvent());
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2)) {
ScriptEvent.registerScriptEvent(new PlayerRightClicksAtEntityScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerSwapsItemsScriptEvent());
}
ScriptEvent.registerScriptEvent(new PlayerRightClicksEntityScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerShearsScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerSneakScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerSprintScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerStatisticIncrementsScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerSteersEntityScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerStepsOnScriptEvent());
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2)) {
ScriptEvent.registerScriptEvent(new PlayerSwapsItemsScriptEvent());
}
ScriptEvent.registerScriptEvent(new PlayerTakesFromFurnaceScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerThrowsEggScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerUsesPortalScriptEvent());
Expand Down Expand Up @@ -785,6 +785,7 @@ public void onEnable() {
propertyParser.registerProperty(EntityAngry.class, dEntity.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2)) {
propertyParser.registerProperty(EntityArmorBonus.class, dEntity.class);
propertyParser.registerProperty(EntityInvulnerable.class, dEntity.class);
propertyParser.registerProperty(EntityBoatType.class, dEntity.class);
}
propertyParser.registerProperty(EntityArmorPose.class, dEntity.class);
Expand All @@ -803,7 +804,6 @@ public void onEnable() {
propertyParser.registerProperty(EntityHealth.class, dEntity.class);
propertyParser.registerProperty(EntityInfected.class, dEntity.class);
propertyParser.registerProperty(EntityInventory.class, dEntity.class);
propertyParser.registerProperty(EntityInvulnerable.class, dEntity.class);
propertyParser.registerProperty(EntityItem.class, dEntity.class);
propertyParser.registerProperty(EntityJumpStrength.class, dEntity.class);
propertyParser.registerProperty(EntityKnockback.class, dEntity.class);
Expand Down Expand Up @@ -843,7 +843,9 @@ public void onEnable() {
propertyParser.registerProperty(ItemNBT.class, dItem.class);
propertyParser.registerProperty(ItemPatterns.class, dItem.class);
propertyParser.registerProperty(ItemPlantgrowth.class, dItem.class);
propertyParser.registerProperty(ItemPotion.class, dItem.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2)) {
propertyParser.registerProperty(ItemPotion.class, dItem.class);
}
propertyParser.registerProperty(ItemQuantity.class, dItem.class);
propertyParser.registerProperty(ItemSkullskin.class, dItem.class);
propertyParser.registerProperty(ItemSpawnEgg.class, dItem.class);
Expand Down
@@ -1,5 +1,7 @@
package net.aufdemrand.denizen.events.core;

import net.aufdemrand.denizen.nms.NMSHandler;
import net.aufdemrand.denizen.nms.NMSVersion;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizen.objects.dMaterial;
Expand Down Expand Up @@ -273,7 +275,7 @@ private boolean isArmor(ItemStack itemStack) {
private boolean isArmor(Material material) {
int id = material.getId();
return id >= 298 && id <= 317
|| material == Material.ELYTRA
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2) && material == Material.ELYTRA)
|| material == Material.PUMPKIN
|| material == Material.JACK_O_LANTERN
|| material == Material.SKULL_ITEM;
Expand All @@ -289,7 +291,7 @@ private boolean didPlayerClickOwnInventory(Player player, Inventory inventory) {
}

private int getArmorTypeNumber(ItemStack itemStack) {
if (itemStack.getType() == Material.ELYTRA) {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2) && itemStack.getType() == Material.ELYTRA) {
return 1;
}
return (itemStack.getTypeId() - 298) % 4;
Expand Down
Expand Up @@ -2,6 +2,7 @@

import net.aufdemrand.denizen.flags.FlagManager;
import net.aufdemrand.denizen.nms.NMSHandler;
import net.aufdemrand.denizen.nms.NMSVersion;
import net.aufdemrand.denizen.nms.abstracts.ImprovedOfflinePlayer;
import net.aufdemrand.denizen.nms.abstracts.Sidebar;
import net.aufdemrand.denizen.objects.properties.entity.EntityHealth;
Expand Down Expand Up @@ -2798,7 +2799,7 @@ else if (split.length > 1) {
// The book can safely be removed from the player's offhand
// without the player closing the book.
// -->
if (mechanism.matches("open_offhand_book")) {
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2) && mechanism.matches("open_offhand_book")) {
NMSHandler.getInstance().getPacketHelper().openBook(getPlayerEntity(), EquipmentSlot.OFF_HAND);
}

Expand Down
@@ -1,5 +1,7 @@
package net.aufdemrand.denizen.objects.properties.entity;

import net.aufdemrand.denizen.nms.NMSHandler;
import net.aufdemrand.denizen.nms.NMSVersion;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Mechanism;
Expand All @@ -19,7 +21,7 @@ public static boolean describes(dObject entity) {
return false;
}
return ((dEntity) entity).getBukkitEntityType() == EntityType.VILLAGER
|| ((dEntity) entity).getBukkitEntityType() == EntityType.ZOMBIE;
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_9_R2) && ((dEntity) entity).getBukkitEntityType() == EntityType.ZOMBIE);
}

public static EntityProfession getFrom(dObject entity) {
Expand Down
Expand Up @@ -13,7 +13,6 @@
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand;
import org.bukkit.Sound;
import org.bukkit.entity.Player;

import java.util.Arrays;
Expand Down Expand Up @@ -97,7 +96,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
for (dPlayer player : players) {
Player ent = player.getPlayerEntity();
if (sound.asBoolean()) {
ent.playSound(location, Sound.BLOCK_CHEST_OPEN, 1, 1);
ent.playSound(location, NMSHandler.getInstance().getSoundHelper().getChestOpen(), 1, 1);
}
packetHelper.showBlockAction(ent, location, 1, 1);
}
Expand All @@ -107,7 +106,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
for (dPlayer player : players) {
Player ent = player.getPlayerEntity();
if (sound.asBoolean()) {
ent.playSound(location, Sound.BLOCK_CHEST_CLOSE, 1, 1);
ent.playSound(location, NMSHandler.getInstance().getSoundHelper().getChestClose(), 1, 1);
}
packetHelper.showBlockAction(ent, location, 1, 0);
}
Expand Down
Expand Up @@ -3,9 +3,12 @@
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.utilities.debugging.dB;
import org.bukkit.Sound;

import javax.sound.midi.*;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Receiver;
import javax.sound.midi.Sequencer;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
Expand Down Expand Up @@ -83,46 +86,5 @@ public static void stopMidi(List<dEntity> entities) {
stopMidi(entity.getUUID().toString());
}
}

// provided by github.com/sk89q/craftbook
private static final int[] instruments = {
0, 0, 0, 0, 0, 0, 0, 5, // 8
6, 0, 0, 0, 0, 0, 0, 0, // 16
0, 0, 0, 0, 0, 0, 0, 5, // 24
5, 5, 5, 5, 5, 5, 5, 5, // 32
6, 6, 6, 6, 6, 6, 6, 6, // 40
5, 5, 5, 5, 5, 5, 5, 2, // 48
5, 5, 5, 5, 0, 0, 0, 0, // 56
0, 0, 0, 0, 0, 0, 0, 0, // 64
0, 0, 0, 0, 0, 0, 0, 0, // 72
0, 0, 0, 0, 0, 0, 0, 0, // 80
0, 0, 0, 0, 0, 0, 0, 0, // 88
0, 0, 0, 0, 0, 0, 0, 0, // 96
0, 0, 0, 0, 0, 0, 0, 0, // 104
0, 0, 0, 0, 0, 0, 0, 0, // 112
1, 1, 1, 3, 1, 1, 1, 5, // 120
1, 1, 1, 1, 1, 2, 4, 3, // 128
};

public static Sound patchToInstrument(int patch) {
// look up the instrument matching the patch
switch (instruments[patch]) {
case 1:
return Sound.BLOCK_NOTE_BASS;
case 2:
return Sound.BLOCK_NOTE_SNARE;
case 3:
return Sound.BLOCK_NOTE_HARP;
case 4:
return Sound.BLOCK_NOTE_HAT;
case 5:
return Sound.BLOCK_NOTE_PLING;
case 6:
return Sound.BLOCK_NOTE_BASEDRUM;
}

// if no instrument match is found, use piano
return Sound.BLOCK_NOTE_HAT;
}
}

@@ -1,6 +1,8 @@
package net.aufdemrand.denizen.utilities.midi;

import com.google.common.collect.Maps;
import net.aufdemrand.denizen.nms.NMSHandler;
import net.aufdemrand.denizen.nms.interfaces.SoundHelper;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizencore.utilities.debugging.dB;
Expand Down Expand Up @@ -94,9 +96,10 @@ public void playNote(ShortMessage message) {
float pitch = (float) ToneUtil.midiToPitch(message);
float volume = VOLUME_RANGE * (message.getData2() / 127.0f);

Sound instrument = Sound.BLOCK_NOTE_HAT;
SoundHelper soundHelper = NMSHandler.getInstance().getSoundHelper();
Sound instrument = soundHelper.getDefaultMidiInstrument();
if (patch != null) {
instrument = MidiUtil.patchToInstrument(patch);
instrument = soundHelper.getMidiInstrumentFromPatch(patch);
}

if (location != null) {
Expand Down
Expand Up @@ -42,6 +42,7 @@ public class Handler_v1_10_R1 extends NMSHandler {
private final EntityHelper entityHelper = new EntityHelper_v1_10_R1();
private final FishingHelper fishingHelper = new FishingHelper_v1_10_R1();
private final ItemHelper itemHelper = new ItemHelper_v1_10_R1();
private final SoundHelper soundHelper = new SoundHelper_v1_10_R1();
private final PacketHelper packetHelper = new PacketHelper_v1_10_R1();
private final ParticleHelper particleHelper = new ParticleHelper_v1_10_R1();
private final PlayerHelper playerHelper = new PlayerHelper_v1_10_R1();
Expand Down Expand Up @@ -94,6 +95,11 @@ public ItemHelper getItemHelper() {
return itemHelper;
}

@Override
public SoundHelper getSoundHelper() {
return soundHelper;
}

@Override
public PacketHelper getPacketHelper() {
return packetHelper;
Expand Down
@@ -0,0 +1,42 @@
package net.aufdemrand.denizen.nms.helpers;

import net.aufdemrand.denizen.nms.interfaces.SoundHelper;
import org.bukkit.Sound;

public class SoundHelper_v1_10_R1 implements SoundHelper {

@Override
public Sound getMidiInstrumentFromPatch(int patch) {
// look up the instrument matching the patch
switch (instruments[patch]) {
case 1:
return Sound.BLOCK_NOTE_BASS;
case 2:
return Sound.BLOCK_NOTE_SNARE;
case 3:
return Sound.BLOCK_NOTE_HARP;
case 4:
return Sound.BLOCK_NOTE_HAT;
case 5:
return Sound.BLOCK_NOTE_PLING;
case 6:
return Sound.BLOCK_NOTE_BASEDRUM;
}
return getDefaultMidiInstrument();
}

@Override
public Sound getDefaultMidiInstrument() {
return Sound.BLOCK_NOTE_HAT;
}

@Override
public Sound getChestOpen() {
return Sound.BLOCK_CHEST_OPEN;
}

@Override
public Sound getChestClose() {
return Sound.BLOCK_CHEST_CLOSE;
}
}
Expand Up @@ -40,6 +40,7 @@ public class Handler_v1_8_R3 extends NMSHandler {
private final EntityHelper entityHelper = new EntityHelper_v1_8_R3();
private final FishingHelper fishingHelper = new FishingHelper_v1_8_R3();
private final ItemHelper itemHelper = new ItemHelper_v1_8_R3();
private final SoundHelper soundHelper = new SoundHelper_v1_8_R3();
private final PacketHelper packetHelper = new PacketHelper_v1_8_R3();
private final ParticleHelper particleHelper = new ParticleHelper_v1_8_R3();
private final PlayerHelper playerHelper = new PlayerHelper_v1_8_R3();
Expand Down Expand Up @@ -92,6 +93,11 @@ public ItemHelper getItemHelper() {
return itemHelper;
}

@Override
public SoundHelper getSoundHelper() {
return soundHelper;
}

@Override
public PacketHelper getPacketHelper() {
return packetHelper;
Expand Down
@@ -0,0 +1,42 @@
package net.aufdemrand.denizen.nms.helpers;

import net.aufdemrand.denizen.nms.interfaces.SoundHelper;
import org.bukkit.Sound;

public class SoundHelper_v1_8_R3 implements SoundHelper {

@Override
public Sound getMidiInstrumentFromPatch(int patch) {
// look up the instrument matching the patch
switch (instruments[patch]) {
case 1:
return Sound.NOTE_BASS_GUITAR;
case 2:
return Sound.NOTE_SNARE_DRUM;
case 3:
return Sound.NOTE_STICKS;
case 4:
return Sound.NOTE_BASS_DRUM;
case 5:
return Sound.NOTE_PLING;
case 6:
return Sound.NOTE_BASS;
}
return getDefaultMidiInstrument();
}

@Override
public Sound getDefaultMidiInstrument() {
return Sound.NOTE_PIANO;
}

@Override
public Sound getChestOpen() {
return Sound.CHEST_OPEN;
}

@Override
public Sound getChestClose() {
return Sound.CHEST_CLOSE;
}
}

0 comments on commit 28fc595

Please sign in to comment.