From e53b8616d14d4ae5d9bc39a3c4c82a40b3aef9d8 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Tue, 15 Mar 2016 10:29:43 -0500 Subject: [PATCH] A ton of tutorial work --- .../core/common/block/DataLocationMap.java | 41 +++++++ .../common/block/schematic/Schematic.java | 62 ++++++++++- .../core/common/generator/VoidGenerator.java | 15 +++ .../core/common/objective/Objective.java | 21 ++-- .../common/objective/OrderedObjective.java | 8 +- .../common/objective/SingleObjective.java | 6 +- .../resourcepack/ResourcePackManager.java | 2 - .../clans/clans/regions/ClansRegions.java | 12 +-- .../game/clans/tutorial/Tutorial.java | 74 +++++++++++-- .../game/clans/tutorial/TutorialManager.java | 7 +- .../game/clans/tutorial/TutorialRegion.java | 75 +++++++++++++ .../game/clans/tutorial/TutorialSession.java | 11 ++ .../game/clans/tutorial/TutorialType.java | 2 +- .../clans/tutorial/TutorialWorldManager.java | 100 ++++++++++++++++++ .../clans/tutorial/command/StartCommand.java | 17 +-- .../tutorial/command/TutorialCommand.java | 4 +- .../tutorials/clans/ClansMainTutorial.java | 50 +++++++++ .../clans/objective/LeaveSpawnObjective.java | 33 ++++++ .../tutorials/combat/CombatTutorial.java | 28 ----- .../objectives/CustomizeKitObjective.java | 35 ------ .../objectives/EquipArmorObjective.java | 77 -------------- .../goals/OpenCustomizationGoal.java | 37 ------- 22 files changed, 490 insertions(+), 227 deletions(-) create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/block/DataLocationMap.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/generator/VoidGenerator.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialRegion.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialWorldManager.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/ClansMainTutorial.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/LeaveSpawnObjective.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/CombatTutorial.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/CustomizeKitObjective.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/EquipArmorObjective.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/goals/OpenCustomizationGoal.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/block/DataLocationMap.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/block/DataLocationMap.java new file mode 100644 index 000000000..afa6237f3 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/block/DataLocationMap.java @@ -0,0 +1,41 @@ +package mineplex.core.common.block; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumMap; +import java.util.List; + +import org.bukkit.DyeColor; +import org.bukkit.Location; + +public class DataLocationMap +{ + private EnumMap> _dataMap; + + public DataLocationMap() + { + _dataMap = new EnumMap<>(DyeColor.class); + } + + public List getLocations(DyeColor color) + { + List list = _dataMap.get(color); + return list == null ? Collections.emptyList() : list; + } + + public void addLocation(DyeColor color, Location location) + { + if (_dataMap.containsKey(color)) + { + _dataMap.get(color).add(location); + } + else + { + List list = new ArrayList<>(); + list.add(location); + _dataMap.put(color, list); + } + } + + +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/block/schematic/Schematic.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/block/schematic/Schematic.java index b64056a47..d604b72b5 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/block/schematic/Schematic.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/block/schematic/Schematic.java @@ -1,9 +1,12 @@ 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; + public class Schematic { private final short _width; @@ -21,8 +24,10 @@ public class Schematic _blockData = blockData; } - public void paste(Location originLocation) + public DataLocationMap paste(Location originLocation) { + DataLocationMap locationMap = new DataLocationMap(); + int startX = originLocation.getBlockX(); int startY = originLocation.getBlockY(); int startZ = originLocation.getBlockZ(); @@ -34,7 +39,6 @@ public class Schematic for (int z = 0; z < _length; z++) { int index = getIndex(x, y, z); - Block block = originLocation.getWorld().getBlockAt(startX + x, startY + y, startZ + z); // some blocks were giving me negative id's in the schematic (like stairs) // not sure why but the math.abs is my simple fix int materialId = Math.abs(_blocks[index]); @@ -42,13 +46,58 @@ public class Schematic Material material = Material.getMaterial(materialId); if (material == null) { - System.out.println(materialId + " data: " + _blockData[index]); + System.err.println("Schematic: Could not find Material [id: " + materialId + " data: " + _blockData[index] + "]"); continue; } + else if (material == Material.GOLD_PLATE) + { + // Check for data wool at location below the gold plate + if (addDataWool(locationMap, originLocation, x, y - 1, z)) + continue; + } + else if (material == Material.WOOL) + { + // Check if this is a dataloc so we can skip setting the block + int aboveIndex = getIndex(x, y + 1, z); + if (hasIndex(aboveIndex)) + { + if (Math.abs(_blocks[aboveIndex]) == Material.GOLD_PLATE.getId()) + continue; + } + } + + Block block = originLocation.getWorld().getBlockAt(startX + x, startY + y, startZ + z); block.setTypeIdAndData(materialId, _blockData[index], false); } } } + + return locationMap; + } + + /** + * Checks the schematic location for x, y, z and adds the a Location to the DataLocationMap if it is a wool block + * + * @return true if a location was added to the DataLocationMap + */ + private boolean addDataWool(DataLocationMap map, Location origin, int x, int y, int z) + { + int index = getIndex(x, y, z); + if (hasIndex(index)) + { + int materialId = Math.abs(_blocks[index]); + if (materialId == 35) // WOOL + { + byte data = _blockData[index]; + DyeColor color = DyeColor.getByWoolData(data); + if (color != null) + { + map.addLocation(color, origin.clone().add(x, y, z)); + return true; + } + } + } + return false; } public int getSize() @@ -61,6 +110,11 @@ public class Schematic return y * _width * _length + z * _width + x; } + public boolean hasIndex(int index) + { + return index < _blocks.length; + } + public short getBlock(int x, int y, int z) { return _blocks[getIndex(x, y, z)]; @@ -99,6 +153,6 @@ public class Schematic @Override public String toString() { - return String.format("width: %d, length: %d, height: %d, blockLength: %d, blockDataLength: %d", _width, _length, _height, _blocks.length, _blockData.length); + return String.format("Schematic [width: %d, length: %d, height: %d, blockLength: %d, blockDataLength: %d]", _width, _length, _height, _blocks.length, _blockData.length); } } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/generator/VoidGenerator.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/generator/VoidGenerator.java new file mode 100644 index 000000000..085678e9c --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/generator/VoidGenerator.java @@ -0,0 +1,15 @@ +package mineplex.core.common.generator; + +import java.util.Random; + +import org.bukkit.World; +import org.bukkit.generator.ChunkGenerator; + +public class VoidGenerator extends ChunkGenerator +{ + @Override + public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) + { + return createChunkData(world); + } +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java index 262c26513..0ac75f747 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java @@ -13,32 +13,39 @@ import org.bukkit.plugin.java.JavaPlugin; /** * 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 implements Listener +public abstract class Objective implements Listener { - private JavaPlugin _plugin; + private Plugin _plugin; + private JavaPlugin _javaPlugin; private String _name; private String _description; private HashMap _active; private List _listeners; - public Objective(JavaPlugin plugin, String name, String description) + public Objective(Plugin plugin, JavaPlugin javaPlugin, String name, String description) { _plugin = plugin; + _javaPlugin = javaPlugin; _name = name; _description = description; _active = new HashMap<>(); _listeners = new LinkedList<>(); - plugin.getServer().getPluginManager().registerEvents(this, plugin); + javaPlugin.getServer().getPluginManager().registerEvents(this, javaPlugin); } - public JavaPlugin getPlugin() + public Plugin getPlugin() { return _plugin; } + public JavaPlugin getJavaPlugin() + { + return _javaPlugin; + } + /** * Get the name of this Objective */ @@ -72,6 +79,8 @@ public abstract class Objective implements Listener _listeners.clear(); } + protected abstract void customStart(Player player); + /** * Start this Objective for a player * @param player @@ -88,8 +97,6 @@ public abstract class Objective implements Listener customStart(player); } - protected abstract void customStart(Player player); - /** * Leave this objective for a specific player * This does not count as completing the object diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/OrderedObjective.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/OrderedObjective.java index 407eb7f6d..5bd6d781c 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/OrderedObjective.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/OrderedObjective.java @@ -7,13 +7,13 @@ import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.bukkit.plugin.java.JavaPlugin; -public abstract class OrderedObjective extends Objective +public abstract class OrderedObjective extends Objective { private List _goals; - public OrderedObjective(JavaPlugin plugin, String name, String description) + public OrderedObjective(Plugin plugin, JavaPlugin javaPlugin, String name, String description) { - super(plugin, name, description); + super(plugin, javaPlugin, name, description); _goals = new ArrayList<>(); } @@ -22,7 +22,7 @@ public abstract class OrderedObjective extends Objective { _goals.add(goal); - getPlugin().getServer().getPluginManager().registerEvents(goal, getPlugin()); + getJavaPlugin().getServer().getPluginManager().registerEvents(goal, getJavaPlugin()); } @Override diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/SingleObjective.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/SingleObjective.java index 0de525913..c8a765190 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/SingleObjective.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/SingleObjective.java @@ -6,13 +6,13 @@ import java.util.UUID; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -public abstract class SingleObjective extends Objective +public abstract class SingleObjective extends Objective { private final ObjectiveData _nullData; - public SingleObjective(JavaPlugin plugin, String name, String description) + public SingleObjective(Plugin plugin, JavaPlugin javaPlugin, String name, String description) { - super(plugin, name, description); + super(plugin, javaPlugin, name, description); _nullData = new ObjectiveData(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResourcePackManager.java b/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResourcePackManager.java index 9dcee5edd..eca9405f6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResourcePackManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/resourcepack/ResourcePackManager.java @@ -148,8 +148,6 @@ public class ResourcePackManager extends MiniPlugin implements CommandCallback { _resourcePackUsers.remove(player.getName()); } - - System.out.println("status: " + player.getName() + " " + event); } @EventHandler diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java index 3aec4d0af..bacd3f6fb 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java @@ -140,8 +140,9 @@ public class ClansRegions extends MiniPlugin public void claimArea(final String clanName, final int chunkRadius, final int claimOffset, final boolean safe, final boolean addNegative, final Location... locations) { final ClanInfo clan = _manager.getClan(clanName); - - if (clan == null ) + + // Only claim if the clan doesn't exist yet. Speeds up startup time + if (clan == null) { _manager.getClanDataAccess().create("ClansRegions", clanName, true, new Callback() { @@ -166,13 +167,6 @@ public class ClansRegions extends MiniPlugin } }); } - else - { - for (Location location : locations) - { - claimArea(clan, location, chunkRadius, claimOffset, addNegative, safe); - } - } } /*private void claimArea(String clanName, int chunkRadius, int claimOffset, boolean safe, Location... locations) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Tutorial.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Tutorial.java index 6730a1a5a..9a0a1fabb 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Tutorial.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Tutorial.java @@ -7,8 +7,10 @@ import java.util.List; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.common.objective.Objective; @@ -24,6 +26,7 @@ public abstract class Tutorial implements Listener, ObjectiveListener private ClansMessageManager _message; private String _name; private String _taskIdentifier; + private TutorialWorldManager _worldManager; // GUI Data private Material _guiMaterial; @@ -54,9 +57,15 @@ public abstract class Tutorial implements Listener, ObjectiveListener public void start(Player player) { System.out.println(String.format("Tutorial> [%s] started tutorial [%s]", player.getName(), getName())); - _playerSessionMap.put(player, new TutorialSession()); + + TutorialSession session = new TutorialSession(); + if (_worldManager != null) + session.setRegion(_worldManager.getNextRegion()); + _playerSessionMap.put(player, session); // Start at first objective! setObjective(player, 0); + + onStart(player); } private void setObjective(Player player, int objective) @@ -126,14 +135,49 @@ public abstract class Tutorial implements Listener, ObjectiveListener private void finish(Player player) { - _playerSessionMap.remove(player); + removePlayer(player); System.out.println(String.format("Tutorial> [%s] finished tutorial [%s]", player.getName(), getName())); - onFinish(); + onFinish(player); } - protected abstract void onFinish(); + private void quit(Player player) + { + removePlayer(player); + + System.out.println(String.format("Tutorial> [%s] quit tutorial [%s]", player.getName(), getName())); + + onQuit(player); + } + + private void removePlayer(Player player) + { + TutorialSession session = _playerSessionMap.remove(player); + + if (session != null) + { + if (session.getRegion() != null) + { + _worldManager.returnRegion(session.getRegion()); + } + } + } + + /** + * Called when the player finishes the tutorial + */ + protected abstract void onFinish(Player player); + + /** + * Called when the player starts the tutorial + */ + protected abstract void onStart(Player player); + + /** + * Called when a player quits the tutorial or leaves the game in the tutorial + */ + protected abstract void onQuit(Player player); public void unregisterAll() { @@ -153,10 +197,26 @@ public abstract class Tutorial implements Listener, ObjectiveListener Objective currentObjective = _objectives.get(objectiveIndex); lines.add(C.cGoldB + "Current Task (" + (objectiveIndex + 1) + "/" + _objectives.size() + ")"); lines.add(" " + currentObjective.getName()); - - lines.add(" "); - lines.add("Type /skip to exit tutorial"); } return lines; } + + public void setWorldManager(TutorialWorldManager worldManager) + { + _worldManager = worldManager; + } + + public TutorialRegion getRegion(Player player) + { + return _playerSessionMap.get(player).getRegion(); + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) + { + if (isInTutorial(event.getPlayer())) + { + quit(event.getPlayer()); + } + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java index 4a714b0ad..79f8ee727 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java @@ -5,9 +5,6 @@ import java.util.EnumMap; import java.util.List; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; @@ -20,7 +17,7 @@ import mineplex.core.scoreboard.elements.ScoreboardElement; import mineplex.game.clans.message.ClansMessageManager; import mineplex.game.clans.tutorial.command.TutorialCommand; import mineplex.game.clans.tutorial.gui.TutorialShop; -import mineplex.game.clans.tutorial.tutorials.combat.CombatTutorial; +import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial; public class TutorialManager extends MiniPlugin implements ScoreboardElement { @@ -42,7 +39,7 @@ public class TutorialManager extends MiniPlugin implements ScoreboardElement _tutorialMap = new EnumMap(TutorialType.class); _shopMap = new EnumMap(TutorialType.class); - addTutorial(TutorialType.COMBAT, new CombatTutorial(plugin, _clansMessageManager)); + addTutorial(TutorialType.MAIN, new ClansMainTutorial(plugin, _clansMessageManager)); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialRegion.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialRegion.java new file mode 100644 index 000000000..256f4fa51 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialRegion.java @@ -0,0 +1,75 @@ +package mineplex.game.clans.tutorial; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; + +import mineplex.core.common.block.DataLocationMap; +import mineplex.core.common.block.schematic.Schematic; + +public class TutorialRegion +{ + private final Schematic _schematic; + private final Location _origin; + private DataLocationMap _locationMap; + + protected TutorialRegion(Schematic schematic, Location origin) + { + _origin = origin; + _schematic = schematic; + + pasteSchematic(); + } + + public Location getOrigin() + { + return _origin; + } + + public DataLocationMap getLocationMap() + { + return _locationMap; + } + + private void pasteSchematic() + { + _locationMap = _schematic.paste(getOrigin()); + } + + /** + * Clear the schematic area. This shouldn't be needed + */ + @Deprecated + private void clearSchematic() + { + for (int x = 0; x < _schematic.getWidth(); x++) + { + for (int y = 0; y < _schematic.getHeight(); y++) + { + for (int z = 0; z < _schematic.getLength(); z++) + { + Block b = _origin.clone().add(x, y, z).getBlock(); + if (b.getType() != Material.AIR) + { + b.setTypeIdAndData(0, (byte) 0, false); + } + } + } + } + } + + protected void reset() + { + long start = System.currentTimeMillis(); + System.out.println("TutorialRegion starting reset..."); + pasteSchematic(); + System.out.println("TutorialRegion finished reset! Took " + (System.currentTimeMillis() - start) + "ms"); + + } + + @Override + public String toString() + { + return "TutorialRegion[" + _origin.toString() + "]"; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialSession.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialSession.java index b14ff8577..fe7be3406 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialSession.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialSession.java @@ -3,6 +3,7 @@ package mineplex.game.clans.tutorial; public class TutorialSession { private int _objectiveIndex; + private TutorialRegion _region; public TutorialSession() { @@ -17,4 +18,14 @@ public class TutorialSession { _objectiveIndex = objectiveIndex; } + + public TutorialRegion getRegion() + { + return _region; + } + + public void setRegion(TutorialRegion region) + { + _region = region; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialType.java index 93d5b38fe..984114613 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialType.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialType.java @@ -2,5 +2,5 @@ package mineplex.game.clans.tutorial; public enum TutorialType { - COMBAT + MAIN } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialWorldManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialWorldManager.java new file mode 100644 index 000000000..32a18c5a2 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialWorldManager.java @@ -0,0 +1,100 @@ +package mineplex.game.clans.tutorial; + +import java.io.File; +import java.io.IOException; +import java.util.Stack; + +import org.bukkit.Bukkit; +import org.bukkit.Difficulty; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; +import mineplex.core.common.block.schematic.Schematic; +import mineplex.core.common.block.schematic.UtilSchematic; +import mineplex.core.common.generator.VoidGenerator; +import mineplex.game.clans.tutorial.TutorialRegion; + +public class TutorialWorldManager extends MiniPlugin +{ + private final World _tutorialWorld; + private final Schematic _schematic; + private Stack _regionStack; + + public TutorialWorldManager(JavaPlugin plugin, String worldName, String schematicName) throws IOException + { + super("Tutorial World", plugin); + + log("Creating Tutorial World"); + WorldCreator creator = new WorldCreator(worldName); + creator.generator(new VoidGenerator()); + _tutorialWorld = Bukkit.createWorld(creator); + _tutorialWorld.setDifficulty(Difficulty.PEACEFUL); + _tutorialWorld.setGameRuleValue("doDaylightCycle", "false"); + _tutorialWorld.setTime(6000); + _tutorialWorld.setAutoSave(false); + _tutorialWorld.setAmbientSpawnLimit(0); + _tutorialWorld.setMonsterSpawnLimit(0); + _tutorialWorld.setWaterAnimalSpawnLimit(0); + log("Tutorial World Created!"); + + log("Loading schematic - " + schematicName); + _schematic = UtilSchematic.loadSchematic(new File(schematicName)); + log("Finished loading schematic"); + + log("Populating Region Stack..."); + populateRegionStack(); + log("Finished loading Tutorial World Manager!"); + } + + private void populateRegionStack() + { + _regionStack = new Stack<>(); + + // Populate the stack with 100 available tutorial regions + for (int x = 0; x < 10; x++) + { + for (int z = 0; z < 10; z++) + { + double xLoc = (x - 5) * 100; // 100x100 regions + double zLoc = (z - 5) * 100; + + _regionStack.add(new TutorialRegion(_schematic, new Location(_tutorialWorld, xLoc, 64, zLoc))); + } + } + } + + /** + * Get the next TutorialRegion in the stack. This region is prepared and ready for use in a tutorial + * @return + */ + public TutorialRegion getNextRegion() + { + return _regionStack.pop(); + } + + /** + * Notify the TutorialWorldManager that this TutorialRegion is no longer needed and should be cleaned up. + * The TutorialRegion should not be used after calling this method + */ + public void returnRegion(TutorialRegion region) + { + region.reset(); + _regionStack.push(region); + 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)); + } + + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/StartCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/StartCommand.java index d6d509a2c..78ca19141 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/StartCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/StartCommand.java @@ -25,14 +25,17 @@ public class StartCommand extends CommandBase return; } - try + TutorialType type = null; + + for (TutorialType check : TutorialType.values()) { - TutorialType type = TutorialType.valueOf(args[0]); + if (check.name().equalsIgnoreCase(args[0])) + type = check; + } + + if (type != null) Plugin.openTutorialMenu(caller, type); - } - catch (IllegalArgumentException ex) - { - UtilPlayer.message(caller, F.main("Tutorial", "Invalid Tutorial: " + F.elem(args[0]))); - } + else + UtilPlayer.message(caller, F.main("Tutorial", "Invalid Tutorial " + F.elem(args[0]))); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/TutorialCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/TutorialCommand.java index 68429b81f..fea9ca3e3 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/TutorialCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/command/TutorialCommand.java @@ -5,6 +5,8 @@ import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; import mineplex.core.command.MultiCommandBase; import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; import mineplex.game.clans.tutorial.TutorialManager; public class TutorialCommand extends MultiCommandBase @@ -19,6 +21,6 @@ public class TutorialCommand extends MultiCommandBase @Override protected void Help(Player caller, String[] args) { - + UtilPlayer.message(caller, F.main("Tutorial", "/tutorial start ")); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/ClansMainTutorial.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/ClansMainTutorial.java new file mode 100644 index 000000000..967d8878e --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/ClansMainTutorial.java @@ -0,0 +1,50 @@ +package mineplex.game.clans.tutorial.tutorials.clans; + +import java.io.IOException; + +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.game.clans.message.ClansMessageManager; +import mineplex.game.clans.tutorial.Tutorial; +import mineplex.game.clans.tutorial.TutorialWorldManager; +import mineplex.game.clans.tutorial.tutorials.clans.objective.LeaveSpawnObjective; + +public class ClansMainTutorial extends Tutorial +{ + public ClansMainTutorial(JavaPlugin plugin, ClansMessageManager message) + { + super(plugin, message, "Clans Tutorial", "Clans.MainTutorial", Material.DIAMOND_SWORD, (byte) 0); + + try + { + setWorldManager(new TutorialWorldManager(plugin, "main_tutorial", "schematic/ClansTutorial.schematic")); + } + catch (IOException e) + { + e.printStackTrace(); + } + + addObjective(new LeaveSpawnObjective(this, plugin)); + } + + @Override + protected void onFinish(Player player) + { + + } + + @Override + protected void onStart(Player player) + { + player.teleport(getRegion(player).getLocationMap().getLocations(DyeColor.RED).get(0)); + } + + @Override + protected void onQuit(Player player) + { + + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/LeaveSpawnObjective.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/LeaveSpawnObjective.java new file mode 100644 index 000000000..0164ac15c --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/LeaveSpawnObjective.java @@ -0,0 +1,33 @@ +package mineplex.game.clans.tutorial.tutorials.clans.objective; + +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.common.objective.SingleObjective; +import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial; + +public class LeaveSpawnObjective extends SingleObjective +{ + public LeaveSpawnObjective(ClansMainTutorial plugin, JavaPlugin javaPlugin) + { + super(plugin, javaPlugin, "Leave Spawn", "Exit the tutorial spawn area"); + } + + @Override + protected void customStart(Player player) + { + + } + + @Override + protected void customLeave(Player player) + { + + } + + @Override + protected void customFinish(Player player) + { + + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/CombatTutorial.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/CombatTutorial.java deleted file mode 100644 index 90d157f75..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/CombatTutorial.java +++ /dev/null @@ -1,28 +0,0 @@ -package mineplex.game.clans.tutorial.tutorials.combat; - -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import mineplex.core.common.objective.Objective; -import mineplex.game.clans.message.ClansMessageManager; -import mineplex.game.clans.tutorial.Tutorial; -import mineplex.game.clans.tutorial.tutorials.combat.objectives.CustomizeKitObjective; -import mineplex.game.clans.tutorial.tutorials.combat.objectives.EquipArmorObjective; - -public class CombatTutorial extends Tutorial -{ - public CombatTutorial(JavaPlugin plugin, ClansMessageManager message) - { - super(plugin, message, "Combat Tutorial", "combat", Material.DIAMOND_SWORD, (byte) 0); - - addObjective(new EquipArmorObjective(plugin)); - addObjective(new CustomizeKitObjective(plugin)); - } - - @Override - protected void onFinish() - { - - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/CustomizeKitObjective.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/CustomizeKitObjective.java deleted file mode 100644 index 367129fc1..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/CustomizeKitObjective.java +++ /dev/null @@ -1,35 +0,0 @@ -package mineplex.game.clans.tutorial.tutorials.combat.objectives; - -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import mineplex.core.common.objective.OrderedObjective; -import mineplex.game.clans.tutorial.tutorials.combat.objectives.goals.OpenCustomizationGoal; - -public class CustomizeKitObjective extends OrderedObjective -{ - public CustomizeKitObjective(JavaPlugin plugin) - { - super(plugin, "Customize Kit", "Customize your kit"); - - addGoal(new OpenCustomizationGoal(this)); - } - - @Override - protected void customStart(Player player) - { - super.customStart(player); - } - - @Override - protected void customLeave(Player player) - { - - } - - @Override - protected void customFinish(Player player) - { - - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/EquipArmorObjective.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/EquipArmorObjective.java deleted file mode 100644 index 1a908a2cf..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/EquipArmorObjective.java +++ /dev/null @@ -1,77 +0,0 @@ -package mineplex.game.clans.tutorial.tutorials.combat.objectives; - -import java.util.UUID; - -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.java.JavaPlugin; - -import mineplex.core.common.objective.SingleObjective; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; - -public class EquipArmorObjective extends SingleObjective -{ - public EquipArmorObjective(JavaPlugin plugin) - { - super(plugin, "Equip Armor", "Equip Armor"); - } - - @Override - protected void customStart(Player player) - { - player.getInventory().addItem(new ItemStack(Material.IRON_HELMET)); - player.getInventory().addItem(new ItemStack(Material.IRON_CHESTPLATE)); - player.getInventory().addItem(new ItemStack(Material.IRON_LEGGINGS)); - player.getInventory().addItem(new ItemStack(Material.IRON_BOOTS)); - } - - @Override - protected void customLeave(Player player) - { - - } - - @Override - protected void customFinish(Player player) - { - - } - - @EventHandler - public void checkArmor(UpdateEvent event) - { - if (event.getType() != UpdateType.FAST) - return; - - for (UUID uuid : getActive()) - { - Player player = UtilPlayer.searchExact(uuid); - - if (player == null) - { - System.out.println("Tutorial Error: " + getName() + " has UUID with null player: " + uuid); - continue; - } - - if (isEquipped(player)) - finish(player); - } - } - - private boolean isEquipped(Player player) - { - boolean equipped = true; - - if (player.getInventory().getHelmet() == null || player.getInventory().getHelmet().getType() != Material.IRON_HELMET || - player.getInventory().getChestplate() == null || player.getInventory().getChestplate().getType() != Material.IRON_CHESTPLATE || - player.getInventory().getLeggings() == null || player.getInventory().getLeggings().getType() != Material.IRON_LEGGINGS || - player.getInventory().getBoots() == null || player.getInventory().getBoots().getType() != Material.IRON_BOOTS) - equipped = false; - - return equipped; - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/goals/OpenCustomizationGoal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/goals/OpenCustomizationGoal.java deleted file mode 100644 index 7e0b8476d..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/goals/OpenCustomizationGoal.java +++ /dev/null @@ -1,37 +0,0 @@ -package mineplex.game.clans.tutorial.tutorials.combat.objectives.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.minecraft.game.classcombat.shop.event.OpenClassShopEvent; - -public class OpenCustomizationGoal extends ObjectiveGoal -{ - public OpenCustomizationGoal(Objective objective) - { - super(objective, "Open Customization", "Open Customization"); - } - - @Override - protected void customStart(Player player) - { - - } - - @Override - protected void customFinish(Player player) - { - - } - - @EventHandler - public void onOpenClassShop(OpenClassShopEvent event) - { - if (contains(event.getPlayer())) - { - finish(event.getPlayer()); - } - } -}