Skip to content

Commit

Permalink
Reward and UI updates
Browse files Browse the repository at this point in the history
  • Loading branch information
NickImpact committed Jul 16, 2018
1 parent e2ae837 commit f247f66
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.nickimpact.impactor.api.rewards;

public interface IdentifiableReward<T> extends Reward<T> {

/**
* Retrieves the ID for this reward. This will be the primary key for referencing
* reward types.
*
* @return The ID of the reward.
*/
String getID();

/**
* Retrieves the name of the reward. This represents the actual display name for the reward.
*
* @return The name of the reward.
*/
String getName();
}
16 changes: 4 additions & 12 deletions src/main/java/com/nickimpact/impactor/api/rewards/Reward.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@

import org.spongepowered.api.entity.living.player.Player;

public interface Reward {
public interface Reward<T> {

/**
* Retrieves the ID for this reward. This will be the primary key for referencing
* reward types.
* Returns an instance of the reward based on the specs of its design.
*
* @return The ID of the reward.
* @return An instance of the defined reward
*/
String getID();

/**
* Retrieves the name of the reward. This represents the actual display name for the reward.
*
* @return The name of the reward.
*/
String getName();
T getReward();

/**
* Gives the current instance of a Reward to a player.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.nickimpact.impactor.api.rewards.impl;

import com.nickimpact.impactor.api.rewards.Reward;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;

public class CommandReward implements Reward<String> {

private String command;

public CommandReward(String command) {
this.command = command;
}

@Override
public String getReward() {
return this.command;
}

@Override
public void give(Player player) throws Exception {
Sponge.getCommandManager().process(Sponge.getServer().getConsole(), command);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.nickimpact.impactor.api.rewards.impl;

import com.nickimpact.impactor.api.rewards.Reward;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;
import scala.actors.threadpool.Arrays;

import java.util.List;

public class CommandSeriesReward implements Reward<List<String>> {

private List<String> commands;

public CommandSeriesReward(List<String> commands) {
this.commands = commands;
}

public CommandSeriesReward(String... commands) {
this.commands = Arrays.asList(commands);
}

@Override
public List<String> getReward() {
return this.commands;
}

@Override
public void give(Player player) throws Exception {
for(String cmd : this.commands) {
Sponge.getCommandManager().process(Sponge.getServer().getConsole(), cmd);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.nickimpact.impactor.api.rewards.impl;

import com.nickimpact.impactor.api.rewards.IdentifiableReward;
import lombok.Getter;

@Getter
public class IdentifiableCommandReward extends CommandReward implements IdentifiableReward<String> {

private String ID;
private String name;

public IdentifiableCommandReward(String ID, String name, String command) {
super(command);
this.ID = ID;
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.nickimpact.impactor.api.rewards.impl;

import com.nickimpact.impactor.api.rewards.IdentifiableReward;
import lombok.Getter;

import java.util.List;

@Getter
public class IdentifiableCommandSeriesReward extends CommandSeriesReward implements IdentifiableReward<List<String>> {

private String ID;
private String name;

public IdentifiableCommandSeriesReward(String ID, String name, List<String> commands) {
super(commands);
this.ID = ID;
this.name = name;
}

public IdentifiableCommandSeriesReward(String ID, String name, String... commands) {
super(commands);
this.ID = ID;
this.name = name;
}
}
59 changes: 59 additions & 0 deletions src/main/java/com/nickimpact/impactor/gui/v2/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,65 @@ public Page update(List<Icon> icons, InventoryDimension dimension, int rOffset,
int pages = icons.isEmpty() ? 1 : icons.size() % capacity == 0 ? icons.size() / capacity : icons.size() / capacity + 1;
for(int i = 1; i <= pages; i++) {
Layout.Builder page = Layout.builder().from(layout).page(icons.subList((i - 1) * capacity, i == pages ? icons.size() : i * capacity), dimension, rOffset, cOffset);
for(Map.Entry<PageIconType, PageIcon> pgt : pageIcons.entrySet()) {
Icon icon = Icon.from(pgt.getValue().rep.getDisplay());
int slot = pgt.getValue().slot;
switch (pgt.getKey()) {
case FIRST:
icon = this.update(
icon,
TextSerializers.FORMATTING_CODE.deserialize(
ImpactorCore.getInstance().getMsgConfig().get(MsgConfigKeys.PAGES_FIRST).replaceAll("\\{\\{page}}", "1")
),
i,
1
);
break;
case PREV:
icon = this.update(
icon,
TextSerializers.FORMATTING_CODE.deserialize(
ImpactorCore.getInstance().getMsgConfig().get(MsgConfigKeys.PAGES_PREV).replaceAll("\\{\\{page}}", "" + (i == 1 ? pages : i - 1))
),
i,
i == 1 ? pages : i - 1
);
break;
case CURRENT:
icon = this.update(
icon,
TextSerializers.FORMATTING_CODE.deserialize(
ImpactorCore.getInstance().getMsgConfig().get(MsgConfigKeys.PAGES_CURR).replaceAll("\\{\\{page}}", "" + i)
),
i,
i
);
break;
case NEXT:
icon = this.update(
icon,
TextSerializers.FORMATTING_CODE.deserialize(
ImpactorCore.getInstance().getMsgConfig().get(MsgConfigKeys.PAGES_NEXT).replaceAll("\\{\\{page}}", "" + (i == pages ? 1 : i + 1))
),
i,
i == pages ? 1 : i + 1
);
break;
case LAST:
icon = this.update(
icon,
TextSerializers.FORMATTING_CODE.deserialize(
ImpactorCore.getInstance().getMsgConfig().get(MsgConfigKeys.PAGES_FIRST).replaceAll("\\{\\{page}}", "" + pages)
),
i,
pages
);
break;
}

page.slot(icon, slot);
}

this.views.get(i - 1).define(page.build());
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/nickimpact/impactor/gui/v2/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void setSlot(int index, Icon icon) {
public void open(Player player) {
player.openInventory(this.inventory);
if(this.debugEnabled()) {
plugin.getLogger().send(Logger.Prefixes.DEBUG, Lists.newArrayList(
ImpactorCore.getInstance().getLogger().send(Logger.Prefixes.DEBUG, Lists.newArrayList(
Text.of("Opening Inventory for ", player.getName(), "..."),
Text.of(" Title: ", this.inventory.getProperty(InventoryTitle.class, InventoryTitle.PROPERTY_NAME).get().getValue()),
Text.of(" Provider: ", this.plugin.getPluginInfo().getName(), "-", this.plugin.getPluginInfo().getVersion())
Expand All @@ -87,7 +87,7 @@ public void open(Player player) {
public void close(Player player) {
player.closeInventory();
if(this.debugEnabled()) {
plugin.getLogger().send(Logger.Prefixes.DEBUG, Lists.newArrayList(
ImpactorCore.getInstance().getLogger().send(Logger.Prefixes.DEBUG, Lists.newArrayList(
Text.of("Closing Inventory for ", player.getName(), "..."),
Text.of(" Title: ", this.inventory.getProperty(InventoryTitle.class, InventoryTitle.PROPERTY_NAME).get().getValue()),
Text.of(" Provider: ", this.plugin.getPluginInfo().getName(), "-", this.plugin.getPluginInfo().getVersion())
Expand All @@ -111,7 +111,7 @@ public void clear(int... slots) {
private void processClick(ClickInventoryEvent event) {
if(this.debugEnabled()) {
Player player = event.getCause().first(Player.class).orElse(null);
plugin.getLogger().send(Logger.Prefixes.DEBUG, Lists.newArrayList(
ImpactorCore.getInstance().getLogger().send(Logger.Prefixes.DEBUG, Lists.newArrayList(
Text.of("Processing inventory click event for ", player == null ? "Unknown" : player.getName(), "..."),
Text.of(" Title: ", this.inventory.getProperty(InventoryTitle.class, InventoryTitle.PROPERTY_NAME).get().getValue()),
Text.of(" Provider: ", this.plugin.getPluginInfo().getName(), "-", this.plugin.getPluginInfo().getVersion())
Expand All @@ -137,7 +137,7 @@ private void processOpen(InteractInventoryEvent.Open event) {
if(openAction != null) {
if(this.debugEnabled()) {
Player player = event.getCause().first(Player.class).orElse(null);
plugin.getLogger().send(Logger.Prefixes.DEBUG, Lists.newArrayList(
ImpactorCore.getInstance().getLogger().send(Logger.Prefixes.DEBUG, Lists.newArrayList(
Text.of("Processing inventory open event for ", player == null ? "Unknown" : player.getName(), "..."),
Text.of(" Title: ", this.inventory.getProperty(InventoryTitle.class, InventoryTitle.PROPERTY_NAME).get().getValue()),
Text.of(" Provider: ", this.plugin.getPluginInfo().getName(), "-", this.plugin.getPluginInfo().getVersion())
Expand All @@ -151,7 +151,7 @@ private void processClose(InteractInventoryEvent.Close event) {
if(closeAction != null) {
if(this.debugEnabled()) {
Player player = event.getCause().first(Player.class).orElse(null);
plugin.getLogger().send(Logger.Prefixes.DEBUG, Lists.newArrayList(
ImpactorCore.getInstance().getLogger().send(Logger.Prefixes.DEBUG, Lists.newArrayList(
Text.of("Processing inventory close event for ", player == null ? "Unknown" : player.getName(), "..."),
Text.of(" Title: ", this.inventory.getProperty(InventoryTitle.class, InventoryTitle.PROPERTY_NAME).get().getValue()),
Text.of(" Provider: ", this.plugin.getPluginInfo().getName(), "-", this.plugin.getPluginInfo().getVersion())
Expand Down

0 comments on commit f247f66

Please sign in to comment.