Add support for 1.9 resource packs, Text Tutorials
This commit is contained in:
parent
2aa68d3e16
commit
1228ca227e
@ -32,6 +32,7 @@ import mineplex.serverdata.commands.ServerCommandManager;
|
||||
public class ResourcePackManager extends MiniPlugin implements CommandCallback
|
||||
{
|
||||
private String _resourcePackUrl;
|
||||
private String _resourcePackUrl19; // Resource pack for 1.9 clients
|
||||
private boolean _resourcePackRequired;
|
||||
private NautHashMap<String, Boolean> _resourcePackUsers = new NautHashMap<String, Boolean>();
|
||||
private NautHashMap<String, Long> _resourcePackNoResponse = new NautHashMap<String, Long>();
|
||||
@ -62,7 +63,10 @@ public class ResourcePackManager extends MiniPlugin implements CommandCallback
|
||||
}
|
||||
|
||||
_resourcePackUsers.put(player.getName(), false);
|
||||
player.setResourcePack(_resourcePackUrl);
|
||||
|
||||
String url = getUrl(player);
|
||||
System.out.println("Set resource pack for player: " + player + " to " + url);
|
||||
player.setResourcePack(url);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -89,7 +93,7 @@ public class ResourcePackManager extends MiniPlugin implements CommandCallback
|
||||
|
||||
// Send it again, enforce it!
|
||||
_resourcePackNoResponse.put(player.getName(), System.currentTimeMillis());
|
||||
player.setResourcePack(_resourcePackUrl);
|
||||
player.setResourcePack(getUrl(player));
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,6 +148,8 @@ public class ResourcePackManager extends MiniPlugin implements CommandCallback
|
||||
{
|
||||
_resourcePackUsers.remove(player.getName());
|
||||
}
|
||||
|
||||
System.out.println("status: " + player.getName() + " " + event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -177,6 +183,11 @@ public class ResourcePackManager extends MiniPlugin implements CommandCallback
|
||||
}
|
||||
|
||||
public void setResourcePack(String resourcePack, boolean forceResourcePack)
|
||||
{
|
||||
setResourcePack(resourcePack, resourcePack, forceResourcePack);
|
||||
}
|
||||
|
||||
public void setResourcePack(String resourcePack, String resourcePack19, boolean forceResourcePack)
|
||||
{
|
||||
if (Objects.equal(resourcePack, _resourcePackUrl) && forceResourcePack == _resourcePackRequired)
|
||||
{
|
||||
@ -186,6 +197,7 @@ public class ResourcePackManager extends MiniPlugin implements CommandCallback
|
||||
_resourcePackNoResponse.clear();
|
||||
_resourcePackUsers.clear();
|
||||
_resourcePackUrl = resourcePack == null || resourcePack.isEmpty() ? null : resourcePack;
|
||||
_resourcePackUrl19 = resourcePack19;
|
||||
_resourcePackRequired = forceResourcePack;
|
||||
|
||||
if (_resourcePackUrl == null || _resourcePackUrl.isEmpty())
|
||||
@ -207,7 +219,7 @@ public class ResourcePackManager extends MiniPlugin implements CommandCallback
|
||||
}
|
||||
|
||||
_resourcePackUsers.put(player.getName(), false);
|
||||
player.setResourcePack(_resourcePackUrl);
|
||||
player.setResourcePack(getUrl(player));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -235,4 +247,9 @@ public class ResourcePackManager extends MiniPlugin implements CommandCallback
|
||||
}
|
||||
}
|
||||
|
||||
private String getUrl(Player player)
|
||||
{
|
||||
return UtilPlayer.is1_9(player) ? _resourcePackUrl19 : _resourcePackUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,154 @@
|
||||
package mineplex.core.texttutorial;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.task.TaskManager;
|
||||
import mineplex.core.texttutorial.tutorial.Tutorial;
|
||||
import mineplex.core.texttutorial.tutorial.TutorialData;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
public class TextTutorialManager extends MiniPlugin
|
||||
{
|
||||
private DonationManager _donationManager;
|
||||
private TaskManager _taskManager;
|
||||
|
||||
private HashSet<Tutorial> _tutorials;
|
||||
|
||||
public TextTutorialManager(JavaPlugin plugin, DonationManager donationManager, TaskManager taskManager)
|
||||
{
|
||||
super("Text Tutorial", plugin);
|
||||
|
||||
_donationManager = donationManager;
|
||||
_taskManager = taskManager;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void startTutorial(PlayerInteractEntityEvent event)
|
||||
{
|
||||
if (isInTutorial(event.getPlayer()))
|
||||
return;
|
||||
|
||||
if (!(event.getRightClicked() instanceof LivingEntity))
|
||||
return;
|
||||
|
||||
LivingEntity ent = (LivingEntity)event.getRightClicked();
|
||||
|
||||
String name = ent.getCustomName();
|
||||
if (name == null)
|
||||
return;
|
||||
|
||||
for (Tutorial tut : _tutorials)
|
||||
{
|
||||
if (name.contains(tut.getName()))
|
||||
{
|
||||
UtilPlayer.message(event.getPlayer(), F.main("Tutorial", "You started " + F.elem(tut.getName()) + "."));
|
||||
tut.startTutorial(event.getPlayer());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void update(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.TICK)
|
||||
return;
|
||||
|
||||
for (final Tutorial tut : _tutorials)
|
||||
{
|
||||
Iterator<TutorialData> iterator = tut.getTutorialDatas().iterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
TutorialData data = iterator.next();
|
||||
final Player player = data.getPlayer();
|
||||
|
||||
//Check if Phase Completed
|
||||
if (data.tick())
|
||||
{
|
||||
//Next Phase
|
||||
if (data.getPhaseStep() < tut.getPhaseSize())
|
||||
{
|
||||
data.setNextPhase(tut.getPhase(data.getPhaseStep()));
|
||||
}
|
||||
//End Tutorial
|
||||
else
|
||||
{
|
||||
iterator.remove();
|
||||
|
||||
//Inform
|
||||
UtilPlayer.message(player, F.main("Tutorial", "You completed " + F.elem(tut.getName()) + "."));
|
||||
|
||||
//Gems
|
||||
if (tut.getGemReward() > 0)
|
||||
{
|
||||
if (!_taskManager.hasCompletedTask(player, tut.getTaskId()))
|
||||
{
|
||||
_taskManager.completedTask(new Callback<Boolean>()
|
||||
{
|
||||
public void run(Boolean completed)
|
||||
{
|
||||
_donationManager.RewardGems(new Callback<Boolean>()
|
||||
{
|
||||
public void run(Boolean completed)
|
||||
{
|
||||
if (completed)
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Tutorial", "You received " + F.elem(C.cGreen + tut.getGemReward() + " Gems") + "."));
|
||||
|
||||
//Sound
|
||||
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
|
||||
}
|
||||
}
|
||||
}, "Tutorial " + tut.getName(), player.getName(), player.getUniqueId(), tut.getGemReward());
|
||||
}
|
||||
}, player, tut.getTaskId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
for (Tutorial tut : _tutorials)
|
||||
tut.stopTutorial(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void cancelInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if (isInTutorial(event.getPlayer()))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public boolean isInTutorial(Player player)
|
||||
{
|
||||
for (Tutorial tutorial : _tutorials)
|
||||
{
|
||||
if (tutorial.isInTutorial(player))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package mineplex.core.texttutorial.tutorial;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class Phase
|
||||
{
|
||||
private Location _location;
|
||||
private String _header;
|
||||
private String[] _text;
|
||||
|
||||
public Phase(Location location, String header, String[] text)
|
||||
{
|
||||
_location = location;
|
||||
_header = header;
|
||||
_text = text;
|
||||
}
|
||||
|
||||
public Location getLocation()
|
||||
{
|
||||
return _location;
|
||||
}
|
||||
|
||||
public void setLocation(Location location)
|
||||
{
|
||||
_location = location;
|
||||
}
|
||||
|
||||
public String getHeader()
|
||||
{
|
||||
return _header;
|
||||
}
|
||||
|
||||
public void setHeader(String header)
|
||||
{
|
||||
_header = header;
|
||||
}
|
||||
|
||||
public String[] getText()
|
||||
{
|
||||
return _text;
|
||||
}
|
||||
|
||||
public void setText(String[] text)
|
||||
{
|
||||
_text = text;
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package mineplex.core.texttutorial.tutorial;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class Tutorial
|
||||
{
|
||||
private String _name;
|
||||
private String _taskId;
|
||||
private int _gemReward;
|
||||
|
||||
private ArrayList<Phase> _phases;
|
||||
private HashMap<Player, TutorialData> _playerMap;
|
||||
|
||||
public Tutorial(String name, String taskId, int gemReward)
|
||||
{
|
||||
_name = name;
|
||||
_taskId = taskId;
|
||||
_gemReward = gemReward;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
public String getTaskId()
|
||||
{
|
||||
return _taskId;
|
||||
}
|
||||
|
||||
public void startTutorial(Player player)
|
||||
{
|
||||
_playerMap.put(player, new TutorialData(player, _phases.get(0)));
|
||||
}
|
||||
|
||||
public void stopTutorial(Player player)
|
||||
{
|
||||
_playerMap.remove(player);
|
||||
}
|
||||
|
||||
public boolean isInTutorial(Player player)
|
||||
{
|
||||
return _playerMap.containsKey(player);
|
||||
}
|
||||
|
||||
protected void addPhase(Phase phase)
|
||||
{
|
||||
_phases.add(phase);
|
||||
}
|
||||
|
||||
public Collection<TutorialData> getTutorialDatas()
|
||||
{
|
||||
return _playerMap.values();
|
||||
}
|
||||
|
||||
public Phase getPhase(int phaseIndex)
|
||||
{
|
||||
return _phases.get(phaseIndex);
|
||||
}
|
||||
|
||||
public int getPhaseSize()
|
||||
{
|
||||
return _phases.size();
|
||||
}
|
||||
|
||||
public int getGemReward()
|
||||
{
|
||||
return _gemReward;
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
package mineplex.core.texttutorial.tutorial;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
|
||||
public class TutorialData
|
||||
{
|
||||
private Player _player;
|
||||
private Phase _phase;
|
||||
private int _phaseStep;
|
||||
private int _textStep;
|
||||
private long _sleep;
|
||||
|
||||
public TutorialData(Player player, Phase startPhase)
|
||||
{
|
||||
_player = player;
|
||||
_phase = startPhase;
|
||||
_phaseStep = 0;
|
||||
_textStep = 0;
|
||||
_sleep = System.currentTimeMillis() + 3000;
|
||||
}
|
||||
|
||||
public boolean tick()
|
||||
{
|
||||
if (!_player.getLocation().equals(_phase.getLocation()))
|
||||
_player.teleport(_phase.getLocation());
|
||||
|
||||
if (System.currentTimeMillis() < _sleep)
|
||||
return false;
|
||||
|
||||
if (_textStep >= _phase.getText().length)
|
||||
{
|
||||
// No more text to display, move to next phase
|
||||
_phaseStep++;
|
||||
_sleep = System.currentTimeMillis() + 2000;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Display Text
|
||||
String text = _phase.getText()[_textStep];
|
||||
|
||||
UtilPlayer.message(_player, " ");
|
||||
UtilPlayer.message(_player, " ");
|
||||
UtilPlayer.message(_player, " ");
|
||||
UtilPlayer.message(_player, C.cGreen + C.Strike + C.Bold + "========================================");
|
||||
UtilPlayer.message(_player, C.cGold + C.Bold + _phase.getHeader());
|
||||
UtilPlayer.message(_player, " ");
|
||||
|
||||
for (int i=0 ; i<=_textStep ; i++)
|
||||
UtilPlayer.message(_player, " " + _phase.getText()[i]);
|
||||
|
||||
for (int i=_textStep ; i<=5 ; i++)
|
||||
UtilPlayer.message(_player, " ");
|
||||
|
||||
UtilPlayer.message(_player, C.cGreen + C.Strike + C.Bold + "========================================");
|
||||
|
||||
if (text.length() > 0)
|
||||
{
|
||||
_player.playSound(_player.getLocation(), Sound.ORB_PICKUP, 2f, 1.5f);
|
||||
_sleep = System.currentTimeMillis() + 1000 + (50*text.length());
|
||||
}
|
||||
else
|
||||
{
|
||||
_sleep = System.currentTimeMillis() + 600;
|
||||
}
|
||||
|
||||
_textStep++;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setNextPhase(Phase phase)
|
||||
{
|
||||
_phase = phase;
|
||||
_textStep = 0;
|
||||
_player.teleport(_phase.getLocation());
|
||||
}
|
||||
|
||||
public Phase getPhase()
|
||||
{
|
||||
return _phase;
|
||||
}
|
||||
|
||||
public long getSleep()
|
||||
{
|
||||
return _sleep;
|
||||
}
|
||||
|
||||
public int getPhaseStep()
|
||||
{
|
||||
return _phaseStep;
|
||||
}
|
||||
|
||||
public Player getPlayer()
|
||||
{
|
||||
return _player;
|
||||
}
|
||||
}
|
@ -127,7 +127,7 @@ public class Clans extends JavaPlugin
|
||||
new FriendManager(this, _clientManager, preferenceManager, portal);
|
||||
new InventoryManager(this, _clientManager);
|
||||
ResourcePackManager resourcePackManager = new ResourcePackManager(this, portal);
|
||||
resourcePackManager.setResourcePack("http://b.garblox.com/CLANS_BETA_PACK_V6.zip", true);
|
||||
resourcePackManager.setResourcePack("http://phinary.ca/ResClans.zip", "http://phinary.ca/ResClans19.zip", true);
|
||||
|
||||
// Enable custom-gear related managers
|
||||
new CustomTagFix(this, packetHandler);
|
||||
|
@ -0,0 +1,14 @@
|
||||
package mineplex.game.clans.texttutorial;
|
||||
|
||||
import mineplex.core.texttutorial.tutorial.Phase;
|
||||
import mineplex.core.texttutorial.tutorial.Tutorial;
|
||||
|
||||
public class ClassTutorial extends Tutorial
|
||||
{
|
||||
public ClassTutorial()
|
||||
{
|
||||
super("Class Guide", "Clans.TextTutorial.Class", 0);
|
||||
|
||||
addPhase(new Phase(null, "Classes", new String[] { "" }));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user