mirror of
https://github.com/TotalFreedomMC/OpenInv.git
synced 2024-12-22 16:05:03 +00:00
Cross world disabled
This commit is contained in:
parent
8908cc918a
commit
70c75996c0
4 changed files with 59 additions and 18 deletions
|
@ -6,6 +6,7 @@ import lishid.openinv.utils.PlayerInventoryChest;
|
|||
|
||||
import net.minecraft.server.ContainerPlayer;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.ICrafting;
|
||||
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.event.Event;
|
||||
|
@ -24,6 +25,7 @@ import org.bukkit.plugin.Plugin;
|
|||
public class OpenInv extends JavaPlugin {
|
||||
private final OpenInvPlayerListener playerListener = new OpenInvPlayerListener(this);
|
||||
private final OpenInvEntityListener entityListener = new OpenInvEntityListener(this);
|
||||
//private final OpenInvInventoryListener inventoryListener = new OpenInvInventoryListener(this);
|
||||
public static PermissionHandler permissionHandler;
|
||||
public void onDisable() {
|
||||
}
|
||||
|
@ -47,10 +49,11 @@ public class OpenInv extends JavaPlugin {
|
|||
//pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Event.Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Event.Priority.Normal, this);
|
||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Event.Priority.Normal, this);
|
||||
//pm.registerEvent(Event.Type.INVENTORY_CLOSE, inventoryListener, Event.Priority.Normal, this);
|
||||
setupPermissions();
|
||||
// EXAMPLE: Custom code, here we just output some info so we can check all is well
|
||||
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
System.out.println("[" + pdfFile.getName() + "] version " + pdfFile.getVersion() + " is enabled!" );
|
||||
System.out.println("[" + pdfFile.getName() + "] version " + pdfFile.getVersion() + " enabled!" );
|
||||
|
||||
getCommand("openinv").setExecutor(new OpenInvPluginCommand(this));
|
||||
getCommand("searchinv").setExecutor(new SearchInvPluginCommand(this));
|
||||
|
@ -59,11 +62,19 @@ public class OpenInv extends JavaPlugin {
|
|||
|
||||
public static void ReplaceInv(CraftPlayer player)
|
||||
{
|
||||
EntityPlayer entityplayer = player.getHandle();
|
||||
entityplayer.inventory = new PlayerInventoryChest(entityplayer.inventory);
|
||||
entityplayer.defaultContainer = new ContainerPlayer(entityplayer.inventory, !entityplayer.world.isStatic);
|
||||
entityplayer.activeContainer = entityplayer.defaultContainer;
|
||||
player.setHandle(entityplayer);
|
||||
try{
|
||||
EntityPlayer entityplayer = player.getHandle();
|
||||
entityplayer.inventory = new PlayerInventoryChest(entityplayer.inventory);
|
||||
entityplayer.defaultContainer = new ContainerPlayer(entityplayer.inventory, !entityplayer.world.isStatic);
|
||||
entityplayer.activeContainer = entityplayer.defaultContainer;
|
||||
//sync
|
||||
((ICrafting)entityplayer).a(entityplayer.activeContainer, entityplayer.activeContainer.b());
|
||||
entityplayer.activeContainer.a();
|
||||
|
||||
player.setHandle(entityplayer);
|
||||
}
|
||||
catch(Exception e)
|
||||
{}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.bukkit.entity.Player;
|
|||
|
||||
public class OpenInvPluginCommand implements CommandExecutor {
|
||||
private final OpenInv plugin;
|
||||
public static HashMap<Player, PlayerInventoryChest> offlineInv = new HashMap<Player, PlayerInventoryChest>();
|
||||
public static HashMap<Player, OpenInvHistory> theOpenInvHistory = new HashMap<Player, OpenInvHistory>();
|
||||
public OpenInvPluginCommand(OpenInv plugin) {
|
||||
this.plugin = plugin;
|
||||
|
@ -30,6 +31,7 @@ public class OpenInvPluginCommand implements CommandExecutor {
|
|||
return true;
|
||||
}
|
||||
|
||||
//boolean Offline = false;
|
||||
Player player = (Player)sender;
|
||||
OpenInvHistory history = theOpenInvHistory.get(player);
|
||||
|
||||
|
@ -60,13 +62,11 @@ public class OpenInvPluginCommand implements CommandExecutor {
|
|||
if(history.lastPlayer != null)
|
||||
{
|
||||
target = this.plugin.getServer().getPlayer(history.lastPlayer);
|
||||
//EntityPlayer entply = new EntityPlayer(((CraftServer)this.plugin.getServer()).getServer(), ((CraftPlayer)player).getHandle().world, "", null);
|
||||
//CraftPlayer ply = new CraftPlayer((CraftServer) this.plugin.getServer(), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage("OpenInv history is empty!");
|
||||
return false;
|
||||
sender.sendMessage(ChatColor.RED + "OpenInv history is empty!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -77,19 +77,44 @@ public class OpenInvPluginCommand implements CommandExecutor {
|
|||
|
||||
if(target == null)
|
||||
{
|
||||
sender.sendMessage("Player not found!");
|
||||
return false;
|
||||
//Offline inv here...
|
||||
/*try{
|
||||
MinecraftServer server = ((CraftServer)this.plugin.getServer()).getServer();
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), args[0], new ItemInWorldManager(server.getWorldServer(0)));
|
||||
target = (entity == null) ? null : (Player) entity.getBukkitEntity();
|
||||
if(target != null)
|
||||
{
|
||||
Offline = true;
|
||||
target.loadData();
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(ChatColor.RED + "Player not found!");
|
||||
return false;
|
||||
}
|
||||
} catch(Exception e)
|
||||
{*/
|
||||
//sender.sendMessage("Error while retrieving offline player data!");
|
||||
sender.sendMessage(ChatColor.RED + "Player '" + args[0] + "' not found!");
|
||||
return true;
|
||||
/*}*/
|
||||
}
|
||||
if(target == player)
|
||||
{
|
||||
sender.sendMessage("Cannot target yourself!");
|
||||
return false;
|
||||
sender.sendMessage(ChatColor.RED + "Cannot OpenInv yourself!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!PermissionRelay.hasPermission(player, "OpenInv.override") && PermissionRelay.hasPermission(target, "OpenInv.exempt")) {
|
||||
sender.sendMessage(ChatColor.RED + target.getDisplayName() + "'s inventory is protected!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if((!PermissionRelay.hasPermission(player, "OpenInv.crossworld") && !PermissionRelay.hasPermission(player, "OpenInv.override")) &&
|
||||
target.getWorld() != player.getWorld()){
|
||||
sender.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!");
|
||||
return true;
|
||||
}
|
||||
|
||||
history.lastPlayer = target.getName();
|
||||
|
||||
|
@ -103,7 +128,12 @@ public class OpenInvPluginCommand implements CommandExecutor {
|
|||
{
|
||||
OpenInv.ReplaceInv((CraftPlayer) target);
|
||||
}
|
||||
|
||||
/*
|
||||
if(Offline && entitytarget.inventory instanceof PlayerInventoryChest)
|
||||
{
|
||||
offlineInv.put(target, (PlayerInventoryChest) entitytarget.inventory);
|
||||
}
|
||||
*/
|
||||
entityplayer.a(entitytarget.inventory);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -20,7 +20,7 @@ public class PlayerInventoryChest extends InventoryPlayer
|
|||
|
||||
@Override
|
||||
public String getName() {
|
||||
return ((EntityPlayer)this.d).displayName;
|
||||
return ((EntityPlayer)this.d).displayName + " (" + this.itemInHandIndex + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: OpenInv
|
||||
main: lishid.openinv.OpenInv
|
||||
version: 1.3.1
|
||||
version: 1.3.3
|
||||
author: lishid
|
||||
description: >
|
||||
This plugin allows you to open another player's inventory as a chest
|
||||
|
|
Loading…
Reference in a new issue