Merge branch 'pregametutorial' of http://184.154.0.242:7990/scm/min/mineplex into type-wars

This commit is contained in:
Sarah 2015-12-19 00:49:16 +01:00
commit dab2416ccd
3 changed files with 132 additions and 35 deletions

View File

@ -3,7 +3,6 @@ package nautilus.game.arcade.gametutorial;
import java.util.HashMap;
import mineplex.core.common.util.UtilServer;
import mineplex.core.visibility.VisibilityManager;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.gametutorial.events.GameTutorialEndEvent;
@ -36,9 +35,11 @@ public abstract class GameTutorial
public boolean RunTasksSync = true;
public boolean PlayTutorialSounds = false;
public boolean ShowPrepareTimer = false;
public boolean CustomEnding = false;
public long TimeBetweenPhase = 0;
public long StartAfterTutorial = 5000;
public long CustomEndingTime = 5000;
public GameTutorial(ArcadeManager manager, TutorialPhase[] phases)
{
@ -47,6 +48,9 @@ public abstract class GameTutorial
_players = new HashMap<>();
}
/**
* start the Tutorial (never use this)
*/
final public void start()
{
_hasStarted = true;
@ -54,7 +58,6 @@ public abstract class GameTutorial
for(TutorialPhase phase : _phases)
phase.setTutorial(this);
//Manager.GetGame().PrepareTime = 60000;
Manager.GetChat().Silence(60000, false);
_started = System.currentTimeMillis();
Manager.getPluginManager().callEvent(new GameTutorialStartEvent(this));
@ -72,6 +75,9 @@ public abstract class GameTutorial
_currentPhase.teleport();
}
/**
* Stting next Phase/ending Tutorial
*/
protected void nextPhase(boolean phaseOne)
{
TutorialPhase from = _currentPhase;
@ -80,25 +86,33 @@ public abstract class GameTutorial
if(_currentPhase == null)
{
onEnd();
_hasEnded = true;
endTutorial();
final GameTutorial tutorial = this;
Manager.runSyncLater(new Runnable()
// has ended
if(!CustomEnding)
{
@Override
public void run()
onEnd();
_hasEnded = true;
endTutorial();
final GameTutorial tutorial = this;
Manager.runSyncLater(new Runnable()
{
Manager.getPluginManager().callEvent(new GameTutorialEndEvent(tutorial));
}
}, 5);
@Override
public void run()
{
Manager.getPluginManager().callEvent(new GameTutorialEndEvent(tutorial));
}
}, 5);
}
}
else
{
Manager.GetChat().Silence(70000, false);
onPhaseChange(_currentPhase);
Manager.getPluginManager().callEvent(new GameTutorialPhaseEvent(this, from, _currentPhase));
_currentPhase.start(phaseOne);
// setting another Phase, if Tutorial hasn't stopped yet
if(!_hasEnded)
{
Manager.GetChat().Silence(70000, false);
onPhaseChange(_currentPhase);
Manager.getPluginManager().callEvent(new GameTutorialPhaseEvent(this, from, _currentPhase));
_currentPhase.start(phaseOne);
}
}
}
@ -111,19 +125,19 @@ public abstract class GameTutorial
{
for(final Player player : _players.keySet())
{
//VisibilityManager.Instance.setVisibility(player, true, UtilServer.getPlayers());
Manager.runSyncLater(new Runnable()
{
@Override
public void run()
{
for(Player player : Manager.GetGame().GetPlayers(true))
// Player visibility/fly mode
for(Player other : Manager.GetGame().GetPlayers(false))
{
for(Player other : Manager.GetGame().GetPlayers(true))
{
player.showPlayer(other);
}
}
if(player == other)
continue;
other.showPlayer(player);
}
player.setAllowFlight(false);
player.setFlying(false);
}
@ -135,17 +149,20 @@ public abstract class GameTutorial
@Override
public void run()
{
// Spawn teleporting
_team.SpawnTeleport();
}
}, 5);
}
}
// setting the right prepare Time after the Tutorial ends
Manager.GetChat().Silence(StartAfterTutorial, false);
Manager.GetGame().PrepareTime = (System.currentTimeMillis() - Manager.GetGame().GetStateTime()) + StartAfterTutorial;
}
protected TutorialPhase getNextPhase()
{
// getting next TutorialPhase
for(TutorialPhase phase : _phases)
{
if(_currentPhase == null && phase.ID() == 1)
@ -164,13 +181,13 @@ public abstract class GameTutorial
{
for(Player player : UtilServer.getPlayers())
{
// setting Players into fly mode and save their Locations
int i = 0;
if(Manager.GetGame().GetTeam(player) == _team)
{
_players.put(player, Manager.GetGame().GetTeam(player).GetSpawns().get(i));
player.setAllowFlight(true);
player.setFlying(true);
// VisibilityManager.Instance.setVisibility(player, false, UtilServer.getPlayers());
i++;
}
}
@ -206,16 +223,42 @@ public abstract class GameTutorial
return _team;
}
public void onTick(int tick){}
public void onStart(){}
public void onPhaseChange(TutorialPhase phase){}
public void onEnd(){}
/**
* only available if CustomEnding is enabled
* You can end the tutorial with this method
* if you set CutomEnding to true, you have to run this method!
*/
public void end()
{
if(CustomEnding)
{
// Ending
onEnd();
_hasEnded = true;
Thread thread = _currentPhase.getThread();
if(thread.isAlive())
thread.destroy();
endTutorial();
final GameTutorial tutorial = this;
Manager.runSyncLater(new Runnable()
{
@Override
public void run()
{
Manager.getPluginManager().callEvent(new GameTutorialEndEvent(tutorial));
}
}, 5);
}
else
{
System.out.println("Only allowed while Custom Ending is enabled");
}
}
public int tick()
{
// Fix for Visibility Manager not really working
if(!_hasEnded && hasStarted())
{
for(Player player : UtilServer.getPlayers())
@ -249,4 +292,17 @@ public abstract class GameTutorial
{
return _currentPhase.getPhaseTime();
}
/*
* some overrideable methods that can be used to synchronize the tutorial events
*/
public void onTick(int tick){}
public void onStart(){}
public void onPhaseChange(TutorialPhase phase){}
public void onEnd(){}
}

View File

@ -18,6 +18,8 @@ public abstract class TutorialPhase
private Location _target;
private boolean _hasEnded;
private Thread _thread;
private long _started;
private TutorialText _currentText;
@ -27,6 +29,9 @@ public abstract class TutorialPhase
_text = text;
}
/**
* start the Phase (never use this as well)
*/
final public void start(boolean phaseOne)
{
_hasEnded = false;
@ -39,6 +44,9 @@ public abstract class TutorialPhase
displayText();
}
/**
* Teleporting Players and keeping them if SetTutorialPositions == true
*/
final public void teleport()
{
if(!getTutorial().SetTutorialPositions)
@ -51,6 +59,9 @@ public abstract class TutorialPhase
}
}
/**
* preparing Pitch/Yaw of the location
*/
private void prepareLocations()
{
Vector vector = new Vector(_target.getBlockX() - _location.getBlockX(), _target.getBlockY() - _location.getBlockY(), _target.getBlockZ() - _location.getBlockZ());
@ -60,6 +71,9 @@ public abstract class TutorialPhase
_location.setYaw(yaw);
}
/**
* teleporting players until Phase ends
*/
private void updatePlayers()
{
new Thread(new Runnable()
@ -74,6 +88,7 @@ public abstract class TutorialPhase
@Override
public void run()
{
// teleport Players Sync
if(!_hasEnded && !getTutorial().hasEnded())
{
for(Player player : _tutorial.getPlayers().keySet())
@ -87,6 +102,7 @@ public abstract class TutorialPhase
});
try
{
// sleep for 1 tick
Thread.sleep(50);
} catch (InterruptedException e)
{
@ -97,9 +113,13 @@ public abstract class TutorialPhase
}).start();
}
/**
* displays all messages set in the constructor
* will end Phase if no more messages are available or Tutorial has already ended
*/
public void displayText()
{
new Thread(new Runnable()
_thread = new Thread(new Runnable()
{
@Override
public void run()
@ -109,6 +129,7 @@ public abstract class TutorialPhase
TutorialText text = getNextMessage();
if(text == null)
{
// ending Phase
_tutorial.Manager.runSyncLater(new Runnable()
{
@Override
@ -123,6 +144,7 @@ public abstract class TutorialPhase
}
else
{
// displaying next message
Player[] players = new Player[_tutorial.getPlayers().keySet().size()];
int i = 0;
for(Player player : _tutorial.getPlayers().keySet())
@ -148,9 +170,13 @@ public abstract class TutorialPhase
}
}
}).start();
});
_thread.start();
}
/**
* firing abstract method Sync/Async depending on the RunTasksSync Flag
*/
private void displayMessage(final TutorialText text)
{
if(_tutorial.RunTasksSync)
@ -170,6 +196,9 @@ public abstract class TutorialPhase
}
}
/**
* getting next message
*/
protected TutorialText getNextMessage()
{
for(TutorialText text : _text)
@ -228,6 +257,15 @@ public abstract class TutorialPhase
return _started;
}
public Thread getThread()
{
return _thread;
}
/*
* some overrideable methods that can be used to synchronize the tutorial events
*/
public void onStart(){}
public void onMessageDisplay(TutorialText text){}

View File

@ -220,6 +220,9 @@ public class GameManager implements Listener
team.getTutorial().start();
timeUsage = team.getTutorial().StartAfterTutorial;
timeUsage = timeUsage + (team.getTutorial().TimeBetweenPhase * team.getTutorial().getPhases().length);
if(team.getTutorial().CustomEnding)
timeUsage = timeUsage + team.getTutorial().CustomEndingTime;
for(TutorialPhase phase : team.getTutorial().getPhases())
{
for(TutorialText text : phase.getText())
@ -234,9 +237,9 @@ public class GameManager implements Listener
if(checkForTimer)
{
if(team.getTutorial().ShowPrepareTimer)
finished = false;
else
finished = true;
else
finished = false;
}
}
}