CombatLog (Logging Inventory)

Discussion in 'Plugin Development' started by YoloSanta, Jan 11, 2018.

Thread Status:
Not open for further replies.
  1. Offline


    How would I go about when saving a loggers inventory?

    More In-depth: When a player is hit in-game, they cannot log out the server for 30 seconds, if they do a villager will spawn in their place to act as them. When the villager spawns it should have the inventory of the person that logged out. So once it dies, it drops the players inventory.

    Current Code:
    package me.yolosanta.combatlog.listeners;
    import java.util.ArrayList;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.plugin.Plugin;
    public class AntiLog implements Listener {
            public ArrayList<String> antilog = new ArrayList<String>();
            public void antiLog(PlayerQuitEvent e) {
                    Player p = e.getPlayer();
                    if(this.antilog.contains(p.getName())) {
                            Bukkit.getServer().getWorld("world").spawnEntity(p.getLocation(), EntityType.VILLAGER);
            public void antiLogDMG(EntityDamageByEntityEvent e) {
                    if ((e.getDamager() instanceof Player) && ((e.getEntity() instanceof Player))) {
                            final Player player = (Player) e.getEntity();
                            final Player target = (Player) e.getDamager();
                            if ((!this.antilog.contains(player.getName())) && (!this.antilog.contains(target.getName()))) {
                                    player.sendMessage(ChatColor.RED + "You have entered into combat with " + target.getName());
                                    target.sendMessage(ChatColor.RED + "You have entered into combat with " + player.getName());
                                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask((Plugin) this, new Runnable() {
                                            public void run() {
                                                    if((AntiLog.this.antilog.contains(player.getName()) && (AntiLog.this.antilog.contains(target.getName())))) {
                                                            player.sendMessage(ChatColor.GREEN + "You are not longer in combat! You may logout.");
                                                            target.sendMessage(ChatColor.GREEN + "You are not longer in combat! You may logout.");
                                    }, 1000L);
  2. Offline


    Haven't tested this but it should work. Side note: you don't need to declare new memory space for the players and such they are already contained in the events (e) memory.

    public void antiLog(PlayerQuitEvent e) {
            if(this.antilog.contains(e.getPlayer().getName())) {      
                Villager villager = (Villager) Bukkit.getServer().getWorld("world").spawnEntity(e.getPlayer().getLocation(), EntityType.VILLAGER);
                for (ItemStack itemStack : e.getPlayer().getInventory()) {
    I duno if the villager will already have an inventory, but this will add all the items.
    Might want to somehow remove the players inventory as well if he is killed.
  3. Offline


    Didn't work.
  4. Offline


    The reason it does not work is because 1.8 does not contain the command. Only the newer versions (1.9 and higher) contain this method.

    From what I can tell, the utils for 1.8 all show that you need NMS in order to edit the villager's menu for that update.
    If you really need to stay on 1.8, use this util. However, I highly recommend you update and use the built-in methods instead.
Thread Status:
Not open for further replies.

Share This Page