Merge branch 'master' of ssh://dev.mineplex.com:7999/min/mineplex

This commit is contained in:
Chiss 2013-10-25 21:25:36 +11:00
commit 61b7a86b67
15 changed files with 676 additions and 42 deletions

Binary file not shown.

View File

@ -11,8 +11,6 @@ public class CoreClient
private Player _player;
private Rank _rank;
private boolean _filterChat;
public CoreClient(Player player)
{
_player = player;
@ -55,16 +53,6 @@ public class CoreClient
_accountId = accountId;
}
public void SetFilterChat(Boolean filterChat)
{
_filterChat = filterChat;
}
public boolean GetFilterChat()
{
return _filterChat;
}
public Rank GetRank()
{
return _rank;

View File

@ -1,10 +1,12 @@
package mineplex.core.account;
import java.sql.Connection;
import java.util.HashSet;
import mineplex.core.account.event.AsyncClientLoadEvent;
import mineplex.core.account.event.ClientUnloadEvent;
import mineplex.core.account.event.ClientWebResponseEvent;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.account.repository.AccountRepository;
import mineplex.core.account.repository.token.ClientToken;
import mineplex.core.common.Rank;
@ -131,6 +133,8 @@ public class CoreClientManager implements Listener
private void LoadClient(CoreClient client, String ipAddress)
{
// Prep for mysql
ClientToken token = null;
Gson gson = new Gson();
@ -142,6 +146,31 @@ public class CoreClientManager implements Listener
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response));
Bukkit.getServer().getPluginManager().callEvent(new AsyncClientLoadEvent(token, client));
Connection connection = null;
try
{
Bukkit.getServer().getPluginManager().callEvent(new RetrieveClientInformationEvent(connection));
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (connection != null)
{
try
{
connection.close();
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
}
}
@EventHandler(priority = EventPriority.LOWEST)

View File

@ -0,0 +1,33 @@
package mineplex.core.account.event;
import java.sql.Connection;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class RetrieveClientInformationEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private Connection _connection;
public RetrieveClientInformationEvent(Connection connection)
{
_connection = connection;
}
public Connection getConnection()
{
return _connection;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -1,7 +1,5 @@
package mineplex.core.account.repository;
import java.util.List;
import mineplex.core.account.repository.token.LoginToken;
import mineplex.core.account.repository.token.RankUpdateToken;
import mineplex.core.common.Rank;
@ -17,12 +15,6 @@ public class AccountRepository
{
_webAddress = webAddress;
}
@SuppressWarnings("unchecked")
public List<String> GetAllClientNames()
{
return new JsonWebCall(_webAddress + "PlayerAccount/GetAccountNames").Execute(List.class);
}
public String GetClient(String name, String ipAddress)
{

View File

@ -0,0 +1,38 @@
package mineplex.core.account.repository;
import mineplex.core.mysql.RepositoryBase;
public class MysqlAccountRepository extends RepositoryBase
{
private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS Accounts (id INT NOT NULL AUTO_INCREMENT, name VARCHAR(40), gems INT, rank VARCHAR(40), rankPerm BOOL, rankExpire LONG, lastLogin LONG, totalPlayTime LONG, PRIMARY KEY (id));";
public MysqlAccountRepository(String connectionUrl, String username, String password)
{
super(connectionUrl, username, password);
}
/*
public String GetClient(String name, String ipAddress)
{
return "";
}
public void SaveRank(Callback<Rank> callback, String name, Rank rank, boolean perm)
{
RankUpdateToken token = new RankUpdateToken();
token.Name = name;
token.Rank = rank.toString();
token.Perm = perm;
//new AsyncJsonWebCall(_webAddress + "PlayerAccount/RankUpdate").Execute(Rank.class, callback, token);
}
*/
@Override
protected void initialize()
{
executeQuery(CREATE_ACCOUNT_TABLE);
}
@Override
protected void update() { }
}

View File

@ -1,12 +1,14 @@
package mineplex.core.chat;
import mineplex.core.MiniPlugin;
import mineplex.core.MiniClientPlugin;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.chat.command.BroadcastCommand;
import mineplex.core.chat.command.SilenceCommand;
import mineplex.core.chat.repository.ChatRepository;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
@ -20,9 +22,10 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class Chat extends MiniPlugin
public class Chat extends MiniClientPlugin<ChatClient>
{
private CoreClientManager _clientManager;
private ChatRepository _repository;
private long _silenced = 0;
@ -31,6 +34,7 @@ public class Chat extends MiniPlugin
super("Chat", plugin);
_clientManager = clientManager;
//_repository = new ChatRepository(plugin);
}
@Override
@ -40,6 +44,12 @@ public class Chat extends MiniPlugin
AddCommand(new BroadcastCommand(this));
}
@EventHandler
public void retrieveClientInformation(RetrieveClientInformationEvent event)
{
_repository.loadClientInformation(event.getConnection());
}
public void Silence(long duration, boolean inform)
{
//Set Silenced
@ -68,6 +78,11 @@ public class Chat extends MiniPlugin
event.getPlayer().sendMessage(F.main(GetName(), "Quite full of yourself aren't you? Nobody cares."));
event.setCancelled(true);
}
else if (event.getMessage().startsWith("/tell"))
{
event.getPlayer().sendMessage(F.main(GetName(), "Step back bro, thats not a command on this server!"));
event.setCancelled(true);
}
}
@EventHandler
@ -140,4 +155,10 @@ public class Chat extends MiniPlugin
{
return _silenced;
}
@Override
protected ChatClient AddPlayer(String player)
{
return new ChatClient();
}
}

