From df843c95efad5a701bbea2d912f6eec8ffd3111a Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 20 Jun 2016 16:03:16 +0200 Subject: [PATCH] Holographic Displays integration; resolves #4 --- pom.xml | 5 ++ .../dungeonsxl/sign/DSignTypeDefault.java | 1 + .../dre2n/dungeonsxl/sign/HologramSign.java | 88 +++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java diff --git a/pom.xml b/pom.xml index 63de8ed6..87a0c76f 100644 --- a/pom.xml +++ b/pom.xml @@ -105,6 +105,11 @@ 2.0.18-SNAPSHOT provided + + com.gmail.filoghost + holographicdisplaysapi + 2.1.7 + diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java index be1cbbea..b5f2b33d 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java @@ -33,6 +33,7 @@ public enum DSignTypeDefault implements DSignType { END("End", "end", false, EndSign.class), EXTERNAL_MOB("ExternalMob", "mob", false, ExternalMobSign.class), FLOOR("Floor", "floor", false, FloorSign.class), + HOLOGRAM("Hologram", "hologram", true, HologramSign.class), INTERACT("Interact", "interact", true, InteractSign.class), LEAVE("Leave", "leave", true, LeaveSign.class), LIVES_MODIFIER("Lives", "lives", false, LivesModifierSign.class), diff --git a/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java b/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java new file mode 100644 index 00000000..f5b431a2 --- /dev/null +++ b/src/main/java/io/github/dre2n/dungeonsxl/sign/HologramSign.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2012-2016 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.sign; + +import com.gmail.filoghost.holographicdisplays.api.Hologram; +import com.gmail.filoghost.holographicdisplays.api.HologramsAPI; +import io.github.dre2n.commons.compatibility.CompatibilityHandler; +import io.github.dre2n.commons.compatibility.Version; +import io.github.dre2n.commons.util.EnumUtil; +import io.github.dre2n.dungeonsxl.world.GameWorld; +import io.github.dre2n.itemsxl.util.commons.util.NumberUtil; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Sign; +import org.bukkit.inventory.ItemStack; + +/** + * @author Daniel Saukel + */ +public class HologramSign extends DSign { + + private DSignType type = DSignTypeDefault.HOLOGRAM; + + private Hologram hologram; + + public HologramSign(Sign sign, String[] lines, GameWorld gameWorld) { + super(sign, lines, gameWorld); + } + + @Override + public boolean check() { + return true; + } + + @Override + @SuppressWarnings("deprecation") + public void onInit() { + getSign().setType(Material.AIR); + + String[] holoLines = lines[1].split("/"); + Location location = getSign().getLocation(); + location = location.add(0, NumberUtil.parseDouble(lines[2]), 0); + + hologram = HologramsAPI.createHologram(plugin, location); + for (String line : holoLines) { + if (line.startsWith("Item:")) { + String id = line.replace("Item:", ""); + ItemStack item; + + if (Version.andHigher(Version.MC1_9).contains(CompatibilityHandler.getInstance().getVersion())) { + item = plugin.getCaliburnAPI().getItems().getById(id).toItemStack(1); + + } else if (EnumUtil.isValidEnum(Material.class, id)) { + item = new ItemStack(Material.valueOf(id)); + + } else { + item = new ItemStack(NumberUtil.parseInt(id)); + } + + hologram.appendItemLine(item); + + } else { + hologram.appendTextLine(ChatColor.translateAlternateColorCodes('&', line)); + } + } + } + + @Override + public DSignType getType() { + return type; + } + +}