Objectives!

This commit is contained in:
Shaun Bennett 2016-03-15 11:50:35 -05:00
parent e53b8616d1
commit 4e85a315f9
12 changed files with 309 additions and 3 deletions

View File

@ -92,7 +92,7 @@ public class Schematic
DyeColor color = DyeColor.getByWoolData(data);
if (color != null)
{
map.addLocation(color, origin.clone().add(x, y, z));
map.addLocation(color, origin.clone().add(x + 0.5, y + 0.5, z + 0.5));
return true;
}
}

View File

@ -1,8 +1,10 @@
package mineplex.core.common.objective;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.bukkit.entity.Player;
@ -10,6 +12,9 @@ import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
/**
* An Objective represents a set of goals that need to be completed to move on to the next Objective in the quest
*/
@ -159,6 +164,20 @@ public abstract class Objective<Plugin, Data extends ObjectiveData> implements L
return new LinkedList<UUID>(_active.keySet());
}
protected final Player[] getActivePlayers()
{
Set<UUID> uuidSet = _active.keySet();
Player[] players = new Player[uuidSet.size()];
int index = 0;
for (UUID uuid : uuidSet)
{
players[index] = UtilPlayer.searchExact(uuid);
index++;
}
return players;
}
public Data getData(Player player)
{
return _active.get(player.getUniqueId());
@ -174,4 +193,6 @@ public abstract class Objective<Plugin, Data extends ObjectiveData> implements L
List<ObjectiveGoal> goals = getGoals();
if (goals != null) goals.forEach(HandlerList::unregisterAll);
}
public abstract void addScoreboardLines(Player player, List<String> lines);
}

View File

@ -7,6 +7,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import net.md_5.bungee.api.ChatColor;
public abstract class OrderedObjective<Plugin> extends Objective<Plugin, OrderedObjectiveData>
{
private List<ObjectiveGoal> _goals;
@ -68,4 +70,28 @@ public abstract class OrderedObjective<Plugin> extends Objective<Plugin, Ordered
{
return _goals;
}
@Override
public void addScoreboardLines(Player player, List<String> lines)
{
if (contains(player))
{
OrderedObjectiveData data = getData(player);
lines.add(" " + getName());
for (int i = 0; i < _goals.size(); i++)
{
String prefix;
if (i > data.getIndex())
prefix = ChatColor.RED.toString();
else if (i == data.getIndex())
prefix = ">" + ChatColor.YELLOW.toString();
else
prefix = ChatColor.GREEN.toString();
lines.add(" " + prefix + _goals.get(i).getName());
}
}
}
}

View File

@ -35,4 +35,12 @@ public abstract class SingleObjective<Plugin> extends Objective<Plugin, Objectiv
return null;
}
@Override
public void addScoreboardLines(Player player, List<String> lines)
{
if (contains(player))
{
lines.add(" " + getName());
}
}
}

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
@ -12,6 +13,8 @@ import mineplex.core.updater.event.UpdateEvent;
public class ClansMessageManager extends MiniPlugin
{
private static final Message BLANK_MESSAGE = new Message("", "", 20);
private HashMap<Player, Message> _playerMessageMap;
public ClansMessageManager(JavaPlugin plugin)
@ -42,4 +45,21 @@ public class ClansMessageManager extends MiniPlugin
_playerMessageMap.put(player, message);
if (displayNow) message.send(player);
}
public void removePlayer(Player player)
{
removePlayer(player, true);
}
public void removePlayer(Player player, boolean sendBlankMessage)
{
BLANK_MESSAGE.send(player);
_playerMessageMap.remove(player);
}
@EventHandler
public void onQuit(PlayerQuitEvent event)
{
removePlayer(event.getPlayer(), false);
}
}

View File

@ -3,6 +3,7 @@ package mineplex.game.clans.tutorial;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import org.bukkit.Material;
import org.bukkit.Sound;
@ -102,6 +103,11 @@ public abstract class Tutorial implements Listener, ObjectiveListener
return _guiData;
}
public ClansMessageManager getMessage()
{
return _message;
}
public final String getTaskIdentifier()
{
return "clans.tutorial." + _taskIdentifier;
@ -164,6 +170,11 @@ public abstract class Tutorial implements Listener, ObjectiveListener
}
}
public Set<Player> getPlayers()
{
return _playerSessionMap.keySet();
}
/**
* Called when the player finishes the tutorial
*/
@ -196,7 +207,7 @@ public abstract class Tutorial implements Listener, ObjectiveListener
int objectiveIndex = session.getObjectiveIndex();
Objective currentObjective = _objectives.get(objectiveIndex);
lines.add(C.cGoldB + "Current Task (" + (objectiveIndex + 1) + "/" + _objectives.size() + ")");
lines.add(" " + currentObjective.getName());
currentObjective.addScoreboardLines(player, lines);
}
return lines;
}

View File