View File

@ -0,0 +1,6 @@
package mineplex.core.chat.repository;
public class ChatClientToken
{
}

View File

@ -0,0 +1,163 @@
package mineplex.core.chat.repository;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.mysql.AccountPreferenceRepository;
public class ChatRepository extends AccountPreferenceRepository
{
private static String ALTER_ACCOUNT_PREFERENCE_TABLE = "SET @s = (SELECT IF((SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'accountPreferences' AND table_schema = DATABASE() AND column_name = 'filterChat') > 0, 'SELECT 1', 'ALTER TABLE accountPreferences ADD filterChat BOOL')); PREPARE stmt FROM @s; EXECUTE stmt;";
private static String CREATE_FILTERED_TABLE = "CREATE TABLE IF NOT EXISTS filteredWords (id INT NOT NULL AUTO_INCREMENT, word VARCHAR(256), PRIMARY KEY (id));";
private static String RETRIEVE_FILTERED_WORDS = "SELECT word FROM filteredWords;";
private static String SAVE_FILTER_VALUE = "REPLACE INTO accountPreferences (filterChat) VALUES (?) WHERE playerName = ?;";
public ChatRepository(JavaPlugin plugin)
{
super(plugin);
}
protected void initialize()
{
super.initialize();
executeQuery(CREATE_FILTERED_TABLE);
}
protected void update()
{
super.update();
executeQuery(ALTER_ACCOUNT_PREFERENCE_TABLE);
}
public List<String> retrieveFilteredWords()
{
List<String> filteredWords = new ArrayList<String>();
Connection connection = null;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
try
{
connection = getConnection();
preparedStatement = connection.prepareStatement(RETRIEVE_FILTERED_WORDS);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
filteredWords.add(resultSet.getString(1));
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try
{
resultSet.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
return filteredWords;
}
public void saveFilterChat(String playerName, boolean filterChat)
{
Connection connection = null;
PreparedStatement preparedStatement = null;
int affectedRows = 0;
try
{
connection = getConnection();
preparedStatement = connection.prepareStatement(SAVE_FILTER_VALUE);
preparedStatement.setString(1, playerName);
affectedRows = preparedStatement.executeUpdate();
if (affectedRows == 0)
{
System.out.println("Error saving FilterChat option.");
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
public void loadClientInformation(Connection connection)
{
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,22 @@
package mineplex.core.mysql;
import org.bukkit.plugin.java.JavaPlugin;
public class AccountPreferenceRepository extends RepositoryBase
{
private static String CREATE_ACCOUNT_PREFERENCE_TABLE = "CREATE TABLE IF NOT EXISTS AccountPreferences (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id));";
public AccountPreferenceRepository(JavaPlugin plugin)
{
super(plugin);
}
@Override
protected void initialize()
{
executeQuery(CREATE_ACCOUNT_PREFERENCE_TABLE);
}
@Override
protected void update() { }
}

View File

@ -0,0 +1,114 @@
package mineplex.core.mysql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.bukkit.plugin.java.JavaPlugin;
public abstract class RepositoryBase
{
private String _connectionString;
private String _userName;
private String _password;
public RepositoryBase(JavaPlugin plugin)
{
_connectionString = plugin.getConfig().getString("serverstatus.connectionurl");
_userName = plugin.getConfig().getString("serverstatus.username");
_password = plugin.getConfig().getString("serverstatus.password");
initialize();
update();
}
protected abstract void initialize();
protected abstract void update();
protected Connection getConnection() throws SQLException
{
return DriverManager.getConnection(_connectionString, _userName, _password);
}
protected int executeQuery(String query)
{
Connection connection = null;
PreparedStatement preparedStatement = null;
int affectedRows = 0;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = connection.prepareStatement(query);
affectedRows = preparedStatement.executeUpdate();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
return affectedRows;
}
protected int executeStatement(PreparedStatement preparedStatement)
{
Connection connection = null;
int affectedRows = 0;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
affectedRows = preparedStatement.executeUpdate();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
return affectedRows;
}
}

View File

@ -52,25 +52,6 @@ public class Punish extends MiniPlugin
AddCommand(new PunishCommand(this));
}
@EventHandler
public void OnClientWebRequest(ClientWebRequestEvent event)
{
/*
try
{
// TODO Parse infractions/punishments here
// event.GetJsonWriter().beginObject();
// event.GetJsonWriter().name("Punish");
// event.GetJsonWriter().value("true");
// event.GetJsonWriter().endObject();
}
catch (IOException e)
{
e.printStackTrace();
}
*/
}
@EventHandler
public void OnClientWebResponse(ClientWebResponseEvent event)
{

View File

@ -0,0 +1,247 @@
package net.minecraft.server.v1_6_R3;
//CraftBukkit start
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
import org.bukkit.event.entity.EntityTargetEvent;
//CraftBukkit end
public class EntityGhast extends EntityFlying implements IMonster {
public int h;
public double i;
public double j;
public double bn;
private Entity target;
private int br;
public int bo;
public int bp;
private int explosionPower = 1;
public EntityGhast(World world) {
super(world);
this.a(4.0F, 4.0F);
this.fireProof = true;
this.b = 5;
}
public boolean damageEntity(DamageSource damagesource, float f) {
if (this.isInvulnerable()) {
return false;
} else if ("fireball".equals(damagesource.n()) && damagesource.getEntity() instanceof EntityHuman) {
super.damageEntity(damagesource, 1000.0F);
((EntityHuman) damagesource.getEntity()).a((Statistic) AchievementList.y);
return true;
} else {
return super.damageEntity(damagesource, f);
}
}
protected void a() {
super.a();
this.datawatcher.a(16, Byte.valueOf((byte) 0));
}
protected void az() {
super.az();
this.getAttributeInstance(GenericAttributes.a).setValue(10.0D);
}
protected void bl() {
if (!this.world.isStatic && this.world.difficulty == 0) {
this.die();
}
if (Vegetated)
return;
this.u();
this.bo = this.bp;
double d0 = this.i - this.locX;
double d1 = this.j - this.locY;
double d2 = this.bn - this.locZ;
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
if (d3 < 1.0D || d3 > 3600.0D) {
this.i = this.locX + (double) ((this.random.nextFloat() * 2.0F - 1.0F) * 16.0F);
this.j = this.locY + (double) ((this.random.nextFloat() * 2.0F - 1.0F) * 16.0F);
this.bn = this.locZ + (double) ((this.random.nextFloat() * 2.0F - 1.0F) * 16.0F);
}
if (this.h-- <= 0) {
this.h += this.random.nextInt(5) + 2;
d3 = (double) MathHelper.sqrt(d3);
if (this.a(this.i, this.j, this.bn, d3)) {
this.motX += d0 / d3 * 0.1D;
this.motY += d1 / d3 * 0.1D;
this.motZ += d2 / d3 * 0.1D;
} else {
this.i = this.locX;
this.j = this.locY;
this.bn = this.locZ;
}
}
if (this.target != null && this.target.dead) {
// CraftBukkit start
EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), null, EntityTargetEvent.TargetReason.TARGET_DIED);
this.world.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
if (event.getTarget() == null) {
this.target = null;
} else {
this.target = ((CraftEntity) event.getTarget()).getHandle();
}
}
// CraftBukkit end
}
if (this.target == null || this.br-- <= 0) {
// CraftBukkit start
Entity target = this.world.findNearbyVulnerablePlayer(this, 100.0D);
if (target != null) {
EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), target.getBukkitEntity(), EntityTargetEvent.TargetReason.CLOSEST_PLAYER);
this.world.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
if (event.getTarget() == null) {
this.target = null;
} else {
this.target = ((CraftEntity) event.getTarget()).getHandle();
}
}
}
// CraftBukkit end
if (this.target != null) {
this.br = 20;
}
}
double d4 = 64.0D;
if (this.target != null && this.target.e((Entity) this) < d4 * d4) {
double d5 = this.target.locX - this.locX;
double d6 = this.target.boundingBox.b + (double) (this.target.length / 2.0F) - (this.locY + (double) (this.length / 2.0F));
double d7 = this.target.locZ - this.locZ;
this.aN = this.yaw = -((float) Math.atan2(d5, d7)) * 180.0F / 3.1415927F;
if (this.o(this.target)) {
if (this.bp == 10) {
this.world.a((EntityHuman) null, 1007, (int) this.locX, (int) this.locY, (int) this.locZ, 0);
}
++this.bp;
if (this.bp == 20) {
this.world.a((EntityHuman) null, 1008, (int) this.locX, (int) this.locY, (int) this.locZ, 0);
EntityLargeFireball entitylargefireball = new EntityLargeFireball(this.world, this, d5, d6, d7);
// CraftBukkit - set bukkitYield when setting explosionpower
entitylargefireball.bukkitYield = entitylargefireball.yield = this.explosionPower;
double d8 = 4.0D;
Vec3D vec3d = this.j(1.0F);
entitylargefireball.locX = this.locX + vec3d.c * d8;
entitylargefireball.locY = this.locY + (double) (this.length / 2.0F) + 0.5D;
entitylargefireball.locZ = this.locZ + vec3d.e * d8;
this.world.addEntity(entitylargefireball);
this.bp = -40;
}
} else if (this.bp > 0) {
--this.bp;
}
} else {
this.aN = this.yaw = -((float) Math.atan2(this.motX, this.motZ)) * 180.0F / 3.1415927F;
if (this.bp > 0) {
--this.bp;
}
}
if (!this.world.isStatic) {
byte b0 = this.datawatcher.getByte(16);
byte b1 = (byte) (this.bp > 10 ? 1 : 0);
if (b0 != b1) {
this.datawatcher.watch(16, Byte.valueOf(b1));
}
}
}
private boolean a(double d0, double d1, double d2, double d3) {
double d4 = (this.i - this.locX) / d3;
double d5 = (this.j - this.locY) / d3;
double d6 = (this.bn - this.locZ) / d3;
AxisAlignedBB axisalignedbb = this.boundingBox.clone();
for (int i = 1; (double) i < d3; ++i) {
axisalignedbb.d(d4, d5, d6);
if (!this.world.getCubes(this, axisalignedbb).isEmpty()) {
return false;
}
}
return true;
}
protected String r() {
return "mob.ghast.moan";
}
protected String aO() {
return "mob.ghast.scream";
}
protected String aP() {
return "mob.ghast.death";
}
protected int getLootId() {
return Item.SULPHUR.id;
}
protected void dropDeathLoot(boolean flag, int i) {
// CraftBukkit start
java.util.List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<org.bukkit.inventory.ItemStack>();
int j = this.random.nextInt(2) + this.random.nextInt(1 + i);
int k;
if (j > 0) {
loot.add(CraftItemStack.asNewCraftStack(Item.GHAST_TEAR, j));
}
j = this.random.nextInt(3) + this.random.nextInt(1 + i);
if (j > 0) {
loot.add(CraftItemStack.asNewCraftStack(Item.SULPHUR, j));
}
org.bukkit.craftbukkit.v1_6_R3.event.CraftEventFactory.callEntityDeathEvent(this, loot);
// CraftBukkit end
}
protected float ba() {
return 10.0F;
}
public boolean canSpawn() {
return this.random.nextInt(20) == 0 && super.canSpawn() && this.world.difficulty > 0;
}
public int bv() {
return 1;
}
public void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound);
nbttagcompound.setInt("ExplosionPower", this.explosionPower);
}
public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
if (nbttagcompound.hasKey("ExplosionPower")) {
this.explosionPower = nbttagcompound.getInt("ExplosionPower");
}
}
}

View File

@ -72,7 +72,7 @@ public class Arcade extends JavaPlugin implements INautilusPlugin, IPlugin
private ConditionManager _condition;
private Creature _creature;
private Fire _fire;
private Logger _logger;
private Logger _logger;
private LootFactory _lootFactory;
private Observer _observer;
private PetManager _petManager;

Binary file not shown.