No chat to show

This project's files are all here to explore.

Files
src
desktop.ini
pom.xml
README.md
Code
6 245
src/main/java/com/sezdev/ShineSmp01/ShineSMP01.java
package com.sezdev.wildcards;

import org.bukkit.*;
import org.bukkit.attribute.Attribute;
import org.bukkit.command.*;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.*;
import org.bukkit.event.*;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.*;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;

import java.util.*;

/** Recreated implementation based on the uploaded Shines 1.0.0 plugin's metadata/config. */
public final class Shines extends JavaPlugin implements Listener, CommandExecutor, TabCompleter {
    enum Shines {
        INFERNO("inferno", "Inferno", ChatColor.RED, Material.BLAZE_POWDER, 10001),
        STORMBREAKER("stormbreaker", "Stormbreaker", ChatColor.AQUA, Material.HEART_OF_THE_SEA, 10002),
        ABYSS("abyss", "Abyss", ChatColor.DARK_PURPLE, Material.ENDER_PEARL, 10003),
        FROSTBITE("frostbite", "Frostbite", ChatColor.WHITE, Material.PACKED_ICE, 10004),
        TITAN("titan", "Titan", ChatColor.DARK_GRAY, Material.DEEPSLATE, 10005),
        PHANTOM("phantom", "Phantom", ChatColor.GRAY, Material.PHANTOM_MEMBRANE, 10006),
        NATUREBORN("natureborn", "Natureborn", ChatColor.GREEN, Material.OAK_LEAVES, 10007);
        final String key, label; final ChatColor color; final Material icon; final int model;
        shine(String key, String label, ChatColor color, Material icon, int model) { this.key=key; this.label=label; this.color=color; this.icon=icon; this.model=model; }
        static shine parse(String s) { for (shine c:values()) if(c.key.equalsIgnoreCase(s)||c.name().equalsIgnoreCase(s)||c.label.equalsIgnoreCase(s)) return c; return null; }
    }
    private NamespacedKey shineKey, firstJoinKey;
    private final Map<UUID, Map<String, Long>> cooldowns = new HashMap<>();
    private boolean started;

    @Override public void onEnable() {
        saveDefaultConfig(); shineKey=new NamespacedKey(this,"shines"); firstJoinKey=new NamespacedKey(this,"received_first_shine");
        started=getConfig().getBoolean("start.auto-start", false);
        Bukkit.getPluginManager().registerEvents(this,this);
        Objects.requireNonNull(getCommand("shines")).setExecutor(this); getCommand("shines").setTabCompleter(this);
        registerRecipes(); getLogger().info("shines recreated enabled. Active="+started);
    }
    @Override public void onDisable() { for (shine c : Cshine.values()) Bukkit.removeRecipe(new NamespacedKey(this, "craft_" + c.key)); }

