mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-15 05:33:40 +00:00
Merge branch 'master' of github.com:essentials/Essentials into essmaster
This commit is contained in:
commit
d4a495fb52
7 changed files with 105 additions and 32 deletions
|
@ -7,6 +7,17 @@ import org.bukkit.entity.Player;
|
||||||
public abstract class AbstractState
|
public abstract class AbstractState
|
||||||
{
|
{
|
||||||
private transient boolean abortion = false;
|
private transient boolean abortion = false;
|
||||||
|
private final transient StateMap stateMap;
|
||||||
|
|
||||||
|
public AbstractState(final StateMap stateMap)
|
||||||
|
{
|
||||||
|
this.stateMap = stateMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractState getState(final Class<? extends AbstractState> stateClass)
|
||||||
|
{
|
||||||
|
return stateMap.get(stateClass);
|
||||||
|
}
|
||||||
|
|
||||||
public abstract AbstractState getNextState();
|
public abstract AbstractState getNextState();
|
||||||
|
|
||||||
|
@ -40,7 +51,7 @@ public abstract class AbstractState
|
||||||
|| trimmedAnswer.equalsIgnoreCase("bye")
|
|| trimmedAnswer.equalsIgnoreCase("bye")
|
||||||
|| trimmedAnswer.equalsIgnoreCase("abort"))
|
|| trimmedAnswer.equalsIgnoreCase("abort"))
|
||||||
{
|
{
|
||||||
abortion = true;
|
abort();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final boolean found = reactOnAnswer(trimmedAnswer);
|
final boolean found = reactOnAnswer(trimmedAnswer);
|
||||||
|
@ -64,4 +75,9 @@ public abstract class AbstractState
|
||||||
{
|
{
|
||||||
return abortion;
|
return abortion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void abort()
|
||||||
|
{
|
||||||
|
abortion = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,17 @@ package com.earth2me.essentials.update.states;
|
||||||
public abstract class AbstractYesNoState extends AbstractState
|
public abstract class AbstractYesNoState extends AbstractState
|
||||||
{
|
{
|
||||||
private boolean answer = false;
|
private boolean answer = false;
|
||||||
private final transient AbstractState yesState;
|
private final transient Class<? extends AbstractState> yesState;
|
||||||
private final transient AbstractState noState;
|
private final transient Class<? extends AbstractState> noState;
|
||||||
|
|
||||||
public AbstractYesNoState(final AbstractState yesState, final AbstractState noState)
|
public AbstractYesNoState(final StateMap states, final Class<? extends AbstractState> nextState)
|
||||||
{
|
{
|
||||||
|
this(states, nextState, nextState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractYesNoState(final StateMap states, final Class<? extends AbstractState> yesState, final Class<? extends AbstractState> noState)
|
||||||
|
{
|
||||||
|
super(states);
|
||||||
this.yesState = yesState;
|
this.yesState = yesState;
|
||||||
this.noState = noState;
|
this.noState = noState;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +22,9 @@ public abstract class AbstractYesNoState extends AbstractState
|
||||||
@Override
|
@Override
|
||||||
public AbstractState getNextState()
|
public AbstractState getNextState()
|
||||||
{
|
{
|
||||||
return answer ? yesState : noState;
|
return answer
|
||||||
|
? (yesState == null ? null : getState(yesState))
|
||||||
|
: (noState == null ? null : getState(noState));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.earth2me.essentials.update.states;
|
package com.earth2me.essentials.update.states;
|
||||||
|
|
||||||
import com.earth2me.essentials.update.WorkListener;
|
import com.earth2me.essentials.update.WorkListener;
|
||||||
import com.earth2me.essentials.update.tasks.InstallChat;
|
import com.earth2me.essentials.update.tasks.InstallModule;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
@ -9,9 +9,9 @@ import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class EssentialsChat extends AbstractYesNoState
|
public class EssentialsChat extends AbstractYesNoState
|
||||||
{
|
{
|
||||||
public EssentialsChat(final AbstractState next)
|
public EssentialsChat(final StateMap states)
|
||||||
{
|
{
|
||||||
super(next, next);
|
super(states, EssentialsProtect.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -38,7 +38,7 @@ public class EssentialsChat extends AbstractYesNoState
|
||||||
{
|
{
|
||||||
if (getAnswer())
|
if (getAnswer())
|
||||||
{
|
{
|
||||||
new InstallChat(listener).start();
|
new InstallModule(listener, "EssentialsChat").start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
listener.onWorkDone();
|
listener.onWorkDone();
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.earth2me.essentials.update.states;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.update.WorkListener;
|
||||||
|
import com.earth2me.essentials.update.tasks.InstallModule;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
|
||||||
|
public class EssentialsProtect extends AbstractYesNoState
|
||||||
|
{
|
||||||
|
public EssentialsProtect(final StateMap states)
|
||||||
|
{
|
||||||
|
super(states, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean guessAnswer()
|
||||||
|
{
|
||||||
|
final Plugin plugin = Bukkit.getPluginManager().getPlugin("EssentialsProtect");
|
||||||
|
if (plugin != null)
|
||||||
|
{
|
||||||
|
setAnswer(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void askQuestion(final Player sender)
|
||||||
|
{
|
||||||
|
sender.sendMessage("Do you want to install EssentialsProtect? (yes/no)");
|
||||||
|
sender.sendMessage("Short descriptive text about what EssentialsProtect does.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doWork(final WorkListener listener)
|
||||||
|
{
|
||||||
|
if (getAnswer())
|
||||||
|
{
|
||||||
|
new InstallModule(listener, "EssentialsProtect").start();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
listener.onWorkDone();
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,8 +2,7 @@ package com.earth2me.essentials.update.states;
|
||||||
|
|
||||||
import com.earth2me.essentials.update.WorkListener;
|
import com.earth2me.essentials.update.WorkListener;
|
||||||
import com.earth2me.essentials.update.VersionInfo;
|
import com.earth2me.essentials.update.VersionInfo;
|
||||||
import java.util.ArrayList;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
@ -15,7 +14,7 @@ public class StateMachine extends WorkListener
|
||||||
{
|
{
|
||||||
ABORT, WAIT, DONE
|
ABORT, WAIT, DONE
|
||||||
}
|
}
|
||||||
private final transient List<AbstractState> states = new ArrayList<AbstractState>();
|
private final transient StateMap states = new StateMap();
|
||||||
private transient AbstractState current;
|
private transient AbstractState current;
|
||||||
private final transient Player player;
|
private final transient Player player;
|
||||||
|
|
||||||
|
@ -24,9 +23,9 @@ public class StateMachine extends WorkListener
|
||||||
super(plugin, newVersionInfo);
|
super(plugin, newVersionInfo);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
states.clear();
|
states.clear();
|
||||||
final AbstractState state = new EssentialsChat(null);
|
states.add(new EssentialsChat(states));
|
||||||
states.add(state);
|
states.add(new EssentialsProtect(states));
|
||||||
current = state;
|
current = states.values().iterator().next();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MachineResult askQuestion()
|
public MachineResult askQuestion()
|
||||||
|
@ -60,16 +59,17 @@ public class StateMachine extends WorkListener
|
||||||
current = next;
|
current = next;
|
||||||
return askQuestion();
|
return askQuestion();
|
||||||
}
|
}
|
||||||
private int position = 0;
|
private transient Iterator<AbstractState> iterator;
|
||||||
|
|
||||||
public void startWork()
|
public void startWork()
|
||||||
{
|
{
|
||||||
|
iterator = states.values().iterator();
|
||||||
callStateWork();
|
callStateWork();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callStateWork()
|
private void callStateWork()
|
||||||
{
|
{
|
||||||
if (position > states.size())
|
if (!iterator.hasNext())
|
||||||
{
|
{
|
||||||
if (player.isOnline())
|
if (player.isOnline())
|
||||||
{
|
{
|
||||||
|
@ -77,14 +77,13 @@ public class StateMachine extends WorkListener
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final AbstractState state = states.get(position);
|
final AbstractState state = iterator.next();
|
||||||
state.doWork(this);
|
state.doWork(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onWorkAbort(final String message)
|
public void onWorkAbort(final String message)
|
||||||
{
|
{
|
||||||
position = 0;
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable()
|
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -101,7 +100,6 @@ public class StateMachine extends WorkListener
|
||||||
@Override
|
@Override
|
||||||
public void onWorkDone(final String message)
|
public void onWorkDone(final String message)
|
||||||
{
|
{
|
||||||
position++;
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable()
|
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.earth2me.essentials.update.states;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
|
||||||
|
public class StateMap extends LinkedHashMap<Class<? extends AbstractState>, AbstractState>
|
||||||
|
{
|
||||||
|
public StateMap()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractState add(AbstractState state)
|
||||||
|
{
|
||||||
|
return put(state.getClass(), state);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,12 +0,0 @@
|
||||||
package com.earth2me.essentials.update.tasks;
|
|
||||||
|
|
||||||
import com.earth2me.essentials.update.WorkListener;
|
|
||||||
|
|
||||||
|
|
||||||
public class InstallChat extends InstallModule
|
|
||||||
{
|
|
||||||
public InstallChat(final WorkListener listener)
|
|
||||||
{
|
|
||||||
super(listener, "EssentialsChat");
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue