Tutorial Gui, Fixes
This commit is contained in:
parent
976779b9f2
commit
947ce254da
@ -0,0 +1,46 @@
|
||||
package mineplex.core.common;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class MaterialData
|
||||
{
|
||||
private final Material _material;
|
||||
private final byte _data;
|
||||
|
||||
private MaterialData(Material material, byte data)
|
||||
{
|
||||
_material = material;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public static MaterialData of(Material material)
|
||||
{
|
||||
return new MaterialData(material, (byte) 0);
|
||||
}
|
||||
|
||||
public static MaterialData of(Material material, byte data)
|
||||
{
|
||||
return new MaterialData(material, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
MaterialData that = (MaterialData) o;
|
||||
|
||||
if (_data != that._data) return false;
|
||||
return _material == that._material;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = _material.hashCode();
|
||||
result = 31 * result + (int) _data;
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package mineplex.core.common.objective;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -12,8 +11,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
/**
|
||||
* An Objective represents
|
||||
*
|
||||
* An Objective represents a set of goals that need to be completed to move on to the next Objective in the quest
|
||||
*/
|
||||
public abstract class Objective<Data extends ObjectiveData> implements Listener
|
||||
{
|
||||
@ -86,6 +84,8 @@ public abstract class Objective<Data extends ObjectiveData> implements Listener
|
||||
_listeners.forEach(listener -> listener.onObjectiveStart(player, this));
|
||||
|
||||
customStart(player);
|
||||
|
||||
System.out.printf("Tutorial> [%s] started objective [%s]\n", player.getName(), getName());
|
||||
}
|
||||
|
||||
protected abstract void customStart(Player player);
|
||||
@ -126,11 +126,13 @@ public abstract class Objective<Data extends ObjectiveData> implements Listener
|
||||
|
||||
protected final void finish(Player player)
|
||||
{
|
||||
System.out.printf("Tutorial> [%s] finished objective [%s]\n", player.getName(), getName());
|
||||
|
||||
_active.remove(player.getUniqueId());
|
||||
|
||||
_listeners.forEach(listener -> listener.onObjectiveFinish(player, this));
|
||||
|
||||
customFinish(player);
|
||||
|
||||
_listeners.forEach(listener -> listener.onObjectiveFinish(player, this));
|
||||
}
|
||||
|
||||
protected abstract void customFinish(Player player);
|
||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -20,14 +21,22 @@ public abstract class Tutorial implements Listener, ObjectiveListener
|
||||
private String _name;
|
||||
private String _taskIdentifier;
|
||||
|
||||
// GUI Data
|
||||
private Material _guiMaterial;
|
||||
private byte _guiData;
|
||||
|
||||
private List<Objective> _objectives;
|
||||
|
||||
public Tutorial(JavaPlugin plugin, String name, String taskIdentifier)
|
||||
public Tutorial(JavaPlugin plugin, String name, String taskIdentifier, Material guiMaterial, byte data)
|
||||
{
|
||||
_plugin = plugin;
|
||||
_name = name;
|
||||
_taskIdentifier = taskIdentifier;
|
||||
|
||||
_guiMaterial = guiMaterial;
|
||||
_guiData = data;
|
||||
|
||||
_playerSessionMap = new HashMap<>();
|
||||
_objectives = new ArrayList<>();
|
||||
}
|
||||
|
||||
@ -38,6 +47,7 @@ public abstract class Tutorial implements Listener, ObjectiveListener
|
||||
|
||||
public void start(Player player)
|
||||
{
|
||||
System.out.printf("Tutorial> [%s] started tutorial [%s]\n", player.getName(), getName());
|
||||
_playerSessionMap.put(player, new TutorialSession());
|
||||
// Start at first objective!
|
||||
setObjective(player, 0);
|
||||
@ -67,6 +77,16 @@ public abstract class Tutorial implements Listener, ObjectiveListener
|
||||
return _name;
|
||||
}
|
||||
|
||||
public Material getGuiMaterial()
|
||||
{
|
||||
return _guiMaterial;
|
||||
}
|
||||
|
||||
public byte getGuiData()
|
||||
{
|
||||
return _guiData;
|
||||
}
|
||||
|
||||
public final String getTaskIdentifier()
|
||||
{
|
||||
return "clans.tutorial." + _taskIdentifier;
|
||||
@ -76,8 +96,36 @@ public abstract class Tutorial implements Listener, ObjectiveListener
|
||||
public void onObjectiveFinish(Player player, Objective objective)
|
||||
{
|
||||
int index = _objectives.indexOf(objective);
|
||||
|
||||
assert index != -1;
|
||||
|
||||
if (index >= _objectives.size())
|
||||
{
|
||||
finish(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
setObjective(player, index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onObjectiveStart(Player player, Objective objective)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void finish(Player player)
|
||||
{
|
||||
_playerSessionMap.remove(player);
|
||||
|
||||
System.out.printf("Tutorial> [%s] finished tutorial [%s]\n", player.getName(), getName());
|
||||
|
||||
onFinish();
|
||||
}
|
||||
|
||||
protected abstract void onFinish();
|
||||
|
||||
public void unregisterAll()
|
||||
{
|
||||
HandlerList.unregisterAll(this);
|
||||
|
@ -8,19 +8,30 @@ import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.game.clans.tutorial.gui.TutorialShop;
|
||||
import mineplex.game.clans.tutorial.tutorials.combat.CombatTutorial;
|
||||
|
||||
public class TutorialManager extends MiniPlugin
|
||||
{
|
||||
private EnumMap<TutorialType, Tutorial> _tutorialMap;
|
||||
private CoreClientManager _clientManager;
|
||||
private DonationManager _donationManager;
|
||||
|
||||
public TutorialManager(JavaPlugin plugin)
|
||||
private EnumMap<TutorialType, Tutorial> _tutorialMap;
|
||||
private EnumMap<TutorialType, TutorialShop> _shopMap; // Don't need to do anything with shops currently
|
||||
|
||||
public TutorialManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
|
||||
{
|
||||
super("Clans Tutorial", plugin);
|
||||
|
||||
_clientManager = clientManager;
|
||||
_donationManager = donationManager;
|
||||
|
||||
_tutorialMap = new EnumMap<TutorialType, Tutorial>(TutorialType.class);
|
||||
_shopMap = new EnumMap<TutorialType, TutorialShop>(TutorialType.class);
|
||||
|
||||
addTutorial(TutorialType.COMBAT, new CombatTutorial(plugin));
|
||||
}
|
||||
@ -33,6 +44,7 @@ public class TutorialManager extends MiniPlugin
|
||||
}
|
||||
|
||||
_tutorialMap.put(type, tutorial);
|
||||
_shopMap.put(type, new TutorialShop(this, _clientManager, _donationManager, tutorial));
|
||||
getPlugin().getServer().getPluginManager().registerEvents(tutorial, getPlugin());
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,43 @@
|
||||
package mineplex.game.clans.tutorial.gui;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.shop.item.ShopItem;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import mineplex.game.clans.tutorial.Tutorial;
|
||||
import mineplex.game.clans.tutorial.TutorialManager;
|
||||
import mineplex.game.clans.tutorial.gui.button.DeclineButton;
|
||||
import mineplex.game.clans.tutorial.gui.button.StartButton;
|
||||
|
||||
public class TutorialSelectPage extends ShopPageBase<TutorialManager, TutorialShop>
|
||||
{
|
||||
public TutorialSelectPage(TutorialManager plugin, TutorialShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
|
||||
{
|
||||
super(plugin, shop, clientManager, donationManager, shop.getTutorial().getName(), player, 45);
|
||||
|
||||
buildPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildPage()
|
||||
{
|
||||
Tutorial tutorial = getShop().getTutorial();
|
||||
|
||||
String name = tutorial.getName();
|
||||
Material material = tutorial.getGuiMaterial();
|
||||
byte data = tutorial.getGuiData();
|
||||
|
||||
ShopItem infoItem = new ShopItem(material, data, name, new String[0], 0, false, false);
|
||||
addItem(13, infoItem);
|
||||
|
||||
ShopItem startItem = new ShopItem(Material.EMERALD_BLOCK, "Start " + tutorial.getName(), new String[0], 0, false, false);
|
||||
addButton(27 + 6, startItem, new StartButton(tutorial));
|
||||
|
||||
ShopItem declineButton = new ShopItem(Material.REDSTONE_BLOCK, "Cancel", new String[0], 0, false, false);
|
||||
addButton(27 + 3, declineButton, new DeclineButton());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package mineplex.game.clans.tutorial.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.shop.ShopBase;
|
||||
import mineplex.core.shop.page.ShopPageBase;
|
||||
import mineplex.game.clans.tutorial.Tutorial;
|
||||
import mineplex.game.clans.tutorial.TutorialManager;
|
||||
|
||||
public class TutorialShop extends ShopBase<TutorialManager>
|
||||
{
|
||||
private final Tutorial _tutorial;
|
||||
|
||||
public TutorialShop(TutorialManager plugin, CoreClientManager clientManager, DonationManager donationManager, Tutorial tutorial)
|
||||
{
|
||||
super(plugin, clientManager, donationManager, tutorial.getName());
|
||||
|
||||
_tutorial = tutorial;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShopPageBase<TutorialManager, ? extends ShopBase<TutorialManager>> buildPagesFor(Player player)
|
||||
{
|
||||
return new TutorialSelectPage(getPlugin(), this, getClientManager(), getDonationManager(), player);
|
||||
}
|
||||
|
||||
public Tutorial getTutorial()
|
||||
{
|
||||
return _tutorial;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package mineplex.game.clans.tutorial.gui.button;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import mineplex.core.shop.item.IButton;
|
||||
|
||||
public class DeclineButton implements IButton
|
||||
{
|
||||
@Override
|
||||
public void onClick(Player player, ClickType clickType)
|
||||
{
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package mineplex.game.clans.tutorial.gui.button;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import mineplex.core.shop.item.IButton;
|
||||
import mineplex.game.clans.tutorial.Tutorial;
|
||||
|
||||
public class StartButton implements IButton
|
||||
{
|
||||
private final Tutorial _tutorial;
|
||||
|
||||
public StartButton(Tutorial tutorial)
|
||||
{
|
||||
_tutorial = tutorial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(Player player, ClickType clickType)
|
||||
{
|
||||
if (!_tutorial.isInTutorial(player))
|
||||
{
|
||||
_tutorial.start(player);
|
||||
}
|
||||
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package mineplex.game.clans.tutorial.tutorials.combat;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@ -11,13 +12,13 @@ public class CombatTutorial extends Tutorial
|
||||
{
|
||||
public CombatTutorial(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, "Combat Tutorial", "combat");
|
||||
super(plugin, "Combat Tutorial", "combat", Material.DIAMOND_SWORD, (byte) 0);
|
||||
|
||||
addObjective(new EquipArmorObjective(plugin));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onObjectiveStart(Player player, Objective objective)
|
||||
protected void onFinish()
|
||||
{
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user