    private String pretty(String s) { return ChatColor.translateAlternateColorCodes('&', s); }
    private void msg(CommandSender s,String text) { s.sendMessage(pretty("&6[ShineSMP] &r"+text)); }
    private ItemStack makeshine(shine c) {
        ItemStack item=new ItemStack(c.icon); ItemMeta meta=item.getItemMeta();
        meta.setDisplayName(c.color+"§l"+c.label+" shine");
        meta.setLore(Arrays.asList("",ChatColor.GRAY+"A mysterious ability card",ChatColor.YELLOW+"Right Click "+ChatColor.GRAY+"- Primary ability",ChatColor.YELLOW+"Shift + Right Click "+ChatColor.GRAY+"- Secondary ability",ChatColor.DARK_GRAY+"shines"));
        meta.setCustomModelData(c.model); meta.getPersistentDataContainer().set(shineKey,PersistentDataType.STRING,c.key);
        item.setItemMeta(meta); return item;
    }
    private shine shineOf(ItemStack item) {
        if(item==null||!item.hasItemMeta()) return null;
        String key=item.getItemMeta().getPersistentDataContainer().get(shineKey,PersistentDataType.STRING);
        return key==null?null:Card.parse(key);
    }
    private void registerRecipes() {
        for(Card c:Card.values()) {
            if(!getConfig().getBoolean("shines."+c.key+".enabled",true)||!getConfig().getBoolean("shines."+c.key+".craftable",true)) continue;
            NamespacedKey rk=new NamespacedKey(this,"craft_"+c.key); Bukkit.removeRecipe(rk);
            ShapedRecipe recipe=new ShapedRecipe(rk,makeshine(c));
            switch(c) {
                case INFERNO -> { recipe.shape("BNB","NPN","BNB"); recipe.setIngredient('B',Material.BLAZE_POWDER); recipe.setIngredient('N',Material.NETHERRACK); recipe.setIngredient('P',Material.PAPER); }
                case STORMBREAKER -> { recipe.shape("ICI","CPC","ICI"); recipe.setIngredient('I',Material.IRON_INGOT); recipe.setIngredient('C',Material.COPPER_INGOT); recipe.setIngredient('P',Material.PAPER); }
                case ABYSS -> { recipe.shape("EOE","OPO","EOE"); recipe.setIngredient('E',Material.ENDER_PEARL); recipe.setIngredient('O',Material.OBSIDIAN); recipe.setIngredient('P',Material.PAPER); }
                case FROSTBITE -> { recipe.shape("SIS","IPI","SIS"); recipe.setIngredient('S',Material.SNOWBALL); recipe.setIngredient('I',Material.PACKED_ICE); recipe.setIngredient('P',Material.PAPER); }
                case TITAN -> { recipe.shape("DSD","SPS","DSD"); recipe.setIngredient('D',Material.DEEPSLATE); recipe.setIngredient('S',Material.STONE); recipe.setIngredient('P',Material.PAPER); }
                case PHANTOM -> { recipe.shape("MGM","GPG","MGM"); recipe.setIngredient('M',Material.PHANTOM_MEMBRANE); recipe.setIngredient('G',Material.GHAST_TEAR); recipe.setIngredient('P',Material.PAPER); }
                case NATUREBORN -> { recipe.shape("VLV","LPL","VLV"); recipe.setIngredient('V',Material.VINE); recipe.setIngredient('L',Material.OAK_LEAVES); recipe.setIngredient('P',Material.PAPER); }
            }
            Bukkit.addRecipe(recipe);
        }
    }
    @EventHandler public void onJoin(PlayerJoinEvent e) {
        Player p=e.getPlayer(); boolean first=!p.getPersistentDataContainer().has(firstJoinKey,PersistentDataType.BYTE);
        if(first && getConfig().getBoolean("join.give-shine-on-first-join",true)) {
            giveRandomLater(p, true);
        } else if(!first && getConfig().getBoolean("join.give-shine-on-every-join",false)) giveRandomLater(p, false);
    }
    private void giveRandomLater(Player p, boolean markFirst) {
        long delay=Math.max(0,getConfig().getLong("join.give-delay",40));
        Bukkit.getScheduler().runTaskLater(this,()->{
            if(!p.isOnline()) return;
            if(getConfig().getBoolean("join.require-started",true)&&!started) return;
            if(getConfig().getBoolean("general.one-shine-only",true)&&hasshine(p)) return;
            List<shine> enabled=new ArrayList<>(); for(shine c:shine.values()) if(getConfig().getBoolean("shines."+c.key+".enabled",true)) enabled.add(c);
            if(enabled.isEmpty()) return; shine c=enabled.get(new Random().nextInt(enabled.size()));
            if(markFirst) p.getPersistentDataContainer().set(firstJoinKey,PersistentDataType.BYTE,(byte)1);
            Map<Integer,ItemStack> rest=p.getInventory().addItem(makesshine(c)); for(ItemStack it:rest.values()) p.getWorld().dropItemNaturally(p.getLocation(),it);
            msg(p,"You received a "+c.color+c.label+" shine& a! Hold it and right-click to use.");
        },delay);
    }
    private boolean hasshine(Player p) { for(ItemStack i:p.getInventory().getContents()) if(cardOf(i)!=null)return true; return false; }
    @EventHandler public void onCraft(CraftItemEvent e) { if(cardOf(e.getCurrentItem())!=null && e.getWhoClicked() instanceof Player p && !p.hasPermission("shineSMP.craft")) { e.setCancelled(true); msg(p,"You don't have permission to Shine."); } }
    @EventHandler public void onUse(PlayerInteractEvent e) {
        if(e.getAction()!=Action.RIGHT_CLICK_AIR && e.getAction()!=Action.RIGHT_CLICK_BLOCK) return;
        shine c=shineOf(e.getItem()); if(c==null) return; e.setCancelled(true); Player p=e.getPlayer();
        if(!p.hasPermission("shineSMP.use")){msg(p,"You don't have permission to use cards.");return;}
        if(!started){msg(p,"Cards are currently disabled.");return;}
        boolean secondary=p.isSneaking(); String ability=(secondary?"secondary":"primary"); int cd=getConfig().getInt("shine."+c.key+"."+ability+".cooldown",20);
        if(!ready(p,c,ability,cd)) return;
        activate(p,c,secondary); setCooldown(p,c,ability,cd);
    }
    private String cooldownKey(shine c,String a){return c.key+":"+a;}
    private boolean ready(Player p,Shine c,String a,int seconds) {
        long until=cooldowns.getOrDefault(p.getUniqueId(),Collections.emptyMap()).getOrDefault(cooldownKey(c,a),0L); long left=until-System.currentTimeMillis();
        if(left>0){msg(p,"Ability cooldown: &e"+((left+999)/1000)+"s");return false;} return true;
    }
    private void setCooldown(Player p,shine c,String a,int sec){cooldowns.computeIfAbsent(p.getUniqueId(),k->new HashMap<>()).put(cooldownKey(c,a),System.currentTimeMillis()+sec*1000L);}
    private void effect(Player p,PotionEffectType type,int seconds,int amp){p.addPotionEffect(new PotionEffect(type,seconds*20,amp,true,true,true));}
    private List<LivingEntity> nearby(Player p,double radius){List<LivingEntity> out=new ArrayList<>(); for(Entity e:p.getNearbyEntities(radius,radius,radius)) if(e instanceof LivingEntity le && e!=p && !(e instanceof ArmorStand)) out.add(le); return out;}
    private void damageNearby(Player p,double radius,double damage,boolean fire,boolean pull,double knockback){ for(LivingEntity le:nearby(p,radius)){ if(fire)le.setFireTicks(80); le.damage(damage,p); Vector v=le.getLocation().toVector().subtract(p.getLocation().toVector()); if(pull)v.multiply(-1); if(v.lengthSquared()>0)le.setVelocity(v.normalize().multiply(knockback).setY(0.35)); } }
    private void activate(Player p,Card c,boolean sec) {
        Location loc=p.getLocation(); World w=p.getWorld(); int duration;
        switch(c) {
            case INFERNO -> { if(!sec){duration=getConfig().getInt("cards.inferno.primary.duration",10);effect(p,PotionEffectType.FIRE_RESISTANCE,duration,0);effect(p,PotionEffectType.INCREASE_DAMAGE,duration,0);p.setFireTicks(0);w.spawnParticle(Particle.FLAME,loc.add(0,1,0),45,.7,.7,.7,.04);w.playSound(p.getLocation(),Sound.ITEM_FIRECHARGE_USE,1,1);} else {damageNearby(p,5,6,true,false,1.5);w.spawnParticle(Particle.FLAME,loc.add(0,1,0),100,2,1,2,.1);w.playSound(p.getLocation(),Sound.ENTITY_BLAZE_SHOOT,1,0.8f);} }
            case STORMBREAKER -> { if(!sec){effect(p,PotionEffectType.SPEED,8,2);effect(p,PotionEffectType.JUMP,8,1);w.spawnParticle(Particle.ELECTRIC_SPARK,loc.add(0,1,0),60,1,1,1,.2);w.playSound(p.getLocation(),Sound.ENTITY_LIGHTNING_BOLT_THUNDER,.8f,1.5f);} else {LivingEntity target=target(p,30); if(target!=null){target.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,80,3));target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,40,0));w.strikeLightningEffect(target.getLocation());}else msg(p,"No target in range.");} }
            case ABYSS -> { if(!sec){Location dest=p.getTargetBlockExact(8)==null?p.getLocation().add(p.getLocation().getDirection().multiply(8)):p.getTargetBlockExact(8).getLocation().add(0,1,0); if(dest.getBlock().isPassable()&&dest.clone().add(0,1,0).getBlock().isPassable())p.teleport(dest);effect(p,PotionEffectType.SLOW_FALLING,5,0);w.spawnParticle(Particle.PORTAL,p.getLocation(),70,1,1,1,.5);w.playSound(p.getLocation(),Sound.ENTITY_ENDERMAN_TELEPORT,1,0.7f);} else {for(LivingEntity le:nearby(p,8)){Vector v=p.getLocation().toVector().subtract(le.getLocation().toVector());if(v.lengthSquared()>0)le.setVelocity(v.normalize().multiply(1.2));le.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS,100,0));}w.spawnParticle(Particle.REVERSE_PORTAL,loc.add(0,1,0),80,2,1,2,.2);} }
            case FROSTBITE -> { if(!sec){for(LivingEntity le:nearby(p,2)){le.setFreezeTicks(60);le.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,60,2));}w.spawnParticle(Particle.SNOWFLAKE,loc.add(0,1,0),35,1,1,1,.02);} else {for(LivingEntity le:nearby(p,8)){le.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,120,2));le.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING,120,1));le.setFreezeTicks(100);}w.spawnParticle(Particle.SNOWFLAKE,loc.add(0,1,0),160,4,1.5,4,.04);w.playSound(p.getLocation(),Sound.WEATHER_RAIN,1,.5f);} }
            case TITAN -> { if(!sec){effect(p,PotionEffectType.DAMAGE_RESISTANCE,10,1);effect(p,PotionEffectType.SLOW,10,0);w.spawnParticle(Particle.BLOCK_CRACK,loc.add(0,1,0),45,1,1,1,Material.STONE.createBlockData());} else {p.setVelocity(p.getLocation().getDirection().multiply(1.2).setY(0.8));new BukkitRunnable(){public void run(){Location l=p.getLocation();w.spawnParticle(Particle.EXPLOSION,l,2);w.spawnParticle(Particle.BLOCK_CRACK,l,90,2,.5,2,Material.DEEPSLATE.createBlockData());damageNearby(p,6,8,false,false,1.0);}}.runTaskLater(this,8L);w.playSound(p.getLocation(),Sound.ENTITY_GENERIC_EXPLODE,1,0.7f);} }
            case PHANTOM -> { if(!sec){effect(p,PotionEffectType.INVISIBILITY,5,0);effect(p,PotionEffectType.SPEED,5,1);effect(p,PotionEffectType.JUMP,5,1);w.spawnParticle(Particle.SMOKE,p.getLocation(),45,.7,1,.7,.05);} else {LivingEntity target=target(p,5);if(target!=null){target.setGlowing(true);target.damage(6,p);Bukkit.getScheduler().runTaskLater(this,()->{if(target.isValid())target.setGlowing(false);},200L);}else msg(p,"Look directly at a target within 5 blocks.");} }
            case NATUREBORN -> { if(!sec){effect(p,PotionEffectType.REGENERATION,10,1);effect(p,PotionEffectType.ABSORPTION,10,0);double max=p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();p.setHealth(Math.min(max,p.getHealth()+4));w.spawnParticle(Particle.VILLAGER_HAPPY,loc.add(0,1,0),40,1,1,1,.1);w.playSound(p.getLocation(),Sound.BLOCK_AMETHYST_BLOCK_CHIME,1,1.3f);} else {for(LivingEntity le:nearby(p,6)){le.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,80,4));le.addPotionEffect(new PotionEffect(PotionEffectType.JUMP,80,128));}w.spawnParticle(Particle.VILLAGER_HAPPY,loc.add(0,1,0),60,2,1,2,.1);} }
        }
        msg(p,(sec?"Secondary":"Primary")+" ability used: "+c.color+c.label+"&r!");
    }
    private LivingEntity target(Player p,double range){ for(Entity e:p.getNearbyEntities(range,range,range)) if(e instanceof LivingEntity le && !(e instanceof ArmorStand) && p.hasLineOfSight(e) && le!=p && e.getLocation().distanceSquared(p.getLocation())<=range*range) return le; return null; }

    @Override public boolean onCommand(CommandSender sender,Command command,String label,String[] args) {
        if(args.length==0){msg(sender,"&e/wc give <player> <shine> | list | start | stop | reload");return true;}
        switch(args[0].toLowerCase(Locale.ROOT)) {
            case "give" -> {if(!sender.hasPermission("ShineSMP.admin")){msg(sender,"No permission.");return true;} if(args.length<3){msg(sender,"Usage: /ss give <player> <shine>");return true;} Player target=Bukkit.getPlayerExact(args[1]);shine c=shine.parse(args[2]);if(target==null||c==null){msg(sender,"Player online hona chahiye aur shine valid hona chahiye.");return true;}target.getInventory().addItem(makeshine(c));msg(sender,"Given "+c.label+" shine to "+target.getName()+".");msg(target,"You received "+c.color+c.label+" shine&r!");}
            case "list" -> {msg(sender,"Available shines: "+String.join(", ",Arrays.stream(shine.values()).map(c->c.color+c.label).toList()));}
            case "start" -> {if(!sender.hasPermission("shineSMP.admin"))return true;started=true;Bukkit.broadcastMessage(pretty("&6[ShineSMP] "+getConfig().getString("start.start-broadcast","&AShine activated!")));}
            case "stop" -> {if(!sender.hasPermission("wildcards.admin"))return true;started=false;Bukkit.broadcastMessage(pretty("&6[ShineSMP] "+getConfig().getString("start.stop-broadcast","&cshineSMP deactivated!")));}
            case "reload" -> {if(!sender.hasPermission("shineSMP.admin"))return true;reloadConfig();registerRecipes();msg(sender,"Config and recipes reloaded.");}
            default -> msg(sender,"&e/ss give <player> <shine> | list | start | stop | reload");
        } return true;
    }
    @Override public List<String> onTabComplete(CommandSender sender,Command command,String alias,String[] args) {
        if(args.length==1)return Arrays.asList("give","list","start","stop","reload").stream().filter(s->s.startsWith(args[0].toLowerCase())).toList();
        if(args.length==2&&args[0].equalsIgnoreCase("give"))return Bukkit.getOnlinePlayers().stream().map(Player::getName).filter(s->s.toLowerCase().startsWith(args[1].toLowerCase())).toList();
        if(args.length==3&&args[0].equalsIgnoreCase("give"))return Arrays.stream(shine.values()).map(c->c.key).filter(s->s.startsWith(args[2].toLowerCase())).toList();return Collections.emptyList();
    }
}