Плагин [INFO/DEV] AwesomeHolograms v1.0 - Создай свои голограммы! [1.7.2-R0.2]

serega6531

Старожил
Девелопер
Пользователь
Баллы
173
AwesomeHolograms - Создай свои голограммы!
Версия: 1.0

Этот плагин позволяет вам создавать голограммы, висящие в воздухе, и содержит API для разработчиков. Вот примеры:
b7a90b82844bb21a92e01c0b342bdeae.png


Для работы нужен ProtocolLib 1.7.
Плагин не работает на версиях ниже 1.7.2.

Работа с API:
  1. Cоздайте новый экземпляр Hologram
    (Hologram(double x, double y, double z, double dy, String message) или
    Hologram(Location loc, double dy, String message))
  2. Используйте AwesomeHolograms.addHologram(Hologram)
  3. Для удаления - removeHologram(Hologram)
Вы также можете использовать /ah add Your text для добавления голограмм от игрока. Она появится на месте головы игрока.

Скачать плагин

Особенности:
  • Создание голограмм.
  • API для разработчиков.
Список изменений:
  • Релиз плагина
 
Последнее редактирование:
Исходный код:

Код:
package ru.serega6531.AwesomeHolograms;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;

import com.comphenix.packetwrapper.WrapperPlayServerAttachEntity;
import com.comphenix.packetwrapper.WrapperPlayServerEntityDestroy;
import com.comphenix.packetwrapper.WrapperPlayServerSpawnEntity;
import com.comphenix.packetwrapper.WrapperPlayServerSpawnEntityLiving;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;

public class AwesomeHolograms extends JavaPlugin implements Listener {

    static ArrayList<Hologram> holograms = new ArrayList<Hologram>();
    FileConfiguration config;

    private static int currentID = 9000;

    private void destroyHolograms(int[] ids){
        WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy();
    
        destroy.setEntities(ids);
    
        for (Player p : Bukkit.getOnlinePlayers()) {
            try {
                ProtocolLibrary.getProtocolManager().sendServerPacket(p, destroy.getHandle());
            }
            catch (InvocationTargetException ex) {
                Bukkit.broadcastMessage("Can not remove nameplates: " + ex.getCause());
            }
        }
    }

    private void destroyHologram(int id){
        destroyHolograms(new int[]{id});
    }

    public static void addHologram(Hologram hologram){
        hologram.setId(currentID);
        holograms.add(hologram);
        spawnHologramForOnline(hologram);
    }

    private void spawnHologram(Hologram hologram, Player player){
        spawnHologram(hologram, new Player[]{player});
    }

    private static void spawnHologramForOnline(Hologram hologram){
        spawnHologram(hologram, Bukkit.getOnlinePlayers());
    }

