ServerPlugin [FIXED] Brauche Hilfe! Doppelte Nachrichtenausgabe!

Dieses Thema im Forum "Programmierung" wurde erstellt von haggishunter2001, 8. Juli 2015.

  1. haggishunter2001
    Offline

    haggishunter2001

    Registriert seit:
    11. Februar 2014
    Beiträge:
    6
    Ort:
    Oberntudorf
    Minecraft:
    Präsident_Kuh
    Hey Leute,

    ich habe ein Plugin entwickelt, wofür ich jetzt eine config.yml erstellent wollte. Alles schön und gut aber dann kommt das:
    http://prntscr.com/7q92g1
    Wie ihr seht, kommt die nachricht 2x anstatt 1x.

    Hier ist der Code:

    package de.GameCubeMC.www;

    import net.md_5.bungee.api.ChatColor;

    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.enchantment.EnchantItemEvent;
    import org.bukkit.event.entity.EntityTameEvent;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerAchievementAwardedEvent;
    import org.bukkit.event.player.PlayerBedEnterEvent;
    import org.bukkit.event.player.PlayerBedLeaveEvent;
    import org.bukkit.event.player.PlayerBucketEmptyEvent;
    import org.bukkit.event.player.PlayerBucketFillEvent;
    import org.bukkit.event.player.PlayerChangedWorldEvent;
    import org.bukkit.event.player.PlayerEggThrowEvent;
    import org.bukkit.event.player.PlayerFishEvent;
    import org.bukkit.event.player.PlayerGameModeChangeEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerKickEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.event.player.PlayerPortalEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class Events implements Listener {
    public static Main plugin;
    public Events(Main instance) {
    plugin = instance;

    plugin.getServer().getPluginManager().registerEvents(this, plugin);

    }

    @EventHandler
    public void onPlayerTod(PlayerDeathEvent pdw) {
    String Player_Death_Global = plugin.getConfig().getString("Config.Player_Death_Global");
    String Player_Death_Victim = plugin.getConfig().getString("Config.Player_Death_Victim");
    String Player_Death_Killer = plugin.getConfig().getString("Config.Player_Death_Killer");
    Player p = pdw.getEntity();
    Player_Death_Global = Player_Death_Global.replace("[PLAYER]", p.getName());
    Player_Death_Global = Player_Death_Global.replace("[KILLER]", p.getKiller().getName());
    Player_Death_Victim = Player_Death_Victim.replace("[PLAYER]", p.getName());
    Player_Death_Victim = Player_Death_Victim.replace("[KILLER]", p.getKiller().getName());
    Player_Death_Killer = Player_Death_Killer.replace("[PLAYER]", p.getName());
    Player_Death_Killer = Player_Death_Killer.replace("[KILLER]", p.getKiller().getName());
    pdw.setDeathMessage("§6" + pdw.getDeathMessage());
    if(pdw.getEntity().getKiller() instanceof Player) {
    pdw.setDeathMessage(ChatColor.translateAlternateColorCodes('&', Player_Death_Global));
    p.sendMessage(ChatColor.translateAlternateColorCodes('&', Player_Death_Victim) + " §7|§2 " + p.getKiller().getName() + " health §8>> §5" + p.getKiller().getHealth());
    p.getKiller().sendMessage(ChatColor.translateAlternateColorCodes('&', Player_Death_Killer));

    }
    }
    @EventHandler
    public void onPlayerBukkitEmpty(PlayerBucketEmptyEvent pbee) {
    String Bucket_Empty = plugin.getConfig().getString("Config.Bucket_Empty");
    Player p = pbee.getPlayer();
    p.sendMessage(ChatColor.translateAlternateColorCodes('&', Bucket_Empty));
    p.playSound(p.getLocation(), Sound.WOLF_BARK, 1.0F, 1.0F);

    }
    @EventHandler
    public void onPlayerBukkitFillEvent(PlayerBucketFillEvent pbfe) {
    String Bucket_Full = plugin.getConfig().getString("Config.Bucket_Full");
    Player p = pbfe.getPlayer();
    p.sendMessage(ChatColor.translateAlternateColorCodes('&', Bucket_Full));
    p.playSound(p.getLocation(), Sound.WOLF_HOWL, 1.0F, 1.0F);
    }
    @EventHandler
    public void onPlayerEggEvent(PlayerEggThrowEvent pete) {
    Player p = pete.getPlayer();
    p.sendMessage("§eSpiegeleier§8!");
    p.playSound(p.getLocation(), Sound.EXPLODE, 1.0F, 1.0F);
    }
    @EventHandler
    public void onPlayerGameModeEvent(PlayerGameModeChangeEvent pgce) {
    Player p = pgce.getPlayer();
    p.sendMessage("§eYour last Gamemode: §6" + p.getGameMode());
    p.playSound(p.getLocation(), Sound.ANVIL_LAND, 1.0F, 1.0F);
    }
    @EventHandler
    public void onPlayerRespawn(PlayerRespawnEvent pre) {
    Player p = pre.getPlayer();
    p.sendMessage("§2New Try §8....");
    }
    @EventHandler
    public void onPlayerFish(PlayerFishEvent pfe) {
    Player p = pfe.getPlayer();
    p.sendMessage("§bhmmmm .... §3Fisch §8;)");
    p.playSound(p.getLocation(), Sound.SHEEP_SHEAR, 1.0F, 1.0F);
    }
    @EventHandler
    public void onPlayerAchievment(PlayerAchievementAwardedEvent paae) {
    Player p = paae.getPlayer();
    p.sendMessage("§e§kLPLPLPLPLPLPLPLPLPLPLPLPLPLPLPLPLP");
    p.sendMessage("§2Gratulation§c! §aYou earned the achievment: §7" + paae.getAchievement() + "§8!");
    p.sendMessage("§e§kLPLPLPLPLPLPLPLPLPLPLPLPLPLPLPLPLP");
    p.playSound(p.getLocation(), Sound.LEVEL_UP, 1.0F, 1.0F);
    }
    @EventHandler
    public void onPlayerBed(PlayerBedEnterEvent pbee) {
    Player p = pbee.getPlayer();
    p.sendMessage("§aGood night§8!");
    p.playSound(p.getLocation(), Sound.CREEPER_DEATH, 1.0F, 1.0F);
    }
    @EventHandler
    public void onPlayerBed(PlayerBedLeaveEvent pble) {
    Player p = pble.getPlayer();
    p.sendMessage("§aGood Morning§8!");
    p.playSound(p.getLocation(), Sound.CREEPER_HISS, 1.0F, 1.0F);
    }
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent pje) {
    Player p = pje.getPlayer();
    p.sendMessage("§2Welcome back, §c" + p.getDisplayName());
    p.playSound(p.getLocation(), Sound.CHEST_OPEN, 1.0F, 1.0F);
    }
    @EventHandler
    public void onPlayerKick(PlayerKickEvent pke) {
    Player p = pke.getPlayer();
    p.sendMessage("§4" + p.getName() + " §cwas kicked§8!");
    pke.setReason("§c7[§3FunMessages§7] §cKicked by an §3Teammember! §eReason§8: §4" + pke.getReason());
    p.playSound(p.getLocation(), Sound.CHEST_CLOSE, 1.0F, 1.0F);
    }
    @EventHandler
    public void onPlayerPortal(PlayerPortalEvent ppe) {
    Player p = ppe.getPlayer();
    p.sendMessage("§cDo you really want that§8?");
    p.playSound(p.getLocation(), Sound.BLAZE_BREATH, 1.0F, 1.0F);
    }
    @EventHandler
    public void onPlayerWorld(PlayerChangedWorldEvent pcwe) {
    Player p = pcwe.getPlayer();
    p.sendMessage("§aWorld changed§8!");
    p.playSound(p.getLocation(), Sound.ENDERMAN_SCREAM, 1.0F, 1.0F);
    }
    @EventHandler
    public void onPlayerJoinM(PlayerJoinEvent pjem) {
    Player p = pjem.getPlayer();
    pjem.setJoinMessage("§8[§2+§8] §2" + p.getDisplayName());
    p.sendMessage("§7[§aMessages-Plugin von §3President_Kuh§7]");
    }
    @EventHandler
    public void onPlayerQuitM(PlayerQuitEvent pjem) {
    Player p = pjem.getPlayer();
    pjem.setQuitMessage("§8[§4-§8] §4" + p.getDisplayName());
    }
    @EventHandler
    public void onTame(EntityTameEvent ete) {
    Player p = (Player) ete.getOwner();
    p.sendMessage("§aThats now your Pet§8!§e Owner§7: §b" + ete.getOwner().getName());
    p.playSound(p.getLocation(),Sound.ANVIL_USE, 1.0F, 1.0F);
    }
    @EventHandler
    public void onMove(PlayerMoveEvent e) {
    Player p = e.getPlayer();
    Location loc = p.getLocation();
    Location loc1 = new Location(loc.getWorld(), loc.getX(), loc.getY() - 1.0D, loc.getZ());
    if ((loc.getBlock().getType() == Material.CARPET) &&
    (loc1.getBlock().getType() == Material.SLIME_BLOCK)) {
    p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 20, 5));
    }
    }
    @EventHandler
    public void onPlayerMove(PlayerMoveEvent pme) {
    Player p = pme.getPlayer();
    Location loc = p.getLocation();
    Location loc1 = new Location(loc.getWorld(), loc.getX(), loc.getY() - 1.0D, loc.getZ());
    if ((loc.getBlock().getType() == Material.CARPET) &&
    (loc1.getBlock().getType() == Material.EMERALD_BLOCK)) {
    p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 20, 15));
    }
    }
    @EventHandler
    public void onPlayerMoveSpeed(PlayerMoveEvent pme) {
    Player p = pme.getPlayer();
    Location loc = p.getLocation();
    Location loc1 = new Location(loc.getWorld(), loc.getX(), loc.getY() - 1.0D, loc.getZ());
    if ((loc.getBlock().getType() == Material.CARPET) &&
    (loc1.getBlock().getType() == Material.LAPIS_BLOCK)) {
    p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 25, 10));
    }
    }
    //Unsichtbarkeitsblock
    @EventHandler
    public void onPlayerMoveInv(PlayerMoveEvent pme) {
    Player p = pme.getPlayer();
    Location loc = p.getLocation();
    Location loc1 = new Location(loc.getWorld(), loc.getX(), loc.getY() - 1.0D, loc.getZ());
    if ((loc.getBlock().getType() == Material.CARPET) &&
    (loc1.getBlock().getType() == Material.BARRIER)) {
    p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 30, 255));
    }
    }
    @EventHandler
    public void onMoveJump(PlayerMoveEvent pme)
    {
    Player p = pme.getPlayer();
    Location loc = p.getLocation();
    Location loc1 = new Location(loc.getWorld(), loc.getX(), loc.getY() - 1.0D, loc.getZ());
    if ((loc.getBlock().getType() == Material.IRON_PLATE) &&
    (loc1.getBlock().getType() == Material.DIAMOND_BLOCK))
    {
    p.setVelocity(p.getLocation().getDirection().multiply(4.5D).setY(1.5D));
    p.playSound(p.getLocation(), Sound.ARROW_HIT, 3.0F, 2.0F);
    }
    }
    @EventHandler
    public void onEnchant(EnchantItemEvent eie) {
    Player p = eie.getEnchanter();
    p.sendMessage("§7[§3FunMessages§7] §5You are an magican!");
    p.sendMessage("§7[§3FunMessages§7] §dEnchantet Item§8: §f§kGAGAG");
    }
    }

    package de.GameCubeMC.www;

    import org.bukkit.Bukkit;
    import org.bukkit.GameMode;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class Main extends JavaPlugin{
    public void onEnable(){
    Bukkit.getServer().getPluginManager().registerEvents(new Events(this), this);
    loadConfig();
    }

    public void loadConfig() {
    saveDefaultConfig();

    }

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    Player p = null;
    if ((sender instanceof Player)) {
    p = (Player)sender;
    }

    if (cmd.getName().equalsIgnoreCase("fm"))
    {
    if (p != null)
    {
    p.sendMessage("");
    p.sendMessage("§a=========§3FunMessages§a=========");
    p.sendMessage("§6Plugin von§9: §3Agent_Kuh");
    p.sendMessage("§eCommands: /fm-cmds§8! Events :)");
    p.sendMessage("§a=========§3FunMessages§a=========");
    p.sendMessage("");
    p.playSound(p.getLocation(), Sound.NOTE_PLING, 1.0F, 1.0F);
    return true;
    }
    sender.sendMessage("§4Nope");
    return true;
    }

    if (cmd.getName().equalsIgnoreCase("fm-list"))
    {
    if (p != null)
    {
    p.sendMessage("");
    p.sendMessage("§a=========§3FunMessages§8-§2Liste§a=========");
    p.sendMessage("§6Death§8: §cYou §4died§8!");
    p.sendMessage("§6Bucket Empty§8: §cThe Bucket is now Empty§8!");
    p.sendMessage("§6Bucket full§8: §aThe Bucket is now Full§8!");
    p.sendMessage("§6Throw egg§8: §eSpiegeleier§8!");
    p.sendMessage("§6Gamemode change§8: §eLast Gamemode: §6<last GameMode>");
    p.sendMessage("§6Respawn§8: §2New Try §8....");
    p.sendMessage("§6Angeln§8: §bhmmmm .... §3Fish §8;)");
    p.sendMessage("§6Achievment§8: §2Gratulation§c! §aYou earned the achievment: §7<achievment>§8!");
    p.sendMessage("§6Went into Bed§8: §aGood Nigth!");
    p.sendMessage("§6Leave Bed§8: §aGood Morning!");
    p.sendMessage("§6Server-Join§8: §2Welcome back, <name>!");
    p.sendMessage("§6Kick§8: §4<name> §cwas kicked§8!");
    p.sendMessage("§6In Portal§8: §cDo you really want that§8?");
    p.sendMessage("§6World change§8: §aWorld changed§8!");
    p.sendMessage("§6Server-join§8: §8[§2+§8] §2<name>");
    p.sendMessage("§6Server-leave§8: §8[§4-§8] §4<name>");
    p.sendMessage("§6Tier tame§8: §aThats now your pet§8! §eOwner§7: §e<name>");
    p.sendMessage("§6Mob / Player Kill§8: §cYou have §4killed §ca §d <Mob-Name> §c!");
    p.sendMessage("§a=========§3FunMessages§8-§2Liste§a=========");
    p.sendMessage("");
    p.playSound(p.getLocation(), Sound.NOTE_PLING, 1.0F, 1.0F);
    return true;
    }
    sender.sendMessage("§4Nope");
    return true;
    }

    if (cmd.getName().equalsIgnoreCase("fm-cmds-1"))
    {
    if (p != null)
    {
    p.sendMessage("");
    p.sendMessage("§a=========§3FunMessages§8-§2Liste§a=========");
    p.sendMessage("§7- §6/fm");
    p.sendMessage("§7- §6/fm-list");
    p.sendMessage("§7- §6/fm-cmds");
    p.sendMessage("§7- §6/fm-death");
    p.sendMessage("§7- §6/fm-bempty");
    p.sendMessage("§7- §6/fm-bfull");
    p.sendMessage("§7- §6/fm-egg");
    p.sendMessage("§7- §6/fm-gamemode");
    p.sendMessage("§7- §6/fm-respawn");
    p.sendMessage("§7- §6/fm-fish");
    p.sendMessage("§7- §6/fm-bedenter");
    p.sendMessage("§7- §6/fm-bedleave");
    p.sendMessage("§7- §6/fm-join");
    p.sendMessage("§7- §6/fm-leave");
    p.sendMessage("");
    p.sendMessage("§bNext Page§8>> §6/fm-cmds-2");
    p.sendMessage("§a=========§3FunMessages§8-§2Liste§a=========");
    p.sendMessage("");
    p.playSound(p.getLocation(), Sound.NOTE_PIANO, 1.0F, 1.0F);
    return true;
    }
    sender.sendMessage("§4Nope");
    return true;
    }

    if (cmd.getName().equalsIgnoreCase("fm-cmds-2"))
    {
    if (p != null)
    {
    p.sendMessage("");
    p.sendMessage("§a=========§3FunMessages§8-§2Liste§a=========");
    p.sendMessage("§7- §6/fm-kick");
    p.sendMessage("§7- §6/fm-portal");
    p.sendMessage("§7- §6/fm-world");
    p.sendMessage("§7- §6/fm-tame");
    p.sendMessage("§7- §6/fm-kill");
    p.sendMessage("§7- §6/fm-cc");
    p.sendMessage("§7- §6/fm-coc");
    p.sendMessage("§7- §6/fm-ospam");
    p.sendMessage("§7- §6/fm-spam");
    p.sendMessage("§7- §6/fm-h10 §7| §615 §7| §620 §7| §630 §7| §640 §7| §650 §7| §660 §7| §670 §7| §680 §7| §690 §7| §6100");
    p.sendMessage("§7- §6/fm-hreset");
    p.sendMessage("§7- §6/fm-heal");
    p.sendMessage("§7- §6/fm-pkill");
    p.sendMessage("§7- §6/fm-fuck");
    p.sendMessage("");
    p.sendMessage("§bNext Page§8>> §6/fm-cmds-3");
    p.sendMessage("§a=========§3FunMessages§8-§2Liste§a=========");
    p.sendMessage("");
    p.playSound(p.getLocation(), Sound.NOTE_PIANO, 1.0F, 1.0F);
    return true;
    }
    sender.sendMessage("§4Nope");
    return true;
    }

    if (cmd.getName().equalsIgnoreCase("fm-cmds-3"))
    {
    if (p != null)
    {
    p.sendMessage("");
    p.sendMessage("§a=========§3FunMessages§8-§2Liste§a=========");
    p.sendMessage("§7- §6/fm-uuid");
    p.sendMessage("§7- §6/fm-ip");
    p.sendMessage("§7- §6/fm-fly-on");
    p.sendMessage("§7- §6/fm-fly-off");
    p.sendMessage("§7- §6/fm-jump-on");
    p.sendMessage("§7- §6/fm-jump-off");
    p.sendMessage("§7- §5/fm-gm-0");
    p.sendMessage("§7- §5/fm-gm-1");
    p.sendMessage("§7- §5/fm-gm-2");
    p.sendMessage("§7- §5/fm-gm-3");
    p.sendMessage("§7- §6/fm-color-<color> §7| §aafter 'color-' press TAB ");
    p.sendMessage("");
    p.sendMessage("§bNext Page§8>> §6No page yet");
    p.sendMessage("§a=========§3FunMessages§8-§2Liste§a=========");
    p.sendMessage("");
    p.playSound(p.getLocation(), Sound.NOTE_PIANO, 1.0F, 1.0F);
    return true;
    }
    sender.sendMessage("§4Nope");
    return true;
    }

    if (cmd.getName().equalsIgnoreCase("fm-death"))
    {
    if (p != null)
    {
    p.sendMessage("");
    p.sendMessage("§a=========§3FunMessages§a=========");
    p.sendMessage("§bPlayed Sound§8: §4Death");
    p.sendMessage("§a=========§3FunMessages§a=========");
    p.sendMessage("");
    p.playSound(p.getLocation(), Sound.WITHER_DEATH, 1.0F, 1.0F);
    return true;
    }
    sender.sendMessage("§4Nope");
    return true;
    }

    if (cmd.getName().equalsIgnoreCase("fm-bempty"))
    {
    if (p != null)
    {
    p.sendMessage("");
    p.sendMessage("§a=========§3FunMessages§a=========");
    p.sendMessage("§bPlayed Sound§8: §cBukkity empty");
    p.sendMessage("§a=========§3FunMessages§a=========");
    p.sendMessage("");
    p.playSound(p.getLocation(), Sound.WOLF_BARK, 1.0F, 1.0F);
    return true;
    }
    sender.sendMessage("§4Nope");
    return true;
    }
    return false;
    }
    }

    Der MAIN Teil ist kürzer, weil er sonst zu lang war!
     
    #1
  2. Vanityra
    Offline

    Vanityra

    Registriert seit:
    9. Juni 2015
    Beiträge:
    219
    Ort:
    Heidelberg
    Minecraft:
    Vanityra
    Nutz das Ganze mal als Code.

    [_CODE] Ohne _ ;)
     
    #2
  3. Du registrierst den Eventlistener mehrfach. Einmal im Constructor und einmal in der Main Klasse.

    Das passiert eben, wenn man code kopiert und nicht selber Programmieren kann.

    PS: Logik ist eine der wichtigsten Grunddisziplinen der Informatik.
     
    #3
    Payno4 und Inkemann gefällt das.
  4. haggishunter2001
    Offline

    haggishunter2001

    Registriert seit:
    11. Februar 2014
    Beiträge:
    6
    Ort:
    Oberntudorf
    Minecraft:
    Präsident_Kuh
    Ich hatte ihn mir abgeguckt, weil ich halt noch KEINE config.yml erstellen konnte :(

    Könnt ihr mir da helfen?
     
    #4
  5. ShareLock
    Offline

    ShareLock

    Registriert seit:
    2. November 2011
    Beiträge:
    70
    Java lernen und sich dann die Javadoc ansehen [siehe Beitrag von @manf ]. Eine statische Methode loadConfiguration mit einem File zu laden aus der Klasse YamlConfiguration wird ja wohl selbst der blutigste Anfänger schaffen.
     
    #5
    [Dev] iTzSasukeHDxLP und Payno4 gefällt das.