Tutorial work

This commit is contained in:
Shaun Bennett 2016-03-24 15:22:07 +11:00
parent 3d473ad00a
commit dbd9567abb
23 changed files with 403 additions and 126 deletions

View File

@ -10,30 +10,52 @@ import org.bukkit.Location;
public class DataLocationMap
{
private EnumMap<DyeColor, List<Location>> _dataMap;
private EnumMap<DyeColor, List<Location>> _goldDataMap;
private EnumMap<DyeColor, List<Location>> _ironDataMap;
public DataLocationMap()
{
_dataMap = new EnumMap<>(DyeColor.class);
_goldDataMap = new EnumMap<>(DyeColor.class);
_ironDataMap = new EnumMap<>(DyeColor.class);
}
public List<Location> getLocations(DyeColor color)
public List<Location> getGoldLocations(DyeColor color)
{
List<Location> list = _dataMap.get(color);
List<Location> list = _goldDataMap.get(color);
return list == null ? Collections.emptyList() : list;
}
public void addLocation(DyeColor color, Location location)
public void addGoldLocation(DyeColor color, Location location)
{
if (_dataMap.containsKey(color))
if (_goldDataMap.containsKey(color))
{
_dataMap.get(color).add(location);
_goldDataMap.get(color).add(location);
}
else
{
List<Location> list = new ArrayList<>();
list.add(location);
_dataMap.put(color, list);
_goldDataMap.put(color, list);
}
}
public List<Location> getIronLocations(DyeColor color)
{
List<Location> list = _ironDataMap.get(color);
return list == null ? Collections.emptyList() : list;
}
public void addIronLocation(DyeColor color, Location location)
{
if (_ironDataMap.containsKey(color))
{
_ironDataMap.get(color).add(location);
}
else
{
List<Location> list = new ArrayList<>();
list.add(location);
_ironDataMap.put(color, list);
}
}

View File

@ -3,9 +3,9 @@ package mineplex.core.common.block.schematic;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import mineplex.core.common.block.DataLocationMap;
import mineplex.core.common.util.UtilBlock;
public class Schematic
{
@ -24,7 +24,7 @@ public class Schematic
_blockData = blockData;
}
public DataLocationMap paste(Location originLocation)
public DataLocationMap paste(Location originLocation, boolean ignoreAir)
{
DataLocationMap locationMap = new DataLocationMap();
@ -43,19 +43,23 @@ public class Schematic
// not sure why but the math.abs is my simple fix
int materialId = Math.abs(_blocks[index]);
Material material = Material.getMaterial(materialId);
if (material == null)
if (ignoreAir && materialId == 0) // Air
{
System.err.println("Schematic: Could not find Material [id: " + materialId + " data: " + _blockData[index] + "]");
continue;
}
else if (material == Material.GOLD_PLATE)
else if (materialId == 147) // Gold Plate
{
// Check for data wool at location below the gold plate
if (addDataWool(locationMap, originLocation, x, y - 1, z))
if (addDataWool(locationMap, true, originLocation, x, y - 1, z))
continue;
}
else if (material == Material.WOOL)
else if (materialId == 148) // Iron Plate
{
// Check for data wool at location below the gold plate
if (addDataWool(locationMap, false, originLocation, x, y - 1, z))
continue;
}
else if (materialId == 35)
{
// Check if this is a dataloc so we can skip setting the block
int aboveIndex = getIndex(x, y + 1, z);
@ -66,8 +70,7 @@ public class Schematic
}
}
Block block = originLocation.getWorld().getBlockAt(startX + x, startY + y, startZ + z);
block.setTypeIdAndData(materialId, _blockData[index], false);
UtilBlock.setQuick(originLocation.getWorld(), startX + x, startY + y, startZ + z, materialId, _blockData[index]);
}
}
}
@ -80,7 +83,7 @@ public class Schematic
*
* @return true if a location was added to the DataLocationMap
*/
private boolean addDataWool(DataLocationMap map, Location origin, int x, int y, int z)
private boolean addDataWool(DataLocationMap map, boolean gold, Location origin, int x, int y, int z)
{
int index = getIndex(x, y, z);
if (hasIndex(index))
@ -92,7 +95,14 @@ public class Schematic
DyeColor color = DyeColor.getByWoolData(data);
if (color != null)
{
map.addLocation(color, origin.clone().add(x + 0.5, y + 0.5, z + 0.5));
if (gold)
{
map.addGoldLocation(color, origin.clone().add(x, y, z));
}
else
{
map.addIronLocation(color, origin.clone().add(x, y, z));
}
return true;
}
}

