Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMI-API Hologram #35

Open
Heriptik opened this issue Feb 23, 2023 · 0 comments
Open

CMI-API Hologram #35

Heriptik opened this issue Feb 23, 2023 · 0 comments

Comments

@Heriptik
Copy link

Hi, i use latest version cmi and cmi lib.
I created a small custom casino plugin that displays % chance of dropping an emerald or redstone

My version is 1.12.2 i use catserver hybrid (latest).
You can view example in video here :
https://drive.google.com/file/d/1jZfsDJntdczaxpWn4VNe-ZQ1J1VVn9EW/view?usp=sharing

You can see that when I leave the area and come back the holograms don't respawn correctly.
It happens 1/2 approximately

My code for create and update hologram is :

`import com.Zrips.CMI.CMI;
import com.Zrips.CMI.Modules.Holograms.CMIHologram;
import org.bukkit.Location;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class HologramsListener {

public static Map<Location, CMIHologram> hologramsMap = new HashMap<>(); // Map Hologram principal
public static Map<Location, Long> hologramsTimeMap = new HashMap<>(); // Map Hologram qui gère le temps
public static Map<Location, String> hologramsUserMap = new HashMap<>(); // Map Hologram qui check le joueur qui a posé

public static void createHologram(Location location, double emeraude, double redstone) {
    long currentTime = System.currentTimeMillis();

    double chanceEmeraude = (double) emeraude / (emeraude + redstone);
    double chanceRedstone = (double) redstone / (emeraude + redstone);

    // Arrondi les pourcentages avec une décimale
    double chanceEmeraudeArrondi = Math.round(chanceEmeraude * 1000) / 10.0;
    double chanceRedstoneArrondi = Math.round(chanceRedstone * 1000) / 10.0;

    if (hologramsMap.containsKey(location)) { // S'il existe on le met juste à jour
        CMIHologram hologram = hologramsMap.get(location);
        hologram.setLines(Arrays.asList("§aGagner: " + chanceEmeraudeArrondi + "§a%", "§cPerdre: " + chanceRedstoneArrondi + "§c%"));
        hologram.update();

        hologramsTimeMap.put(location, currentTime);
    } else {
        CMIHologram hologram = new CMIHologram(String.valueOf(location), location.clone().add(0.5, 1.75, 0.5));
        hologram.setLines(Arrays.asList("§aGagner: " + chanceEmeraudeArrondi + "§a%", "§cPerdre: " + chanceRedstoneArrondi + "§c%"));
        CMI.getInstance().getHologramManager().addHologram(hologram);
        hologram.update();

        hologramsMap.put(location, hologram);
        hologramsTimeMap.put(location, currentTime);
    }

}

public static void removeHologram(Location location){
    CMIHologram hologram = hologramsMap.remove(location);
    if(hologram != null){
        hologram.remove();
    }
    hologramsTimeMap.remove(location);
    hologramsUserMap.remove(location);
}

}`

Thanks for your help in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant