Testing ArcadePlayer implementation
This commit is contained in:
parent
ee202bc7f5
commit
7d9b97180d
@ -26,6 +26,7 @@ public abstract class MiniClientPlugin<DataType extends Object> extends MiniPlug
|
||||
{
|
||||
synchronized (_clientDataLock)
|
||||
{
|
||||
saveData(event.GetName());
|
||||
_clientData.remove(event.GetName());
|
||||
}
|
||||
}
|
||||
@ -40,6 +41,8 @@ public abstract class MiniClientPlugin<DataType extends Object> extends MiniPlug
|
||||
return _clientData.get(name);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveData(String name) {}
|
||||
|
||||
public DataType Get(Player player)
|
||||
{
|
||||
|
@ -3,6 +3,7 @@ package mineplex.core.customdata;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -23,7 +24,7 @@ public class CustomDataManager extends MiniDbClientPlugin<PlayerCustomData>
|
||||
{
|
||||
super("Custom Data Manager", plugin, clientManager);
|
||||
|
||||
_repository = new CustomDataRepository(plugin, clientManager);
|
||||
_repository = new CustomDataRepository(plugin, clientManager, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,16 +50,9 @@ public class CustomDataManager extends MiniDbClientPlugin<PlayerCustomData>
|
||||
return new PlayerCustomData(_repository);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(final PlayerQuitEvent e)
|
||||
@Override
|
||||
public void saveData(String name)
|
||||
{
|
||||
getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
_repository.saveData(e.getPlayer(), Get(e.getPlayer()));
|
||||
}
|
||||
});
|
||||
_repository.saveData(name);
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.customdata.CustomData;
|
||||
import mineplex.core.customdata.CustomDataManager;
|
||||
import mineplex.core.customdata.PlayerCustomData;
|
||||
import mineplex.core.database.DBPool;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
@ -30,12 +31,14 @@ public class CustomDataRepository extends RepositoryBase
|
||||
private ArrayList<CustomData> _dataKeys;
|
||||
|
||||
private CoreClientManager _clientManager;
|
||||
private CustomDataManager _customDataManager;
|
||||
|
||||
public CustomDataRepository(JavaPlugin plugin, CoreClientManager clientManager)
|
||||
public CustomDataRepository(JavaPlugin plugin, CoreClientManager clientManager, CustomDataManager customDataManager)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
|
||||
_clientManager = clientManager;
|
||||
_customDataManager = customDataManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,32 +67,47 @@ public class CustomDataRepository extends RepositoryBase
|
||||
});
|
||||
}
|
||||
|
||||
public void saveData(Player player, PlayerCustomData data)
|
||||
public void saveData(String name)
|
||||
{
|
||||
PlayerCustomData data = _customDataManager.Get(name);
|
||||
|
||||
System.out.println("saving data for " + name);
|
||||
System.out.println("size = " + data.getDataMap().keySet().size());
|
||||
|
||||
for (CustomData cd : data.getDataMap().keySet())
|
||||
{
|
||||
executeQuery(UPDATE_DATA, new ResultSetCallable()
|
||||
{
|
||||
@Override
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||
{
|
||||
if (!resultSet.next())
|
||||
System.out.println(cd.getKey());
|
||||
|
||||
executeInsert(UPDATE_DATA, new ResultSetCallable()
|
||||
{
|
||||
// Not already in the DB
|
||||
executeUpdate(
|
||||
INSERT_DATA,
|
||||
new ColumnInt("account", _clientManager.getAccountId(player)),
|
||||
new ColumnInt("customData", cd.getId()),
|
||||
new ColumnInt("data", data.getDataMap().get(cd))
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
@Override
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||
{
|
||||
System.out.println("executed update data");
|
||||
|
||||
if (!resultSet.isBeforeFirst())
|
||||
{
|
||||
System.out.println("empty result set");
|
||||
|
||||
// Not already in the DB
|
||||
executeUpdate(
|
||||
INSERT_DATA,
|
||||
new ColumnInt("account", _clientManager.Get(name).getAccountId()),
|
||||
new ColumnInt("customData", cd.getId()),
|
||||
new ColumnInt("data", data.getDataMap().get(cd))
|
||||
);
|
||||
}
|
||||
else
|
||||
System.out.println("no second execute");
|
||||
}
|
||||
},
|
||||
new ColumnInt("data", data.getDataMap().get(cd)),
|
||||
new ColumnInt("account", _clientManager.getAccountId(player)),
|
||||
new ColumnInt("account", _clientManager.Get(name).getAccountId()),
|
||||
new ColumnInt("customData", cd.getId())
|
||||
);
|
||||
}
|
||||
|
||||
System.out.println("complete");
|
||||
}
|
||||
|
||||
public void registerKey(String key)
|
||||
|
@ -22,6 +22,7 @@ import org.bukkit.entity.Zombie;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
@ -125,6 +126,23 @@ public class Gladiators extends SoloGame
|
||||
_firstRound = true;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void testPlayer(PlayerCommandPreprocessEvent e)
|
||||
{
|
||||
if (!e.getPlayer().getName().equals("WilliamTiger"))
|
||||
return;
|
||||
|
||||
if (e.getMessage().equalsIgnoreCase("/arcadeplayer"))
|
||||
{
|
||||
Manager.getArcadePlayer(e.getPlayer()).put("test", 100);
|
||||
e.getPlayer().sendMessage(C.cGreen + "Added the test value!");
|
||||
}
|
||||
else if (e.getMessage().equalsIgnoreCase("/getback"))
|
||||
{
|
||||
e.getPlayer().sendMessage("value: " + Manager.getArcadePlayer(e.getPlayer()).get("test"));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void tutorialStart(GameTutorialStartEvent e)
|
||||
{
|
||||
|
@ -24,6 +24,6 @@ public class ArcadePlayer extends MineplexPlayer
|
||||
@Override
|
||||
public String getKeyPrefix()
|
||||
{
|
||||
return "arcade." + _arcadeManager.GetGame().GetName() + ".";
|
||||
return "arcade." + _arcadeManager.GetGame().GetName().toLowerCase().replaceAll(" ", ".") + ".";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user