View File

@ -24,16 +24,18 @@ public abstract class Objective<Plugin, Data extends ObjectiveData> implements L
private JavaPlugin _javaPlugin;
private String _name;
private String _description;
private String _extraDescription;
private HashMap<UUID, Data> _active;
private List<ObjectiveListener> _listeners;
public Objective(Plugin plugin, JavaPlugin javaPlugin, String name, String description)
public Objective(Plugin plugin, JavaPlugin javaPlugin, String name, String description, String extraDescription)
{
_plugin = plugin;
_javaPlugin = javaPlugin;
_name = name;
_description = description;
_extraDescription = extraDescription;
_active = new HashMap<>();
_listeners = new LinkedList<>();
@ -41,6 +43,11 @@ public abstract class Objective<Plugin, Data extends ObjectiveData> implements L
javaPlugin.getServer().getPluginManager().registerEvents(this, javaPlugin);
}
public Objective(Plugin plugin, JavaPlugin javaPlugin, String name, String description)
{
this(plugin, javaPlugin, name, description, null);
}
public Plugin getPlugin()
{
return _plugin;
@ -54,7 +61,7 @@ public abstract class Objective<Plugin, Data extends ObjectiveData> implements L
/**
* Get the name of this Objective
*/
public String getName()
public String getName(Player player)
{
return _name;
}
@ -62,11 +69,20 @@ public abstract class Objective<Plugin, Data extends ObjectiveData> implements L
/**
* Get the description of this Objective
*/
public String getDescription()
public String getDescription(Player player)
{
return _description;
}
/**
* Get the extra description for this Objective
* Extra description should be any additional useful information that isn't required to complete the objective
*/
public String getExtraDescription(Player player)
{
return _extraDescription;
}
/**
* Add an ObjectiveListener to this Objective
* @param listener
@ -92,7 +108,7 @@ public abstract class Objective<Plugin, Data extends ObjectiveData> implements L
*/
public void start(Player player)
{
System.out.println(String.format("Tutorial> [%s] started objective [%s]", player.getName(), getName()));
System.out.println(String.format("Tutorial> [%s] started objective [%s]", player.getName(), getName(player)));
Data data = createDataObject(player);
_active.put(player.getUniqueId(), data);
@ -138,7 +154,7 @@ public abstract class Objective<Plugin, Data extends ObjectiveData> implements L
protected final void finish(Player player)
{
System.out.println(String.format("Tutorial> [%s] finished objective [%s]", player.getName(), getName()));
System.out.println(String.format("Tutorial> [%s] finished objective [%s]", player.getName(), getName(player)));
_active.remove(player.getUniqueId());
@ -147,6 +163,11 @@ public abstract class Objective<Plugin, Data extends ObjectiveData> implements L
_listeners.forEach(listener -> listener.onObjectiveFinish(player, this));
}
protected final void notifyUpdate(Player player)
{
_listeners.forEach(listener -> listener.onObjectivePlayerUpdate(player, this));
}
protected abstract void customFinish(Player player);
public boolean contains(Player player)

View File

@ -7,32 +7,44 @@ import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
public abstract class ObjectiveGoal implements Listener
public abstract class ObjectiveGoal <T extends Objective> implements Listener
{
private Objective _objective;
private T _objective;
private HashSet<UUID> _active;
private String _name;
private String _description;
private String _extraDescription;
public ObjectiveGoal(Objective objective, String name, String description)
public ObjectiveGoal(T objective, String name, String description)
{
this(objective, name, description, null);
}
public ObjectiveGoal(T objective, String name, String description, String extraDescription)
{
_objective = objective;
_active = new HashSet<>();
_name = name;
_description = description;
_extraDescription = extraDescription;
}
public String getName()
public String getName(Player player)
{
return _name;
}
public String getDescription()
public String getDescription(Player player)
{
return _description;
}
public String getExtraDescription(Player player)
{
return _extraDescription;
}
public Set<UUID> getActivePlayers()
{
@ -51,7 +63,7 @@ public abstract class ObjectiveGoal implements Listener
public final void start(Player player)
{
System.out.println(String.format("Tutorial> [%s] started objective goal [%s]", player.getName(), getName()));
System.out.println(String.format("Tutorial> [%s] started objective goal [%s]", player.getName(), getName(player)));
_active.add(player.getUniqueId());
customStart(player);
@ -65,7 +77,7 @@ public abstract class ObjectiveGoal implements Listener
{
if (_active.contains(player.getUniqueId()))
{
System.out.println(String.format("Tutorial> [%s] finished objective goal [%s]", player.getName(), getName()));
System.out.println(String.format("Tutorial> [%s] finished objective goal [%s]", player.getName(), getName(player)));
_active.remove(player.getUniqueId());
customFinish(player);
@ -74,4 +86,9 @@ public abstract class ObjectiveGoal implements Listener
}
}
public T getObjective()
{
return _objective;
}
}

View File

@ -4,7 +4,20 @@ import org.bukkit.entity.Player;
public interface ObjectiveListener
{
/**
* Called when a player starts an objective
*/
public void onObjectiveStart(Player player, Objective objective);
/**
* Called when a player progresses in an objective
* For example, in an OrderedObjective this will be called when the player
* moves to the next ObjectiveGoal
*/
public void onObjectivePlayerUpdate(Player player, Objective objective);
/**
* Called when a player finishes an objective
*/
public void onObjectiveFinish(Player player, Objective objective);
}

View File

@ -13,13 +13,18 @@ public abstract class OrderedObjective<Plugin> extends Objective<Plugin, Ordered
{
private List<ObjectiveGoal> _goals;
public OrderedObjective(Plugin plugin, JavaPlugin javaPlugin, String name, String description)
public OrderedObjective(Plugin plugin, JavaPlugin javaPlugin, String name, String description, String extraDescription)
{
super(plugin, javaPlugin, name, description);
super(plugin, javaPlugin, name, description, extraDescription);
_goals = new ArrayList<>();
}
public OrderedObjective(Plugin plugin, JavaPlugin javaPlugin, String name, String description)
{
this(plugin, javaPlugin, name, description, null);
}
protected void addGoal(ObjectiveGoal goal)
{
_goals.add(goal);
@ -48,9 +53,34 @@ public abstract class OrderedObjective<Plugin> extends Objective<Plugin, Ordered
else
{
setGoal(player, data.getIndex() + 1);
notifyUpdate(player);
}
}
@Override
public String getName(Player player)
{
OrderedObjectiveData data = getData(player);
int index = data.getIndex();
return _goals.get(index).getName(player);
}
@Override
public String getDescription(Player player)
{
OrderedObjectiveData data = getData(player);
int index = data.getIndex();
return _goals.get(index).getDescription(player);
}
@Override
public String getExtraDescription(Player player)
{
OrderedObjectiveData data = getData(player);
int index = data.getIndex();
return _goals.get(index).getExtraDescription(player);
}
@Override
protected void customStart(Player player)
{
@ -77,7 +107,7 @@ public abstract class OrderedObjective<Plugin> extends Objective<Plugin, Ordered
if (contains(player))
{
OrderedObjectiveData data = getData(player);
lines.add(" " + getName());
// lines.add(" " + getName());
for (int i = 0; i < _goals.size(); i++)
{
@ -90,7 +120,7 @@ public abstract class OrderedObjective<Plugin> extends Objective<Plugin, Ordered
else
prefix = ChatColor.GREEN.toString();
lines.add(" " + prefix + _goals.get(i).getName());
lines.add(" " + prefix + _goals.get(i).getName(player));
}
}
}

View File

@ -10,13 +10,18 @@ public abstract class SingleObjective<Plugin> extends Objective<Plugin, Objectiv
{
private final ObjectiveData _nullData;
public SingleObjective(Plugin plugin, JavaPlugin javaPlugin, String name, String description)
public SingleObjective(Plugin plugin, JavaPlugin javaPlugin, String name, String description, String extraDescription)
{
super(plugin, javaPlugin, name, description);
super(plugin, javaPlugin, name, description, extraDescription);
_nullData = new ObjectiveData();
}
public SingleObjective(Plugin plugin, JavaPlugin javaPlugin, String name, String description)
{
this(plugin, javaPlugin, name, description, null);
}
@Override
protected ObjectiveData createDataObject(Player player)
{
@ -40,7 +45,7 @@ public abstract class SingleObjective<Plugin> extends Objective<Plugin, Objectiv
{
if (contains(player))
{
lines.add(" " + getName());
lines.add(" " + getName(player));
}
}
}

View File

@ -3,6 +3,7 @@ package mineplex.core.common.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Queue;
import org.bukkit.Location;
import org.bukkit.Material;
@ -30,6 +31,7 @@ import org.bukkit.material.Bed;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.Blocks;
import net.minecraft.server.v1_8_R3.EnumDirection;
import net.minecraft.server.v1_8_R3.IBlockData;
import net.minecraft.server.v1_8_R3.Item;
import net.minecraft.server.v1_8_R3.MathHelper;
import net.minecraft.server.v1_8_R3.MinecraftKey;
@ -1463,4 +1465,19 @@ public class UtilBlock
return state.update(false, false);
}
public static void setQuick(World world, int x, int y, int z, int type, byte data)
{
int cx = x >> 4;
int cz = z >> 4;
if (!world.isChunkLoaded(cx, cz))
{
world.loadChunk(cx, cz, true);
}
net.minecraft.server.v1_8_R3.Chunk chunk = ((CraftWorld) world).getHandle().getChunkAt(x >> 4, z >> 4);
BlockPosition pos = new BlockPosition(x, y, z);
IBlockData ibd = net.minecraft.server.v1_8_R3.Block.getById(type).fromLegacyData(data);
chunk.a(pos, ibd);
}
}

View File

@ -170,6 +170,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
private DonationManager _donationManager;
private NetherManager _netherManager;
private DamageManager _damageManager;
private SiegeManager _siegeManager;
private ClansBlacklist _blacklist;
@ -403,7 +404,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "Replay|Restrict");
new SiegeManager(this);
_siegeManager = new SiegeManager(this);
// _netherManager = new NetherManager(this);
}
@ -1305,4 +1306,9 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
{
return _blacklist;
}
public SiegeManager getSiegeManager()
{
return _siegeManager;
}
}

View File

@ -19,13 +19,15 @@ public class ClansBlacklist extends MiniPlugin
public ClansBlacklist(JavaPlugin plugin)
{
super("Clan Name Blacklist", plugin);
_repository = new ClanNameBlacklistRepository(plugin, this);
}
// Fetch new blacklisted clans every 16 seconds (in case someone blacklists a clan name on a different server)
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOWER)
if (event.getType() == UpdateType.SLOWER)
{
runAsync(() -> _repository.loadNames(this::setBlacklist));
}

View File

@ -133,10 +133,18 @@ public abstract class Tutorial implements Listener, ObjectiveListener
@Override
public void onObjectiveStart(Player player, Objective objective)
{
String title = objective.getName();
String desc = objective.getDescription();
String title = objective.getName(player);
String desc = objective.getDescription(player);
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 1f);
_message.setMessage(player, title, desc, 100, true);
_message.setMessage(player, title, desc, 20, true);
}
@Override
public void onObjectivePlayerUpdate(Player player, Objective objective)
{
String desc = objective.getDescription(player);
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1f, 1f);
_message.setMessage(player, "", desc, 20, true);
}
private void finish(Player player)

View File

@ -33,7 +33,7 @@ public class TutorialRegion
private void pasteSchematic()
{
_locationMap = _schematic.paste(getOrigin());
_locationMap = _schematic.paste(getOrigin(), true);
}
/**

View File

@ -56,14 +56,16 @@ public class TutorialWorldManager extends MiniPlugin
_regionStack = new Stack<>();
// Populate the stack with 100 available tutorial regions
for (int x = 0; x < 10; x++)
for (int x = 0; x < 8; x++)
{
for (int z = 0; z < 10; z++)
for (int z = 0; z < 8; z++)
{
double xLoc = (x - 5) * 100; // 100x100 regions
double zLoc = (z - 5) * 100;
long time = System.currentTimeMillis();
double xLoc = (x - 5) * 1000; // 1000x1000 regions
double zLoc = (z - 5) * 1000;
_regionStack.add(new TutorialRegion(_schematic, new Location(_tutorialWorld, xLoc, 64, zLoc)));
System.out.println("Finished Generating Region: " + ((x * 10) + z) + ". Took " + (System.currentTimeMillis() - time) + " ms");
}
}
}
@ -88,13 +90,4 @@ public class TutorialWorldManager extends MiniPlugin
log("Returned " + region.toString());
}
@EventHandler
public void onCommand(PlayerCommandPreprocessEvent event)
{
if (event.getPlayer().getName().contains("Phinary") && event.getMessage().contains("tw"))
{
event.getPlayer().teleport(new Location(_tutorialWorld, 0, 64, 0));
}
}
}

View File

@ -6,6 +6,8 @@ import java.util.List;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
@ -13,8 +15,6 @@ import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.message.ClansMessageManager;
import mineplex.game.clans.tutorial.Tutorial;
@ -59,8 +59,8 @@ public class ClansMainTutorial extends Tutorial
@Override
protected void onStart(Player player)
{
player.teleport(getRegion(player).getLocationMap().getLocations(DyeColor.RED).get(0));
player.teleport(getSpawn(getRegion(player)));
player.getInventory().clear();
ClansManager.getInstance().getItemMapManager().setMap(player);
}
@ -69,7 +69,80 @@ public class ClansMainTutorial extends Tutorial
protected void onQuit(Player player)
{
}
public boolean isIn(Location location, TutorialRegion region, Bounds bounds)
{
List<Location> locs = region.getLocationMap().getGoldLocations(bounds.getDataLocColor());
return UtilAlg.inBoundingBox(location, locs.get(0), locs.get(1));
}
public boolean isIn(Player player, Bounds bounds)
{
TutorialRegion region = getRegion(player);
if (region != null)
{
return isIn(player.getLocation(), region, bounds);
}
return false;
}
public Location getSpawn(TutorialRegion region)
{
return region.getLocationMap().getGoldLocations(DyeColor.MAGENTA).get(0);
}
public enum Bounds
{
LAND_CLAIM(DyeColor.RED), // Should be 16x16
ENEMY_LAND(DyeColor.LIGHT_BLUE), // Should be 16x16
SPAWN(DyeColor.GREEN), // Spawn Platform
FIELDS(DyeColor.PURPLE), // Boulders for ores to spawn in?
SHOPS(DyeColor.YELLOW); // Little shop areas similar to Shops in clans map
// Gray Wool - Cannon Location
// Magenta Wool - Spawn
// Lime Wool - Farming Shop
// Purple Wool - Pvp Shop
// Light Gray Wool - Energy Shop
private DyeColor _dataLocColor;
Bounds(DyeColor dataLocColor)
{
_dataLocColor = dataLocColor;
}
public DyeColor getDataLocColor()
{
return _dataLocColor;
}
}
public enum Point
{
SPAWN(DyeColor.MAGENTA),
FARMING_SHOP(DyeColor.LIME),
PVP_SHOP(DyeColor.PURPLE),
ENERGY_SHOP(DyeColor.SILVER);
private DyeColor _dataLocColor;
Point(DyeColor dataLocColor)
{
_dataLocColor = dataLocColor;
}
public DyeColor getDataLocColor()
{
return _dataLocColor;
}
}
/**
* Events
*/
@EventHandler
public void dropItem(PlayerDropItemEvent event)
{
@ -78,7 +151,7 @@ public class ClansMainTutorial extends Tutorial
event.setCancelled(true);
}
}
@EventHandler
public void breakBlock(BlockBreakEvent event)
{
@ -88,6 +161,48 @@ public class ClansMainTutorial extends Tutorial
}
}
// Fences
// Black = fields
// Brown = shops
public void spawnFence(Block startBlock)
{
Block block = startBlock;
int count = 0;
while (block.getType() != Material.AIR && count < 100)
{
block.setType(Material.FENCE);
block = block.getRelative(BlockFace.UP);
count++;
}
}
public void destroyFence(Block startBlock)
{
Block block = startBlock;
int count = 0;
while (block.getType() == Material.FENCE && count < 100)
{
block.setType(Material.AIR);
block = block.getRelative(BlockFace.UP);
count++;
}
}
public void spawnFences(TutorialRegion region, DyeColor dataLoc)
{
List<Location> locations = region.getLocationMap().getIronLocations(dataLoc);
locations.stream().map(Location::getBlock).forEach(this::spawnFence);
}
public void destroyFences(TutorialRegion region, DyeColor dataLoc)
{
List<Location> locations = region.getLocationMap().getIronLocations(dataLoc);
locations.stream().map(Location::getBlock).forEach(this::spawnFence);
}
/*
@EventHandler
public void checkInRegion(UpdateEvent event)
{
@ -98,37 +213,11 @@ public class ClansMainTutorial extends Tutorial
{
TutorialRegion region = getRegion(player);
if (!isInRegion(player.getLocation(), region))
if (!isIn(player.getLocation(), region, Bounds.TUTORIAL_AREA))
{
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

@ -1,5 +1,7 @@
package mineplex.game.clans.tutorial.tutorials.clans.objective;
import java.util.Optional;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
@ -39,7 +41,7 @@ public class LeaveSpawnObjective extends SingleObjective<ClansMainTutorial>
for (Player player : getActivePlayers())
{
if (!getPlugin().isInSpawn(player))
if (!getPlugin().isIn(player, ClansMainTutorial.Bounds.SPAWN))
{
finish(player);
}

View File

@ -1,11 +1,14 @@
package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent;
public class AttackEnemyGoal extends ObjectiveGoal
@ -18,8 +21,8 @@ public class AttackEnemyGoal extends ObjectiveGoal
@Override
protected void customStart(Player player)
{
// give tnt (For cannon)
// and place cannon?
player.getInventory().addItem(new ItemStack(Material.TNT, 20));
finish(player);
}
// use this event for figuring out if the cannon hit the base

View File

@ -19,8 +19,11 @@ import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.tutorial.TutorialRegion;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import mineplex.game.clans.tutorial.tutorials.clans.objective.ClanObjective;
public class BuildHouseGoal extends ObjectiveGoal
public class BuildHouseGoal extends ObjectiveGoal<ClanObjective>
{
private List<ItemStack> _items = Lists.newArrayList(
new ItemStack(Material.SMOOTH_BRICK, 54),
@ -29,7 +32,7 @@ public class BuildHouseGoal extends ObjectiveGoal
);
public BuildHouseGoal(Objective objective)
public BuildHouseGoal(ClanObjective objective)
{
super(objective, "Build House", "Build a Stone Brick house. (Place all your blocks)");
}
@ -55,7 +58,7 @@ public class BuildHouseGoal extends ObjectiveGoal
return;
}
if (!isInBuildArea(event.getBlock()))
if (!isInBuildArea(event.getPlayer(), event.getBlock()))
{
return;
}
@ -82,7 +85,7 @@ public class BuildHouseGoal extends ObjectiveGoal
return;
}
if (isInBuildArea(event.getBlock()))
if (isInBuildArea(event.getPlayer(), event.getBlock()))
{
// Run 1 tick later because inventory doesn't get updated instantly
ClansManager.getInstance().runSync(() -> {
@ -110,8 +113,9 @@ public class BuildHouseGoal extends ObjectiveGoal
}
}
private boolean isInBuildArea(Block block)
private boolean isInBuildArea(Player player, Block block)
{
return true; // TODO
TutorialRegion region = getObjective().getPlugin().getRegion(player);
return getObjective().getPlugin().isIn(block.getLocation(), region, ClansMainTutorial.Bounds.LAND_CLAIM);
}
}

View File

@ -5,11 +5,15 @@ import org.bukkit.event.EventHandler;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.event.PlayerPreClaimTerritoryEvent;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import mineplex.game.clans.tutorial.tutorials.clans.objective.ClanObjective;
public class ClaimLandGoal extends ObjectiveGoal
public class ClaimLandGoal extends ObjectiveGoal<ClanObjective>
{
public ClaimLandGoal(Objective objective)
public ClaimLandGoal(ClanObjective objective)
{
super(objective, "Claim Land", "Claim land with /c claim");
}
@ -29,8 +33,16 @@ public class ClaimLandGoal extends ObjectiveGoal
{
if (contains(event.getClaimer()))
{
if (getObjective().getPlugin().isIn(event.getClaimer(), ClansMainTutorial.Bounds.LAND_CLAIM))
{
finish(event.getClaimer());
}
else
{
UtilPlayer.message(event.getClaimer(), F.main("Tutorial", "You must claim the land inside the blue outline"));
}
event.setCancelled(true);
finish(event.getClaimer());
}
}
}

View File

@ -3,13 +3,15 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan;
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.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.event.ClansCommandExecutedEvent;
import mineplex.game.clans.tutorial.tutorials.clans.objective.ClanObjective;
public class ClanDetailsGoal extends ObjectiveGoal
public class ClanDetailsGoal extends ObjectiveGoal<ClanObjective>
{
public ClanDetailsGoal(Objective objective)
public ClanDetailsGoal(ClanObjective objective)
{
super(objective, "View Clan Details", "View Clan Details with /c");
}
@ -29,7 +31,8 @@ public class ClanDetailsGoal extends ObjectiveGoal
{
if (contains(event.getPlayer()))
{
if (event.getCommand().equalsIgnoreCase("info"))
ClanInfo clan = ClansManager.getInstance().getClan(event.getPlayer());
if (event.getCommand().equalsIgnoreCase(clan.getName()))
{
finish(event.getPlayer());
}

View File

@ -6,10 +6,11 @@ import org.bukkit.event.EventHandler;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.clans.event.ClanCreatedEvent;
import mineplex.game.clans.tutorial.tutorials.clans.objective.ClanObjective;
public class CreateClanGoal extends ObjectiveGoal
public class CreateClanGoal extends ObjectiveGoal<ClanObjective>
{
public CreateClanGoal(Objective objective)
public CreateClanGoal(ClanObjective objective)
{
super(objective, "Create a Clan", "Create a Clan");
}

View File

@ -5,11 +5,15 @@ import org.bukkit.event.EventHandler;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.event.ClanSetHomeEvent;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import mineplex.game.clans.tutorial.tutorials.clans.objective.ClanObjective;
public class SetHomeGoal extends ObjectiveGoal
public class SetHomeGoal extends ObjectiveGoal<ClanObjective>
{
public SetHomeGoal(Objective objective)
public SetHomeGoal(ClanObjective objective)
{
super(objective, "Set Home", "Set your Clan's home by typing /c sethome");
}
@ -29,7 +33,16 @@ public class SetHomeGoal extends ObjectiveGoal
{
if (contains(event.getPlayer()))
{
if (getObjective().getPlugin().isIn(event.getPlayer(), ClansMainTutorial.Bounds.LAND_CLAIM))
{
finish(event.getPlayer());
}
else
{
UtilPlayer.message(event.getPlayer(), F.main("Tutorial", "You must set your home in your own land claim"));
}
finish(event.getPlayer());
event.setCancelled(true);
}
}
}

View File

@ -17,7 +17,7 @@ public class StealEnemyPotatoesGoal extends ObjectiveGoal
@Override
protected void customStart(Player player)
{
finish(player);
}
@Override

View File

@ -1,16 +1,23 @@
package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.shops;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.event.ClanCreatedEvent;
import mineplex.game.clans.clans.event.PlayerEnterTerritoryEvent;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import mineplex.game.clans.tutorial.tutorials.clans.objective.ShopsObjective;
public class GoToShopsGoal extends ObjectiveGoal
public class GoToShopsGoal extends ObjectiveGoal<ShopsObjective>
{
public GoToShopsGoal(Objective objective)
public GoToShopsGoal(ShopsObjective objective)
{
super(objective, "Go to the Shops", "Head over to the Shops (use your map)");
}
@ -26,21 +33,20 @@ public class GoToShopsGoal extends ObjectiveGoal
{
}
@EventHandler
public void enterRegion(PlayerEnterTerritoryEvent event)
public void checkRegion(UpdateEvent event)
{
if (!contains(event.getPlayer()))
{
if (event.getType() != UpdateType.FAST)
return;
}
// This "reverse" equals is to prevent an NPE
if (!"Shops".equals(event.getNewTerritory()))
for (UUID uuid : getActivePlayers())
{
return;
Player player = UtilPlayer.searchExact(uuid);
if (getObjective().getPlugin().isIn(player, ClansMainTutorial.Bounds.SHOPS))
{
finish(player);
}
}
finish(event.getPlayer());
}
}