Please specify commit message

This commit is contained in:
坏黑 2018-06-24 20:17:54 +08:00
parent 81fb265a8f
commit bb75dfbe68
7 changed files with 142 additions and 60 deletions

View File

@ -102,7 +102,9 @@ public class TLib {
} catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException ignored) { } catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException ignored) {
TLocale.Logger.fatal("TLIB.INJECTION-FAILED"); TLocale.Logger.fatal("TLIB.INJECTION-FAILED");
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
if (plugin != Main.getInst()) TDependencyInjector.inject(plugin, plugin); if (plugin != Main.getInst()) {
TDependencyInjector.inject(plugin, plugin);
}
} }
} }
} }

View File

@ -37,8 +37,9 @@ public class TPluginManager implements PluginManager {
private List<Plugin> delayedDisable = new ArrayList<>(); private List<Plugin> delayedDisable = new ArrayList<>();
public static void delayDisable(Plugin plugin) { public static void delayDisable(Plugin plugin) {
if (!singleton.delayedDisable.contains(plugin)) if (!singleton.delayedDisable.contains(plugin)) {
singleton.delayedDisable.add(plugin); singleton.delayedDisable.add(plugin);
}
} }
public TPluginManager() { public TPluginManager() {

View File

@ -500,7 +500,7 @@ public class CsvReader {
++dataBuffer2.Position; ++dataBuffer2.Position;
if (this.userSettings.SafetySwitch && this.dataBuffer.Position - this.dataBuffer.ColumnStart + this.columnBuffer.Position > 100000) { if (this.userSettings.SafetySwitch && this.dataBuffer.Position - this.dataBuffer.ColumnStart + this.columnBuffer.Position > 100000) {
this.close(); this.close();
throw new IOException("Maximum addColumn length of 100,000 exceeded in addColumn " + NumberFormat.getIntegerInstance().format(this.columnsCount) + " in record " + NumberFormat.getIntegerInstance().format(this.currentRecord) + ". Set the SafetySwitch property to false" + " if you're expecting addColumn lengths greater than 100,000 characters to" + " avoid this error."); throw new IOException("Maximum column length of 100,000 exceeded in column " + NumberFormat.getIntegerInstance().format(this.columnsCount) + " in record " + NumberFormat.getIntegerInstance().format(this.currentRecord) + ". Set the SafetySwitch property to false" + " if you're expecting column lengths greater than 100,000 characters to" + " avoid this error.");
} }
} }
} while (this.hasMoreData && this.startedColumn); } while (this.hasMoreData && this.startedColumn);
@ -695,7 +695,7 @@ public class CsvReader {
++dataBuffer3.Position; ++dataBuffer3.Position;
if (this.userSettings.SafetySwitch && this.dataBuffer.Position - this.dataBuffer.ColumnStart + this.columnBuffer.Position > 100000) { if (this.userSettings.SafetySwitch && this.dataBuffer.Position - this.dataBuffer.ColumnStart + this.columnBuffer.Position > 100000) {
this.close(); this.close();
throw new IOException("Maximum addColumn length of 100,000 exceeded in addColumn " + NumberFormat.getIntegerInstance().format(this.columnsCount) + " in record " + NumberFormat.getIntegerInstance().format(this.currentRecord) + ". Set the SafetySwitch property to false" + " if you're expecting addColumn lengths greater than 100,000 characters to" + " avoid this error."); throw new IOException("Maximum column length of 100,000 exceeded in column " + NumberFormat.getIntegerInstance().format(this.columnsCount) + " in record " + NumberFormat.getIntegerInstance().format(this.currentRecord) + ". Set the SafetySwitch property to false" + " if you're expecting column lengths greater than 100,000 characters to" + " avoid this error.");
} }
} }
} while (this.hasMoreData && this.startedColumn); } while (this.hasMoreData && this.startedColumn);
@ -868,7 +868,7 @@ public class CsvReader {
this.startedColumn = false; this.startedColumn = false;
if (this.columnsCount >= 100000 && this.userSettings.SafetySwitch) { if (this.columnsCount >= 100000 && this.userSettings.SafetySwitch) {
this.close(); this.close();
throw new IOException("Maximum addColumn count of 100,000 exceeded in record " + NumberFormat.getIntegerInstance().format(this.currentRecord) + ". Set the SafetySwitch property to false" + " if you're expecting more than 100,000 columns per record to" + " avoid this error."); throw new IOException("Maximum column count of 100,000 exceeded in record " + NumberFormat.getIntegerInstance().format(this.currentRecord) + ". Set the SafetySwitch property to false" + " if you're expecting more than 100,000 columns per record to" + " avoid this error.");
} }
if (this.columnsCount == this.values.length) { if (this.columnsCount == this.values.length) {
final int n3 = this.values.length * 2; final int n3 = this.values.length * 2;

View File

@ -32,14 +32,7 @@ public class EntityUtils implements Listener {
* @return * @return
*/ */
public static Entity getEntityWithUUID(UUID u) { public static Entity getEntityWithUUID(UUID u) {
for (World w : Bukkit.getWorlds()) { return Bukkit.getWorlds().stream().flatMap(w -> w.getLivingEntities().stream()).filter(e -> e.getUniqueId().equals(u)).findFirst().orElse(null);
for (Entity e : w.getLivingEntities()) {
if (e.getUniqueId().equals(u)) {
return e;
}
}
}
return null;
} }
/** /**
@ -50,12 +43,7 @@ public class EntityUtils implements Listener {
* @return * @return
*/ */
public static Entity getEntityWithUUID_World(UUID u, World world) { public static Entity getEntityWithUUID_World(UUID u, World world) {
for (Entity e : world.getLivingEntities()) { return world.getLivingEntities().stream().filter(e -> e.getUniqueId().equals(u)).findFirst().orElse(null);
if (e.getUniqueId().equals(u)) {
return e;
}
}
return null;
} }
/** /**
@ -66,11 +54,7 @@ public class EntityUtils implements Listener {
*/ */
public static void addGlow(Player player, Entity entity) { public static void addGlow(Player player, Entity entity) {
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") == null) { if (Bukkit.getPluginManager().getPlugin("ProtocolLib") == null) {
try { TLocale.sendToConsole("ENTITY-UTILS.NOTFOUND-PROTOCOLLIB");
throw new PluginNotFoundException(TLocale.asString("ENTITY-UTILS.NOTFOUND-PROTOCOLLIB"));
} catch (Exception e) {
//
}
} }
PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA); PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA);
packet.getIntegers().write(0, entity.getEntityId()); packet.getIntegers().write(0, entity.getEntityId());
@ -94,11 +78,7 @@ public class EntityUtils implements Listener {
*/ */
public static void delGlow(Player player, Entity entity) { public static void delGlow(Player player, Entity entity) {
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") == null) { if (Bukkit.getPluginManager().getPlugin("ProtocolLib") == null) {
try { TLocale.sendToConsole("ENTITY-UTILS.NOTFOUND-PROTOCOLLIB");
throw new PluginNotFoundException(TLocale.asString("ENTITY-UTILS.NOTFOUND-PROTOCOLLIB"));
} catch (Exception e) {
//
}
} }
PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA); PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_METADATA);
packet.getIntegers().write(0, entity.getEntityId()); packet.getIntegers().write(0, entity.getEntityId());

View File

@ -0,0 +1,122 @@
package me.skymc.taboolib.entity;
import me.skymc.taboolib.other.NumberUtils;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import java.util.stream.IntStream;
/**
* @Author sky
* @Since 2018-06-24 16:32
*/
public class VectorUtils {
/**
* 物品丢弃
*
* 常用参数
* itemDrop(player, itemStack, 0.2, 0.5)
*
* @param player 玩家
* @param itemStack 丢弃物品
* @param bulletSpread 视角偏移
* @param radius 距离
* @return {@link Item}
*/
public static Item itemDrop(Player player, ItemStack itemStack, double bulletSpread, double radius) {
Location location = player.getLocation().add(0, 1.5, 0);
Item item = player.getWorld().dropItem(location, itemStack);
double yaw = Math.toRadians(-player.getLocation().getYaw() - 90.0F);
double pitch = Math.toRadians(-player.getLocation().getPitch());
double x;
double y;
double z;
if (bulletSpread > 0) {
double[] spread = {1.0D, 1.0D, 1.0D};
IntStream.range(0, 3).forEach(t -> spread[t] = ((NumberUtils.getRandom().nextDouble() - NumberUtils.getRandom().nextDouble()) * bulletSpread * 0.1D));
x = Math.cos(pitch) * Math.cos(yaw) + spread[0];
y = Math.sin(pitch) + spread[1];
z = -Math.sin(yaw) * Math.cos(pitch) + spread[2];
} else {
x = Math.cos(pitch) * Math.cos(yaw);
y = Math.sin(pitch);
z = -Math.sin(yaw) * Math.cos(pitch);
}
Vector dirVel = new Vector(x, y, z);
item.setVelocity(dirVel.normalize().multiply(radius));
return item;
}
/**
* 生物抛射
*
* 常用参数
* entityPush(entity, location, 15)
*
* @param entity 目标生物
* @param to 目标坐标
* @param velocity 力量
*/
public static void entityPush(Entity entity, Location to, double velocity) {
Location from = entity.getLocation();
Vector test = to.clone().subtract(from).toVector();
Double elevation = test.getY();
Double launchAngle = calculateLaunchAngle(from, to, velocity, elevation, 20.0D);
Double distance = Math.sqrt(Math.pow(test.getX(), 2.0D) + Math.pow(test.getZ(), 2.0D));
if (distance == 0.0D) {
return;
}
if (launchAngle == null) {
launchAngle = Math.atan((40.0D * elevation + Math.pow(velocity, 2.0D)) / (40.0D * elevation + 2.0D * Math.pow(velocity, 2.0D)));
}
Double hangTime = calculateHangTime(launchAngle, velocity, elevation, 20.0D);
test.setY(Math.tan(launchAngle) * distance);
test = normalizeVector(test);
Vector noise = Vector.getRandom();
noise = noise.multiply(1 / 10.0D);
test.add(noise);
velocity = velocity + 1.188D * Math.pow(hangTime, 2.0D) + (NumberUtils.getRandom().nextDouble() - 0.8D) / 2.0D;
test = test.multiply(velocity / 20.0D);
entity.setVelocity(test);
}
// *********************************
//
// Private Methods
//
// *********************************
private static double calculateHangTime(double launchAngle, double v, double elev, double g) {
double a = v * Math.sin(launchAngle);
double b = -2.0D * g * elev;
return Math.pow(a, 2.0D) + b < 0.0D ? 0.0D : (a + Math.sqrt(Math.pow(a, 2.0D) + b)) / g;
}
private static Vector normalizeVector(Vector victor) {
double mag = Math.sqrt(Math.pow(victor.getX(), 2.0D) + Math.pow(victor.getY(), 2.0D) + Math.pow(victor.getZ(), 2.0D));
return mag != 0.0D ? victor.multiply(1.0D / mag) : victor.multiply(0);
}
private static Double calculateLaunchAngle(Location from, Location to, double v, double elevation, double g) {
Vector vector = from.clone().subtract(to).toVector();
Double distance = Math.sqrt(Math.pow(vector.getX(), 2.0D) + Math.pow(vector.getZ(), 2.0D));
double v2 = Math.pow(v, 2.0D);
double v4 = Math.pow(v, 4.0D);
double check = g * (g * Math.pow(distance, 2.0D) + 2.0D * elevation * v2);
return v4 < check ? null : Math.atan((v2 - Math.sqrt(v4 - check)) / (g * distance));
}
}

View File

@ -1,5 +1,6 @@
package me.skymc.taboolib.inventory; package me.skymc.taboolib.inventory;
import me.skymc.taboolib.entity.VectorUtils;
import me.skymc.taboolib.other.NumberUtils; import me.skymc.taboolib.other.NumberUtils;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
@ -9,35 +10,11 @@ import org.bukkit.util.Vector;
import java.util.stream.IntStream; import java.util.stream.IntStream;
@Deprecated
public class DropUtils { public class DropUtils {
public static Item drop(Player player, ItemStack itemStack, double bulletSpread, double radius) { public static Item drop(Player player, ItemStack itemStack, double bulletSpread, double radius) {
Location location = player.getLocation(); return VectorUtils.itemDrop(player, itemStack, bulletSpread, radius);
location.setY(location.getY() + 1.5);
Item item = player.getWorld().dropItem(location, itemStack);
double yaw = Math.toRadians(-player.getLocation().getYaw() - 90.0F);
double pitch = Math.toRadians(-player.getLocation().getPitch());
double x;
double y;
double z;
if (bulletSpread > 0) {
double[] spread = {1.0D, 1.0D, 1.0D};
IntStream.range(0, 3).forEach(t -> spread[t] = ((NumberUtils.getRandom().nextDouble() - NumberUtils.getRandom().nextDouble()) * bulletSpread * 0.1D));
x = Math.cos(pitch) * Math.cos(yaw) + spread[0];
y = Math.sin(pitch) + spread[1];
z = -Math.sin(yaw) * Math.cos(pitch) + spread[2];
} else {
x = Math.cos(pitch) * Math.cos(yaw);
y = Math.sin(pitch);
z = -Math.sin(yaw) * Math.cos(pitch);
}
Vector dirVel = new Vector(x, y, z);
dirVel.normalize().multiply(radius);
item.setVelocity(dirVel);
return item;
} }
} }

View File

@ -163,7 +163,7 @@ public class MetaModel implements Serializable {
} }
/** /**
* @return name of the addColumn for optimistic locking record version * @return name of the column for optimistic locking record version
*/ */
public String getVersionColumn() { public String getVersionColumn() {
return versionColumn; return versionColumn;
@ -401,11 +401,11 @@ public class MetaModel implements Serializable {
} }
/** /**
* FK name is a foreign key name used in relationships as a foreign key addColumn in a child table (table represented by this * FK name is a foreign key name used in relationships as a foreign key column in a child table (table represented by this
* instance is a parent table). * instance is a parent table).
* The FK name is derived using {@link org.javalite.common.Inflector}: It is a singular version of this table name plus "_id". * The FK name is derived using {@link org.javalite.common.Inflector}: It is a singular version of this table name plus "_id".
* *
* @return foreign key name used in relationships as a foreign key addColumn in a child table. * @return foreign key name used in relationships as a foreign key column in a child table.
*/ */
public String getFKName() { public String getFKName() {
return singularize(getTableName()).toLowerCase() + "_id"; return singularize(getTableName()).toLowerCase() + "_id";
@ -469,10 +469,10 @@ public class MetaModel implements Serializable {
} }
/** /**
* Provides addColumn metadata map, keyed by attribute names. * Provides column metadata map, keyed by attribute names.
* Table columns correspond to ActiveJDBC model attributes. * Table columns correspond to ActiveJDBC model attributes.
* *
* @return Provides addColumn metadata map, keyed by attribute names. * @return Provides column metadata map, keyed by attribute names.
*/ */
public Map<String, ColumnMetadata> getColumnMetadata() { public Map<String, ColumnMetadata> getColumnMetadata() {
if (columnMetadata == null || columnMetadata.isEmpty()) { if (columnMetadata == null || columnMetadata.isEmpty()) {