@ -1,15 +1,24 @@
package mineplex.game.clans.tutorial.tutorials.clans;
import java.io.IOException;
import java.util.List;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.Pair;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.message.ClansMessageManager;
import mineplex.game.clans.tutorial.Tutorial;
import mineplex.game.clans.tutorial.TutorialRegion;
import mineplex.game.clans.tutorial.TutorialWorldManager;
import mineplex.game.clans.tutorial.tutorials.clans.objective.ClanObjective;
import mineplex.game.clans.tutorial.tutorials.clans.objective.LeaveSpawnObjective;
public class ClansMainTutorial extends Tutorial
@ -28,12 +37,13 @@ public class ClansMainTutorial extends Tutorial
}
addObjective(new LeaveSpawnObjective(this, plugin));
addObjective(new ClanObjective(this, plugin));
}
@Override
protected void onFinish(Player player)
{
getMessage().removePlayer(player);
}
@Override
@ -45,6 +55,49 @@ public class ClansMainTutorial extends Tutorial
@Override
protected void onQuit(Player player)
{
}
@EventHandler
public void checkInRegion(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
for (Player player : getPlayers())
{
TutorialRegion region = getRegion(player);
if (!isInRegion(player.getLocation(), region))
{
player.teleport(getSpawn(region));
}
}
}
public Location getSpawn(TutorialRegion region)
{
return region.getLocationMap().getLocations(DyeColor.RED).get(0);
}
public boolean isInSpawn(Player player)
{
return isInSpawn(player.getLocation(), getRegion(player));
}
public boolean isInSpawn(Location location, TutorialRegion region)
{
List<Location> locs = region.getLocationMap().getLocations(DyeColor.ORANGE);
return UtilAlg.inBoundingBox(location, locs.get(0), locs.get(1));
}
public boolean isInRegion(Player player)
{
return isInRegion(player.getLocation(), getRegion(player));
}
public boolean isInRegion(Location location, TutorialRegion region)
{
List<Location> locs = region.getLocationMap().getLocations(DyeColor.GREEN);
return UtilAlg.inBoundingBox(location, locs.get(0), locs.get(1));
}
}

View File

@ -0,0 +1,34 @@
package mineplex.game.clans.tutorial.tutorials.clans.objective;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.objective.OrderedObjective;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.ClaimLandGoal;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.ClanDetailsGoal;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.CreateClanGoal;
public class ClanObjective extends OrderedObjective<ClansMainTutorial>
{
public ClanObjective(ClansMainTutorial clansMainTutorial, JavaPlugin javaPlugin)
{
super(clansMainTutorial, javaPlugin, "Clans", "Create clan with /c create <name>");
addGoal(new CreateClanGoal(this));
addGoal(new ClanDetailsGoal(this));
addGoal(new ClaimLandGoal(this));
}
@Override
protected void customLeave(Player player)
{
}
@Override
protected void customFinish(Player player)
{
}
}

View File

@ -1,9 +1,12 @@
package mineplex.game.clans.tutorial.tutorials.clans.objective;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.objective.SingleObjective;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
public class LeaveSpawnObjective extends SingleObjective<ClansMainTutorial>
@ -30,4 +33,19 @@ public class LeaveSpawnObjective extends SingleObjective<ClansMainTutorial>
{
}
@EventHandler
public void checkRegion(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
for (Player player : getActivePlayers())
{
if (!getPlugin().isInSpawn(player))
{
finish(player);
}
}
}
}

View File

@ -0,0 +1,38 @@
package mineplex.game.clans.tutorial.tutorials.clans.objective.goals;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.clans.event.PlayerPreClaimTerritoryEvent;
public class ClaimLandGoal extends ObjectiveGoal
{
public ClaimLandGoal(Objective objective)
{
super(objective, "Claim Land", "Claim land with /c claim");
}
@Override
protected void customStart(Player player)
{
}
@Override
protected void customFinish(Player player)
{
}
@EventHandler
public void onClaim(PlayerPreClaimTerritoryEvent event)
{
if (contains(event.getClaimer()))
{
event.setCancelled(true);
finish(event.getClaimer());
}
}
}

View File

@ -0,0 +1,40 @@
package mineplex.game.clans.tutorial.tutorials.clans.objective.goals;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.clans.event.ClansCommandExecutedEvent;
public class ClanDetailsGoal extends ObjectiveGoal
{
public ClanDetailsGoal(Objective objective)
{
super(objective, "View Clan Details", "View Clan Details with /c");
}
@Override
protected void customStart(Player player)
{
}
@Override
protected void customFinish(Player player)
{
}
@EventHandler
public void onClanInfo(ClansCommandExecutedEvent event)
{
if (contains(event.getPlayer()))
{
if (event.getCommand().equalsIgnoreCase("info"))
{
finish(event.getPlayer());
}
}
}
}

View File

@ -0,0 +1,37 @@
package mineplex.game.clans.tutorial.tutorials.clans.objective.goals;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.clans.event.ClanCreatedEvent;
public class CreateClanGoal extends ObjectiveGoal
{
public CreateClanGoal(Objective objective)
{
super(objective, "Create a Clan", "Create a Clan");
}
@Override
protected void customStart(Player player)
{
}
@Override
protected void customFinish(Player player)
{
}
@EventHandler
public void onClanCreate(ClanCreatedEvent event)
{
if (contains(event.getFounder()))
{
finish(event.getFounder());
}
}
}