mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-22 04:37:42 +01:00
Fixed error when inputing custom item in shaped recipe
This commit is contained in:
parent
a8e8c43f51
commit
94eeb834ee
@ -11,53 +11,51 @@ import net.Indyuce.mmoitems.gui.PluginInventory;
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
|
||||
public class NewItemEdition implements Edition {
|
||||
private final ItemBrowser inv;
|
||||
private final ItemBrowser inv;
|
||||
|
||||
public NewItemEdition(ItemBrowser inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
public NewItemEdition(ItemBrowser inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginInventory getInventory() {
|
||||
return inv;
|
||||
}
|
||||
@Override
|
||||
public PluginInventory getInventory() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable(String... message) {
|
||||
inv.getPlayer().closeInventory();
|
||||
@Override
|
||||
public void enable(String... message) {
|
||||
inv.getPlayer().closeInventory();
|
||||
|
||||
inv.getPlayer().sendMessage(ChatColor.YELLOW + "" + ChatColor.STRIKETHROUGH + "-----------------------------------------------------");
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Write in the chat, the id of the new item.");
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Type 'cancel' to abort editing.");
|
||||
inv.getPlayer().sendMessage(ChatColor.YELLOW + "" + ChatColor.STRIKETHROUGH + "-----------------------------------------------------");
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Write in the chat, the id of the new item.");
|
||||
inv.getPlayer().sendMessage(MMOItems.plugin.getPrefix() + "Type 'cancel' to abort editing.");
|
||||
|
||||
/*
|
||||
* anvil text input feature. enables players to use an anvil to input
|
||||
* text if they are having conflicts with their chat management plugins.
|
||||
*/
|
||||
if (MMOItems.plugin.getConfig().getBoolean("anvil-text-input") && MythicLib.plugin.getVersion().isBelowOrEqual(1, 13)) {
|
||||
new AnvilGUI(this);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* Anvil text input feature. Enables players to use an anvil to input
|
||||
* text if they are having conflicts with their chat management plugins.
|
||||
*/
|
||||
if (MMOItems.plugin.getConfig().getBoolean("anvil-text-input") && MythicLib.plugin.getVersion().isBelowOrEqual(1, 13)) {
|
||||
new AnvilGUI(this);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* default chat edition feature
|
||||
*/
|
||||
new ChatEdition(this);
|
||||
inv.getPlayer().sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "Item Creation", "See chat.", 10, 40, 10);
|
||||
}
|
||||
// Default chat edition feature
|
||||
new ChatEdition(this);
|
||||
inv.getPlayer().sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "Item Creation", "See chat.", 10, 40, 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processInput(String input) {
|
||||
if (input.equals("cancel"))
|
||||
return true;
|
||||
@Override
|
||||
public boolean processInput(String input) {
|
||||
if (input.equals("cancel"))
|
||||
return true;
|
||||
|
||||
Bukkit.getScheduler().runTask(MMOItems.plugin, () -> Bukkit.dispatchCommand(inv.getPlayer(),
|
||||
"mmoitems create " + inv.getType().getId() + " " + input.toUpperCase().replace(" ", "_").replace("-", "_")));
|
||||
return true;
|
||||
}
|
||||
Bukkit.dispatchCommand(inv.getPlayer(),
|
||||
"mmoitems create " + inv.getType().getId() + " " + input.toUpperCase().replace(" ", "_").replace("-", "_"));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGoBack() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldGoBack() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class ChatEdition extends PlayerInputHandler implements Listener {
|
||||
public void a(AsyncPlayerChatEvent event) {
|
||||
if (getPlayer() != null && event.getPlayer().equals(getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
registerInput(event.getMessage());
|
||||
Bukkit.getScheduler().runTask(MMOItems.plugin, () -> registerInput(event.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,45 +1,51 @@
|
||||
package net.Indyuce.mmoitems.api.edition.input;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.Indyuce.mmoitems.api.edition.Edition;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class PlayerInputHandler {
|
||||
|
||||
/**
|
||||
* Saves the last inventory opened, the item data, and the last opened page;
|
||||
* allows for a much easier access to this data
|
||||
*/
|
||||
private final Edition edition;
|
||||
/**
|
||||
* Saves the last inventory opened, the item data, and the last opened page;
|
||||
* allows for a much easier access to this data
|
||||
*/
|
||||
private final Edition edition;
|
||||
|
||||
/**
|
||||
* Abstract class which lists all possible ways to retrieve player input
|
||||
*
|
||||
* @param edition The edition object
|
||||
*/
|
||||
public PlayerInputHandler(Edition edition) {
|
||||
this.edition = edition;
|
||||
}
|
||||
/**
|
||||
* Abstract class which lists all possible ways to retrieve player input
|
||||
*
|
||||
* @param edition The edition object
|
||||
*/
|
||||
public PlayerInputHandler(Edition edition) {
|
||||
this.edition = edition;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return edition.getInventory().getPlayer();
|
||||
}
|
||||
public Player getPlayer() {
|
||||
return edition.getInventory().getPlayer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the player input, closes the edition process if needed and
|
||||
* opens the previously opened GUI if needed. This method is protected
|
||||
* because it should only be ran by edition process classes
|
||||
*
|
||||
* @param input Player input
|
||||
*/
|
||||
protected void registerInput(String input) {
|
||||
if (!edition.processInput(input))
|
||||
return;
|
||||
/**
|
||||
* Processes the player input, closes the edition process if needed and
|
||||
* opens the previously opened GUI if needed. This method is protected
|
||||
* because it should only be ran by edition process classes.
|
||||
* For security this method should be called on the main server thread.
|
||||
*
|
||||
* @param input Player input
|
||||
*/
|
||||
protected void registerInput(@NotNull String input) {
|
||||
Validate.isTrue(Bukkit.isPrimaryThread(), "Input must be registered on primary thread");
|
||||
|
||||
if (edition.shouldGoBack())
|
||||
edition.getInventory().open();
|
||||
close();
|
||||
}
|
||||
if (!edition.processInput(input))
|
||||
return;
|
||||
|
||||
public abstract void close();
|
||||
if (edition.shouldGoBack())
|
||||
edition.getInventory().open();
|
||||
close();
|
||||
}
|
||||
|
||||
public abstract void close();
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public abstract class EditionInventory extends PluginInventory {
|
||||
* base item data
|
||||
*
|
||||
* @deprecated Not being used atm, the item editor only lets the user
|
||||
* edit the base item data.
|
||||
* edit the base item data.
|
||||
*/
|
||||
@Deprecated
|
||||
private TemplateModifier editedModifier = null;
|
||||
@ -137,9 +137,9 @@ public abstract class EditionInventory extends PluginInventory {
|
||||
|
||||
/**
|
||||
* @return The currently edited configuration section. It depends on if the
|
||||
* player is editing the base item data or editing a modifier. This
|
||||
* config section contains item data (either the 'base' config
|
||||
* section or the 'stats' section for modifiers).
|
||||
* player is editing the base item data or editing a modifier. This
|
||||
* config section contains item data (either the 'base' config
|
||||
* section or the 'stats' section for modifiers).
|
||||
*/
|
||||
public ConfigurationSection getEditedSection() {
|
||||
ConfigurationSection config = configFile.getConfig().getConfigurationSection(template.getId());
|
||||
@ -180,16 +180,9 @@ public abstract class EditionInventory extends PluginInventory {
|
||||
template = MMOItems.plugin.getTemplates().getTemplate(template.getType(), template.getId());
|
||||
//editedModifier = editedModifier != null ? template.getModifier(editedModifier.getId()) : null;
|
||||
|
||||
/*
|
||||
* The instant task brings the Bukkit event call from the
|
||||
* updateCachedItem() method back to SYNC since registerTemplateEdition()
|
||||
* is called ASYNC inside of an AsyncChatEvent
|
||||
*/
|
||||
Bukkit.getScheduler().runTask(MMOItems.plugin, () -> {
|
||||
updateCachedItem();
|
||||
refreshInventory();
|
||||
//open();
|
||||
});
|
||||
updateCachedItem();
|
||||
refreshInventory();
|
||||
//open();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user