    private static void spawnHologram(Hologram hologram, Player[] players) {
        try {
            WrapperPlayServerSpawnEntityLiving horse = new WrapperPlayServerSpawnEntityLiving();
        
            horse.setEntityID(currentID);
    
            horse.setType(EntityType.HORSE);
    
            horse.setX(hologram.getX());
            horse.setY(hologram.getY()+ hologram.getDY() + 55);
            horse.setZ(hologram.getZ());
    
            WrappedDataWatcher wdw = new WrappedDataWatcher();
    
            wdw.setObject(10, hologram.getMessage());
            wdw.setObject(11, (byte) 1);
    
            wdw.setObject(12, -1700000);
    
            horse.setMetadata(wdw);
    
            for(Player player : players){
                ProtocolLibrary.getProtocolManager().sendServerPacket(player, horse.getHandle());
            }
    
            WrapperPlayServerSpawnEntity skull = new WrapperPlayServerSpawnEntity();
    
            skull.setEntityID(currentID + 1);
    
            skull.setType(66);
    
            skull.setX(hologram.getX());
            skull.setY(hologram.getY() + hologram.getDY() + 55);
            skull.setZ(hologram.getZ());
    
            for(Player player : players){
                ProtocolLibrary.getProtocolManager().sendServerPacket(player, skull.getHandle());
            }
    
            WrapperPlayServerAttachEntity attach = new WrapperPlayServerAttachEntity();
    
            attach.setEntityId(currentID);
            attach.setVehicleId(currentID + 1);
    
            for(Player player : players){
                ProtocolLibrary.getProtocolManager().sendServerPacket(player, attach.getHandle());
            }
        
            currentID += 2;
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public void removeHologram(Hologram hologram){
        destroyHologram(hologram.getId());
        holograms.remove(hologram);
    }

    public void onEnable(){
        if(!(Bukkit.getVersion().startsWith("git-Bukkit-1.7.2") || (Bukkit.getVersion().startsWith("git-Bukkit-1.7.4")))){
            getLogger().warning("AwesomeHolograms need 1.7+ server, but " + Bukkit.getVersion() + " found");
            this.setEnabled(false);
        }
        config = getConfig();
        getServer().getPluginManager().registerEvents(this, this);
        List<String> nholograms = getConfNamesList(config, "holograms");
        for(String name : nholograms){
            addHologram(Hologram.loadFromConfig(config, "holograms." + name));
        }
    }

    public void onDisable(){
        int[] ids = new int[holograms.size()];
        int i = 0;
        new File(getDataFolder() + "/config.yml").delete();
        for(Hologram hologram : holograms){
            hologram.saveToConfig(config, "holograms." + i);
            ids[i] = hologram.getId();
            i++;
        }
        saveConfig();
        destroyHolograms(ids);
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent e){
        Player p = e.getPlayer();
        for(Hologram hologram : holograms){
            spawnHologram(hologram, p);
        }
    }

    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if(command.getName().equalsIgnoreCase("ah") && args.length >= 2 && args[0].equalsIgnoreCase("add") && sender instanceof Player){
            addHologram(new Hologram(((Player) sender).getLocation(), 1, getTextFromArgs(args)));
            return true;
        }
        return false;
    }

    private String getTextFromArgs(String[] args){
        String result = "";
        for(int i = 1; i < args.length; i++){
            result = result + args[i];
            if(!(i == args.length - 1)){
                result = result + " ";
            }
        }
        return result;
    }

    public static List<String> getConfNamesList(FileConfiguration config, String path){
        ConfigurationSection conf = config.getConfigurationSection(path);
        if(conf != null){
        Iterator<String> iterator = conf.getKeys(false).iterator();
        List<String> list = new ArrayList<String>();
        while (iterator.hasNext()) {
            list.add(iterator.next().toString());
        }
        return list;
        } else {
            return new ArrayList<String>();
        }
    }

}

Код:
public class Hologram {

    double x, y, z, dy;
    String message;
    int id;

    public Hologram(double x, double y, double z, double dy, String message){
        this.x = x;
        this.y = y;
        this.z = z;
        this.dy = dy;
        this.message = message;
    }

    public Hologram(Location loc, double dy, String message){
        this.x = loc.getX();
        this.y = loc.getY();
        this.z = loc.getZ();
        this.dy = dy;
        this.message = message;
    }

    public int getId(){
        return id;
    }

    public void setId(int id){
        this.id = id;
    }

    public double getX(){
        return x;
    }

    public double getY(){
        return y;
    }

    public double getZ(){
        return z;
    }

    public double getDY(){
        return dy;
    }

    public String getMessage(){
        return message;
    }

    public void saveToConfig(FileConfiguration conf, String path){
        conf.set(path + ".x", x);
        conf.set(path + ".y", y);
        conf.set(path + ".z", z);
        conf.set(path + ".dy", dy);
        conf.set(path + ".message", message);
    }

    public static Hologram loadFromConfig(FileConfiguration conf, String path){
        return new Hologram(
                conf.getDouble(path + ".x"),
                conf.getDouble(path + ".y"),
                conf.getDouble(path + ".z"),
                conf.getDouble(path + ".dy"),
                conf.getString(path + ".message"));
    }

}

Мне нужна помощь в создании многострочного текста. Подскажите, как это сделать? \n не работает.
 
Последнее редактирование:
на 1.5.2 такое реально реализовать? :3
 
на баките такой же плагин есть, называется немного по-другому, случайно не твой?
 
Хм... А с какого расстояния они видны? У меня есть любопытная идея....
 
Назад
Верх