This commit is contained in:
rockyhawk64 2021-07-04 18:15:39 +10:00
parent a88ffc13b4
commit 87a5765fd6
7 changed files with 61 additions and 81 deletions

View File

@ -1,4 +1,4 @@
version: 3.15.7.0
version: 3.15.7.1
main: me.rockyhawk.commandpanels.CommandPanels
name: CommandPanels
author: RockyHawk

View File

@ -6,7 +6,7 @@ import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.classresources.ExecuteOpenVoids;
import me.rockyhawk.commandpanels.classresources.GetCustomHeads;
import me.rockyhawk.commandpanels.classresources.ItemCreation;
import me.rockyhawk.commandpanels.classresources.OpenEditorGuis;
import me.rockyhawk.commandpanels.ingameeditor.OpenEditorGuis;
import me.rockyhawk.commandpanels.classresources.item_fall.ItemFallManager;
import me.rockyhawk.commandpanels.classresources.placeholders.CreateText;
import me.rockyhawk.commandpanels.classresources.placeholders.HexColours;

View File

@ -2,6 +2,7 @@ package me.rockyhawk.commandpanels.ingameeditor;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
@ -372,19 +373,18 @@ public class EditorUserInput implements Listener {
}
try {
int loc = Integer.parseInt(e.getMessage());
if (loc >= 34 || loc <= -1) {
//if the number isn't between 1-9
p.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.GREEN + "Choose an integer between 0 to 33!"));
if (loc >= 36 || loc <= -1) {
//if the number isn't between the numbers
p.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.GREEN + "Choose an integer between 0 to 35!"));
return;
}
p.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.GREEN + "Set Hotbar Location to " + loc + "!"));
//because it needs to convert 1-9 to 0-8 for in the panel
loc -= 1;
cf.set("open-with-item.stationary", loc);
savePanelFile(cf, cfile, panelName, panelFile);
} catch (Exception io) {
plugin.debug(io,p);
}
plugin.hotbar.reloadHotbarSlots();
break;
case "panel.hotbar.name":
cf.set("open-with-item.name",e.getMessage());

View File

@ -316,7 +316,7 @@ public class EditorUtils implements Listener {
boolean found = false;
boolean hotbarItems = false;
try {
//neew to loop through files to get file names
//need to loop through files to get file names
for(Panel panel : plugin.panelList) { //will loop through all the files in folder
if(e.getView().getTitle().equals("Panel Settings: " + panel.getName())){
panelName = panel.getName();
@ -440,7 +440,7 @@ public class EditorUtils implements Listener {
}
if(e.getSlot() == 42 && hotbarItems){
plugin.editorInputStrings.add(new String[]{p.getName(),panelName,"panel.hotbar.stationary"});
p.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.WHITE + "Enter Location (1 to 9)"));
p.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.WHITE + "Enter Location (0 to 35)"));
p.closeInventory();
}
if(e.getSlot() == 44 && hotbarItems){

View File

@ -1,4 +1,4 @@
package me.rockyhawk.commandpanels.classresources;
package me.rockyhawk.commandpanels.ingameeditor;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
@ -306,7 +306,7 @@ public class OpenEditorGuis {
temp = new ItemStack(Material.BEDROCK, 1);
lore.clear();
lore.add(ChatColor.GRAY + "Hotbar location for the item");
lore.add(ChatColor.GRAY + "choose a number from 0 to 33");
lore.add(ChatColor.GRAY + "choose a number from 0 to 35");
if (cf.contains("open-with-item.stationary")) {
lore.add(ChatColor.WHITE + "-------------------------");
int location = cf.getInt("open-with-item.stationary");

View File

@ -2,7 +2,8 @@ package me.rockyhawk.commandpanels.openwithitem;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.apache.commons.lang.ObjectUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -15,7 +16,7 @@ public class HotbarItemLoader {
this.plugin = pl;
}
//stationary slots 0-8 are the hotbar, using 9-33 for inside the inventory
//stationary slots 0-8 are the hotbar, using 9-35 for inside the inventory
HashMap<Integer,Panel> stationaryItems = new HashMap<>();
//will compile the ArrayList {slot 0-4, index of panelNames}
@ -26,6 +27,10 @@ public class HotbarItemLoader {
stationaryItems.put(panel.getConfig().getInt("open-with-item.stationary"), panel.copy());
}
}
//update hotbar items for all players when reloaded
for(Player p : Bukkit.getServer().getOnlinePlayers()){
plugin.hotbar.updateHotbarItems(p);
}
}
public Set<Integer> getStationaryItemSlots(){
@ -68,7 +73,7 @@ public class HotbarItemLoader {
if (plugin.nbt.getNBT(invItem, "CommandPanelsHotbar") == null) {
return false;
}
}catch(NullPointerException nu){
}catch(IllegalArgumentException | NullPointerException nu){
return false;
}
for(Panel panel : plugin.panelList) {
@ -98,4 +103,43 @@ public class HotbarItemLoader {
}
return false;
}
public void updateHotbarItems(Player p){
/*
If the player is using disabled-worlds/enabled-worlds
and they change worlds, it will check if the player can have the item
and if they can, it gives the item. This is because onRespawn doesn't
give the item to the player in all the worlds that it could automatically.
The player will of course need a plugin to split inventories between worlds
for this to take effect. I don't want to delete the item on the wrong world
because then it might overwrite one of their actual slots upon rejoining the enabled world.
*/
if(!plugin.openWithItem){
//if none of the panels have open-with-item
return;
}
//remove any old hotbar items
for(int i = 0; i <= 35; i++){
try {
if (plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar") != null) {
p.getInventory().setItem(i,new ItemStack(Material.AIR));
}
}catch(NullPointerException | IllegalArgumentException ignore){}
}
//add current hotbar items
for(Panel panel : plugin.panelList) { //will loop through all the files in folder
if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
continue;
}
if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm")) && panel.hasHotbarItem()) {
ItemStack s = panel.getHotbarItem(p);
if(panel.getConfig().contains("open-with-item.stationary")) {
p.getInventory().setItem(panel.getConfig().getInt("open-with-item.stationary"),s);
}
}
}
}
}

