Major update of the code #3

Closed
Belphemur wants to merge 7 commits from master into master
11 changed files with 1375 additions and 993 deletions
Showing only changes of commit 3aa12cbe54 - Show all commits

View File

@@ -25,12 +25,14 @@ import java.util.Map;
import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPlayer;
import net.minecraft.server.ItemInWorldManager; import net.minecraft.server.ItemInWorldManager;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerInventory;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.google.common.collect.MapMaker; import com.google.common.collect.MapMaker;
@@ -42,6 +44,7 @@ import com.google.common.collect.MapMaker;
public class InventoryManager { public class InventoryManager {
public static InventoryManager INSTANCE; public static InventoryManager INSTANCE;
private final Map<Player, ACPlayerInventory> replacedInv = new MapMaker().makeMap(); private final Map<Player, ACPlayerInventory> replacedInv = new MapMaker().makeMap();
private final Map<String, ACPlayerInventory> offlineInv = new MapMaker().makeMap();
/** /**
* *
@@ -61,9 +64,23 @@ public class InventoryManager {
void closeOfflineInv(final Player p) { void closeOfflineInv(final Player p) {
onQuit(p); onQuit(p);
offlineInv.remove(p.getName());
p.saveData(); p.saveData();
} }
public void onJoin(Player p) {
ACPlayerInventory inv = offlineInv.get(p.getName());
if (inv == null) {
return;
}
if (inv instanceof ACOfflinePlayerInventory) {
CraftPlayer cp = (CraftPlayer) p;
PlayerInventory mcInv = ((CraftInventoryPlayer) cp.getInventory()).getInventory();
mcInv.items = inv.items;
mcInv.armor = inv.armor;
}
}
/** /**
* Open the inventory of an offline player * Open the inventory of an offline player
* *
@@ -128,16 +145,17 @@ public class InventoryManager {
} }
private void openInv(final Player sender, final Player target, final boolean offline) { private void openInv(final Player sender, final Player target, final boolean offline) {
//Permissions checks // Permissions checks
if (!sender.hasPermission("OpenInv.override") && target.hasPermission("OpenInv.exempt")) { if (!sender.hasPermission("OpenInv.override") && target.hasPermission("OpenInv.exempt")) {
sender.sendMessage(ChatColor.RED + target.getDisplayName() + "'s inventory is protected!"); sender.sendMessage(ChatColor.RED + target.getDisplayName()
return ; + "'s inventory is protected!");
} return;
}
if((!sender.hasPermission("OpenInv.crossworld") && !sender.hasPermission("OpenInv.override")) && if ((!sender.hasPermission("OpenInv.crossworld") && !sender
target.getWorld() != sender.getWorld()){ .hasPermission("OpenInv.override")) && target.getWorld() != sender.getWorld()) {
sender.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!"); sender.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!");
return ; return;
} }
final ACPlayerInventory inventory = getInventory(target, offline); final ACPlayerInventory inventory = getInventory(target, offline);
final EntityPlayer eh = ((CraftPlayer) sender).getHandle(); final EntityPlayer eh = ((CraftPlayer) sender).getHandle();
@@ -149,6 +167,7 @@ public class InventoryManager {
if (inventory == null) { if (inventory == null) {
if (offline) { if (offline) {
inventory = new ACOfflinePlayerInventory(player); inventory = new ACOfflinePlayerInventory(player);
offlineInv.put(player.getName(), inventory);
} else { } else {
inventory = new ACPlayerInventory(player); inventory = new ACPlayerInventory(player);
} }

View File

@@ -38,6 +38,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import balor.OpenInv.InventoryManager; import balor.OpenInv.InventoryManager;
@@ -49,6 +50,11 @@ public class OpenInvPlayerListener implements Listener {
plugin = scrap; plugin = scrap;
} }
@EventHandler(priority = EventPriority.LOWEST)
public void onJoin(PlayerJoinEvent event) {
InventoryManager.INSTANCE.onJoin(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK if (event.getAction() == Action.RIGHT_CLICK_BLOCK