Always use the username of the command target if the command exceeds the maximum chat message length and command blocks need to be used
This commit is contained in:
@@ -3,6 +3,7 @@ package exopandora.worldhandler.usercontent.factory;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -34,13 +35,13 @@ public class ActionHandlerFactory
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ActionHandler createActionHandler(Content content, Action action)
|
||||
public ActionHandler createActionHandler(Content content, Action action, Supplier<String> player)
|
||||
{
|
||||
return this.createActionHandler(content, action, null);
|
||||
return this.createActionHandler(content, action, player, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ActionHandler createActionHandler(Content content, Action action, String value)
|
||||
public ActionHandler createActionHandler(Content content, Action action, Supplier<String> player, String value)
|
||||
{
|
||||
if(action == null)
|
||||
{
|
||||
@@ -76,7 +77,7 @@ public class ActionHandlerFactory
|
||||
{
|
||||
if(action.getAttributes().getValue() == null)
|
||||
{
|
||||
CommandHelper.sendCommand(this.builders.get(action.getAttributes().getCommand()).getObject());
|
||||
CommandHelper.sendCommand(player.get(), this.builders.get(action.getAttributes().getCommand()).getObject());
|
||||
}
|
||||
else if(!action.getAttributes().getValue().isEmpty())
|
||||
{
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ButtonFactory extends WidgetFactory
|
||||
button.getDimensions().getHeight(),
|
||||
TextUtils.formatNonnull(button.getText()),
|
||||
TextUtils.formatNonnull(button.getAttributes() != null ? button.getAttributes().getTooltip() : null),
|
||||
this.getActionHandlerFactory().createActionHandler(content, button.getAction())
|
||||
this.getActionHandlerFactory().createActionHandler(content, button.getAction(), container::getPlayer)
|
||||
);
|
||||
}
|
||||
else if(JsonButton.Type.ITEM_BUTTON.equals(button.getType()))
|
||||
@@ -58,7 +58,7 @@ public class ButtonFactory extends WidgetFactory
|
||||
button.getDimensions().getWidth(),
|
||||
button.getDimensions().getHeight(),
|
||||
ForgeRegistries.ITEMS.getValue(new ResourceLocation(button.getAttributes().getItem())),
|
||||
this.getActionHandlerFactory().createActionHandler(content, button.getAction())
|
||||
this.getActionHandlerFactory().createActionHandler(content, button.getAction(), container::getPlayer)
|
||||
);
|
||||
}
|
||||
else if(JsonButton.Type.ICON_BUTTON.equals(button.getType()))
|
||||
@@ -71,7 +71,7 @@ public class ButtonFactory extends WidgetFactory
|
||||
button.getDimensions().getHeight(),
|
||||
button.getAttributes().getIcon(),
|
||||
TextUtils.formatNonnull(button.getAttributes().getTooltip()),
|
||||
this.getActionHandlerFactory().createActionHandler(content, button.getAction())
|
||||
this.getActionHandlerFactory().createActionHandler(content, button.getAction(), container::getPlayer)
|
||||
);
|
||||
}
|
||||
else if(JsonButton.Type.LIST_BUTTON.equals(button.getType()))
|
||||
@@ -84,7 +84,7 @@ public class ButtonFactory extends WidgetFactory
|
||||
button.getDimensions().getWidth(),
|
||||
button.getDimensions().getHeight(),
|
||||
container,
|
||||
new UsercontentLogicMapped<JsonButton.Type>(this.getApi(), this.getActionHandlerFactory(), content, button)
|
||||
new UsercontentLogicMapped<JsonButton.Type>(this.getApi(), this.getActionHandlerFactory(), content, button, container::getPlayer)
|
||||
);
|
||||
}
|
||||
else if(JsonButton.Type.SLIDER.equals(button.getType()))
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package exopandora.worldhandler.usercontent.factory;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.gui.button.GuiButtonBase;
|
||||
@@ -40,7 +42,7 @@ public class MenuFactory extends WidgetFactory
|
||||
menu.getDimensions().getHeight(),
|
||||
menu.getAttributes().getLength(),
|
||||
container,
|
||||
new UsercontentLogicPageList<JsonMenu.Type>(this.getApi(), this.getActionHandlerFactory(), content, container, menu)
|
||||
new UsercontentLogicPageList<JsonMenu.Type>(this.getApi(), this.getActionHandlerFactory(), content, container, menu, container::getPlayer)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,9 +54,9 @@ public class MenuFactory extends WidgetFactory
|
||||
{
|
||||
private final Container container;
|
||||
|
||||
public UsercontentLogicPageList(UsercontentAPI api, ActionHandlerFactory actionHandlerFactory, Content content, Container container, JsonWidget<T> widget)
|
||||
public UsercontentLogicPageList(UsercontentAPI api, ActionHandlerFactory actionHandlerFactory, Content content, Container container, JsonWidget<T> widget, Supplier<String> player)
|
||||
{
|
||||
super(api, actionHandlerFactory, content, widget);
|
||||
super(api, actionHandlerFactory, content, widget, player);
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package exopandora.worldhandler.usercontent.factory;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import exopandora.worldhandler.WorldHandler;
|
||||
import exopandora.worldhandler.gui.content.Content;
|
||||
import exopandora.worldhandler.gui.menu.impl.ILogicMapped;
|
||||
@@ -42,13 +44,15 @@ public abstract class WidgetFactory
|
||||
private final UsercontentAPI api;
|
||||
private final Content content;
|
||||
private final JsonWidget<T> widget;
|
||||
private final Supplier<String> player;
|
||||
|
||||
public UsercontentLogicMapped(UsercontentAPI api, ActionHandlerFactory actionHandlerFactory, Content content, JsonWidget<T> widget)
|
||||
public UsercontentLogicMapped(UsercontentAPI api, ActionHandlerFactory actionHandlerFactory, Content content, JsonWidget<T> widget, Supplier<String> player)
|
||||
{
|
||||
this.api = api;
|
||||
this.actionHandlerFactory = actionHandlerFactory;
|
||||
this.content = content;
|
||||
this.widget = widget;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,7 +78,7 @@ public abstract class WidgetFactory
|
||||
try
|
||||
{
|
||||
this.api.updateValue(this.widget.getAttributes().getId(), item.getId());
|
||||
ActionHandler action = this.actionHandlerFactory.createActionHandler(this.content, this.widget.getAction(), item.getId());
|
||||
ActionHandler action = this.actionHandlerFactory.createActionHandler(this.content, this.widget.getAction(), this.player, item.getId());
|
||||
|
||||
if(action != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user