View File

@ -68,52 +68,11 @@ public class UtilsOpenWithItem implements Listener {
}
@EventHandler
public void onWorldChange(PlayerChangedWorldEvent e){
/*
This world change event is added so if the player is using disabled-worlds
and they change worlds, it will check if the player can have the item
and if they can, it gives the item. This is because onRespawn doesn't
give the item to the player in all the worlds that it could automatically.
The player will of course need a plugin to split inventories between worlds
for this to take effect. I don't want to delete the item on the wrong world
because then it might overwrite one of their actual slots upon rejoining the enabled world.
*/
if(!plugin.openWithItem){
//if none of the panels have open-with-item
return;
}
Player p = e.getPlayer();
for(Panel panel : plugin.panelList) { //will loop through all the files in folder
if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
continue;
}
if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm")) && panel.hasHotbarItem()) {
ItemStack s = panel.getHotbarItem(p);
if(panel.getConfig().contains("open-with-item.stationary")) {
p.getInventory().setItem(panel.getConfig().getInt("open-with-item.stationary"),s);
}
}
}
plugin.hotbar.updateHotbarItems(e.getPlayer());
}
@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent e){
if(!plugin.openWithItem){
//if none of the panels have open-with-item
return;
}
Player p = e.getPlayer();
for(Panel panel : plugin.panelList) { //will loop through all the files in folder
if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
continue;
}
if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm")) && panel.hasHotbarItem()) {
ItemStack s = panel.getHotbarItem(p);
if(panel.getConfig().contains("open-with-item.stationary")){
p.getInventory().setItem(panel.getConfig().getInt("open-with-item.stationary"), s);
}
}
}
plugin.hotbar.updateHotbarItems(e.getPlayer());
}
@EventHandler
public void onPlayerDeath(PlayerDeathEvent e){
@ -133,30 +92,7 @@ public class UtilsOpenWithItem implements Listener {
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e){
if(!plugin.openWithItem){
//if none of the panels have open-with-item
return;
}
Player p = e.getPlayer();
for(Panel panel : plugin.panelList) { //will loop through all the files in folder
if(!panel.getConfig().contains("open-with-item.stationary")){
continue;
}
if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))){
if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
continue;
}
ItemStack s = panel.getHotbarItem(p);
p.getInventory().setItem(panel.getConfig().getInt("open-with-item.stationary"), s);
}else{
//if the player has an item that they have no permission for, remove it
ItemStack s;
s = panel.getHotbarItem(p);
if (p.getInventory().getItem(panel.getConfig().getInt("open-with-item.stationary")).isSimilar(s)) {
p.getInventory().setItem(panel.getConfig().getInt("open-with-item.stationary"), null);
}
}
}
plugin.hotbar.updateHotbarItems(e.getPlayer());
}
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent e){