Merge branch 'thanos-mineware' into MortensRawBugFixes
Conflicts: .gitignore
BIN
Art/BlackFriday.png
Normal file
After Width: | Height: | Size: 170 KiB |
BIN
Art/ChristmasChaos.png
Normal file
After Width: | Height: | Size: 438 KiB |
BIN
Art/ClansBanner.png
Normal file
After Width: | Height: | Size: 1017 KiB |
BIN
Art/MS SMoke.psd
Normal file
BIN
Art/TitanLogo.png
Normal file
After Width: | Height: | Size: 375 KiB |
BIN
Art/WinterTreasure.png
Normal file
After Width: | Height: | Size: 1.4 MiB |
BIN
Art/WinterTreasureTrim.png
Normal file
After Width: | Height: | Size: 1.4 MiB |
BIN
Art/y5O7WYh.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
Art/zKzkfLE.png
Normal file
After Width: | Height: | Size: 93 KiB |
47
Patches/Bukkit-Patches/0031-EntityDismountEvent.patch
Normal file
@ -0,0 +1,47 @@
|
||||
From c6e51ae8ffc31d0fc059d33ca159df31c2b7a83e Mon Sep 17 00:00:00 2001
|
||||
From: libraryaddict <libraryaddict115@yahoo.co.nz>
|
||||
Date: Sun, 22 Nov 2015 14:37:11 +1300
|
||||
Subject: [PATCH] EntityDismountEvent
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/spigotmc/event/entity/EntityDismountEvent.java b/src/main/java/org/spigotmc/event/entity/EntityDismountEvent.java
|
||||
index 24d4942..02943d6 100644
|
||||
--- a/src/main/java/org/spigotmc/event/entity/EntityDismountEvent.java
|
||||
+++ b/src/main/java/org/spigotmc/event/entity/EntityDismountEvent.java
|
||||
@@ -2,13 +2,14 @@ package org.spigotmc.event.entity;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.HandlerList;
|
||||
+import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.entity.EntityEvent;
|
||||
|
||||
/**
|
||||
* Called when an entity stops riding another entity.
|
||||
*
|
||||
*/
|
||||
-public class EntityDismountEvent extends EntityEvent
|
||||
+public class EntityDismountEvent extends EntityEvent implements Cancellable
|
||||
{
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
@@ -36,4 +37,17 @@ public class EntityDismountEvent extends EntityEvent
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isCancelled()
|
||||
+ {
|
||||
+ return cancelled;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setCancelled(boolean cancel)
|
||||
+ {
|
||||
+ this.cancelled = cancel;
|
||||
+ }
|
||||
+
|
||||
}
|
||||
--
|
||||
1.9.5.msysgit.0
|
||||
|
37
Patches/CraftBukkit-Patches/0175-Fix-schedulers.patch
Normal file
@ -0,0 +1,37 @@
|
||||
From 896df3218cf190a29901619e762b5399517dbfbd Mon Sep 17 00:00:00 2001
|
||||
From: libraryaddict <libraryaddict115@yahoo.co.nz>
|
||||
Date: Wed, 11 Nov 2015 11:43:17 +1300
|
||||
Subject: [PATCH] Fix schedulers
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 1d29ae7..55e2afd 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -705,6 +705,11 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
|
||||
}
|
||||
|
||||
public void B() {
|
||||
+ SpigotTimings.schedulerTimer.startTiming(); // Spigot
|
||||
+ // CraftBukkit start
|
||||
+ this.server.getScheduler().mainThreadHeartbeat(this.ticks);
|
||||
+ SpigotTimings.schedulerTimer.stopTiming(); // Spigot
|
||||
+
|
||||
this.methodProfiler.a("jobs");
|
||||
Queue queue = this.j;
|
||||
|
||||
@@ -718,11 +723,6 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
|
||||
|
||||
this.methodProfiler.c("levels");
|
||||
|
||||
- SpigotTimings.schedulerTimer.startTiming(); // Spigot
|
||||
- // CraftBukkit start
|
||||
- this.server.getScheduler().mainThreadHeartbeat(this.ticks);
|
||||
- SpigotTimings.schedulerTimer.stopTiming(); // Spigot
|
||||
-
|
||||
// Run tasks that are waiting on processing
|
||||
SpigotTimings.processQueueTimer.startTiming(); // Spigot
|
||||
while (!processQueue.isEmpty()) {
|
||||
--
|
||||
1.9.5.msysgit.0
|
||||
|
@ -0,0 +1,159 @@
|
||||
From bc86c3b02f2efa4c1194fc908e8d1ee8723f62c5 Mon Sep 17 00:00:00 2001
|
||||
From: libraryaddict <libraryaddict115@yahoo.co.nz>
|
||||
Date: Sun, 22 Nov 2015 14:41:11 +1300
|
||||
Subject: [PATCH] EntityDismountEvent & teleport crash fix
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
||||
index 81ca499..7165579 100644
|
||||
--- a/src/main/java/net/minecraft/server/Entity.java
|
||||
+++ b/src/main/java/net/minecraft/server/Entity.java
|
||||
@@ -23,6 +23,8 @@ import org.bukkit.event.painting.PaintingBreakByEntityEvent;
|
||||
import org.bukkit.event.vehicle.VehicleBlockCollisionEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.event.vehicle.VehicleExitEvent;
|
||||
+import org.spigotmc.event.entity.EntityDismountEvent;
|
||||
+import org.spigotmc.event.entity.EntityMountEvent;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
@@ -1591,7 +1593,12 @@ public abstract class Entity implements ICommandListener {
|
||||
}
|
||||
}
|
||||
// CraftBukkit end
|
||||
- pluginManager.callEvent( new org.spigotmc.event.entity.EntityDismountEvent( this.getBukkitEntity(), this.vehicle.getBukkitEntity() ) ); // Spigot
|
||||
+ EntityDismountEvent event = new org.spigotmc.event.entity.EntityDismountEvent(this.getBukkitEntity(), this.vehicle.getBukkitEntity());
|
||||
+ pluginManager.callEvent(event); // Spigot
|
||||
+
|
||||
+ if (event.isCancelled() || vehicle != originalVehicle) {
|
||||
+ return;
|
||||
+ } // Spigot
|
||||
this.setPositionRotation(this.vehicle.locX, this.vehicle.getBoundingBox().b + (double) this.vehicle.length, this.vehicle.locZ, this.yaw, this.pitch);
|
||||
this.vehicle.passenger = null;
|
||||
}
|
||||
@@ -1599,44 +1606,45 @@ public abstract class Entity implements ICommandListener {
|
||||
this.vehicle = null;
|
||||
} else {
|
||||
// CraftBukkit start
|
||||
- if ((this.bukkitEntity instanceof LivingEntity) && (entity.getBukkitEntity() instanceof Vehicle) && entity.world.isChunkLoaded((int) entity.locX >> 4, (int) entity.locZ >> 4, true)) {
|
||||
+ if (entity.world.isChunkLoaded((int) entity.locX >> 4, (int) entity.locZ >> 4, true)) {
|
||||
// It's possible to move from one vehicle to another. We need to check if they're already in a vehicle, and fire an exit event if they are.
|
||||
VehicleExitEvent exitEvent = null;
|
||||
+ EntityDismountEvent exitEvent1 = null;
|
||||
if (this.vehicle != null) {
|
||||
- exitEvent = new VehicleExitEvent((Vehicle) this.vehicle.getBukkitEntity(), (LivingEntity) this.bukkitEntity);
|
||||
+ if ((this.bukkitEntity instanceof LivingEntity) && (entity.getBukkitEntity() instanceof Vehicle))
|
||||
+ exitEvent = new VehicleExitEvent((Vehicle) this.vehicle.getBukkitEntity(), (LivingEntity) this.bukkitEntity);
|
||||
pluginManager.callEvent(exitEvent);
|
||||
|
||||
if (exitEvent.isCancelled() || this.vehicle != originalVehicle || (this.vehicle != null && this.vehicle.passenger != originalPassenger)) {
|
||||
return;
|
||||
}
|
||||
+
|
||||
+ exitEvent1 = new EntityDismountEvent(this.vehicle.getBukkitEntity(), this.bukkitEntity);
|
||||
+
|
||||
+ pluginManager.callEvent(exitEvent1);
|
||||
+
|
||||
+ if (exitEvent1.isCancelled() || this.vehicle != originalVehicle || (this.vehicle != null && this.vehicle.passenger != originalPassenger)) {
|
||||
+ return;
|
||||
+ }
|
||||
}
|
||||
|
||||
- VehicleEnterEvent event = new VehicleEnterEvent((Vehicle) entity.getBukkitEntity(), this.bukkitEntity);
|
||||
- pluginManager.callEvent(event);
|
||||
+ if ((this.bukkitEntity instanceof LivingEntity) && (entity.getBukkitEntity() instanceof Vehicle)) {
|
||||
+ VehicleEnterEvent event = new VehicleEnterEvent((Vehicle) entity.getBukkitEntity(), this.bukkitEntity);
|
||||
+ pluginManager.callEvent(event);
|
||||
|
||||
- // If a plugin messes with the vehicle or the vehicle's passenger
|
||||
- if (event.isCancelled() || this.vehicle != originalVehicle || (this.vehicle != null && this.vehicle.passenger != originalPassenger)) {
|
||||
- // If we only cancelled the enterevent then we need to put the player in a decent position.
|
||||
- if (exitEvent != null && this.vehicle == originalVehicle && this.vehicle != null && this.vehicle.passenger == originalPassenger) {
|
||||
- this.setPositionRotation(this.vehicle.locX, this.vehicle.getBoundingBox().b + (double) this.vehicle.length, this.vehicle.locZ, this.yaw, this.pitch);
|
||||
- this.vehicle.passenger = null;
|
||||
- this.vehicle = null;
|
||||
+ // If a plugin messes with the vehicle or the vehicle's passenger
|
||||
+ if (event.isCancelled() || this.vehicle != originalVehicle || (this.vehicle != null && this.vehicle.passenger != originalPassenger)) {
|
||||
+ // If we only cancelled the enterevent then we need to put the player in a decent position.
|
||||
+ if (exitEvent != null && this.vehicle == originalVehicle && this.vehicle != null && this.vehicle.passenger == originalPassenger) {
|
||||
+ this.setPositionRotation(this.vehicle.locX, this.vehicle.getBoundingBox().b + (double) this.vehicle.length, this.vehicle.locZ, this.yaw, this.pitch);
|
||||
+ this.vehicle.passenger = null;
|
||||
+ this.vehicle = null;
|
||||
+ }
|
||||
+ return;
|
||||
}
|
||||
- return;
|
||||
}
|
||||
}
|
||||
// CraftBukkit end
|
||||
- // Spigot Start
|
||||
- if ( entity.world.isChunkLoaded( (int) entity.locX >> 4, (int) entity.locZ >> 4, true ) )
|
||||
- {
|
||||
- org.spigotmc.event.entity.EntityMountEvent event = new org.spigotmc.event.entity.EntityMountEvent( this.getBukkitEntity(), entity.getBukkitEntity() );
|
||||
- pluginManager.callEvent( event );
|
||||
- if ( event.isCancelled() )
|
||||
- {
|
||||
- return;
|
||||
- }
|
||||
- }
|
||||
- // Spigot End
|
||||
|
||||
if (this.vehicle != null) {
|
||||
this.vehicle.passenger = null;
|
||||
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
|
||||
index b861dbe..96b3905 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityLiving.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
|
||||
@@ -21,6 +21,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.bukkit.event.vehicle.VehicleExitEvent;
|
||||
+import org.spigotmc.event.entity.EntityDismountEvent;
|
||||
// CraftBukkit end
|
||||
|
||||
import org.bukkit.craftbukkit.SpigotTimings; // Spigot
|
||||
@@ -1725,8 +1726,15 @@ public abstract class EntityLiving extends Entity {
|
||||
return;
|
||||
}
|
||||
}
|
||||
+
|
||||
+ EntityDismountEvent event = new EntityDismountEvent(this.vehicle.getBukkitEntity(), (LivingEntity) this.bukkitEntity);
|
||||
+ getBukkitEntity().getServer().getPluginManager().callEvent(event);
|
||||
+
|
||||
+ if (event.isCancelled() || vehicle != originalVehicle) {
|
||||
+ return;
|
||||
+ }
|
||||
// CraftBukkit end
|
||||
-
|
||||
+
|
||||
if (!this.world.isClientSide) {
|
||||
this.q(this.vehicle);
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
||||
index efbf1a8..dbc7b54 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
+import com.google.common.primitives.Doubles;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -234,6 +235,12 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
// If this entity is riding another entity, we must dismount before teleporting.
|
||||
entity.mount(null);
|
||||
|
||||
+ if (!Doubles.isFinite(location.getX()) || !Doubles.isFinite(location.getY()) || !Doubles.isFinite(location.getZ()))
|
||||
+ {
|
||||
+ Thread.dumpStack();
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
// Spigot start
|
||||
if (!location.getWorld().equals(getWorld())) {
|
||||
entity.teleportTo(location, cause.equals(TeleportCause.NETHER_PORTAL));
|
||||
--
|
||||
1.9.5.msysgit.0
|
||||
|
@ -18,6 +18,9 @@
|
||||
<element id="file-copy" path="$PROJECT_DIR$/Mineplex.Game.Clans/plugin.yml" />
|
||||
<element id="module-output" name="Mineplex.ServerData" />
|
||||
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/jooq-3.5.2.jar" path-in-jar="/" />
|
||||
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/commons-dbcp2-2.0.1.jar" path-in-jar="/" />
|
||||
<element id="module-output" name="Mineplex.Game.Clans.Core" />
|
||||
<element id="module-output" name="Mineplex.Cache" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
@ -20,7 +20,8 @@
|
||||
<element id="module-output" name="Mineplex.Database" />
|
||||
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/jooq-3.5.2.jar" path-in-jar="/" />
|
||||
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/commons-dbcp2-2.0.1.jar" path-in-jar="/" />
|
||||
<element id="module-output" name="Mineplex.PlayerCache" />
|
||||
<element id="module-output" name="Mineplex.Game.Clans.Core" />
|
||||
<element id="module-output" name="Mineplex.Cache" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
@ -1,9 +0,0 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="Nautilus.Core.Craftbukkit:jar">
|
||||
<output-path>$PROJECT_DIR$/bin</output-path>
|
||||
<root id="archive" name="craftbukkit.jar">
|
||||
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/craftbukkit_official.jar" path-in-jar="/" />
|
||||
<element id="module-output" name="Nautilus.Core.CraftBukkit" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
@ -19,7 +19,7 @@
|
||||
<element id="module-output" name="Mineplex.Database" />
|
||||
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/jooq-3.5.2.jar" path-in-jar="/" />
|
||||
<element id="extracted-dir" path="$PROJECT_DIR$/Libraries/commons-dbcp2-2.0.1.jar" path-in-jar="/" />
|
||||
<element id="module-output" name="Mineplex.PlayerCache" />
|
||||
<element id="module-output" name="Mineplex.Cache" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
@ -7,6 +7,14 @@
|
||||
<option name="STATIC_FIELD_NAME_PREFIX" value="_" />
|
||||
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="20" />
|
||||
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="10" />
|
||||
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
|
||||
<value>
|
||||
<package name="java.awt" withSubpackages="false" static="false" />
|
||||
<package name="org.jooq.impl.DSL" withSubpackages="false" static="true" />
|
||||
<package name="mineplex.database.Tables" withSubpackages="false" static="true" />
|
||||
<package name="javax.swing" withSubpackages="false" static="false" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="IMPORT_LAYOUT_TABLE">
|
||||
<value>
|
||||
<package name="javax" withSubpackages="true" static="false" />
|
||||
|
@ -5,9 +5,6 @@
|
||||
<excludeFromCompile>
|
||||
<directory url="file://$PROJECT_DIR$/Nautilus.Game.PvP" includeSubdirectories="true" />
|
||||
<directory url="file://$PROJECT_DIR$/Mineplex.ServerMonitor" includeSubdirectories="true" />
|
||||
<directory url="file://$PROJECT_DIR$/Mineplex.Game.Clans" includeSubdirectories="true" />
|
||||
<directory url="file://$PROJECT_DIR$/Nautilus.Game.Arcade" includeSubdirectories="true" />
|
||||
<directory url="file://$PROJECT_DIR$/Mineplex.Hub" includeSubdirectories="true" />
|
||||
</excludeFromCompile>
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
@ -26,14 +23,12 @@
|
||||
</profile>
|
||||
<profile default="false" name="Annotation profile for bungee" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target\generated-test-sources\test-annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<processorPath useClasspath="true" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel target="1.7">
|
||||
<module name="bungee" target="1.7" />
|
||||
</bytecodeTargetLevel>
|
||||
<bytecodeTargetLevel target="1.8" />
|
||||
</component>
|
||||
<component name="JavacSettings">
|
||||
<option name="GENERATE_NO_WARNINGS" value="true" />
|
||||
|
@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" hash="4268976312">
|
||||
<component name="DataSourceManagerImpl" format="xml" hash="1486084220">
|
||||
<data-source source="LOCAL" name="Mineplex" uuid="14dfc55d-5343-47c4-ab24-76a055b8059e">
|
||||
<driver-ref>mysql</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>com.mysql.jdbc.Driver</jdbc-driver>
|
||||
<jdbc-url>jdbc:mysql://db.mineplex.com:3306</jdbc-url>
|
||||
<jdbc-url>jdbc:mysql://db.mineplex.com:3306/Account</jdbc-url>
|
||||
<driver-properties>
|
||||
<property name="zeroDateTimeBehavior" value="convertToNull" />
|
||||
<property name="tinyInt1isBit" value="false" />
|
||||
|
@ -4,7 +4,7 @@
|
||||
<root url="jar://$PROJECT_DIR$/Libraries/craftbukkit.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="http://jd.bukkit.org/dev/apidocs/" />
|
||||
<root url="https://hub.spigotmc.org/javadocs/spigot/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/Libraries/craftbukkit.jar!/" />
|
||||
|
@ -16,7 +16,7 @@
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -3,21 +3,23 @@
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Classpath.Dummy/Classpath.Dummy.iml" filepath="$PROJECT_DIR$/Classpath.Dummy/Classpath.Dummy.iml" group="Core" />
|
||||
<module fileurl="file://$PROJECT_DIR$/JedisTest/JedisTest.iml" filepath="$PROJECT_DIR$/JedisTest/JedisTest.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/JedisTest/JedisTest.iml" filepath="$PROJECT_DIR$/JedisTest/JedisTest.iml" group="Legacy" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Bungee.Mineplexer/Mineplex.Bungee.Mineplexer.iml" filepath="$PROJECT_DIR$/Mineplex.Bungee.Mineplexer/Mineplex.Bungee.Mineplexer.iml" group="Bungee" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Cache/Mineplex.Cache.iml" filepath="$PROJECT_DIR$/Mineplex.Cache/Mineplex.Cache.iml" group="Core" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Core/Mineplex.Core.iml" filepath="$PROJECT_DIR$/Mineplex.Core/Mineplex.Core.iml" group="Core" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Core.Common/Mineplex.Core.Common.iml" filepath="$PROJECT_DIR$/Mineplex.Core.Common/Mineplex.Core.Common.iml" group="Core" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Database/Mineplex.Database.iml" filepath="$PROJECT_DIR$/Mineplex.Database/Mineplex.Database.iml" group="Core" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Game.Clans/Mineplex.Game.Clans.iml" filepath="$PROJECT_DIR$/Mineplex.Game.Clans/Mineplex.Game.Clans.iml" group="Game" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Hub/Mineplex.Hub.iml" filepath="$PROJECT_DIR$/Mineplex.Hub/Mineplex.Hub.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.MapParser/Mineplex.MapParser.iml" filepath="$PROJECT_DIR$/Mineplex.MapParser/Mineplex.MapParser.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Game.Clans/Mineplex.Game.Clans.iml" filepath="$PROJECT_DIR$/Mineplex.Game.Clans/Mineplex.Game.Clans.iml" group="Clans" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Game.Clans.Core/Mineplex.Game.Clans.Core.iml" filepath="$PROJECT_DIR$/Mineplex.Game.Clans.Core/Mineplex.Game.Clans.Core.iml" group="Clans" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Hub/Mineplex.Hub.iml" filepath="$PROJECT_DIR$/Mineplex.Hub/Mineplex.Hub.iml" group="Other" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.MapParser/Mineplex.MapParser.iml" filepath="$PROJECT_DIR$/Mineplex.MapParser/Mineplex.MapParser.iml" group="Other" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Minecraft.Game.ClassCombat/Mineplex.Minecraft.Game.ClassCombat.iml" filepath="$PROJECT_DIR$/Mineplex.Minecraft.Game.ClassCombat/Mineplex.Minecraft.Game.ClassCombat.iml" group="Game" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Minecraft.Game.Core/Mineplex.Minecraft.Game.Core.iml" filepath="$PROJECT_DIR$/Mineplex.Minecraft.Game.Core/Mineplex.Minecraft.Game.Core.iml" group="Game" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.PlayerCache/Mineplex.PlayerCache.iml" filepath="$PROJECT_DIR$/Mineplex.PlayerCache/Mineplex.PlayerCache.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.ServerData/Mineplex.ServerData.iml" filepath="$PROJECT_DIR$/Mineplex.ServerData/Mineplex.ServerData.iml" group="Core" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.ServerMonitor/Mineplex.ServerMonitor.iml" filepath="$PROJECT_DIR$/Mineplex.ServerMonitor/Mineplex.ServerMonitor.iml" group="Core" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Votifier/Mineplex.Votifier.iml" filepath="$PROJECT_DIR$/Mineplex.Votifier/Mineplex.Votifier.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Mineplex.Votifier/Mineplex.Votifier.iml" filepath="$PROJECT_DIR$/Mineplex.Votifier/Mineplex.Votifier.iml" group="Other" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Nautilus.Game.Arcade/Nautilus.Game.Arcade.iml" filepath="$PROJECT_DIR$/Nautilus.Game.Arcade/Nautilus.Game.Arcade.iml" group="Game" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Nautilus.Game.PvP/Nautilus.Game.PvP.iml" filepath="$PROJECT_DIR$/Nautilus.Game.PvP/Nautilus.Game.PvP.iml" group="Legacy" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -9,6 +9,7 @@
|
||||
<jar jarfile="../bin/Mineplex.Core.Common.jar">
|
||||
<fileset dir="../Mineplex.Core.Common/bin">
|
||||
<include name="**/*.class"/>
|
||||
<include name="**/*.png"/>
|
||||
</fileset>
|
||||
</jar>
|
||||
<copy file="../bin/Mineplex.Core.Common.jar" todir="../Libraries"/>
|
||||
@ -66,10 +67,10 @@
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.Core/bin">
|
||||
<include name="**/*.class"/>
|
||||
<include name="**/*.png"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.Core.Common/bin">
|
||||
<include name="**/*.class"/>
|
||||
<include name="**/*.png"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.Minecraft.Game.ClassCombat/bin">
|
||||
<include name="**/*.class"/>
|
||||
@ -86,7 +87,7 @@
|
||||
<fileset dir="../Mineplex.ServerData/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.PlayerCache/bin">
|
||||
<fileset dir="../Mineplex.Cache/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
|
||||
@ -110,6 +111,7 @@
|
||||
<jar jarfile="../bin/Mineplex.Core.Common.jar">
|
||||
<fileset dir="../Mineplex.Core.Common/bin">
|
||||
<include name="**/*.class"/>
|
||||
<include name="**/*.png"/>
|
||||
</fileset>
|
||||
</jar>
|
||||
<copy file="../bin/Mineplex.Core.Common.jar" todir="../Libraries"/>
|
||||
@ -142,6 +144,7 @@
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.Core.Common/bin">
|
||||
<include name="**/*.class"/>
|
||||
<include name="**/*.png"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.Minecraft.Game.ClassCombat/bin">
|
||||
<include name="**/*.class"/>
|
||||
@ -149,13 +152,16 @@
|
||||
<fileset dir="../Mineplex.Minecraft.Game.Core/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.Game.Clans.Core/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.Hub">
|
||||
<include name="*.yml"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.Database/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.PlayerCache/bin">
|
||||
<fileset dir="../Mineplex.Cache/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.ServerData/bin">
|
||||
@ -188,6 +194,10 @@
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.Core.Common/bin">
|
||||
<include name="**/*.class"/>
|
||||
<include name="**/*.png"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.Game.Clans.Core/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.Minecraft.Game.ClassCombat/bin">
|
||||
<include name="**/*.class"/>
|
||||
@ -204,7 +214,7 @@
|
||||
<fileset dir="../Mineplex.ServerData/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.PlayerCache/bin">
|
||||
<fileset dir="../Mineplex.Cache/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
|
||||
@ -233,6 +243,7 @@
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.Core.Common/bin">
|
||||
<include name="**/*.class"/>
|
||||
<include name="**/*.png"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.StaffServer">
|
||||
<include name="*.yml"/>
|
||||
@ -243,7 +254,7 @@
|
||||
<fileset dir="../Mineplex.ServerData/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.PlayerCache/bin">
|
||||
<fileset dir="../Mineplex.Cache/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
|
||||
@ -270,6 +281,7 @@
|
||||
|
||||
<fileset dir="../Mineplex.Core.Common/bin">
|
||||
<include name="**/*.class"/>
|
||||
<include name="**/*.png"/>
|
||||
</fileset>
|
||||
|
||||
<fileset dir="../Mineplex.MapParser">
|
||||
@ -323,7 +335,7 @@
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
|
||||
<fileset dir="../Mineplex.PlayerCache/bin">
|
||||
<fileset dir="../Mineplex.Cache/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
|
||||
@ -397,6 +409,7 @@
|
||||
<jar jarfile="../bin/ServerMonitor.jar">
|
||||
<fileset dir="../Mineplex.Core.Common/bin">
|
||||
<include name="**/*.class"/>
|
||||
<include name="**/*.png"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.ServerMonitor/bin">
|
||||
<include name="**/*.class"/>
|
||||
@ -429,6 +442,7 @@
|
||||
<jar jarfile="../bin/TaskConverter.jar">
|
||||
<fileset dir="../Mineplex.Core.Common/bin">
|
||||
<include name="**/*.class"/>
|
||||
<include name="**/*.png"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.ChestConverter/bin">
|
||||
<include name="**/*.class"/>
|
||||
@ -456,6 +470,7 @@
|
||||
<jar jarfile="../bin/PetConverter.jar">
|
||||
<fileset dir="../Mineplex.Core.Common/bin">
|
||||
<include name="**/*.class"/>
|
||||
<include name="**/*.png"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.PetConverter/bin">
|
||||
<include name="**/*.class"/>
|
||||
@ -484,6 +499,7 @@
|
||||
<jar jarfile="../bin/Queuer.jar">
|
||||
<fileset dir="../Mineplex.Core.Common/bin">
|
||||
<include name="**/*.class"/>
|
||||
<include name="**/*.png"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.Queuer/bin">
|
||||
<include name="**/*.class"/>
|
||||
|
@ -12,5 +12,4 @@
|
||||
<orderEntry type="library" name="commons-pool2" level="project" />
|
||||
<orderEntry type="library" name="commons-logging" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
</module>
|
@ -1,328 +0,0 @@
|
||||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by Fernflower decompiler)
|
||||
//
|
||||
|
||||
package org.bukkit.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.FormattedCommandAlias;
|
||||
import org.bukkit.command.defaults.AchievementCommand;
|
||||
import org.bukkit.command.defaults.BanCommand;
|
||||
import org.bukkit.command.defaults.BanIpCommand;
|
||||
import org.bukkit.command.defaults.BanListCommand;
|
||||
import org.bukkit.command.defaults.ClearCommand;
|
||||
import org.bukkit.command.defaults.DefaultGameModeCommand;
|
||||
import org.bukkit.command.defaults.DeopCommand;
|
||||
import org.bukkit.command.defaults.DifficultyCommand;
|
||||
import org.bukkit.command.defaults.EffectCommand;
|
||||
import org.bukkit.command.defaults.EnchantCommand;
|
||||
import org.bukkit.command.defaults.ExpCommand;
|
||||
import org.bukkit.command.defaults.GameModeCommand;
|
||||
import org.bukkit.command.defaults.GameRuleCommand;
|
||||
import org.bukkit.command.defaults.GiveCommand;
|
||||
import org.bukkit.command.defaults.HelpCommand;
|
||||
import org.bukkit.command.defaults.KickCommand;
|
||||
import org.bukkit.command.defaults.KillCommand;
|
||||
import org.bukkit.command.defaults.ListCommand;
|
||||
import org.bukkit.command.defaults.MeCommand;
|
||||
import org.bukkit.command.defaults.OpCommand;
|
||||
import org.bukkit.command.defaults.PardonCommand;
|
||||
import org.bukkit.command.defaults.PardonIpCommand;
|
||||
import org.bukkit.command.defaults.PlaySoundCommand;
|
||||
import org.bukkit.command.defaults.PluginsCommand;
|
||||
import org.bukkit.command.defaults.ReloadCommand;
|
||||
import org.bukkit.command.defaults.SaveCommand;
|
||||
import org.bukkit.command.defaults.SaveOffCommand;
|
||||
import org.bukkit.command.defaults.SaveOnCommand;
|
||||
import org.bukkit.command.defaults.SayCommand;
|
||||
import org.bukkit.command.defaults.ScoreboardCommand;
|
||||
import org.bukkit.command.defaults.SeedCommand;
|
||||
import org.bukkit.command.defaults.SetIdleTimeoutCommand;
|
||||
import org.bukkit.command.defaults.SetWorldSpawnCommand;
|
||||
import org.bukkit.command.defaults.SpawnpointCommand;
|
||||
import org.bukkit.command.defaults.SpreadPlayersCommand;
|
||||
import org.bukkit.command.defaults.StopCommand;
|
||||
import org.bukkit.command.defaults.TeleportCommand;
|
||||
import org.bukkit.command.defaults.TellCommand;
|
||||
import org.bukkit.command.defaults.TestForCommand;
|
||||
import org.bukkit.command.defaults.TimeCommand;
|
||||
import org.bukkit.command.defaults.TimingsCommand;
|
||||
import org.bukkit.command.defaults.ToggleDownfallCommand;
|
||||
import org.bukkit.command.defaults.VanillaCommand;
|
||||
import org.bukkit.command.defaults.VersionCommand;
|
||||
import org.bukkit.command.defaults.WeatherCommand;
|
||||
import org.bukkit.command.defaults.WhitelistCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.TabCompleteEvent;
|
||||
import org.bukkit.util.Java15Compat;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
public class SimpleCommandMap implements CommandMap {
|
||||
private static final Pattern PATTERN_ON_SPACE = Pattern.compile(" ", 16);
|
||||
protected final Map<String, Command> knownCommands = new HashMap<String, Command>();
|
||||
private final Server server;
|
||||
|
||||
public SimpleCommandMap(Server server) {
|
||||
this.server = server;
|
||||
this.setDefaultCommands();
|
||||
}
|
||||
|
||||
private void setDefaultCommands() {
|
||||
this.register("bukkit", new SaveCommand());
|
||||
this.register("bukkit", new SaveOnCommand());
|
||||
this.register("bukkit", new SaveOffCommand());
|
||||
this.register("bukkit", new StopCommand());
|
||||
this.register("bukkit", new VersionCommand("version"));
|
||||
this.register("bukkit", new ReloadCommand("reload"));
|
||||
this.register("bukkit", new PluginsCommand("plugins"));
|
||||
this.register("bukkit", new TimingsCommand("timings"));
|
||||
}
|
||||
|
||||
public void setFallbackCommands() {
|
||||
this.register("bukkit", new ListCommand());
|
||||
this.register("bukkit", new OpCommand());
|
||||
this.register("bukkit", new DeopCommand());
|
||||
this.register("bukkit", new BanIpCommand());
|
||||
this.register("bukkit", new PardonIpCommand());
|
||||
this.register("bukkit", new BanCommand());
|
||||
this.register("bukkit", new PardonCommand());
|
||||
this.register("bukkit", new KickCommand());
|
||||
this.register("bukkit", new TeleportCommand());
|
||||
this.register("bukkit", new GiveCommand());
|
||||
this.register("bukkit", new TimeCommand());
|
||||
this.register("bukkit", new SayCommand());
|
||||
this.register("bukkit", new WhitelistCommand());
|
||||
this.register("bukkit", new TellCommand());
|
||||
this.register("bukkit", new MeCommand());
|
||||
this.register("bukkit", new KillCommand());
|
||||
this.register("bukkit", new GameModeCommand());
|
||||
this.register("bukkit", new HelpCommand());
|
||||
this.register("bukkit", new ExpCommand());
|
||||
this.register("bukkit", new ToggleDownfallCommand());
|
||||
this.register("bukkit", new BanListCommand());
|
||||
this.register("bukkit", new DefaultGameModeCommand());
|
||||
this.register("bukkit", new SeedCommand());
|
||||
this.register("bukkit", new DifficultyCommand());
|
||||
this.register("bukkit", new WeatherCommand());
|
||||
this.register("bukkit", new SpawnpointCommand());
|
||||
this.register("bukkit", new ClearCommand());
|
||||
this.register("bukkit", new GameRuleCommand());
|
||||
this.register("bukkit", new EnchantCommand());
|
||||
this.register("bukkit", new TestForCommand());
|
||||
this.register("bukkit", new EffectCommand());
|
||||
this.register("bukkit", new ScoreboardCommand());
|
||||
this.register("bukkit", new PlaySoundCommand());
|
||||
this.register("bukkit", new SpreadPlayersCommand());
|
||||
this.register("bukkit", new SetWorldSpawnCommand());
|
||||
this.register("bukkit", new SetIdleTimeoutCommand());
|
||||
this.register("bukkit", new AchievementCommand());
|
||||
}
|
||||
|
||||
public void registerAll(String fallbackPrefix, List<Command> commands) {
|
||||
if(commands != null) {
|
||||
Iterator var3 = commands.iterator();
|
||||
|
||||
while(var3.hasNext()) {
|
||||
Command c = (Command)var3.next();
|
||||
this.register(fallbackPrefix, c);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean register(String fallbackPrefix, Command command) {
|
||||
return this.register(command.getName(), fallbackPrefix, command);
|
||||
}
|
||||
|
||||
public boolean register(String label, String fallbackPrefix, Command command) {
|
||||
label = label.toLowerCase().trim();
|
||||
fallbackPrefix = fallbackPrefix.toLowerCase().trim();
|
||||
boolean registered = this.register(label, command, false, fallbackPrefix);
|
||||
Iterator iterator = command.getAliases().iterator();
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
if(!this.register((String)iterator.next(), command, true, fallbackPrefix)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
if(!registered) {
|
||||
command.setLabel(fallbackPrefix + ":" + label);
|
||||
}
|
||||
|
||||
command.register(this);
|
||||
return registered;
|
||||
}
|
||||
|
||||
private synchronized boolean register(String label, Command command, boolean isAlias, String fallbackPrefix) {
|
||||
this.knownCommands.put(fallbackPrefix + ":" + label, command);
|
||||
if((command instanceof VanillaCommand || isAlias) && this.knownCommands.containsKey(label)) {
|
||||
return false;
|
||||
} else {
|
||||
boolean registered = true;
|
||||
Command conflict = (Command)this.knownCommands.get(label);
|
||||
if(conflict != null && conflict.getLabel().equals(label)) {
|
||||
return false;
|
||||
} else {
|
||||
if(!isAlias) {
|
||||
command.setLabel(label);
|
||||
}
|
||||
|
||||
this.knownCommands.put(label, command);
|
||||
return registered;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean dispatch(CommandSender sender, String commandLine) throws CommandException {
|
||||
String[] args = PATTERN_ON_SPACE.split(commandLine);
|
||||
if(args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
String sentCommandLabel = args[0].toLowerCase();
|
||||
Command target = this.getCommand(sentCommandLabel);
|
||||
if(target == null) {
|
||||
return false;
|
||||
} else {
|
||||
try {
|
||||
target.timings.startTiming();
|
||||
target.execute(sender, sentCommandLabel, (String[])Java15Compat.Arrays_copyOfRange(args, 1, args.length));
|
||||
target.timings.stopTiming();
|
||||
return true;
|
||||
} catch (CommandException var7) {
|
||||
target.timings.stopTiming();
|
||||
throw var7;
|
||||
} catch (Throwable var8) {
|
||||
target.timings.stopTiming();
|
||||
throw new CommandException("Unhandled exception executing \'" + commandLine + "\' in " + target, var8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void clearCommands() {
|
||||
Iterator var1 = this.knownCommands.entrySet().iterator();
|
||||
|
||||
while(var1.hasNext()) {
|
||||
Entry entry = (Entry)var1.next();
|
||||
((Command)entry.getValue()).unregister(this);
|
||||
}
|
||||
|
||||
this.knownCommands.clear();
|
||||
this.setDefaultCommands();
|
||||
}
|
||||
|
||||
public Command getCommand(String name) {
|
||||
Command target = (Command)this.knownCommands.get(name.toLowerCase());
|
||||
return target;
|
||||
}
|
||||
|
||||
public List<String> tabComplete(CommandSender sender, String cmdLine) {
|
||||
Validate.notNull(sender, "Sender cannot be null");
|
||||
Validate.notNull(cmdLine, "Command line cannot null");
|
||||
int spaceIndex = cmdLine.indexOf(32);
|
||||
String argLine;
|
||||
if(spaceIndex == -1) {
|
||||
ArrayList commandName1 = new ArrayList();
|
||||
Map target1 = this.knownCommands;
|
||||
argLine = sender instanceof Player?"/":"";
|
||||
Iterator args1 = target1.entrySet().iterator();
|
||||
|
||||
while(args1.hasNext()) {
|
||||
Entry ex = (Entry)args1.next();
|
||||
Command command = (Command)ex.getValue();
|
||||
if(command.testPermissionSilent(sender)) {
|
||||
String name = (String)ex.getKey();
|
||||
if(StringUtil.startsWithIgnoreCase(name, cmdLine)) {
|
||||
commandName1.add(argLine + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(commandName1, String.CASE_INSENSITIVE_ORDER);
|
||||
return commandName1;
|
||||
} else {
|
||||
String commandName = cmdLine.substring(0, spaceIndex);
|
||||
Command target = this.getCommand(commandName);
|
||||
|
||||
argLine = cmdLine.substring(spaceIndex + 1, cmdLine.length());
|
||||
String[] args = PATTERN_ON_SPACE.split(argLine, -1);
|
||||
TabCompleteEvent event = new TabCompleteEvent(sender, commandName, args);
|
||||
|
||||
if (target != null) {
|
||||
try {
|
||||
event.getSuggestions().addAll(target.tabComplete(sender, commandName, args));
|
||||
} catch (CommandException var11) {
|
||||
throw var11;
|
||||
} catch (Throwable var12) {
|
||||
throw new CommandException("Unhandled exception executing tab-completer for \'" + cmdLine + "\' in " + target, var12);
|
||||
}
|
||||
}
|
||||
|
||||
server.getPluginManager().callEvent(event);
|
||||
|
||||
return event.getSuggestions();
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<Command> getCommands() {
|
||||
return Collections.unmodifiableCollection(this.knownCommands.values());
|
||||
}
|
||||
|
||||
public void registerServerAliases() {
|
||||
Map values = this.server.getCommandAliases();
|
||||
Iterator var2 = values.keySet().iterator();
|
||||
|
||||
while(var2.hasNext()) {
|
||||
String alias = (String)var2.next();
|
||||
if(!alias.contains(":") && !alias.contains(" ")) {
|
||||
String[] commandStrings = (String[])values.get(alias);
|
||||
ArrayList targets = new ArrayList();
|
||||
StringBuilder bad = new StringBuilder();
|
||||
String[] var7 = commandStrings;
|
||||
int var8 = commandStrings.length;
|
||||
|
||||
for(int var9 = 0; var9 < var8; ++var9) {
|
||||
String commandString = var7[var9];
|
||||
String[] commandArgs = commandString.split(" ");
|
||||
Command command = this.getCommand(commandArgs[0]);
|
||||
if(command == null) {
|
||||
if(bad.length() > 0) {
|
||||
bad.append(", ");
|
||||
}
|
||||
|
||||
bad.append(commandString);
|
||||
} else {
|
||||
targets.add(commandString);
|
||||
}
|
||||
}
|
||||
|
||||
if(bad.length() > 0) {
|
||||
this.server.getLogger().warning("Could not register alias " + alias + " because it contains commands that do not exist: " + bad);
|
||||
} else if(targets.size() > 0) {
|
||||
this.knownCommands.put(alias.toLowerCase(), new FormattedCommandAlias(alias.toLowerCase(), (String[])targets.toArray(new String[targets.size()])));
|
||||
} else {
|
||||
this.knownCommands.remove(alias.toLowerCase());
|
||||
}
|
||||
} else {
|
||||
this.server.getLogger().warning("Could not register alias " + alias + " because it contains illegal characters");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package org.bukkit.event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class TabCompleteEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private CommandSender _sender;
|
||||
private String _command;
|
||||
private String[] _args;
|
||||
|
||||
private List<String> _suggestions;
|
||||
|
||||
public TabCompleteEvent(CommandSender sender, String command, String[] args)
|
||||
{
|
||||
_sender = sender;
|
||||
_command = command;
|
||||
_args = args;
|
||||
|
||||
_suggestions = new ArrayList<String>();
|
||||
}
|
||||
|
||||
public CommandSender getSender()
|
||||
{
|
||||
return _sender;
|
||||
}
|
||||
|
||||
public String getCommand()
|
||||
{
|
||||
return _command;
|
||||
}
|
||||
|
||||
public String[] getArgs()
|
||||
{
|
||||
return _args;
|
||||
}
|
||||
|
||||
public List<String> getSuggestions()
|
||||
{
|
||||
return _suggestions;
|
||||
}
|
||||
|
||||
public void setSuggestions(List<String> suggestions)
|
||||
{
|
||||
_suggestions = suggestions;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
package org.bukkit.scoreboard;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
public abstract interface Team
|
||||
{
|
||||
public abstract String getName()
|
||||
throws IllegalStateException;
|
||||
|
||||
public abstract String getDisplayName()
|
||||
throws IllegalStateException;
|
||||
|
||||
public abstract void setDisplayName(String paramString)
|
||||
throws IllegalStateException, IllegalArgumentException;
|
||||
|
||||
public abstract String getPrefix()
|
||||
throws IllegalStateException;
|
||||
|
||||
public abstract void setPrefix(String paramString)
|
||||
throws IllegalStateException, IllegalArgumentException;
|
||||
|
||||
public abstract String getSuffix()
|
||||
throws IllegalStateException;
|
||||
|
||||
public abstract void setSuffix(String paramString)
|
||||
throws IllegalStateException, IllegalArgumentException;
|
||||
|
||||
public abstract boolean allowFriendlyFire()
|
||||
throws IllegalStateException;
|
||||
|
||||
// Mineplex
|
||||
public abstract void setNameTagVisibility(TeamNameTagVisibility visibility)
|
||||
throws IllegalStateException;
|
||||
|
||||
public abstract void setAllowFriendlyFire(boolean paramBoolean)
|
||||
throws IllegalStateException;
|
||||
|
||||
public abstract boolean canSeeFriendlyInvisibles()
|
||||
throws IllegalStateException;
|
||||
|
||||
public abstract void setCanSeeFriendlyInvisibles(boolean paramBoolean)
|
||||
throws IllegalStateException;
|
||||
|
||||
public abstract Set<OfflinePlayer> getPlayers()
|
||||
throws IllegalStateException;
|
||||
|
||||
public abstract Set<String> getEntries()
|
||||
throws IllegalStateException;
|
||||
|
||||
public abstract int getSize()
|
||||
throws IllegalStateException;
|
||||
|
||||
public abstract Scoreboard getScoreboard();
|
||||
|
||||
public abstract void addPlayer(OfflinePlayer paramOfflinePlayer)
|
||||
throws IllegalStateException, IllegalArgumentException;
|
||||
|
||||
public abstract void addEntry(String paramString)
|
||||
throws IllegalStateException, IllegalArgumentException;
|
||||
|
||||
public abstract boolean removePlayer(OfflinePlayer paramOfflinePlayer)
|
||||
throws IllegalStateException, IllegalArgumentException;
|
||||
|
||||
public abstract boolean removeEntry(String paramString)
|
||||
throws IllegalStateException, IllegalArgumentException;
|
||||
|
||||
public abstract void unregister()
|
||||
throws IllegalStateException;
|
||||
|
||||
public abstract boolean hasPlayer(OfflinePlayer paramOfflinePlayer)
|
||||
throws IllegalArgumentException, IllegalStateException;
|
||||
|
||||
public abstract boolean hasEntry(String paramString)
|
||||
throws IllegalArgumentException, IllegalStateException;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package org.bukkit.scoreboard;
|
||||
|
||||
/**
|
||||
* Created by shaun on 14-10-05.
|
||||
*/
|
||||
public enum TeamNameTagVisibility
|
||||
{
|
||||
NEVER("never"), HIDE_FOR_OTHER_TEAMS("hideForOtherTeams"), HIDE_FOR_OWN_TEAM("hideForOwnTeam"), ALWAYS("always");
|
||||
|
||||
private String _keyword;
|
||||
|
||||
TeamNameTagVisibility(String keyword)
|
||||
{
|
||||
_keyword = keyword;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return _keyword;
|
||||
}
|
||||
}
|
@ -8,6 +8,6 @@
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.ServerData"/>
|
||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpclient-4.2.jar"/>
|
||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpcore-4.2.jar"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.PlayerCache"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Cache"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
@ -1,11 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
@ -13,6 +13,6 @@
|
||||
<orderEntry type="module" module-name="Mineplex.ServerData" />
|
||||
<orderEntry type="library" name="httpcore" level="project" />
|
||||
<orderEntry type="library" name="httpclient" level="project" />
|
||||
<orderEntry type="module" module-name="Mineplex.PlayerCache" />
|
||||
<orderEntry type="module" module-name="Mineplex.Cache" />
|
||||
</component>
|
||||
</module>
|
@ -55,12 +55,12 @@ public class MotdManager implements Listener, Runnable
|
||||
|
||||
//String motdLine = "§f§l◄ §c§lMaintenance§f§l ►";
|
||||
//String motdLine = "§f§l◄ §a§lCarl the Creeper§f§l ►";
|
||||
String motdLine = " §2§l§n M O N S T E R M A Z E B E T A §f";
|
||||
//String motdLine = " §f§l◄ §a§lCarl the Creeper§f§l ▬ §c§l75% OFF SALE§f§l ►";
|
||||
// String motdLine = " §2§l§n M O N S T E R M A Z E B E T A §f";
|
||||
String motdLine = " §f❄ §2§lWinter Update §f❄ §2§lSnow Fight §f❄";
|
||||
//String motdLine = " §d§lRank Sale §a§l40% Off");
|
||||
//String motdLine = " §f§l◄§c§lMAINTENANCE§f§l►");
|
||||
|
||||
updateMainMotd(" §4§l§m §f§l§m §8§l§m[ §r §4§lMineplex§r §f§lGames§r §8§l§m ]§f§l§m §4§l§m §r", motdLine);
|
||||
updateMainMotd(" §c§m §f§m §c§m §f§m §2§l§m[ §r §c§lMineplex§r §f§lGames§r §2§l§m ]§f§m §c§m §f§m §c§m §r", motdLine);
|
||||
System.out.println("Updated Bungee MOTD");
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import mineplex.bungee.playerStats.data.IpInfo;
|
||||
import mineplex.playerCache.PlayerCache;
|
||||
import mineplex.playerCache.PlayerInfo;
|
||||
import mineplex.cache.player.PlayerCache;
|
||||
import mineplex.cache.player.PlayerInfo;
|
||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
|
@ -9,7 +9,7 @@ import java.sql.Statement;
|
||||
import java.util.UUID;
|
||||
|
||||
import mineplex.bungee.playerStats.data.IpInfo;
|
||||
import mineplex.playerCache.PlayerInfo;
|
||||
import mineplex.cache.player.PlayerInfo;
|
||||
|
||||
public class PlayerStatsRepository
|
||||
{
|
||||
|
@ -38,9 +38,8 @@ public class PlayerTracker implements Listener, Runnable
|
||||
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||
_plugin.getProxy().getScheduler().schedule(_plugin, this, 1L, 1L, TimeUnit.MINUTES);
|
||||
|
||||
Region region = !new File("eu.dat").exists() ? Region.US : Region.EU;
|
||||
_repository = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
|
||||
region, PlayerStatus.class, "playerStatus");
|
||||
Region.currentRegion(), PlayerStatus.class, "playerStatus");
|
||||
|
||||
ServerCommandManager.getInstance().registerCommandType("PlayerJoinCommand", mineplex.serverdata.commands.PlayerJoinCommand.class, new PlayerJoinHandler(this));
|
||||
|
||||
|
@ -1,11 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
@ -1,4 +1,4 @@
|
||||
package mineplex.playerCache;
|
||||
package mineplex.cache.player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package mineplex.playerCache;
|
||||
package mineplex.cache.player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -1,11 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
57
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ByteArrayTag.java
Executable file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
/**
|
||||
* The {@code TAG_Byte_Array} tag.
|
||||
*/
|
||||
public final class ByteArrayTag extends Tag {
|
||||
|
||||
private final byte[] value;
|
||||
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public ByteArrayTag(byte[] value) {
|
||||
super();
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder hex = new StringBuilder();
|
||||
for (byte b : value) {
|
||||
String hexDigits = Integer.toHexString(b).toUpperCase();
|
||||
if (hexDigits.length() == 1) {
|
||||
hex.append("0");
|
||||
}
|
||||
hex.append(hexDigits).append(" ");
|
||||
}
|
||||
return "TAG_Byte_Array(" + hex + ")";
|
||||
}
|
||||
|
||||
}
|
49
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ByteTag.java
Executable file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
/**
|
||||
* The {@code TAG_Byte} tag.
|
||||
*/
|
||||
public final class ByteTag extends Tag {
|
||||
|
||||
private final byte value;
|
||||
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public ByteTag(byte value) {
|
||||
super();
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Byte getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TAG_Byte(" + value + ")";
|
||||
}
|
||||
|
||||
}
|
420
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/CompoundTag.java
Executable file
@ -0,0 +1,420 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The {@code TAG_Compound} tag.
|
||||
*/
|
||||
public final class CompoundTag extends Tag {
|
||||
|
||||
private final Map<String, Tag> value;
|
||||
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public CompoundTag(Map<String, Tag> value) {
|
||||
super();
|
||||
this.value = Collections.unmodifiableMap(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this compound tag contains the given key.
|
||||
*
|
||||
* @param key the given key
|
||||
* @return true if the tag contains the given key
|
||||
*/
|
||||
public boolean containsKey(String key) {
|
||||
return value.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Tag> getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new compound tag with the given values.
|
||||
*
|
||||
* @param value the value
|
||||
* @return the new compound tag
|
||||
*/
|
||||
public CompoundTag setValue(Map<String, Tag> value) {
|
||||
return new CompoundTag(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a compound tag builder.
|
||||
*
|
||||
* @return the builder
|
||||
*/
|
||||
public CompoundTagBuilder createBuilder() {
|
||||
return new CompoundTagBuilder(new HashMap<String, Tag>(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a byte array named with the given key.
|
||||
*
|
||||
* <p>If the key does not exist or its value is not a byte array tag,
|
||||
* then an empty byte array will be returned.</p>
|
||||
*
|
||||
* @param key the key
|
||||
* @return a byte array
|
||||
*/
|
||||
public byte[] getByteArray(String key) {
|
||||
Tag tag = value.get(key);
|
||||
if (tag instanceof ByteArrayTag) {
|
||||
return ((ByteArrayTag) tag).getValue();
|
||||
} else {
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a byte named with the given key.
|
||||
*
|
||||
* <p>If the key does not exist or its value is not a byte tag,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param key the key
|
||||
* @return a byte
|
||||
*/
|
||||
public byte getByte(String key) {
|
||||
Tag tag = value.get(key);
|
||||
if (tag instanceof ByteTag) {
|
||||
return ((ByteTag) tag).getValue();
|
||||
} else {
|
||||
return (byte) 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a double named with the given key.
|
||||
*
|
||||
* <p>If the key does not exist or its value is not a double tag,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param key the key
|
||||
* @return a double
|
||||
*/
|
||||
public double getDouble(String key) {
|
||||
Tag tag = value.get(key);
|
||||
if (tag instanceof DoubleTag) {
|
||||
return ((DoubleTag) tag).getValue();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a double named with the given key, even if it's another
|
||||
* type of number.
|
||||
*
|
||||
* <p>If the key does not exist or its value is not a number,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param key the key
|
||||
* @return a double
|
||||
*/
|
||||
public double asDouble(String key) {
|
||||
Tag tag = value.get(key);
|
||||
if (tag instanceof ByteTag) {
|
||||
return ((ByteTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof ShortTag) {
|
||||
return ((ShortTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof IntTag) {
|
||||
return ((IntTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof LongTag) {
|
||||
return ((LongTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof FloatTag) {
|
||||
return ((FloatTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof DoubleTag) {
|
||||
return ((DoubleTag) tag).getValue();
|
||||
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a float named with the given key.
|
||||
*
|
||||
* <p>If the key does not exist or its value is not a float tag,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param key the key
|
||||
* @return a float
|
||||
*/
|
||||
public float getFloat(String key) {
|
||||
Tag tag = value.get(key);
|
||||
if (tag instanceof FloatTag) {
|
||||
return ((FloatTag) tag).getValue();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@code int[]} named with the given key.
|
||||
*
|
||||
* <p>If the key does not exist or its value is not an int array tag,
|
||||
* then an empty array will be returned.</p>
|
||||
*
|
||||
* @param key the key
|
||||
* @return an int array
|
||||
*/
|
||||
public int[] getIntArray(String key) {
|
||||
Tag tag = value.get(key);
|
||||
if (tag instanceof IntArrayTag) {
|
||||
return ((IntArrayTag) tag).getValue();
|
||||
} else {
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an int named with the given key.
|
||||
*
|
||||
* <p>If the key does not exist or its value is not an int tag,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param key the key
|
||||
* @return an int
|
||||
*/
|
||||
public int getInt(String key) {
|
||||
Tag tag = value.get(key);
|
||||
if (tag instanceof IntTag) {
|
||||
return ((IntTag) tag).getValue();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an int named with the given key, even if it's another
|
||||
* type of number.
|
||||
*
|
||||
* <p>If the key does not exist or its value is not a number,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param key the key
|
||||
* @return an int
|
||||
*/
|
||||
public int asInt(String key) {
|
||||
Tag tag = value.get(key);
|
||||
if (tag instanceof ByteTag) {
|
||||
return ((ByteTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof ShortTag) {
|
||||
return ((ShortTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof IntTag) {
|
||||
return ((IntTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof LongTag) {
|
||||
return ((LongTag) tag).getValue().intValue();
|
||||
|
||||
} else if (tag instanceof FloatTag) {
|
||||
return ((FloatTag) tag).getValue().intValue();
|
||||
|
||||
} else if (tag instanceof DoubleTag) {
|
||||
return ((DoubleTag) tag).getValue().intValue();
|
||||
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of tags named with the given key.
|
||||
*
|
||||
* <p>If the key does not exist or its value is not a list tag,
|
||||
* then an empty list will be returned.</p>
|
||||
*
|
||||
* @param key the key
|
||||
* @return a list of tags
|
||||
*/
|
||||
public List<Tag> getList(String key) {
|
||||
Tag tag = value.get(key);
|
||||
if (tag instanceof ListTag) {
|
||||
return ((ListTag) tag).getValue();
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@code TagList} named with the given key.
|
||||
*
|
||||
* <p>If the key does not exist or its value is not a list tag,
|
||||
* then an empty tag list will be returned.</p>
|
||||
*
|
||||
* @param key the key
|
||||
* @return a tag list instance
|
||||
*/
|
||||
public ListTag getListTag(String key) {
|
||||
Tag tag = value.get(key);
|
||||
if (tag instanceof ListTag) {
|
||||
return (ListTag) tag;
|
||||
} else {
|
||||
return new ListTag(StringTag.class, Collections.<Tag>emptyList());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of tags named with the given key.
|
||||
*
|
||||
* <p>If the key does not exist or its value is not a list tag,
|
||||
* then an empty list will be returned. If the given key references
|
||||
* a list but the list of of a different type, then an empty
|
||||
* list will also be returned.</p>
|
||||
*
|
||||
* @param key the key
|
||||
* @param listType the class of the contained type
|
||||
* @return a list of tags
|
||||
* @param <T> the type of list
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Tag> List<T> getList(String key, Class<T> listType) {
|
||||
Tag tag = value.get(key);
|
||||
if (tag instanceof ListTag) {
|
||||
ListTag listTag = (ListTag) tag;
|
||||
if (listTag.getType().equals(listType)) {
|
||||
return (List<T>) listTag.getValue();
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a long named with the given key.
|
||||
*
|
||||
* <p>If the key does not exist or its value is not a long tag,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param key the key
|
||||
* @return a long
|
||||
*/
|
||||
public long getLong(String key) {
|
||||
Tag tag = value.get(key);
|
||||
if (tag instanceof LongTag) {
|
||||
return ((LongTag) tag).getValue();
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a long named with the given key, even if it's another
|
||||
* type of number.
|
||||
*
|
||||
* <p>If the key does not exist or its value is not a number,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param key the key
|
||||
* @return a long
|
||||
*/
|
||||
public long asLong(String key) {
|
||||
Tag tag = value.get(key);
|
||||
if (tag instanceof ByteTag) {
|
||||
return ((ByteTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof ShortTag) {
|
||||
return ((ShortTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof IntTag) {
|
||||
return ((IntTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof LongTag) {
|
||||
return ((LongTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof FloatTag) {
|
||||
return ((FloatTag) tag).getValue().longValue();
|
||||
|
||||
} else if (tag instanceof DoubleTag) {
|
||||
return ((DoubleTag) tag).getValue().longValue();
|
||||
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a short named with the given key.
|
||||
*
|
||||
* <p>If the key does not exist or its value is not a short tag,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param key the key
|
||||
* @return a short
|
||||
*/
|
||||
public short getShort(String key) {
|
||||
Tag tag = value.get(key);
|
||||
if (tag instanceof ShortTag) {
|
||||
return ((ShortTag) tag).getValue();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string named with the given key.
|
||||
*
|
||||
* <p>If the key does not exist or its value is not a string tag,
|
||||
* then {@code ""} will be returned.</p>
|
||||
*
|
||||
* @param key the key
|
||||
* @return a string
|
||||
*/
|
||||
public String getString(String key) {
|
||||
Tag tag = value.get(key);
|
||||
if (tag instanceof StringTag) {
|
||||
return ((StringTag) tag).getValue();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder bldr = new StringBuilder();
|
||||
bldr.append("TAG_Compound").append(": ").append(value.size()).append(" entries\r\n{\r\n");
|
||||
for (Map.Entry<String, Tag> entry : value.entrySet()) {
|
||||
bldr.append(" ").append(entry.getValue().toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
|
||||
}
|
||||
bldr.append("}");
|
||||
return bldr.toString();
|
||||
}
|
||||
|
||||
}
|
204
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/CompoundTagBuilder.java
Executable file
@ -0,0 +1,204 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Helps create compound tags.
|
||||
*/
|
||||
public class CompoundTagBuilder {
|
||||
|
||||
private final Map<String, Tag> entries;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*/
|
||||
CompoundTagBuilder() {
|
||||
this.entries = new HashMap<String, Tag>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance and use the given map (which will be modified).
|
||||
*
|
||||
* @param value the value
|
||||
*/
|
||||
CompoundTagBuilder(Map<String, Tag> value) {
|
||||
checkNotNull(value);
|
||||
this.entries = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the given key and tag into the compound tag.
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder put(String key, Tag value) {
|
||||
checkNotNull(key);
|
||||
checkNotNull(value);
|
||||
entries.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the given key and value into the compound tag as a
|
||||
* {@code ByteArrayTag}.
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putByteArray(String key, byte[] value) {
|
||||
return put(key, new ByteArrayTag(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the given key and value into the compound tag as a
|
||||
* {@code ByteTag}.
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putByte(String key, byte value) {
|
||||
return put(key, new ByteTag(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the given key and value into the compound tag as a
|
||||
* {@code DoubleTag}.
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putDouble(String key, double value) {
|
||||
return put(key, new DoubleTag(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the given key and value into the compound tag as a
|
||||
* {@code FloatTag}.
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putFloat(String key, float value) {
|
||||
return put(key, new FloatTag(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the given key and value into the compound tag as a
|
||||
* {@code IntArrayTag}.
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putIntArray(String key, int[] value) {
|
||||
return put(key, new IntArrayTag(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the given key and value into the compound tag as an {@code IntTag}.
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putInt(String key, int value) {
|
||||
return put(key, new IntTag(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the given key and value into the compound tag as a
|
||||
* {@code LongTag}.
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putLong(String key, long value) {
|
||||
return put(key, new LongTag(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the given key and value into the compound tag as a
|
||||
* {@code ShortTag}.
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putShort(String key, short value) {
|
||||
return put(key, new ShortTag(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the given key and value into the compound tag as a
|
||||
* {@code StringTag}.
|
||||
*
|
||||
* @param key they key
|
||||
* @param value the value
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putString(String key, String value) {
|
||||
return put(key, new StringTag(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Put all the entries from the given map into this map.
|
||||
*
|
||||
* @param value the map of tags
|
||||
* @return this object
|
||||
*/
|
||||
public CompoundTagBuilder putAll(Map<String, ? extends Tag> value) {
|
||||
checkNotNull(value);
|
||||
for (Map.Entry<String, ? extends Tag> entry : value.entrySet()) {
|
||||
put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an unnamed compound tag with this builder's entries.
|
||||
*
|
||||
* @return the new compound tag
|
||||
*/
|
||||
public CompoundTag build() {
|
||||
return new CompoundTag(new HashMap<String, Tag>(entries));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new builder instance.
|
||||
*
|
||||
* @return a new builder
|
||||
*/
|
||||
public static CompoundTagBuilder create() {
|
||||
return new CompoundTagBuilder();
|
||||
}
|
||||
|
||||
}
|
50
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/DoubleTag.java
Executable file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
/**
|
||||
* The {@code TAG_Double} tag.
|
||||
*
|
||||
*/
|
||||
public final class DoubleTag extends Tag {
|
||||
|
||||
private final double value;
|
||||
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public DoubleTag(double value) {
|
||||
super();
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TAG_Double(" + value + ")";
|
||||
}
|
||||
|
||||
}
|
37
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/EndTag.java
Executable file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
/**
|
||||
* The {@code TAG_End} tag.
|
||||
*/
|
||||
public final class EndTag extends Tag {
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TAG_End";
|
||||
}
|
||||
|
||||
}
|
49
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/FloatTag.java
Executable file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
/**
|
||||
* The {@code TAG_Float} tag.
|
||||
*/
|
||||
public final class FloatTag extends Tag {
|
||||
|
||||
private final float value;
|
||||
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public FloatTag(float value) {
|
||||
super();
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TAG_Float(" + value + ")";
|
||||
}
|
||||
|
||||
}
|
60
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/IntArrayTag.java
Executable file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* The {@code TAG_Int_Array} tag.
|
||||
*/
|
||||
public final class IntArrayTag extends Tag {
|
||||
|
||||
private final int[] value;
|
||||
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public IntArrayTag(int[] value) {
|
||||
super();
|
||||
checkNotNull(value);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder hex = new StringBuilder();
|
||||
for (int b : value) {
|
||||
String hexDigits = Integer.toHexString(b).toUpperCase();
|
||||
if (hexDigits.length() == 1) {
|
||||
hex.append("0");
|
||||
}
|
||||
hex.append(hexDigits).append(" ");
|
||||
}
|
||||
return "TAG_Int_Array(" + hex + ")";
|
||||
}
|
||||
|
||||
}
|
49
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/IntTag.java
Executable file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
/**
|
||||
* The {@code TAG_Int} tag.
|
||||
*/
|
||||
public final class IntTag extends Tag {
|
||||
|
||||
private final int value;
|
||||
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public IntTag(int value) {
|
||||
super();
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TAG_Int(" + value + ")";
|
||||
}
|
||||
|
||||
}
|
431
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ListTag.java
Executable file
@ -0,0 +1,431 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* The {@code TAG_List} tag.
|
||||
*/
|
||||
public final class ListTag extends Tag {
|
||||
|
||||
private final Class<? extends Tag> type;
|
||||
private final List<Tag> value;
|
||||
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param type the type of tag
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public ListTag(Class<? extends Tag> type, List<? extends Tag> value) {
|
||||
super();
|
||||
checkNotNull(value);
|
||||
this.type = type;
|
||||
this.value = Collections.unmodifiableList(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of item in this list.
|
||||
*
|
||||
* @return The type of item in this list.
|
||||
*/
|
||||
public Class<? extends Tag> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag> getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new list tag with this tag's name and type.
|
||||
*
|
||||
* @param list the new list
|
||||
* @return a new list tag
|
||||
*/
|
||||
public ListTag setValue(List<Tag> list) {
|
||||
return new ListTag(getType(), list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tag if it exists at the given index.
|
||||
*
|
||||
* @param index the index
|
||||
* @return the tag or null
|
||||
*/
|
||||
@Nullable
|
||||
public Tag getIfExists(int index) {
|
||||
try {
|
||||
return value.get(index);
|
||||
} catch (NoSuchElementException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a byte array named with the given index.
|
||||
*
|
||||
* <p>If the index does not exist or its value is not a byte array tag,
|
||||
* then an empty byte array will be returned.</p>
|
||||
*
|
||||
* @param index the index
|
||||
* @return a byte array
|
||||
*/
|
||||
public byte[] getByteArray(int index) {
|
||||
Tag tag = getIfExists(index);
|
||||
if (tag instanceof ByteArrayTag) {
|
||||
return ((ByteArrayTag) tag).getValue();
|
||||
} else {
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a byte named with the given index.
|
||||
*
|
||||
* <p>If the index does not exist or its value is not a byte tag,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param index the index
|
||||
* @return a byte
|
||||
*/
|
||||
public byte getByte(int index) {
|
||||
Tag tag = getIfExists(index);
|
||||
if (tag instanceof ByteTag) {
|
||||
return ((ByteTag) tag).getValue();
|
||||
} else {
|
||||
return (byte) 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a double named with the given index.
|
||||
*
|
||||
* <p>If the index does not exist or its value is not a double tag,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param index the index
|
||||
* @return a double
|
||||
*/
|
||||
public double getDouble(int index) {
|
||||
Tag tag = getIfExists(index);
|
||||
if (tag instanceof DoubleTag) {
|
||||
return ((DoubleTag) tag).getValue();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a double named with the given index, even if it's another
|
||||
* type of number.
|
||||
*
|
||||
* <p>If the index does not exist or its value is not a number,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param index the index
|
||||
* @return a double
|
||||
*/
|
||||
public double asDouble(int index) {
|
||||
Tag tag = getIfExists(index);
|
||||
if (tag instanceof ByteTag) {
|
||||
return ((ByteTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof ShortTag) {
|
||||
return ((ShortTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof IntTag) {
|
||||
return ((IntTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof LongTag) {
|
||||
return ((LongTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof FloatTag) {
|
||||
return ((FloatTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof DoubleTag) {
|
||||
return ((DoubleTag) tag).getValue();
|
||||
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a float named with the given index.
|
||||
*
|
||||
* <p>If the index does not exist or its value is not a float tag,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param index the index
|
||||
* @return a float
|
||||
*/
|
||||
public float getFloat(int index) {
|
||||
Tag tag = getIfExists(index);
|
||||
if (tag instanceof FloatTag) {
|
||||
return ((FloatTag) tag).getValue();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@code int[]} named with the given index.
|
||||
*
|
||||
* <p>If the index does not exist or its value is not an int array tag,
|
||||
* then an empty array will be returned.</p>
|
||||
*
|
||||
* @param index the index
|
||||
* @return an int array
|
||||
*/
|
||||
public int[] getIntArray(int index) {
|
||||
Tag tag = getIfExists(index);
|
||||
if (tag instanceof IntArrayTag) {
|
||||
return ((IntArrayTag) tag).getValue();
|
||||
} else {
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an int named with the given index.
|
||||
*
|
||||
* <p>If the index does not exist or its value is not an int tag,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param index the index
|
||||
* @return an int
|
||||
*/
|
||||
public int getInt(int index) {
|
||||
Tag tag = getIfExists(index);
|
||||
if (tag instanceof IntTag) {
|
||||
return ((IntTag) tag).getValue();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an int named with the given index, even if it's another
|
||||
* type of number.
|
||||
*
|
||||
* <p>If the index does not exist or its value is not a number,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param index the index
|
||||
* @return an int
|
||||
*/
|
||||
public int asInt(int index) {
|
||||
Tag tag = getIfExists(index);
|
||||
if (tag instanceof ByteTag) {
|
||||
return ((ByteTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof ShortTag) {
|
||||
return ((ShortTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof IntTag) {
|
||||
return ((IntTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof LongTag) {
|
||||
return ((LongTag) tag).getValue().intValue();
|
||||
|
||||
} else if (tag instanceof FloatTag) {
|
||||
return ((FloatTag) tag).getValue().intValue();
|
||||
|
||||
} else if (tag instanceof DoubleTag) {
|
||||
return ((DoubleTag) tag).getValue().intValue();
|
||||
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of tags named with the given index.
|
||||
*
|
||||
* <p>If the index does not exist or its value is not a list tag,
|
||||
* then an empty list will be returned.</p>
|
||||
*
|
||||
* @param index the index
|
||||
* @return a list of tags
|
||||
*/
|
||||
public List<Tag> getList(int index) {
|
||||
Tag tag = getIfExists(index);
|
||||
if (tag instanceof ListTag) {
|
||||
return ((ListTag) tag).getValue();
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a {@code TagList} named with the given index.
|
||||
*
|
||||
* <p>If the index does not exist or its value is not a list tag,
|
||||
* then an empty tag list will be returned.</p>
|
||||
*
|
||||
* @param index the index
|
||||
* @return a tag list instance
|
||||
*/
|
||||
public ListTag getListTag(int index) {
|
||||
Tag tag = getIfExists(index);
|
||||
if (tag instanceof ListTag) {
|
||||
return (ListTag) tag;
|
||||
} else {
|
||||
return new ListTag(StringTag.class, Collections.<Tag>emptyList());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of tags named with the given index.
|
||||
*
|
||||
* <p>If the index does not exist or its value is not a list tag,
|
||||
* then an empty list will be returned. If the given index references
|
||||
* a list but the list of of a different type, then an empty
|
||||
* list will also be returned.</p>
|
||||
*
|
||||
* @param index the index
|
||||
* @param listType the class of the contained type
|
||||
* @return a list of tags
|
||||
* @param <T> the NBT type
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Tag> List<T> getList(int index, Class<T> listType) {
|
||||
Tag tag = getIfExists(index);
|
||||
if (tag instanceof ListTag) {
|
||||
ListTag listTag = (ListTag) tag;
|
||||
if (listTag.getType().equals(listType)) {
|
||||
return (List<T>) listTag.getValue();
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a long named with the given index.
|
||||
*
|
||||
* <p>If the index does not exist or its value is not a long tag,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param index the index
|
||||
* @return a long
|
||||
*/
|
||||
public long getLong(int index) {
|
||||
Tag tag = getIfExists(index);
|
||||
if (tag instanceof LongTag) {
|
||||
return ((LongTag) tag).getValue();
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a long named with the given index, even if it's another
|
||||
* type of number.
|
||||
*
|
||||
* <p>If the index does not exist or its value is not a number,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param index the index
|
||||
* @return a long
|
||||
*/
|
||||
public long asLong(int index) {
|
||||
Tag tag = getIfExists(index);
|
||||
if (tag instanceof ByteTag) {
|
||||
return ((ByteTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof ShortTag) {
|
||||
return ((ShortTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof IntTag) {
|
||||
return ((IntTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof LongTag) {
|
||||
return ((LongTag) tag).getValue();
|
||||
|
||||
} else if (tag instanceof FloatTag) {
|
||||
return ((FloatTag) tag).getValue().longValue();
|
||||
|
||||
} else if (tag instanceof DoubleTag) {
|
||||
return ((DoubleTag) tag).getValue().longValue();
|
||||
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a short named with the given index.
|
||||
*
|
||||
* <p>If the index does not exist or its value is not a short tag,
|
||||
* then {@code 0} will be returned.</p>
|
||||
*
|
||||
* @param index the index
|
||||
* @return a short
|
||||
*/
|
||||
public short getShort(int index) {
|
||||
Tag tag = getIfExists(index);
|
||||
if (tag instanceof ShortTag) {
|
||||
return ((ShortTag) tag).getValue();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string named with the given index.
|
||||
*
|
||||
* <p>If the index does not exist or its value is not a string tag,
|
||||
* then {@code ""} will be returned.</p>
|
||||
*
|
||||
* @param index the index
|
||||
* @return a string
|
||||
*/
|
||||
public String getString(int index) {
|
||||
Tag tag = getIfExists(index);
|
||||
if (tag instanceof StringTag) {
|
||||
return ((StringTag) tag).getValue();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder bldr = new StringBuilder();
|
||||
bldr.append("TAG_List").append(": ").append(value.size()).append(" entries of type ").append(NBTUtils.getTypeName(type)).append("\r\n{\r\n");
|
||||
for (Tag t : value) {
|
||||
bldr.append(" ").append(t.toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
|
||||
}
|
||||
bldr.append("}");
|
||||
return bldr.toString();
|
||||
}
|
||||
|
||||
}
|
119
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ListTagBuilder.java
Executable file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Helps create list tags.
|
||||
*/
|
||||
public class ListTagBuilder {
|
||||
|
||||
private final Class<? extends Tag> type;
|
||||
private final List<Tag> entries;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param type of tag contained in this list
|
||||
*/
|
||||
ListTagBuilder(Class<? extends Tag> type) {
|
||||
checkNotNull(type);
|
||||
this.type = type;
|
||||
this.entries = new ArrayList<Tag>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given tag.
|
||||
*
|
||||
* @param value the tag
|
||||
* @return this object
|
||||
*/
|
||||
public ListTagBuilder add(Tag value) {
|
||||
checkNotNull(value);
|
||||
if (!type.isInstance(value)) {
|
||||
throw new IllegalArgumentException(value.getClass().getCanonicalName() + " is not of expected type " + type.getCanonicalName());
|
||||
}
|
||||
entries.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all the tags in the given list.
|
||||
*
|
||||
* @param value a list of tags
|
||||
* @return this object
|
||||
*/
|
||||
public ListTagBuilder addAll(Collection<? extends Tag> value) {
|
||||
checkNotNull(value);
|
||||
for (Tag v : value) {
|
||||
add(v);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an unnamed list tag with this builder's entries.
|
||||
*
|
||||
* @return the new list tag
|
||||
*/
|
||||
public ListTag build() {
|
||||
return new ListTag(type, new ArrayList<Tag>(entries));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new builder instance.
|
||||
*
|
||||
* @return a new builder
|
||||
*/
|
||||
public static ListTagBuilder create(Class<? extends Tag> type) {
|
||||
return new ListTagBuilder(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new builder instance.
|
||||
*
|
||||
* @return a new builder
|
||||
*/
|
||||
public static <T extends Tag> ListTagBuilder createWith(T ... entries) {
|
||||
checkNotNull(entries);
|
||||
|
||||
if (entries.length == 0) {
|
||||
throw new IllegalArgumentException("This method needs an array of at least one entry");
|
||||
}
|
||||
|
||||
Class<? extends Tag> type = entries[0].getClass();
|
||||
for (int i = 1; i < entries.length; i++) {
|
||||
if (!type.isInstance(entries[i])) {
|
||||
throw new IllegalArgumentException("An array of different tag types was provided");
|
||||
}
|
||||
}
|
||||
|
||||
ListTagBuilder builder = new ListTagBuilder(type);
|
||||
builder.addAll(Arrays.asList(entries));
|
||||
return builder;
|
||||
}
|
||||
|
||||
}
|
50
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/LongTag.java
Executable file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
/**
|
||||
* The {@code TAG_Long} tag.
|
||||
*
|
||||
*/
|
||||
public final class LongTag extends Tag {
|
||||
|
||||
private final long value;
|
||||
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public LongTag(long value) {
|
||||
super();
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TAG_Long(" + value + ")";
|
||||
}
|
||||
|
||||
}
|
81
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTConstants.java
Executable file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* A class which holds constant values.
|
||||
*/
|
||||
public final class NBTConstants {
|
||||
|
||||
public static final Charset CHARSET = Charset.forName("UTF-8");
|
||||
|
||||
public static final int TYPE_END = 0, TYPE_BYTE = 1, TYPE_SHORT = 2,
|
||||
TYPE_INT = 3, TYPE_LONG = 4, TYPE_FLOAT = 5, TYPE_DOUBLE = 6,
|
||||
TYPE_BYTE_ARRAY = 7, TYPE_STRING = 8, TYPE_LIST = 9,
|
||||
TYPE_COMPOUND = 10, TYPE_INT_ARRAY = 11;
|
||||
|
||||
/**
|
||||
* Default private constructor.
|
||||
*/
|
||||
private NBTConstants() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a type ID to its corresponding {@link Tag} class.
|
||||
*
|
||||
* @param id type ID
|
||||
* @return tag class
|
||||
* @throws IllegalArgumentException thrown if the tag ID is not valid
|
||||
*/
|
||||
public static Class<? extends Tag> getClassFromType(int id) {
|
||||
switch (id) {
|
||||
case TYPE_END:
|
||||
return EndTag.class;
|
||||
case TYPE_BYTE:
|
||||
return ByteTag.class;
|
||||
case TYPE_SHORT:
|
||||
return ShortTag.class;
|
||||
case TYPE_INT:
|
||||
return IntTag.class;
|
||||
case TYPE_LONG:
|
||||
return LongTag.class;
|
||||
case TYPE_FLOAT:
|
||||
return FloatTag.class;
|
||||
case TYPE_DOUBLE:
|
||||
return DoubleTag.class;
|
||||
case TYPE_BYTE_ARRAY:
|
||||
return ByteArrayTag.class;
|
||||
case TYPE_STRING:
|
||||
return StringTag.class;
|
||||
case TYPE_LIST:
|
||||
return ListTag.class;
|
||||
case TYPE_COMPOUND:
|
||||
return CompoundTag.class;
|
||||
case TYPE_INT_ARRAY:
|
||||
return IntArrayTag.class;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown tag type ID of " + id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
171
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTInputStream.java
Executable file
@ -0,0 +1,171 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class reads <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
|
||||
* streams, and produces an object graph of subclasses of the {@code Tag}
|
||||
* object.
|
||||
*
|
||||
* <p>The NBT format was created by Markus Persson, and the specification may be
|
||||
* found at <a href="http://www.minecraft.net/docs/NBT.txt">
|
||||
* http://www.minecraft.net/docs/NBT.txt</a>.</p>
|
||||
*/
|
||||
public final class NBTInputStream implements Closeable {
|
||||
|
||||
private final DataInputStream is;
|
||||
|
||||
/**
|
||||
* Creates a new {@code NBTInputStream}, which will source its data
|
||||
* from the specified input stream.
|
||||
*
|
||||
* @param is the input stream
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
public NBTInputStream(InputStream is) throws IOException {
|
||||
this.is = new DataInputStream(is);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an NBT tag from the stream.
|
||||
*
|
||||
* @return The tag that was read.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public NamedTag readNamedTag() throws IOException {
|
||||
return readNamedTag(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an NBT from the stream.
|
||||
*
|
||||
* @param depth the depth of this tag
|
||||
* @return The tag that was read.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private NamedTag readNamedTag(int depth) throws IOException {
|
||||
int type = is.readByte() & 0xFF;
|
||||
|
||||
String name;
|
||||
if (type != NBTConstants.TYPE_END) {
|
||||
int nameLength = is.readShort() & 0xFFFF;
|
||||
byte[] nameBytes = new byte[nameLength];
|
||||
is.readFully(nameBytes);
|
||||
name = new String(nameBytes, NBTConstants.CHARSET);
|
||||
} else {
|
||||
name = "";
|
||||
}
|
||||
|
||||
return new NamedTag(name, readTagPayload(type, depth));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the payload of a tag given the type.
|
||||
*
|
||||
* @param type the type
|
||||
* @param depth the depth
|
||||
* @return the tag
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
private Tag readTagPayload(int type, int depth) throws IOException {
|
||||
switch (type) {
|
||||
case NBTConstants.TYPE_END:
|
||||
if (depth == 0) {
|
||||
throw new IOException(
|
||||
"TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
|
||||
} else {
|
||||
return new EndTag();
|
||||
}
|
||||
case NBTConstants.TYPE_BYTE:
|
||||
return new ByteTag(is.readByte());
|
||||
case NBTConstants.TYPE_SHORT:
|
||||
return new ShortTag(is.readShort());
|
||||
case NBTConstants.TYPE_INT:
|
||||
return new IntTag(is.readInt());
|
||||
case NBTConstants.TYPE_LONG:
|
||||
return new LongTag(is.readLong());
|
||||
case NBTConstants.TYPE_FLOAT:
|
||||
return new FloatTag(is.readFloat());
|
||||
case NBTConstants.TYPE_DOUBLE:
|
||||
return new DoubleTag(is.readDouble());
|
||||
case NBTConstants.TYPE_BYTE_ARRAY:
|
||||
int length = is.readInt();
|
||||
byte[] bytes = new byte[length];
|
||||
is.readFully(bytes);
|
||||
return new ByteArrayTag(bytes);
|
||||
case NBTConstants.TYPE_STRING:
|
||||
length = is.readShort();
|
||||
bytes = new byte[length];
|
||||
is.readFully(bytes);
|
||||
return new StringTag(new String(bytes, NBTConstants.CHARSET));
|
||||
case NBTConstants.TYPE_LIST:
|
||||
int childType = is.readByte();
|
||||
length = is.readInt();
|
||||
|
||||
List<Tag> tagList = new ArrayList<Tag>();
|
||||
for (int i = 0; i < length; ++i) {
|
||||
Tag tag = readTagPayload(childType, depth + 1);
|
||||
if (tag instanceof EndTag) {
|
||||
throw new IOException("TAG_End not permitted in a list.");
|
||||
}
|
||||
tagList.add(tag);
|
||||
}
|
||||
|
||||
return new ListTag(NBTUtils.getTypeClass(childType), tagList);
|
||||
case NBTConstants.TYPE_COMPOUND:
|
||||
Map<String, Tag> tagMap = new HashMap<String, Tag>();
|
||||
while (true) {
|
||||
NamedTag namedTag = readNamedTag(depth + 1);
|
||||
Tag tag = namedTag.getTag();
|
||||
if (tag instanceof EndTag) {
|
||||
break;
|
||||
} else {
|
||||
tagMap.put(namedTag.getName(), tag);
|
||||
}
|
||||
}
|
||||
|
||||
return new CompoundTag(tagMap);
|
||||
case NBTConstants.TYPE_INT_ARRAY:
|
||||
length = is.readInt();
|
||||
int[] data = new int[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
data[i] = is.readInt();
|
||||
}
|
||||
return new IntArrayTag(data);
|
||||
default:
|
||||
throw new IOException("Invalid tag type: " + type + ".");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
is.close();
|
||||
}
|
||||
|
||||
}
|
294
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTOutputStream.java
Executable file
@ -0,0 +1,294 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
|
||||
* {@code Tag} objects to an underlying {@code OutputStream}.
|
||||
*
|
||||
* <p>The NBT format was created by Markus Persson, and the specification may be
|
||||
* found at <a href="http://www.minecraft.net/docs/NBT.txt">
|
||||
* http://www.minecraft.net/docs/NBT.txt</a>.</p>
|
||||
*/
|
||||
public final class NBTOutputStream implements Closeable {
|
||||
|
||||
/**
|
||||
* The output stream.
|
||||
*/
|
||||
private final DataOutputStream os;
|
||||
|
||||
/**
|
||||
* Creates a new {@code NBTOutputStream}, which will write data to the
|
||||
* specified underlying output stream.
|
||||
*
|
||||
* @param os
|
||||
* The output stream.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*/
|
||||
public NBTOutputStream(OutputStream os) throws IOException {
|
||||
this.os = new DataOutputStream(os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a tag.
|
||||
*
|
||||
* @param tag
|
||||
* The tag to write.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*/
|
||||
public void writeNamedTag(String name, Tag tag) throws IOException {
|
||||
checkNotNull(name);
|
||||
checkNotNull(tag);
|
||||
|
||||
int type = NBTUtils.getTypeCode(tag.getClass());
|
||||
byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
|
||||
|
||||
os.writeByte(type);
|
||||
os.writeShort(nameBytes.length);
|
||||
os.write(nameBytes);
|
||||
|
||||
if (type == NBTConstants.TYPE_END) {
|
||||
throw new IOException("Named TAG_End not permitted.");
|
||||
}
|
||||
|
||||
writeTagPayload(tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes tag payload.
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*/
|
||||
private void writeTagPayload(Tag tag) throws IOException {
|
||||
int type = NBTUtils.getTypeCode(tag.getClass());
|
||||
switch (type) {
|
||||
case NBTConstants.TYPE_END:
|
||||
writeEndTagPayload((EndTag) tag);
|
||||
break;
|
||||
case NBTConstants.TYPE_BYTE:
|
||||
writeByteTagPayload((ByteTag) tag);
|
||||
break;
|
||||
case NBTConstants.TYPE_SHORT:
|
||||
writeShortTagPayload((ShortTag) tag);
|
||||
break;
|
||||
case NBTConstants.TYPE_INT:
|
||||
writeIntTagPayload((IntTag) tag);
|
||||
break;
|
||||
case NBTConstants.TYPE_LONG:
|
||||
writeLongTagPayload((LongTag) tag);
|
||||
break;
|
||||
case NBTConstants.TYPE_FLOAT:
|
||||
writeFloatTagPayload((FloatTag) tag);
|
||||
break;
|
||||
case NBTConstants.TYPE_DOUBLE:
|
||||
writeDoubleTagPayload((DoubleTag) tag);
|
||||
break;
|
||||
case NBTConstants.TYPE_BYTE_ARRAY:
|
||||
writeByteArrayTagPayload((ByteArrayTag) tag);
|
||||
break;
|
||||
case NBTConstants.TYPE_STRING:
|
||||
writeStringTagPayload((StringTag) tag);
|
||||
break;
|
||||
case NBTConstants.TYPE_LIST:
|
||||
writeListTagPayload((ListTag) tag);
|
||||
break;
|
||||
case NBTConstants.TYPE_COMPOUND:
|
||||
writeCompoundTagPayload((CompoundTag) tag);
|
||||
break;
|
||||
case NBTConstants.TYPE_INT_ARRAY:
|
||||
writeIntArrayTagPayload((IntArrayTag) tag);
|
||||
break;
|
||||
default:
|
||||
throw new IOException("Invalid tag type: " + type + ".");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Byte} tag.
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*/
|
||||
private void writeByteTagPayload(ByteTag tag) throws IOException {
|
||||
os.writeByte(tag.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Byte_Array} tag.
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*/
|
||||
private void writeByteArrayTagPayload(ByteArrayTag tag) throws IOException {
|
||||
byte[] bytes = tag.getValue();
|
||||
os.writeInt(bytes.length);
|
||||
os.write(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Compound} tag.
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*/
|
||||
private void writeCompoundTagPayload(CompoundTag tag) throws IOException {
|
||||
for (Map.Entry<String, Tag> entry : tag.getValue().entrySet()) {
|
||||
writeNamedTag(entry.getKey(), entry.getValue());
|
||||
}
|
||||
os.writeByte((byte) 0); // end tag - better way?
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_List} tag.
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*/
|
||||
private void writeListTagPayload(ListTag tag) throws IOException {
|
||||
Class<? extends Tag> clazz = tag.getType();
|
||||
List<Tag> tags = tag.getValue();
|
||||
int size = tags.size();
|
||||
|
||||
os.writeByte(NBTUtils.getTypeCode(clazz));
|
||||
os.writeInt(size);
|
||||
for (Tag tag1 : tags) {
|
||||
writeTagPayload(tag1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_String} tag.
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*/
|
||||
private void writeStringTagPayload(StringTag tag) throws IOException {
|
||||
byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET);
|
||||
os.writeShort(bytes.length);
|
||||
os.write(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Double} tag.
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*/
|
||||
private void writeDoubleTagPayload(DoubleTag tag) throws IOException {
|
||||
os.writeDouble(tag.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Float} tag.
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*/
|
||||
private void writeFloatTagPayload(FloatTag tag) throws IOException {
|
||||
os.writeFloat(tag.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Long} tag.
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*/
|
||||
private void writeLongTagPayload(LongTag tag) throws IOException {
|
||||
os.writeLong(tag.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Int} tag.
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*/
|
||||
private void writeIntTagPayload(IntTag tag) throws IOException {
|
||||
os.writeInt(tag.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Short} tag.
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*/
|
||||
private void writeShortTagPayload(ShortTag tag) throws IOException {
|
||||
os.writeShort(tag.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Empty} tag.
|
||||
*
|
||||
* @param tag the tag
|
||||
*/
|
||||
private void writeEndTagPayload(EndTag tag) {
|
||||
/* empty */
|
||||
}
|
||||
|
||||
private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException {
|
||||
int[] data = tag.getValue();
|
||||
os.writeInt(data.length);
|
||||
for (int aData : data) {
|
||||
os.writeInt(aData);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
os.close();
|
||||
}
|
||||
|
||||
}
|
170
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTUtils.java
Executable file
@ -0,0 +1,170 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A class which contains NBT-related utility methods.
|
||||
*
|
||||
*/
|
||||
public final class NBTUtils {
|
||||
|
||||
/**
|
||||
* Default private constructor.
|
||||
*/
|
||||
private NBTUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type name of a tag.
|
||||
*
|
||||
* @param clazz the tag class
|
||||
* @return The type name.
|
||||
*/
|
||||
public static String getTypeName(Class<? extends Tag> clazz) {
|
||||
if (clazz.equals(ByteArrayTag.class)) {
|
||||
return "TAG_Byte_Array";
|
||||
} else if (clazz.equals(ByteTag.class)) {
|
||||
return "TAG_Byte";
|
||||
} else if (clazz.equals(CompoundTag.class)) {
|
||||
return "TAG_Compound";
|
||||
} else if (clazz.equals(DoubleTag.class)) {
|
||||
return "TAG_Double";
|
||||
} else if (clazz.equals(EndTag.class)) {
|
||||
return "TAG_End";
|
||||
} else if (clazz.equals(FloatTag.class)) {
|
||||
return "TAG_Float";
|
||||
} else if (clazz.equals(IntTag.class)) {
|
||||
return "TAG_Int";
|
||||
} else if (clazz.equals(ListTag.class)) {
|
||||
return "TAG_List";
|
||||
} else if (clazz.equals(LongTag.class)) {
|
||||
return "TAG_Long";
|
||||
} else if (clazz.equals(ShortTag.class)) {
|
||||
return "TAG_Short";
|
||||
} else if (clazz.equals(StringTag.class)) {
|
||||
return "TAG_String";
|
||||
} else if (clazz.equals(IntArrayTag.class)) {
|
||||
return "TAG_Int_Array";
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid tag classs ("
|
||||
+ clazz.getName() + ").");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type code of a tag class.
|
||||
*
|
||||
* @param clazz the tag class
|
||||
* @return The type code.
|
||||
* @throws IllegalArgumentException if the tag class is invalid.
|
||||
*/
|
||||
public static int getTypeCode(Class<? extends Tag> clazz) {
|
||||
if (clazz.equals(ByteArrayTag.class)) {
|
||||
return NBTConstants.TYPE_BYTE_ARRAY;
|
||||
} else if (clazz.equals(ByteTag.class)) {
|
||||
return NBTConstants.TYPE_BYTE;
|
||||
} else if (clazz.equals(CompoundTag.class)) {
|
||||
return NBTConstants.TYPE_COMPOUND;
|
||||
} else if (clazz.equals(DoubleTag.class)) {
|
||||
return NBTConstants.TYPE_DOUBLE;
|
||||
} else if (clazz.equals(EndTag.class)) {
|
||||
return NBTConstants.TYPE_END;
|
||||
} else if (clazz.equals(FloatTag.class)) {
|
||||
return NBTConstants.TYPE_FLOAT;
|
||||
} else if (clazz.equals(IntTag.class)) {
|
||||
return NBTConstants.TYPE_INT;
|
||||
} else if (clazz.equals(ListTag.class)) {
|
||||
return NBTConstants.TYPE_LIST;
|
||||
} else if (clazz.equals(LongTag.class)) {
|
||||
return NBTConstants.TYPE_LONG;
|
||||
} else if (clazz.equals(ShortTag.class)) {
|
||||
return NBTConstants.TYPE_SHORT;
|
||||
} else if (clazz.equals(StringTag.class)) {
|
||||
return NBTConstants.TYPE_STRING;
|
||||
} else if (clazz.equals(IntArrayTag.class)) {
|
||||
return NBTConstants.TYPE_INT_ARRAY;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid tag classs ("
|
||||
+ clazz.getName() + ").");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the class of a type of tag.
|
||||
*
|
||||
* @param type the type
|
||||
* @return The class.
|
||||
* @throws IllegalArgumentException if the tag type is invalid.
|
||||
*/
|
||||
public static Class<? extends Tag> getTypeClass(int type) {
|
||||
switch (type) {
|
||||
case NBTConstants.TYPE_END:
|
||||
return EndTag.class;
|
||||
case NBTConstants.TYPE_BYTE:
|
||||
return ByteTag.class;
|
||||
case NBTConstants.TYPE_SHORT:
|
||||
return ShortTag.class;
|
||||
case NBTConstants.TYPE_INT:
|
||||
return IntTag.class;
|
||||
case NBTConstants.TYPE_LONG:
|
||||
return LongTag.class;
|
||||
case NBTConstants.TYPE_FLOAT:
|
||||
return FloatTag.class;
|
||||
case NBTConstants.TYPE_DOUBLE:
|
||||
return DoubleTag.class;
|
||||
case NBTConstants.TYPE_BYTE_ARRAY:
|
||||
return ByteArrayTag.class;
|
||||
case NBTConstants.TYPE_STRING:
|
||||
return StringTag.class;
|
||||
case NBTConstants.TYPE_LIST:
|
||||
return ListTag.class;
|
||||
case NBTConstants.TYPE_COMPOUND:
|
||||
return CompoundTag.class;
|
||||
case NBTConstants.TYPE_INT_ARRAY:
|
||||
return IntArrayTag.class;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid tag type : " + type
|
||||
+ ".");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get child tag of a NBT structure.
|
||||
*
|
||||
* @param items the map to read from
|
||||
* @param key the key to look for
|
||||
* @param expected the expected NBT class type
|
||||
* @return child tag
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public static <T extends Tag> T getChildTag(Map<String, Tag> items, String key, Class<T> expected) throws IllegalArgumentException {
|
||||
if (!items.containsKey(key)) {
|
||||
throw new IllegalArgumentException("Missing a \"" + key + "\" tag");
|
||||
}
|
||||
Tag tag = items.get(key);
|
||||
if (!expected.isInstance(tag)) {
|
||||
throw new IllegalArgumentException(key + " tag is not of tag type " + expected.getName());
|
||||
}
|
||||
return expected.cast(tag);
|
||||
}
|
||||
|
||||
}
|
63
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NamedTag.java
Executable file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A tag that has a name.
|
||||
*/
|
||||
public class NamedTag {
|
||||
|
||||
private final String name;
|
||||
private final Tag tag;
|
||||
|
||||
/**
|
||||
* Create a new named tag.
|
||||
*
|
||||
* @param name the name
|
||||
* @param tag the tag
|
||||
*/
|
||||
public NamedTag(String name, Tag tag) {
|
||||
checkNotNull(name);
|
||||
checkNotNull(tag);
|
||||
this.name = name;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the tag.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tag.
|
||||
*
|
||||
* @return the tag
|
||||
*/
|
||||
public Tag getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
}
|
49
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ShortTag.java
Executable file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
/**
|
||||
* The {@code TAG_Short} tag.
|
||||
*/
|
||||
public final class ShortTag extends Tag {
|
||||
|
||||
private final short value;
|
||||
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public ShortTag(short value) {
|
||||
super();
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TAG_Short(" + value + ")";
|
||||
}
|
||||
|
||||
}
|
52
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/StringTag.java
Executable file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* The {@code TAG_String} tag.
|
||||
*/
|
||||
public final class StringTag extends Tag {
|
||||
|
||||
private final String value;
|
||||
|
||||
/**
|
||||
* Creates the tag with an empty name.
|
||||
*
|
||||
* @param value the value of the tag
|
||||
*/
|
||||
public StringTag(String value) {
|
||||
super();
|
||||
checkNotNull(value);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TAG_String(" + value + ")";
|
||||
}
|
||||
|
||||
}
|
34
Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/Tag.java
Executable file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.java.sk89q.jnbt;
|
||||
|
||||
/**
|
||||
* Represents a NBT tag.
|
||||
*/
|
||||
public abstract class Tag {
|
||||
|
||||
/**
|
||||
* Gets the value of this tag.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public abstract Object getValue();
|
||||
|
||||
}
|
@ -4,10 +4,11 @@ import org.bukkit.Material;
|
||||
|
||||
public enum CurrencyType
|
||||
{
|
||||
Tokens(" Tokens", Material.EMERALD),
|
||||
Coins(" Coins", Material.DOUBLE_PLANT),
|
||||
Gems(" Gems", Material.EMERALD);
|
||||
|
||||
Tokens("Tokens", Material.EMERALD),
|
||||
Coins("Treasure Shards", Material.PRISMARINE_SHARD),
|
||||
Gems("Gems", Material.EMERALD),
|
||||
Gold("Gold", Material.GOLD_NUGGET);
|
||||
|
||||
private String _prefix;
|
||||
private Material _displayMaterial;
|
||||
|
||||
|
@ -26,7 +26,7 @@ public enum Rank
|
||||
|
||||
//Media
|
||||
YOUTUBE("YouTube", ChatColor.RED),
|
||||
YOUTUBE_SMALL("MooTube", ChatColor.DARK_PURPLE),
|
||||
YOUTUBE_SMALL("YT", ChatColor.DARK_PURPLE),
|
||||
TWITCH("Twitch", ChatColor.DARK_PURPLE),
|
||||
|
||||
//Player
|
||||
@ -116,4 +116,12 @@ public enum Rank
|
||||
{
|
||||
return _donor;
|
||||
}
|
||||
|
||||
public String getRawTag()
|
||||
{
|
||||
if (Name.equalsIgnoreCase("ALL"))
|
||||
return "";
|
||||
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
|
BIN
Plugins/Mineplex.Core.Common/src/mineplex/core/common/ascii.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
@ -1,4 +1,4 @@
|
||||
package mineplex.core.data;
|
||||
package mineplex.core.common.block;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.Material;
|
@ -0,0 +1,104 @@
|
||||
package mineplex.core.common.block.schematic;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public class Schematic
|
||||
{
|
||||
private final short _width;
|
||||
private final short _height;
|
||||
private final short _length;
|
||||
private final short[] _blocks;
|
||||
private final byte[] _blockData;
|
||||
|
||||
public Schematic(short width, short height, short length, short[] blocks, byte[] blockData)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_length = length;
|
||||
_blocks = blocks;
|
||||
_blockData = blockData;
|
||||
}
|
||||
|
||||
public void paste(Location originLocation)
|
||||
{
|
||||
int startX = originLocation.getBlockX();
|
||||
int startY = originLocation.getBlockY();
|
||||
int startZ = originLocation.getBlockZ();
|
||||
|
||||
for (int x = 0; x < _width; x++)
|
||||
{
|
||||
for (int y = 0; y < _height; y++)
|
||||
{
|
||||
for (int z = 0; z < _length; z++)
|
||||
{
|
||||
int index = getIndex(x, y, z);
|
||||
Block block = originLocation.getWorld().getBlockAt(startX + x, startY + y, startZ + z);
|
||||
// some blocks were giving me negative id's in the schematic (like stairs)
|
||||
// not sure why but the math.abs is my simple fix
|
||||
int materialId = Math.abs(_blocks[index]);
|
||||
|
||||
Material material = Material.getMaterial(materialId);
|
||||
if (material == null)
|
||||
{
|
||||
System.out.println(materialId + " data: " + _blockData[index]);
|
||||
continue;
|
||||
}
|
||||
block.setTypeIdAndData(materialId, _blockData[index], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getSize()
|
||||
{
|
||||
return _blocks.length;
|
||||
}
|
||||
|
||||
public int getIndex(int x, int y, int z)
|
||||
{
|
||||
return y * _width * _length + z * _width + x;
|
||||
}
|
||||
|
||||
public short getBlock(int x, int y, int z)
|
||||
{
|
||||
return _blocks[getIndex(x, y, z)];
|
||||
}
|
||||
|
||||
public byte getData(int x, int y, int z)
|
||||
{
|
||||
return _blockData[getIndex(x, y, z)];
|
||||
}
|
||||
|
||||
public short getWidth()
|
||||
{
|
||||
return _width;
|
||||
}
|
||||
|
||||
public short getHeight()
|
||||
{
|
||||
return _height;
|
||||
}
|
||||
|
||||
public short getLength()
|
||||
{
|
||||
return _length;
|
||||
}
|
||||
|
||||
public short[] getBlocks()
|
||||
{
|
||||
return _blocks;
|
||||
}
|
||||
|
||||
public byte[] getBlockData()
|
||||
{
|
||||
return _blockData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("width: %d, length: %d, height: %d, blockLength: %d, blockDataLength: %d", _width, _length, _height, _blocks.length, _blockData.length);
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
package mineplex.core.common.block.schematic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import mineplex.core.common.block.BlockData;
|
||||
import mineplex.core.common.util.Callback;
|
||||
|
||||
public class SchematicRunnable implements Runnable
|
||||
{
|
||||
private JavaPlugin _plugin;
|
||||
private boolean _started;
|
||||
private BukkitTask _task;
|
||||
private List<BlockData> _changedBlocks;
|
||||
private Callback<List<BlockData>> _callback;
|
||||
|
||||
private Schematic _schematic;
|
||||
private Block _startBlock;
|
||||
private int _currentX = 0;
|
||||
private int _currentY = 0;
|
||||
private int _currentZ = 0;
|
||||
private int _blocksPerTick = 1000;
|
||||
|
||||
public SchematicRunnable(JavaPlugin plugin, Schematic schematic, Block startBlock, Callback<List<BlockData>> callback)
|
||||
{
|
||||
_plugin = plugin;
|
||||
_changedBlocks = new ArrayList<BlockData>(schematic.getSize());
|
||||
_started = false;
|
||||
_callback = callback;
|
||||
|
||||
_schematic = schematic;
|
||||
_startBlock = startBlock;
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
if (!_started)
|
||||
{
|
||||
_task = Bukkit.getScheduler().runTaskTimer(_plugin, this, 1, 1);
|
||||
_started = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void pause()
|
||||
{
|
||||
if (_started)
|
||||
{
|
||||
_task.cancel();
|
||||
_started = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setBlocksPerTick(int blocksPerTick)
|
||||
{
|
||||
_blocksPerTick = blocksPerTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
for (int i = 0; i < _blocksPerTick; i++)
|
||||
{
|
||||
setBlock(_startBlock.getRelative(_currentX, _currentY, _currentZ), _currentX, _currentY, _currentZ);
|
||||
|
||||
_currentX++;
|
||||
|
||||
if (_currentX >= _schematic.getWidth())
|
||||
{
|
||||
_currentX = 0;
|
||||
_currentZ++;
|
||||
|
||||
if (_currentZ >= _schematic.getLength())
|
||||
{
|
||||
_currentZ = 0;
|
||||
_currentY++;
|
||||
|
||||
if (_currentY >= _schematic.getHeight())
|
||||
{
|
||||
// We are done
|
||||
System.out.println("Finished importing schematic with setblockrunnable!");
|
||||
|
||||
if (_callback != null)
|
||||
_callback.run(_changedBlocks);
|
||||
|
||||
_task.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setBlock(Block block, int x, int y, int z)
|
||||
{
|
||||
|
||||
int materialId = _schematic.getBlock(x, y, z);
|
||||
byte data = _schematic.getData(x, y, z);
|
||||
|
||||
Material material = Material.getMaterial(materialId);
|
||||
if (material == null)
|
||||
{
|
||||
System.out.println("Failed to find material with id: " + materialId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (block.getTypeId() == materialId && block.getData() == data)
|
||||
return;
|
||||
|
||||
BlockData blockData = new BlockData(block);
|
||||
_changedBlocks.add(blockData);
|
||||
block.setTypeIdAndData(materialId, data, false);
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package mineplex.core.common.block.schematic;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import com.java.sk89q.jnbt.ByteArrayTag;
|
||||
import com.java.sk89q.jnbt.CompoundTag;
|
||||
import com.java.sk89q.jnbt.NBTInputStream;
|
||||
import com.java.sk89q.jnbt.NamedTag;
|
||||
import com.java.sk89q.jnbt.ShortTag;
|
||||
import com.java.sk89q.jnbt.Tag;
|
||||
|
||||
public class UtilSchematic
|
||||
{
|
||||
public static Schematic loadSchematic(File file) throws IOException
|
||||
{
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
NBTInputStream nbtStream = new NBTInputStream(new GZIPInputStream(fis));
|
||||
|
||||
NamedTag rootTag = nbtStream.readNamedTag();
|
||||
nbtStream.close();
|
||||
|
||||
if (!rootTag.getName().equals("Schematic"))
|
||||
return null;
|
||||
|
||||
CompoundTag schematicTag = (CompoundTag) rootTag.getTag();
|
||||
Map<String, Tag> schematic = schematicTag.getValue();
|
||||
|
||||
short width = getChildTag(schematic, "Width", ShortTag.class).getValue();
|
||||
short height = getChildTag(schematic, "Height", ShortTag.class).getValue();
|
||||
short length = getChildTag(schematic, "Length", ShortTag.class).getValue();
|
||||
byte[] blockId = getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
|
||||
byte[] addId = new byte[0];
|
||||
short[] blocks = new short[blockId.length];
|
||||
byte[] blockData = getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
|
||||
|
||||
if (schematic.containsKey("AddBlocks"))
|
||||
{
|
||||
addId = getChildTag(schematic, "AddBlocks", ByteArrayTag.class).getValue();
|
||||
}
|
||||
|
||||
for (int index = 0; index < blockId.length; index++)
|
||||
{
|
||||
if ((index >> 1) >= addId.length)
|
||||
blocks[index] = (short) (blockId[index] & 0xFF);
|
||||
else
|
||||
{
|
||||
if ((index & 1) == 0)
|
||||
blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (blockId[index] & 0xFF));
|
||||
else
|
||||
blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (blockId[index] & 0xFF));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return new Schematic(width, height, length, blocks, blockData);
|
||||
}
|
||||
|
||||
|
||||
private static <T extends Tag> T getChildTag(Map<String, Tag> items, String key, Class<T> expected)
|
||||
{
|
||||
Tag tag = items.get(key);
|
||||
return expected.cast(tag);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException
|
||||
{
|
||||
File file = new File("test.schematic");
|
||||
System.out.println(file.getAbsoluteFile());
|
||||
Schematic m = UtilSchematic.loadSchematic(file);
|
||||
System.out.println(m);
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package mineplex.core.common.player;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class PlayerSnapshot
|
||||
{
|
||||
private Location _location;
|
||||
private ItemStack[] _armor;
|
||||
private ItemStack[] _items;
|
||||
private double _health;
|
||||
private int _hunger;
|
||||
private float _saturation;
|
||||
private float _exhaustion;
|
||||
private int _experience;
|
||||
private Vector _velocity;
|
||||
|
||||
private PlayerSnapshot(Location location, ItemStack[] armor, ItemStack[] items, double health, int hunger, float saturation, float exhaustion, int experience, Vector velocity)
|
||||
{
|
||||
_location = location;
|
||||
_armor = armor;
|
||||
_items = items;
|
||||
_health = health;
|
||||
_hunger = hunger;
|
||||
_saturation = saturation;
|
||||
_exhaustion = exhaustion;
|
||||
_experience = experience;
|
||||
_velocity = velocity;
|
||||
}
|
||||
|
||||
public void applySnapshot(Player player)
|
||||
{
|
||||
player.teleport(_location);
|
||||
player.getInventory().setArmorContents(_armor);
|
||||
player.getInventory().setContents(_items);
|
||||
player.setHealth(_health);
|
||||
player.setFoodLevel(_hunger);
|
||||
player.setSaturation(_saturation);
|
||||
player.setExhaustion(_exhaustion);
|
||||
player.setVelocity(_velocity);
|
||||
player.setTotalExperience(_experience);
|
||||
}
|
||||
|
||||
public static PlayerSnapshot getSnapshot(Player player)
|
||||
{
|
||||
Location location = player.getLocation();
|
||||
|
||||
// Inventory
|
||||
ItemStack[] bArmor = player.getInventory().getArmorContents();
|
||||
ItemStack[] armor = new ItemStack[bArmor.length];
|
||||
|
||||
for (int i = 0; i < bArmor.length; i++)
|
||||
{
|
||||
armor[i] = bArmor[i];
|
||||
}
|
||||
|
||||
ItemStack[] bItems = player.getInventory().getContents();
|
||||
ItemStack[] items = new ItemStack[bItems.length];
|
||||
|
||||
for (int i = 0; i < bItems.length; i++)
|
||||
{
|
||||
items[i] = bItems[i];
|
||||
}
|
||||
|
||||
// Health
|
||||
double health = player.getHealth();
|
||||
int hunger = player.getFoodLevel();
|
||||
float saturation = player.getSaturation();
|
||||
float exhaustion = player.getExhaustion();
|
||||
int experience = player.getTotalExperience();
|
||||
|
||||
Vector velocity = player.getVelocity();
|
||||
|
||||
return new PlayerSnapshot(location, armor, items, health, hunger, saturation, exhaustion, experience, velocity);
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package mineplex.core.common.skin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.Item;
|
||||
import net.minecraft.server.v1_8_R3.MinecraftKey;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagCompound;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagList;
|
||||
import net.minecraft.server.v1_8_R3.NBTTagString;
|
||||
|
||||
public class SkinData
|
||||
{
|
||||
|
||||
private static long _nameCount = -99999999999999L;
|
||||
|
||||
public final static SkinData MOOSHROOM = new SkinData("eyJ0aW1lc3RhbXAiOjE0NDk4NzI0OTU0MTcsInByb2ZpbGVJZCI6ImE5ZDBjMDcyYmYxOTQwYTFhMTkzNjhkMDlkNTAwMjZlIiwicHJvZmlsZU5hbWUiOiJTcGlyaXR1c1NhbmN0dXMiLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzIxOWJlYTU0Y2FkN2Q1OGFiNWRhNDA2YjBhOTJhYjNhODI0MjI1MjY2Nzc3ZTUzNGI3ZGI2YzM3MmRkZmY3ZiJ9fX0=","UoSif81+UyvkcaanU8KAMYBpw9mefAmWehE2liDUFvk+y0X/9NovsxTYVpIDCltTSpLW3sNgamvbj4Ybs+s6DbudPiEkvh0ER7Bv2v29UJw7RzIdr6/1g548X12zcnh5iPGz/P75uNRnSfTFQx0ed8P/GNkPIjWpDuJFxEj6KcPzrCAGMx+BVw1VwryBIYf9cCDHky8z0bxR89rjiIvPTBFI6MRhqI3vgpEBTySHDS+Ki0Hwl5oa3PwS6+jgYx/4RSfFsb+BawcvDk2Xpkt5UimvqZ5BceYLIfCt4KbShYipgLXLfYUZrntjPemd3SxthjxUuA07i44UxRdiC8uqy1twLT/HUS28gpk68lA/id9tKFwu1CUzshgcmvQPt3ghtNViNziR/2t7D/+5D31Vzmhf6n7Pnpdirt/5frMi2BKMMs7pLa0EF8CrrDU7QCwPav+EZVGFvVZbxSkCDq+n3IQ3PUWSCzy6KPxpdOlUjD0pAfLoiNj0P8u4+puQtID76r/St8ExchYl2dodUImu1ZETWeFUClF3ZGat62evx8uRQEI2W4dsVwj40VUfjaAuvyDzuouaKTrCzJXLQZZjR1B8URvuK61fGX0nhW607mEi6DE+nxP2ZoBrROEX4e37Ap6+TQn9Q8tKDPdcxtwSOpPO4Qkncjn/mGtP9lZU/DQ=");
|
||||
public final static SkinData SNOWMAN = new SkinData("eyJ0aW1lc3RhbXAiOjE0NTAwMTk4Nzk5NDIsInByb2ZpbGVJZCI6ImE5ZDBjMDcyYmYxOTQwYTFhMTkzNjhkMDlkNTAwMjZlIiwicHJvZmlsZU5hbWUiOiJTcGlyaXR1c1NhbmN0dXMiLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzEzMTgxYWViODQzODk3NzM1ZDQwMmIyNDk2OTQxNmZkYjBjZTM0YTZiOTM3ODE2MjQzNzU2ZTlkYWU1OGUzIn19fQ==","NZvsNu+HQ5uvGWq6O8VNDGq9A145bmk2IkHiz916uRVPMRqqCI/zwhKWNLlFACE/feuLkhYAois29ec6sVVOtHIoNA+S5q1Mb/Vjc3TJQxzqmx2FZOhJiIttFwYuo9WomQKBqrPMSJ9tpQig4wzoqldeeTjWC3dLz7JeX+gkzinryVjG7NNN9L5hXK5/BBxRcrtwmXJfUlSANyrd8RZW7mEUgU8yxlzdqTu0w7bZLjQNd4vciwoF3NelXDorMIIqiHTkuQesG91Njtu25VCUDK3nXbqEnZw2ZtxB5fT5G2Omm/vkNSRXc0P7iqchVowdYQcMlQUsp65xpkBbFS4LwjzDkYIfLmF++hePb8z72Gz77FxhO5sRLGreSH227McyL/0CtWNKm9ZZIfQtZZjEZTj9+eiJMCloCMg3yWa1VBOiLHzz0wY6gGklccIImPyXEg7E0dIK8qYseJMhmmBNZ8pDOkbUDp3mRlrQ2iyClgQkbuR63j79IBUaCxmsa3NnrAtaJklzd9mzkHXfMBh2XT7Gl8AhJS6JK5kCvip1rBBI8yjrsjE/E+lyJFIbC4rXxyMDGZWkcdrd7U4ZFYKiLHbzdFRqX+11qs9xO2BvomGXkATCzYmOf2kQ86R6rNN0+JfE4QpKzj2WWt3C8ky2qpuXZz29p0816E3/qseYtgg=");
|
||||
public final static SkinData SANTA = new SkinData("eyJ0aW1lc3RhbXAiOjE0NTAwMTk3OTM3NTgsInByb2ZpbGVJZCI6ImE5ZDBjMDcyYmYxOTQwYTFhMTkzNjhkMDlkNTAwMjZlIiwicHJvZmlsZU5hbWUiOiJTcGlyaXR1c1NhbmN0dXMiLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2MyNTM5ZGFkZDUxYmE5ZTg0YzFhOTE1OTY3NWUxZTJiYWM1NmFlNmFlNTMxNTQyZDI1YTlkM2Q1YzQ2ODZmNiJ9fX0=","gvLc0Vo6+1vl17vrFCbK1eNqa4/ix4xiwcWae7WOCvqiVIX4sdIPagOGUrKsDdEhuWCKkTWILGP1K3wYfC9v/0mXZvbu0sRln+APTOsswMkQmbKcA1zTFTMpwEI+nIMzYJSbIx5wjz28K5hDf/umtHH2GADTENdJGGUtU4CyEdeHTzcqIAEV3bcMLkfTKvwKUWqI5gZbbercqmDeGkmXVS9297a9paRX1NfEL9pFT0pjdH3tCjgvvKfAwGC6tYtvTFbfcJocqgI+PI2f5OFf62A4XjWwWFi4wxCHVYNpqs/XTbfF64K7KVE0d9gsLjJoB8DMZPxlNpMFA0R5OIW6Q7Qjyz9IKxUqEYRCQbuUKpHyNDcmVKcTJRwBpCHeqAbTbweZHd5tzrT/terWhLEMsK1+lH2KBfIRIRB9kd3epyShNjSEKoly6uRXVxU+IJtfcq0aFVZlwgG3c1Ds9jbsNJV158e1n6WCmvT00RLdvpcIekwUKODhi3zFeFkrVvV50tGYqXLRZenitLJvDzx4c0IGK4krALrUS0oybinBS7/GmW3Ktz3xbGKZSzzaDw0EKB7Y6XHdb4yqR1xS7lAWgv4cNDEIUSzUDJ7HpmDCIF2A5kPS4XVYFCclyR6qPGD5e+9apVhBMz4lfYlT1IfRAUQlucO4UpAlkXs7ho3pQXU=");
|
||||
public final static SkinData PRESENT = new SkinData("eyJ0aW1lc3RhbXAiOjE0NTAwMTk3MDIxNjIsInByb2ZpbGVJZCI6ImE5ZDBjMDcyYmYxOTQwYTFhMTkzNjhkMDlkNTAwMjZlIiwicHJvZmlsZU5hbWUiOiJTcGlyaXR1c1NhbmN0dXMiLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2U2YzRkZWQwNTdjMjhiMTU0NjVkYzQzNmFmODIyYTNkZTY4NzgyZTZjMzgyOGMzMmFhYWE4ZjRiOTIzOWVjIn19fQ==","rJNlxTqHHmOoWwbXdMQLcj0P9w/PIr/hWKXH0nbhm/S2CFo/zfefffZlnQmpKCgn1Y8tXvcRwLGQ4CLpm9m2ZrKprSWRhrnOtZWYabrhExQESEammS3TY81VoNt+4On0pAGBippz/bRfWLuDne2rDbhuljnqvxjROmxpky7gRCU06VMlm2WLFC5XYJkiAaOXBqzpiHMMRPNnCvtcbtpILKi/Luj302eyN8nRKjHHbbiDmttwvlshxZ8UxJHvALtM506IUHba10Q6QX2zCeDAU5/WYRKa6e19r8plROcgGbKYFSq8JW5cWuWT3/rveZM6FnU6ABn9DWsCyfQ5wr2jdBd+xaevGTAScRHA5J493GqL1bBZYKj9yhQFtxJHCAf0++raAVPCZgyPtwTth4TAQisn8gnhM5R+txnW6xK+oflLy0dwEN1YdPLN/h7yuDnyjSMDe9RZT2NKMjok2C6Kux4WBI0KFXKC5Gqwa3Htku4v3WEOWMaVoWOtchQ9BzpQ/etD0ylmzjALQLB+HtndEEm1Jd3tmob42X4hBE8hCce7C3EtGINB33dlx4CK1xBqyGTJEqi69DJRzVL99u98+7kJ1Db9+MaPOfI4B2RY3XbvnSYwecandY//A3bb19FGSdl299ZXbp4zpm8fivzeB1rUAhhmtaA3Iwu/nEQNMkU=");
|
||||
public final static SkinData RUDOLPH = new SkinData("eyJ0aW1lc3RhbXAiOjE0NTAwMTk1NjgxODIsInByb2ZpbGVJZCI6ImE5ZDBjMDcyYmYxOTQwYTFhMTkzNjhkMDlkNTAwMjZlIiwicHJvZmlsZU5hbWUiOiJTcGlyaXR1c1NhbmN0dXMiLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2IzZjdlMjhiNTJkZjJjZjhlZWM2NDk2ZmM0NWFlMGQ2NTM0Njc5OGIxYWRjNzM3ZDcxYzBmOTRlNDIyMSJ9fX0=","uUBOTe63CL+qRvtsb2g4AjB2YzxE3N6AUqIsTv8n0jYyPsuXpuOmZPSMEdgDVONywEJ1L4XRx05sjnGu56A8vuXmGI/uHQWuMZzbOSjiFfT3DkEm8zEl5AWpH9dz/t8nZ1WYUIwy0pN5VrZqIr1DAkF6AMh/Qy+FGDw1GG9ReRr80eJ0JiRskpkCpCZIGGjrgwNKAM8JOuNZ4gCQOTRC3etrcfls3qmUMFcVlhuB4bydxSR01i2w0A4b5KpufsJjLKw4InWn2+m/druo8hl9sYuusTeItW0MQmZqCAqXCc9YBnRPQ0hDXFgnPxOh3RwGWiZvL4MnWUVmLwZWh/Fk9QmyVbd7zVao0lxS8YNsKtP8j5B+hs4l9qNohhf0A07bt4oPeTtd5fQeOU5N87fUGuUAcpC4gP9U5WpVY5FFPBvLvGbXdV5jpuAQz4lLSoo1grsP9baR2IBvdN/0awjQWoPJfGOttegubkBHwz3LNcVqvZLtX/M13IDHZa6zQZEX0wsnMX60LeWgBWfTON1l2cSgaPTerHFS2EifJ2LvTBife3s9/4XR6Zth3FLFqxI3MSlqT2hVFRPLke6rBqfqPoWOj2MCykQ70IAwb3oTHcJDJ86V2DdNaU2bZ8V4TjaP+nRobsLJOImoPYEPq23MP36X8gbXEIjmuu8S5xRlrrc=");
|
||||
public final static SkinData THE_GRINCH = new SkinData("eyJ0aW1lc3RhbXAiOjE0NTAwMTYxNDMwMDQsInByb2ZpbGVJZCI6ImE5ZDBjMDcyYmYxOTQwYTFhMTkzNjhkMDlkNTAwMjZlIiwicHJvZmlsZU5hbWUiOiJTcGlyaXR1c1NhbmN0dXMiLCJzaWduYXR1cmVSZXF1aXJlZCI6dHJ1ZSwidGV4dHVyZXMiOnsiU0tJTiI6eyJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzg4ZWRlOTI3ZDQzOWVmMzliMzFhYzFkYzJhODM5NGZlNzlhY2U4NDMyNzBjYmUxMjg2ZGM3NTE3ZjMxYTk2In19fQ==","ELo594vTzPq9ZmPYOtVr4kim/k19gzmoxEIK1ehS87gwgag5HcgM+P1FMnHIyrmSvTVaMh0NxwXmNS+JETFL7OrmgRYNpkxkkO4VBA0pfSn3dA9ujnXpDnDiWEPxKdMgQspIOOI0Z3esNt3pj8qIj6dWPtGwtso48tjHl2o/kazfa82yvGORlFhGkeEJKQMno/Buc12C0foQw39XI8GjvlSkFN2eH4Fp16RLu8/hf7SqJQC3L1KacvzMW1d8BWEIgACCJDni29+YqxflSqSyYrV4Z+D66S0jYvUUL/vM4/q/p/YWX/vs/FtMtHQTj4PCpAmMNTgfkahuhb6rCvKHukbjA+WhUdwyxSqXU5YnpXCu1M2dzZgiXjIi+fnyn4CmXKindWCQtSwu+mCA2ILv/6vEHoYJgdlz+DXyRkFx+DH4Sl74HBCOXTOq5AGjq5h3LYfsre+UjCCUv8VgxbVprOyj35So7K0m+6faCFVSt35T3RgicDQfdiWUrW7kmHQVvJpvaq9Vu+63F/0X93cwqwaR0buMirxRx7qkFrRunSI4T+9fsN02t1fAieeu80lBSv83wr7BFneSsLsdVAND9xttTb6fClg7anr8/XVEVIkylB4B+ZcWQbH61XP1nn7oFP2VBg1h6XuuLp8FGSgYf/LW+54/KZci/MnanqQE6QQ=");
|
||||
|
||||
private Property _skinProperty;
|
||||
|
||||
public SkinData(String value, String signature)
|
||||
{
|
||||
_skinProperty = new Property("textures", value, signature);
|
||||
}
|
||||
|
||||
public SkinData(GameProfile profile)
|
||||
{
|
||||
_skinProperty = profile.getProperties().get("textures").iterator().next();
|
||||
}
|
||||
|
||||
public SkinData(Player player)
|
||||
{
|
||||
this(((CraftPlayer)player).getProfile());
|
||||
}
|
||||
|
||||
public ItemStack getSkull()
|
||||
{
|
||||
NBTTagCompound arrayElement = new NBTTagCompound();
|
||||
arrayElement.setString("Value", _skinProperty.getValue());
|
||||
arrayElement.setString("Signature", _skinProperty.getSignature());
|
||||
|
||||
NBTTagList textures = new NBTTagList();
|
||||
textures.add(arrayElement);
|
||||
|
||||
NBTTagCompound properties = new NBTTagCompound();
|
||||
properties.set("textures", textures);
|
||||
|
||||
NBTTagCompound skullOwner = new NBTTagCompound();
|
||||
skullOwner.set("Properties", properties);
|
||||
skullOwner.set("Name", new NBTTagString(getUnusedSkullName()));
|
||||
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.set("SkullOwner", skullOwner);
|
||||
|
||||
|
||||
net.minecraft.server.v1_8_R3.ItemStack nmsItem = new net.minecraft.server.v1_8_R3.ItemStack(Item.REGISTRY.get(new MinecraftKey("skull")), 1, 3);
|
||||
nmsItem.setTag(tag);
|
||||
|
||||
|
||||
return CraftItemStack.asBukkitCopy(nmsItem);
|
||||
}
|
||||
|
||||
public ItemStack getSkull(String name, List<String> lore)
|
||||
{
|
||||
ItemStack stack = getSkull();
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
meta.setLore(lore);
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public Property getProperty()
|
||||
{
|
||||
return new Property(_skinProperty.getName(), _skinProperty.getValue(), _skinProperty.getSignature());
|
||||
}
|
||||
|
||||
public static String getUnusedSkullName()
|
||||
{
|
||||
_nameCount++;
|
||||
return "_" + _nameCount;
|
||||
}
|
||||
|
||||
}
|
@ -4,12 +4,15 @@ import org.bukkit.ChatColor;
|
||||
|
||||
public class C
|
||||
{
|
||||
public static final String blankLine = ChatColor.RESET + " ";
|
||||
|
||||
public static String Scramble = "§k";
|
||||
public static String Bold = "§l";
|
||||
public static String Strike = "§m";
|
||||
public static String BoldStrike = "§l§m";
|
||||
public static String Line = "§n";
|
||||
public static String Italics = "§o";
|
||||
public static String Reset = "§r";
|
||||
|
||||
public static String cAqua = "" + ChatColor.AQUA;
|
||||
public static String cBlack = "" + ChatColor.BLACK;
|
||||
@ -87,22 +90,26 @@ public class C
|
||||
public static String chat = "" + ChatColor.WHITE;
|
||||
|
||||
public static String xBorderlands = "" + ChatColor.GOLD;
|
||||
public static String xWilderness = "" + ChatColor.YELLOW;
|
||||
public static String xWilderness = "" + ChatColor.GRAY;
|
||||
public static String xMid = "" + ChatColor.WHITE;
|
||||
public static String xNone = "" + ChatColor.GRAY;
|
||||
public static ChatColor xNone = ChatColor.YELLOW;
|
||||
|
||||
public static ChatColor xAdmin = ChatColor.WHITE;
|
||||
public static ChatColor xSafe = ChatColor.AQUA;
|
||||
|
||||
public static ChatColor xNeutral = ChatColor.YELLOW;
|
||||
public static ChatColor xSelf = ChatColor.AQUA;
|
||||
public static ChatColor xAlly = ChatColor.GREEN;
|
||||
public static ChatColor xEnemy = ChatColor.YELLOW;
|
||||
public static ChatColor xWar = ChatColor.RED;
|
||||
public static ChatColor xEnemy = ChatColor.RED;
|
||||
public static ChatColor xWarWinning = ChatColor.LIGHT_PURPLE;
|
||||
public static ChatColor xWarLosing = ChatColor.RED;
|
||||
public static ChatColor xPillage = ChatColor.LIGHT_PURPLE;
|
||||
|
||||
|
||||
public static ChatColor xdNeutral = ChatColor.GOLD;
|
||||
public static ChatColor xdSelf = ChatColor.DARK_AQUA;
|
||||
public static ChatColor xdAlly = ChatColor.DARK_GREEN;
|
||||
public static ChatColor xdEnemy = ChatColor.GOLD;
|
||||
public static ChatColor xdWar = ChatColor.DARK_RED;
|
||||
public static ChatColor xdEnemy = ChatColor.DARK_RED;
|
||||
public static ChatColor xdWarWinning = ChatColor.DARK_PURPLE;
|
||||
public static ChatColor xdWarLosing = ChatColor.DARK_RED;
|
||||
public static ChatColor xdPillage = ChatColor.DARK_PURPLE;
|
||||
}
|
||||
|
@ -106,6 +106,11 @@ public class F
|
||||
return rank.getTag(false, false);
|
||||
}
|
||||
|
||||
public static String value(String variable, int value)
|
||||
{
|
||||
return value(variable, "" + value);
|
||||
}
|
||||
|
||||
public static String value(String variable, String value)
|
||||
{
|
||||
return value(0, variable, value);
|
||||
|
@ -0,0 +1,18 @@
|
||||
package mineplex.core.common.util;
|
||||
|
||||
public enum LineFormat
|
||||
{
|
||||
LORE(220), CHAT(319);
|
||||
|
||||
private int _length;
|
||||
|
||||
private LineFormat(int length)
|
||||
{
|
||||
_length = length;
|
||||
}
|
||||
|
||||
public int getLength()
|
||||
{
|
||||
return _length;
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
package mineplex.core.common.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class NautArrayList<Elem>
|
||||
{
|
||||
private ArrayList<Elem> _wrappedArrayList = new ArrayList<Elem>();
|
||||
|
||||
public boolean add(Elem elem)
|
||||
{
|
||||
return _wrappedArrayList.add(elem);
|
||||
}
|
||||
|
||||
public void add(int index, Elem elem)
|
||||
{
|
||||
_wrappedArrayList.add(index, elem);
|
||||
}
|
||||
|
||||
public boolean addAll(Collection<? extends Elem> elements)
|
||||
{
|
||||
return _wrappedArrayList.addAll(elements);
|
||||
}
|
||||
|
||||
public boolean addAll(int index, Collection<? extends Elem> elements)
|
||||
{
|
||||
return _wrappedArrayList.addAll(index, elements);
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
_wrappedArrayList.clear();
|
||||
}
|
||||
|
||||
public boolean contains(Elem elem)
|
||||
{
|
||||
return _wrappedArrayList.contains(elem);
|
||||
}
|
||||
|
||||
public boolean containsAll(Collection<? extends Elem> elements)
|
||||
{
|
||||
return _wrappedArrayList.containsAll(elements);
|
||||
}
|
||||
|
||||
public Elem get(int index)
|
||||
{
|
||||
return _wrappedArrayList.get(index);
|
||||
}
|
||||
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
return _wrappedArrayList.equals(o);
|
||||
}
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
return _wrappedArrayList.hashCode();
|
||||
}
|
||||
|
||||
public int indexOf(Elem elem)
|
||||
{
|
||||
return _wrappedArrayList.indexOf(elem);
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return _wrappedArrayList.isEmpty();
|
||||
}
|
||||
|
||||
public Iterator<Elem> iterator()
|
||||
{
|
||||
return _wrappedArrayList.iterator();
|
||||
}
|
||||
|
||||
public int lastIndexOf(Elem elem)
|
||||
{
|
||||
return _wrappedArrayList.lastIndexOf(elem);
|
||||
}
|
||||
|
||||
public ListIterator<Elem> listIterator()
|
||||
{
|
||||
return _wrappedArrayList.listIterator();
|
||||
}
|
||||
|
||||
public ListIterator<Elem> listIterator(int index)
|
||||
{
|
||||
return _wrappedArrayList.listIterator(index);
|
||||
}
|
||||
|
||||
public Elem remove(int index)
|
||||
{
|
||||
return _wrappedArrayList.remove(index);
|
||||
}
|
||||
|
||||
public boolean remove(Elem element)
|
||||
{
|
||||
return _wrappedArrayList.remove(element);
|
||||
}
|
||||
|
||||
public boolean removeAll(Collection<? extends Elem> elements)
|
||||
{
|
||||
return _wrappedArrayList.removeAll(elements);
|
||||
}
|
||||
|
||||
public boolean retainAll(Collection<? extends Elem> elements)
|
||||
{
|
||||
return _wrappedArrayList.retainAll(elements);
|
||||
}
|
||||
|
||||
public Elem set(int index, Elem element)
|
||||
{
|
||||
return _wrappedArrayList.set(index, element);
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return _wrappedArrayList.size();
|
||||
}
|
||||
|
||||
public List<Elem> subList(int begin, int end)
|
||||
{
|
||||
return _wrappedArrayList.subList(begin, end);
|
||||
}
|
||||
|
||||
public Object[] toArray()
|
||||
{
|
||||
return _wrappedArrayList.toArray();
|
||||
}
|
||||
}
|
@ -35,4 +35,4 @@ public class RadarData
|
||||
{
|
||||
return _bearing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package mineplex.core.common.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
@ -8,17 +10,26 @@ import java.util.TreeSet;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.EulerAngle;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.EnumDirection;
|
||||
|
||||
public class UtilAlg
|
||||
{
|
||||
{
|
||||
public static TreeSet<String> sortKey(Set<String> toSort)
|
||||
{
|
||||
TreeSet<String> sortedSet = new TreeSet<String>();
|
||||
for (String cur : toSort)
|
||||
return sortSet(toSort, null);
|
||||
}
|
||||
|
||||
public static <T> TreeSet<T> sortSet(Collection<T> toSort, Comparator<T> comparator)
|
||||
{
|
||||
TreeSet<T> sortedSet = new TreeSet<T>(comparator);
|
||||
for (T cur : toSort)
|
||||
sortedSet.add(cur);
|
||||
|
||||
|
||||
return sortedSet;
|
||||
}
|
||||
|
||||
@ -39,7 +50,7 @@ public class UtilAlg
|
||||
|
||||
public static Vector getTrajectory(Vector from, Vector to)
|
||||
{
|
||||
return to.subtract(from).normalize();
|
||||
return to.clone().subtract(from).normalize();
|
||||
}
|
||||
|
||||
public static Vector getTrajectory2d(Entity from, Entity to)
|
||||
@ -54,7 +65,7 @@ public class UtilAlg
|
||||
|
||||
public static Vector getTrajectory2d(Vector from, Vector to)
|
||||
{
|
||||
return to.subtract(from).setY(0).normalize();
|
||||
return to.clone().subtract(from).setY(0).normalize();
|
||||
}
|
||||
|
||||
public static boolean HasSight(Location from, Player to)
|
||||
@ -407,6 +418,55 @@ public class UtilAlg
|
||||
return bestLoc;
|
||||
}
|
||||
|
||||
public static Vector calculateVelocity(Vector from, Vector to, double heightGain, Entity entity)
|
||||
{
|
||||
if (entity instanceof LivingEntity)
|
||||
{
|
||||
return calculateVelocity(from, to, heightGain, 1.15);
|
||||
}
|
||||
else
|
||||
{
|
||||
return calculateVelocity(from, to, heightGain, 0.115);
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector calculateVelocity(Vector from, Vector to, double heightGain)
|
||||
{
|
||||
return calculateVelocity(from, to, heightGain, 0.115);
|
||||
}
|
||||
|
||||
public static Vector calculateVelocity(Vector from, Vector to, double heightGain, double gravity)
|
||||
{
|
||||
// Block locations
|
||||
int endGain = to.getBlockY() - from.getBlockY();
|
||||
|
||||
double dx1 = to.getBlockX() - from.getBlockX();
|
||||
double dz1 = to.getBlockZ() - from.getBlockZ();
|
||||
|
||||
double horizDist = Math.sqrt(dx1 * dx1 + dz1 * dz1);
|
||||
// Height gain
|
||||
double maxGain = heightGain > (endGain + heightGain) ? heightGain : (endGain + heightGain);
|
||||
// Solve quadratic equation for velocity
|
||||
double a = -horizDist * horizDist / (4 * maxGain);
|
||||
double b = horizDist;
|
||||
double c = -endGain;
|
||||
double slope = -b / (2 * a) - Math.sqrt(b * b - 4 * a * c) / (2 * a);
|
||||
// Vertical velocity
|
||||
double vy = Math.sqrt(maxGain * gravity);
|
||||
// Horizontal velocity
|
||||
double vh = vy / slope;
|
||||
// Calculate horizontal direction
|
||||
int dx = to.getBlockX() - from.getBlockX();
|
||||
int dz = to.getBlockZ() - from.getBlockZ();
|
||||
double mag = Math.sqrt(dx * dx + dz * dz);
|
||||
double dirx = dx / mag;
|
||||
double dirz = dz / mag;
|
||||
// Horizontal velocity components
|
||||
double vx = vh * dirx;
|
||||
double vz = vh * dirz;
|
||||
return new Vector(vx, vy, vz);
|
||||
}
|
||||
|
||||
public static Location getNearestCornerLocation(Location near, Block block)
|
||||
{
|
||||
ArrayList<Location> corners = new ArrayList<Location>();
|
||||
@ -439,4 +499,15 @@ public class UtilAlg
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
public static EulerAngle vectorToEuler(Vector vector)
|
||||
{
|
||||
//JUST MAKE SURE THE ARMOR STAND ISNT ROTATED.
|
||||
|
||||
return new EulerAngle(
|
||||
Math.toRadians(UtilAlg.GetPitch(vector)),
|
||||
Math.toRadians(UtilAlg.GetYaw(vector)),
|
||||
0);
|
||||
}
|
||||
}
|
||||
|
@ -29,11 +29,11 @@ import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftCreature;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -78,10 +78,13 @@ public class UtilEnt
|
||||
|
||||
public static void Leash(LivingEntity leashed, Entity holder, boolean pull, boolean breakable)
|
||||
{
|
||||
leashed.setPullWhileLeashed(pull);
|
||||
leashed.setShouldBreakLeash(breakable);
|
||||
|
||||
leashed.setLeashHolder(holder);
|
||||
|
||||
if (!(((CraftLivingEntity)leashed).getHandle() instanceof EntityInsentient))
|
||||
return;
|
||||
|
||||
((EntityInsentient)((CraftLivingEntity)leashed).getHandle()).setPullWhileLeashed(pull);
|
||||
((EntityInsentient)((CraftLivingEntity)leashed).getHandle()).setShouldBreakLeash(breakable);
|
||||
}
|
||||
|
||||
public static void addLookAtPlayerAI(Entity entity, float dist)
|
||||
@ -288,6 +291,8 @@ public class UtilEnt
|
||||
creatureMap.put("WitherSkull", EntityType.WITHER_SKULL);
|
||||
creatureMap.put("Wolf", EntityType.WOLF);
|
||||
creatureMap.put("Zombie", EntityType.ZOMBIE);
|
||||
creatureMap.put("Guardian", EntityType.GUARDIAN);
|
||||
creatureMap.put("Rabbit", EntityType.RABBIT);
|
||||
|
||||
creatureMap.put("Item", EntityType.DROPPED_ITEM);
|
||||
}
|
||||
@ -454,6 +459,28 @@ public class UtilEnt
|
||||
return ents;
|
||||
}
|
||||
|
||||
public static HashMap<Entity, Double> getAllInRadius(Location loc, double dR)
|
||||
{
|
||||
HashMap<Entity, Double> ents = new HashMap<Entity, Double>();
|
||||
|
||||
for (Entity cur : loc.getWorld().getEntities())
|
||||
{
|
||||
if (UtilPlayer.isSpectator(cur))
|
||||
continue;
|
||||
|
||||
//Loc
|
||||
double offset = UtilMath.offset(loc, cur.getLocation());
|
||||
|
||||
if (offset < dR)
|
||||
{
|
||||
ents.put(cur, 1 - (offset/dR));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return ents;
|
||||
}
|
||||
|
||||
public static boolean hitBox(Location loc, LivingEntity ent, double mult, EntityType disguise)
|
||||
{
|
||||
if (disguise != null)
|
||||
@ -477,7 +504,7 @@ public class UtilEnt
|
||||
}
|
||||
else if (UtilMath.offset2d(loc, player.getLocation()) < 0.6 * mult)
|
||||
{
|
||||
if (loc.getY() > player.getLocation().getY() && loc.getY() < player.getEyeLocation().getY())
|
||||
if (loc.getY() >= player.getLocation().getY() - 0.2*mult && loc.getY() <= player.getEyeLocation().getY() + 0.2*mult)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -505,10 +532,27 @@ public class UtilEnt
|
||||
}
|
||||
|
||||
public static boolean isGrounded(Entity ent)
|
||||
{
|
||||
|
||||
if(!(ent instanceof Player)) {
|
||||
return ent.isOnGround();
|
||||
}
|
||||
|
||||
AxisAlignedBB box = ((CraftEntity)ent).getHandle().getBoundingBox().shrink(0.05, 0, 0.05);
|
||||
Location bottom_corner_1 = new Location(ent.getWorld(), box.a, ent.getLocation().getY()-0.05, box.c);
|
||||
Location bottom_corner_2 = new Location(ent.getWorld(), box.d, ent.getLocation().getY()-0.05, box.f);
|
||||
|
||||
for(Block b : UtilBlock.getInBoundingBox(bottom_corner_1, bottom_corner_2)){
|
||||
if(UtilBlock.solid(b)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isGrounded(Entity ent, Location loc)
|
||||
{
|
||||
AxisAlignedBB box = ((CraftEntity)ent).getHandle().getBoundingBox();
|
||||
Location bottom_corner_1 = new Location(ent.getWorld(), box.a, ent.getLocation().getY()-0.1, box.c);
|
||||
Location bottom_corner_2 = new Location(ent.getWorld(), box.d, ent.getLocation().getY()-0.1, box.f);
|
||||
Location bottom_corner_1 = new Location(ent.getWorld(), box.a, loc.getY()-0.1, box.c);
|
||||
Location bottom_corner_2 = new Location(ent.getWorld(), box.d, loc.getY()-0.1, box.f);
|
||||
|
||||
for(Block b : UtilBlock.getInBoundingBox(bottom_corner_1, bottom_corner_2)){
|
||||
if(UtilBlock.solid(b)) return true;
|
||||
@ -613,6 +657,11 @@ public class UtilEnt
|
||||
return CreatureLook(ent, UtilAlg.GetPitch(vec), UtilAlg.GetYaw(vec));
|
||||
}
|
||||
|
||||
public static boolean CreatureLook(Entity ent, Vector target)
|
||||
{
|
||||
return CreatureLook(ent, UtilAlg.GetPitch(target), UtilAlg.GetYaw(target));
|
||||
}
|
||||
|
||||
public static void setFakeHead(Entity ent, boolean fakeHead)
|
||||
{
|
||||
net.minecraft.server.v1_8_R3.Entity ec = ((CraftEntity) ent).getHandle();
|
||||
@ -755,6 +804,20 @@ public class UtilEnt
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setAI(LivingEntity entity, boolean ai)
|
||||
{
|
||||
if(entity instanceof ArmorStand)
|
||||
{
|
||||
((ArmorStand)entity).setGravity(ai);
|
||||
return;
|
||||
}
|
||||
CraftEntity e = (CraftEntity)entity;
|
||||
if(e.getHandle() instanceof EntityInsentient)
|
||||
{
|
||||
((EntityInsentient)e.getHandle()).k(!ai);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean inWater(LivingEntity ent)
|
||||
{
|
||||
|
@ -16,7 +16,8 @@ public class UtilEvent
|
||||
L_BLOCK,
|
||||
R,
|
||||
R_AIR,
|
||||
R_BLOCK
|
||||
R_BLOCK,
|
||||
ANY
|
||||
}
|
||||
|
||||
public static boolean isAction(PlayerInteractEvent event, ActionType action)
|
||||
@ -39,6 +40,9 @@ public class UtilEvent
|
||||
if (action == ActionType.R_BLOCK)
|
||||
return (event.getAction() == Action.RIGHT_CLICK_BLOCK);
|
||||
|
||||
if (action == ActionType.ANY)
|
||||
return event.getAction() != Action.PHYSICAL;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,310 @@
|
||||
package mineplex.core.common.util;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class UtilFile
|
||||
{
|
||||
public static void writePlainFile(File file, String text) throws FileNotFoundException
|
||||
{
|
||||
PrintWriter writer = new PrintWriter(file);
|
||||
writer.print(text);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Will read the specified file, and return the contents, or a null value,
|
||||
* if an exception is thrown. Will handle all exceptions, and simply ignore
|
||||
* them and return null. No stack trace printed or anything.
|
||||
*/
|
||||
public static String readIgnoreErrors(File file)
|
||||
{
|
||||
try
|
||||
{
|
||||
return readToStr(file);
|
||||
}
|
||||
catch (IOException exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String readToStr(File file) throws IOException
|
||||
{
|
||||
return new String(readAllBytes(file));
|
||||
}
|
||||
|
||||
public static byte[] readAllBytes(File file) throws IOException
|
||||
{
|
||||
return Files.readAllBytes(Paths.get(file.toURI()));
|
||||
}
|
||||
|
||||
public static void writePlainFile(String file, String text) throws FileNotFoundException
|
||||
{
|
||||
writePlainFile(new File(file), text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will read the specified file, and return the contents, or a null value,
|
||||
* if an exception is thrown. Will handle all exceptions, and simply ignore
|
||||
* them and return null. No stack trace printed or anything.
|
||||
*/
|
||||
public static String readIgnoreErrors(String file)
|
||||
{
|
||||
return readIgnoreErrors(new File(file));
|
||||
}
|
||||
|
||||
public static String readToStr(String file) throws IOException
|
||||
{
|
||||
return readToStr(new File(file));
|
||||
}
|
||||
|
||||
public static byte[] readAllBytes(String file) throws IOException
|
||||
{
|
||||
return readAllBytes(new File(file));
|
||||
}
|
||||
|
||||
public static void writeDataFile(File file, DataFileChunk... chunks) throws IOException
|
||||
{
|
||||
DataOutputStream stream = new DataOutputStream(new FileOutputStream(file));
|
||||
for (DataFileChunk chunk : chunks)
|
||||
{
|
||||
chunk.writeTo(stream);
|
||||
}
|
||||
stream.close();
|
||||
}
|
||||
|
||||
public static DataFileReader beginReading(String file) throws FileNotFoundException
|
||||
{
|
||||
return beginReading(new File(file));
|
||||
}
|
||||
|
||||
public static DataFileReader beginReading(File file) throws FileNotFoundException
|
||||
{
|
||||
return new DataFileReader(file);
|
||||
}
|
||||
|
||||
public static void writeDataFile(String file, DataFileChunk... chunks) throws IOException
|
||||
{
|
||||
writeDataFile(new File(file), chunks);
|
||||
}
|
||||
|
||||
public static class DataFileChunk
|
||||
{
|
||||
private ChunkType _type;
|
||||
private Object _value;
|
||||
|
||||
public DataFileChunk(ChunkType type, Object value)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
throw new RuntimeException("ChunkType can NOT be null.");
|
||||
}
|
||||
|
||||
_type = type;
|
||||
|
||||
if (!_type.isValid(value))
|
||||
{
|
||||
throw new RuntimeException("Invalid value provided for the specified ChunkType.");
|
||||
}
|
||||
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public void writeTo(DataOutputStream stream) throws IOException
|
||||
{
|
||||
_type.writeTo(stream, _value);
|
||||
}
|
||||
}
|
||||
|
||||
public static enum ChunkType
|
||||
{
|
||||
STRING(new ChunkImpl()
|
||||
{
|
||||
public void writeTo(DataOutputStream stream, Object value) throws IOException
|
||||
{
|
||||
String str = (String) value;
|
||||
|
||||
INTEGER.writeTo(stream, str.length());
|
||||
for (char b : str.toCharArray())
|
||||
{
|
||||
CHAR.writeTo(stream, b);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isValid(Object value)
|
||||
{
|
||||
return value.getClass().equals(String.class);
|
||||
}
|
||||
|
||||
public Object readFrom(DataInputStream stream) throws IOException
|
||||
{
|
||||
int length = (int) INTEGER.readFrom(stream);
|
||||
|
||||
StringBuilder string = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
string.append(CHAR.readFrom(stream));
|
||||
}
|
||||
|
||||
return string.toString();
|
||||
}
|
||||
}),
|
||||
DOUBLE(new ChunkImpl()
|
||||
{
|
||||
public void writeTo(DataOutputStream stream, Object value) throws IOException
|
||||
{
|
||||
double number = (double) value;
|
||||
|
||||
stream.writeDouble(number);
|
||||
}
|
||||
|
||||
public boolean isValid(Object value)
|
||||
{
|
||||
return value.getClass().equals(Double.class);
|
||||
}
|
||||
|
||||
public Object readFrom(DataInputStream stream) throws IOException
|
||||
{
|
||||
return stream.readDouble();
|
||||
}
|
||||
}),
|
||||
INTEGER(new ChunkImpl()
|
||||
{
|
||||
public void writeTo(DataOutputStream stream, Object value) throws IOException
|
||||
{
|
||||
int number = (int) value;
|
||||
|
||||
stream.writeInt(number);
|
||||
}
|
||||
|
||||
public boolean isValid(Object value)
|
||||
{
|
||||
return value.getClass().equals(Integer.class);
|
||||
}
|
||||
|
||||
public Object readFrom(DataInputStream stream) throws IOException
|
||||
{
|
||||
return stream.readInt();
|
||||
}
|
||||
}),
|
||||
BYTE(new ChunkImpl()
|
||||
{
|
||||
public void writeTo(DataOutputStream stream, Object value) throws IOException
|
||||
{
|
||||
byte number = (byte) value;
|
||||
|
||||
stream.writeByte(number);
|
||||
}
|
||||
|
||||
public boolean isValid(Object value)
|
||||
{
|
||||
return value.getClass().equals(Byte.class);
|
||||
}
|
||||
|
||||
public Object readFrom(DataInputStream stream) throws IOException
|
||||
{
|
||||
return stream.readByte();
|
||||
}
|
||||
}),
|
||||
CHAR(new ChunkImpl()
|
||||
{
|
||||
public void writeTo(DataOutputStream stream, Object value) throws IOException
|
||||
{
|
||||
char number = (char) value;
|
||||
|
||||
stream.writeChar(number);
|
||||
}
|
||||
|
||||
public boolean isValid(Object value)
|
||||
{
|
||||
return value.getClass().equals(Character.class);
|
||||
}
|
||||
|
||||
public Object readFrom(DataInputStream stream) throws IOException
|
||||
{
|
||||
return stream.readChar();
|
||||
}
|
||||
}),
|
||||
LONG(new ChunkImpl()
|
||||
{
|
||||
public void writeTo(DataOutputStream stream, Object value) throws IOException
|
||||
{
|
||||
long number = (long) value;
|
||||
|
||||
stream.writeLong(number);
|
||||
}
|
||||
|
||||
public boolean isValid(Object value)
|
||||
{
|
||||
return value.getClass().equals(Long.class);
|
||||
}
|
||||
|
||||
public Object readFrom(DataInputStream stream) throws IOException
|
||||
{
|
||||
return stream.readLong();
|
||||
}
|
||||
});
|
||||
|
||||
private ChunkImpl _impl;
|
||||
|
||||
ChunkType(ChunkImpl impl)
|
||||
{
|
||||
_impl = impl;
|
||||
}
|
||||
|
||||
protected void writeTo(DataOutputStream stream, Object value) throws IOException
|
||||
{
|
||||
_impl.writeTo(stream, value);
|
||||
}
|
||||
|
||||
protected boolean isValid(Object value)
|
||||
{
|
||||
return value != null && _impl.isValid(value);
|
||||
}
|
||||
|
||||
public Object readFrom(DataInputStream stream) throws IOException
|
||||
{
|
||||
return _impl.readFrom(stream);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DataFileReader
|
||||
{
|
||||
private DataInputStream _stream;
|
||||
|
||||
public DataFileReader(File file) throws FileNotFoundException
|
||||
{
|
||||
_stream = new DataInputStream(new FileInputStream(file));
|
||||
}
|
||||
|
||||
public Object readChunk(ChunkType type) throws IOException
|
||||
{
|
||||
return type.readFrom(_stream);
|
||||
}
|
||||
|
||||
public void close() throws IOException
|
||||
{
|
||||
_stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected interface ChunkImpl
|
||||
{
|
||||
void writeTo(DataOutputStream stream, Object value) throws IOException;
|
||||
|
||||
Object readFrom(DataInputStream stream) throws IOException;
|
||||
|
||||
boolean isValid(Object value);
|
||||
}
|
||||
|
||||
}
|
@ -13,7 +13,44 @@ public class UtilGear
|
||||
private static HashSet<Material> pickSet = new HashSet<Material>();
|
||||
private static HashSet<Material> diamondSet = new HashSet<Material>();
|
||||
private static HashSet<Material> goldSet = new HashSet<Material>();
|
||||
|
||||
private static HashSet<Material> _armorSet = new HashSet<Material>();
|
||||
|
||||
public static boolean isArmor(ItemStack item)
|
||||
{
|
||||
if (item == null)
|
||||
return false;
|
||||
|
||||
if (_armorSet.isEmpty())
|
||||
{
|
||||
_armorSet.add(Material.LEATHER_HELMET);
|
||||
_armorSet.add(Material.LEATHER_CHESTPLATE);
|
||||
_armorSet.add(Material.LEATHER_LEGGINGS);
|
||||
_armorSet.add(Material.LEATHER_BOOTS);
|
||||
|
||||
_armorSet.add(Material.GOLD_HELMET);
|
||||
_armorSet.add(Material.GOLD_CHESTPLATE);
|
||||
_armorSet.add(Material.GOLD_LEGGINGS);
|
||||
_armorSet.add(Material.GOLD_BOOTS);
|
||||
|
||||
_armorSet.add(Material.CHAINMAIL_HELMET);
|
||||
_armorSet.add(Material.CHAINMAIL_CHESTPLATE);
|
||||
_armorSet.add(Material.CHAINMAIL_LEGGINGS);
|
||||
_armorSet.add(Material.CHAINMAIL_BOOTS);
|
||||
|
||||
_armorSet.add(Material.IRON_HELMET);
|
||||
_armorSet.add(Material.IRON_CHESTPLATE);
|
||||
_armorSet.add(Material.IRON_LEGGINGS);
|
||||
_armorSet.add(Material.IRON_BOOTS);
|
||||
|
||||
_armorSet.add(Material.DIAMOND_HELMET);
|
||||
_armorSet.add(Material.DIAMOND_CHESTPLATE);
|
||||
_armorSet.add(Material.DIAMOND_LEGGINGS);
|
||||
_armorSet.add(Material.DIAMOND_BOOTS);
|
||||
}
|
||||
|
||||
return _armorSet.contains(item.getType());
|
||||
}
|
||||
|
||||
public static boolean isAxe(ItemStack item)
|
||||
{
|
||||
if (item == null)
|
||||
@ -126,6 +163,10 @@ public class UtilGear
|
||||
{
|
||||
goldSet.add(Material.GOLD_SWORD);
|
||||
goldSet.add(Material.GOLD_AXE);
|
||||
goldSet.add(Material.GOLD_HELMET);
|
||||
goldSet.add(Material.GOLD_CHESTPLATE);
|
||||
goldSet.add(Material.GOLD_LEGGINGS);
|
||||
goldSet.add(Material.GOLD_BOOTS);
|
||||
}
|
||||
|
||||
return goldSet.contains(item.getType());
|
||||
|
@ -2,7 +2,7 @@ package mineplex.core.common.util;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
@ -12,31 +12,36 @@ import org.bukkit.util.Vector;
|
||||
|
||||
public class UtilMath
|
||||
{
|
||||
public static double trim(int degree, double d)
|
||||
public static double trim(int degree, double d)
|
||||
{
|
||||
String format = "#.#";
|
||||
|
||||
for (int i=1 ; i<degree ; i++)
|
||||
for (int i = 1; i < degree; i++)
|
||||
format += "#";
|
||||
|
||||
|
||||
DecimalFormatSymbols symb = new DecimalFormatSymbols(Locale.US);
|
||||
DecimalFormat twoDForm = new DecimalFormat(format, symb);
|
||||
return Double.valueOf(twoDForm.format(d));
|
||||
}
|
||||
|
||||
|
||||
public static Random random = new Random();
|
||||
public static int r(int i)
|
||||
|
||||
public static int r(int i)
|
||||
{
|
||||
return random.nextInt(i);
|
||||
}
|
||||
|
||||
public static double offset2d(Entity a, Entity b)
|
||||
public static int rRange(int min, int max)
|
||||
{
|
||||
return min + r(1 + max - min);
|
||||
}
|
||||
|
||||
public static double offset2d(Entity a, Entity b)
|
||||
{
|
||||
return offset2d(a.getLocation().toVector(), b.getLocation().toVector());
|
||||
}
|
||||
|
||||
public static double offset2d(Location a, Location b)
|
||||
public static double offset2d(Location a, Location b)
|
||||
{
|
||||
return offset2d(a.toVector(), b.toVector());
|
||||
}
|
||||
@ -48,48 +53,67 @@ public class UtilMath
|
||||
return a.subtract(b).length();
|
||||
}
|
||||
|
||||
public static double offset(Entity a, Entity b)
|
||||
public static double offset(Entity a, Entity b)
|
||||
{
|
||||
return offset(a.getLocation().toVector(), b.getLocation().toVector());
|
||||
}
|
||||
|
||||
public static double offset(Location a, Location b)
|
||||
public static double offset(Location a, Location b)
|
||||
{
|
||||
return offset(a.toVector(), b.toVector());
|
||||
}
|
||||
|
||||
public static double offset(Vector a, Vector b)
|
||||
{
|
||||
return a.subtract(b).length();
|
||||
return a.clone().subtract(b).length();
|
||||
}
|
||||
|
||||
|
||||
public static double offsetSquared(Entity a, Entity b)
|
||||
{
|
||||
return offsetSquared(a.getLocation(), b.getLocation());
|
||||
}
|
||||
|
||||
|
||||
public static double offsetSquared(Location a, Location b)
|
||||
{
|
||||
return offsetSquared(a.toVector(), b.toVector());
|
||||
}
|
||||
|
||||
|
||||
public static double offsetSquared(Vector a, Vector b)
|
||||
{
|
||||
return a.distanceSquared(b);
|
||||
}
|
||||
|
||||
|
||||
public static double rr(double d, boolean bidirectional)
|
||||
{
|
||||
if (bidirectional)
|
||||
return Math.random() * (2 * d) - d;
|
||||
if (bidirectional) return Math.random() * (2 * d) - d;
|
||||
|
||||
return Math.random() * d;
|
||||
}
|
||||
|
||||
public static <T> T randomElement(T[] array) {
|
||||
if (array.length == 0)
|
||||
return null;
|
||||
public static <T> T randomElement(T[] array)
|
||||
{
|
||||
if (array.length == 0) return null;
|
||||
return array[random.nextInt(array.length)];
|
||||
}
|
||||
|
||||
public static <T> T randomElement(List<T> list)
|
||||
{
|
||||
if (list.isEmpty()) return null;
|
||||
return list.get(random.nextInt(list.size()));
|
||||
}
|
||||
|
||||
public static double clamp(double num, double min, double max)
|
||||
{
|
||||
return num < min ? min : (num > max ? max : num);
|
||||
}
|
||||
|
||||
public static long clamp(long num, long min, long max)
|
||||
{
|
||||
return num < min ? min : (num > max ? max : num);
|
||||
}
|
||||
|
||||
public static int clamp(int num, int min, int max)
|
||||
{
|
||||
return num < min ? min : (num > max ? max : num);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,12 @@
|
||||
package mineplex.core.common.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import mineplex.core.common.util.UtilParticle.ViewDist;
|
||||
import net.minecraft.server.v1_8_R3.EnumParticle;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutWorldParticles;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.EnumParticle;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutWorldParticles;
|
||||
|
||||
public class UtilParticle
|
||||
{
|
||||
@ -95,7 +93,7 @@ public class UtilParticle
|
||||
LARGE_EXPLODE(EnumParticle.EXPLOSION_LARGE, "largeexplode", "Explosion", Material.FIREBALL, (byte) 0),
|
||||
|
||||
LARGE_SMOKE(EnumParticle.SMOKE_LARGE, "largesmoke", "Black Smoke", Material.INK_SACK, (byte) 0),
|
||||
|
||||
|
||||
SMOKE(EnumParticle.SMOKE_NORMAL, "smoke", "Smoke", Material.INK_SACK, (byte) 0),
|
||||
|
||||
LAVA(EnumParticle.LAVA, "lava", "Lava Debris", Material.LAVA, (byte) 0),
|
||||
@ -242,7 +240,47 @@ public class UtilParticle
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static void PlayParticle(ParticleType type,Location location, float offsetX, float offsetY,
|
||||
float offsetZ, float speed, int count, ViewDist dist)
|
||||
{
|
||||
PlayParticle(type, location, offsetX, offsetY, offsetZ, speed, count, dist, UtilServer.getPlayers());
|
||||
}
|
||||
|
||||
public static void PlayParticleToAll(ParticleType type, Location location, Vector offset, float speed, int count, ViewDist dist)
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
float z = 0;
|
||||
if(offset != null)
|
||||
{
|
||||
x = (float) offset.getX();
|
||||
y = (float) offset.getY();
|
||||
z = (float) offset.getZ();
|
||||
}
|
||||
PlayParticle(type, location, x, y, z, speed, count, dist, UtilServer.getPlayers());
|
||||
}
|
||||
|
||||
public static void PlayParticle(ParticleType type, Location location, Vector offset, float speed, int count, ViewDist dist, Player... players)
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
float z = 0;
|
||||
if(offset != null)
|
||||
{
|
||||
x = (float) offset.getX();
|
||||
y = (float) offset.getY();
|
||||
z = (float) offset.getZ();
|
||||
}
|
||||
PlayParticle(type, location, x, y, z, speed, count, dist, players);
|
||||
}
|
||||
|
||||
public static void PlayParticleToAll(ParticleType type, Location location, float offsetX, float offsetY, float offsetZ,
|
||||
float speed, int count, ViewDist dist)
|
||||
{
|
||||
PlayParticle(type.particleName, location, offsetX, offsetY, offsetZ, speed, count, dist, UtilServer.getPlayers());
|
||||
}
|
||||
|
||||
public static void PlayParticle(ParticleType type, Location location, float offsetX, float offsetY, float offsetZ,
|
||||
float speed, int count, ViewDist dist, Player... players)
|
||||
{
|
||||
@ -263,4 +301,26 @@ public class UtilParticle
|
||||
UtilPlayer.sendPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PlayParticleToAll(String particle, Location location, Vector offset, float speed, int count, ViewDist dist)
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
float z = 0;
|
||||
if(offset != null)
|
||||
{
|
||||
x = (float) offset.getX();
|
||||
y = (float) offset.getY();
|
||||
z = (float) offset.getZ();
|
||||
}
|
||||
PlayParticle(particle, location, x, y, z, speed, count, dist, UtilServer.getPlayers());
|
||||
}
|
||||
|
||||
public static void PlayParticleToAll(String particle, Location location, float offsetX, float offsetY, float offsetZ,
|
||||
float speed, int count, ViewDist dist)
|
||||
{
|
||||
PlayParticle(particle, location, offsetX, offsetY, offsetZ, speed, count, dist, UtilServer.getPlayers());
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,16 +1,17 @@
|
||||
package mineplex.core.common.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_8_R3.Packet;
|
||||
import net.minecraft.server.v1_8_R3.PlayerConnection;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
|
||||
@ -21,10 +22,23 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_8_R3.Packet;
|
||||
import net.minecraft.server.v1_8_R3.PlayerConnection;
|
||||
|
||||
public class UtilPlayer
|
||||
{
|
||||
private static Random RANDOM = new Random();
|
||||
|
||||
// A mapping of player names (Keys) to the system time when they last changed active Hotbar Slot
|
||||
private static Map<String, Long> _hotbarUpdates = new HashMap<String, Long>();
|
||||
|
||||
// The amount of time (in milliseconds) after changin hotbars that you can block
|
||||
public static final long BLOCKING_HOTBAR_DELAY = 100;
|
||||
|
||||
private static boolean hasIntersection(Vector3D p1, Vector3D p2, Vector3D min, Vector3D max)
|
||||
{
|
||||
final double epsilon = 0.0001f;
|
||||
@ -154,6 +168,30 @@ public class UtilPlayer
|
||||
return hit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player - the player to be checked for blocking status
|
||||
* @return true, if the {@code player} is blocking and has not recently
|
||||
* changed hotbar slots (within {@value BLOCKING_HOTBAR_DELAY} milliseconds), false otherwise.
|
||||
*/
|
||||
public static boolean isBlocking(Player player)
|
||||
{
|
||||
String name = player.getName();
|
||||
long lastUpdate = _hotbarUpdates.containsKey(name) ? _hotbarUpdates.get(name) : 0;;
|
||||
long duration = System.currentTimeMillis() - lastUpdate;
|
||||
|
||||
return player.isBlocking();// && UtilItem.isSword(player.getItemInHand())
|
||||
//&& duration >= BLOCKING_HOTBAR_DELAY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the {@code player} as having changed hotbar slots.
|
||||
* @param player - the player to be marked
|
||||
*/
|
||||
public static void onHotbarChange(Player player)
|
||||
{
|
||||
_hotbarUpdates.put(player.getName(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* AviodAllies doesn't work. Leaving as a param as it sounds like something you may want in the future.
|
||||
*/
|
||||
@ -392,7 +430,12 @@ public class UtilPlayer
|
||||
return matchList;
|
||||
}
|
||||
|
||||
public static LinkedList<Player> getNearby(Location loc, double maxDist)
|
||||
public static List<Player> getNearby(Location loc, double maxDist)
|
||||
{
|
||||
return getNearby(loc, maxDist, false);
|
||||
}
|
||||
|
||||
public static List<Player> getNearby(Location loc, double maxDist, boolean onlySurvival)
|
||||
{
|
||||
LinkedList<Player> nearbyMap = new LinkedList<Player>();
|
||||
|
||||
@ -404,8 +447,10 @@ public class UtilPlayer
|
||||
if (cur.isDead())
|
||||
continue;
|
||||
|
||||
double dist = loc.toVector().subtract(cur.getLocation().toVector()).length();
|
||||
if (onlySurvival && cur.getGameMode() != GameMode.SURVIVAL)
|
||||
continue;
|
||||
|
||||
double dist = loc.distance(cur.getLocation());
|
||||
if (dist > maxDist)
|
||||
continue;
|
||||
|
||||
@ -453,7 +498,7 @@ public class UtilPlayer
|
||||
return best;
|
||||
}
|
||||
|
||||
public static Player getClosest(Location loc, Entity ignore)
|
||||
public static Player getClosest(Location loc, Entity... ignore)
|
||||
{
|
||||
Player best = null;
|
||||
double bestDist = 0;
|
||||
@ -466,8 +511,22 @@ public class UtilPlayer
|
||||
if (cur.isDead())
|
||||
continue;
|
||||
|
||||
if (ignore != null && ignore.equals(cur))
|
||||
continue;
|
||||
//Ignore Check
|
||||
if (ignore != null)
|
||||
{
|
||||
boolean shouldIgnore = false;
|
||||
for (Entity ent : ignore)
|
||||
{
|
||||
if (cur.equals(ent))
|
||||
{
|
||||
shouldIgnore = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldIgnore)
|
||||
continue;
|
||||
}
|
||||
|
||||
double dist = UtilMath.offset(cur.getLocation(), loc);
|
||||
|
||||
@ -498,6 +557,14 @@ public class UtilPlayer
|
||||
if (log)
|
||||
System.out.println("Kicked Client [" + player.getName() + "] for [" + module + " - " + message + "]");
|
||||
}
|
||||
|
||||
public static void kick(Collection<Player> players, String module, String message, boolean log)
|
||||
{
|
||||
for (Player player : players)
|
||||
{
|
||||
kick(player, module, message, log);
|
||||
}
|
||||
}
|
||||
|
||||
public static HashMap<Player, Double> getInRadius(Location loc, double dR)
|
||||
{
|
||||
@ -527,7 +594,7 @@ public class UtilPlayer
|
||||
continue;
|
||||
|
||||
//Get lower offset (eye to eye, eye to feet)
|
||||
double offset = Math.min(UtilMath.offset(player.getEyeLocation(), cur.getEyeLocation()),
|
||||
double offset = Math.min(UtilMath.offset(player.getEyeLocation(), cur.getEyeLocation()),
|
||||
UtilMath.offset(player.getEyeLocation(), cur.getLocation()));
|
||||
|
||||
if (offset < distance && UtilAlg.isTargetInPlayerPyramid(player, cur, angleLimit))
|
||||
@ -590,6 +657,23 @@ public class UtilPlayer
|
||||
return (((CraftEntity) player).getHandle().getDataWatcher().getByte(0) & 1 << 4) != 0;
|
||||
}
|
||||
|
||||
public static void clearInventory(Player player)
|
||||
{
|
||||
player.getInventory().clear();
|
||||
player.getInventory().setHelmet(null);
|
||||
player.getInventory().setChestplate(null);
|
||||
player.getInventory().setLeggings(null);
|
||||
player.getInventory().setBoots(null);
|
||||
}
|
||||
|
||||
public static void clearPotionEffects(Player player)
|
||||
{
|
||||
for (PotionEffect effect : player.getActivePotionEffects())
|
||||
{
|
||||
player.removePotionEffect(effect.getType());
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacket(Player player, Packet... packets)
|
||||
{
|
||||
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||
@ -603,6 +687,18 @@ public class UtilPlayer
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random player within maxDist of the target location
|
||||
* @param location The center location to look for the player
|
||||
* @param maxDist The max distance from location that the player can be
|
||||
* @return A random player that is within maxDist of location, or null if no players apply
|
||||
*/
|
||||
public static Player getRandomTarget(Location location, double maxDist)
|
||||
{
|
||||
List<Player> nearby = getNearby(location, maxDist, true);
|
||||
return nearby.size() > 0 ? nearby.get(RANDOM.nextInt(nearby.size())) : null;
|
||||
}
|
||||
|
||||
public static boolean isSpectator(Entity player)
|
||||
{
|
||||
if (player instanceof Player)
|
||||
|
@ -84,6 +84,8 @@ public class UtilRadar
|
||||
|
||||
text += C.cPurple + C.Bold + "] Radar";
|
||||
|
||||
UtilTextTop.display(text, player);
|
||||
|
||||
if(bossBar)
|
||||
{
|
||||
UtilTextTop.display(text, player);
|
||||
@ -109,4 +111,4 @@ public class UtilRadar
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,13 @@
|
||||
package mineplex.core.common.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.Sound;
|
||||
@ -12,6 +20,30 @@ public class UtilServer
|
||||
return getServer().getOnlinePlayers().toArray(new Player[0]);
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> getPlayersCollection()
|
||||
{
|
||||
return getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static List<Player> getSortedPlayers()
|
||||
{
|
||||
return getSortedPlayers(new Comparator<Player>()
|
||||
{
|
||||
@Override
|
||||
public int compare(Player o1, Player o2)
|
||||
{
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static List<Player> getSortedPlayers(Comparator<Player> comparator)
|
||||
{
|
||||
ArrayList<Player> players = new ArrayList<Player>(getServer().getOnlinePlayers());
|
||||
Collections.sort(players, comparator);
|
||||
return players;
|
||||
}
|
||||
|
||||
public static Server getServer()
|
||||
{
|
||||
return Bukkit.getServer();
|
||||
@ -23,6 +55,12 @@ public class UtilServer
|
||||
UtilPlayer.message(cur, message);
|
||||
}
|
||||
|
||||
public static void broadcast(LinkedList<String> messages)
|
||||
{
|
||||
for (Player cur : getPlayers())
|
||||
UtilPlayer.message(cur, messages);
|
||||
}
|
||||
|
||||
public static void broadcastSpecial(String event, String message)
|
||||
{
|
||||
for (Player cur : getPlayers())
|
||||
|
@ -1,6 +1,13 @@
|
||||
package mineplex.core.common.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
public class UtilSkull
|
||||
{
|
||||
@ -25,6 +32,19 @@ public class UtilSkull
|
||||
return 3;
|
||||
}
|
||||
|
||||
public static ItemStack getPlayerHead(String playerName, String itemName, List<String> itemLore)
|
||||
{
|
||||
boolean displayHead = !playerName.isEmpty();
|
||||
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 0, displayHead ? (byte) 3 : 0);
|
||||
SkullMeta meta = ((SkullMeta) skull.getItemMeta());
|
||||
if (displayHead)
|
||||
meta.setOwner(playerName);
|
||||
meta.setDisplayName(itemName);
|
||||
meta.setLore(itemLore);
|
||||
skull.setItemMeta(meta);
|
||||
return skull;
|
||||
}
|
||||
|
||||
public static boolean isPlayerHead(byte data)
|
||||
{
|
||||
return data == 3;
|
||||
|
@ -1,51 +1,487 @@
|
||||
package mineplex.core.common.util;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import mineplex.core.common.CurrencyType;
|
||||
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class UtilText {
|
||||
public static <T> String listToString(Collection<T> inputList, boolean comma) {
|
||||
String out = "";
|
||||
public class UtilText
|
||||
{
|
||||
private static HashMap<Character, Integer> _characters = new HashMap<Character, Integer>();
|
||||
|
||||
for (T cur : inputList) {
|
||||
out += cur.toString() + (comma ? ", " : " ");
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
InputStream inputStream = CurrencyType.class.getResourceAsStream("ascii.png");
|
||||
BufferedImage image = ImageIO.read(inputStream);
|
||||
|
||||
char[] text = new char[]
|
||||
{
|
||||
' ',
|
||||
'!',
|
||||
'"',
|
||||
'#',
|
||||
'$',
|
||||
'%',
|
||||
'&',
|
||||
'\'',
|
||||
'(',
|
||||
')',
|
||||
'*',
|
||||
'+',
|
||||
',',
|
||||
'-',
|
||||
'.',
|
||||
'/',
|
||||
'0',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
'7',
|
||||
'8',
|
||||
'9',
|
||||
':',
|
||||
';',
|
||||
'<',
|
||||
'=',
|
||||
'>',
|
||||
'?',
|
||||
'@',
|
||||
'A',
|
||||
'B',
|
||||
'C',
|
||||
'D',
|
||||
'E',
|
||||
'F',
|
||||
'G',
|
||||
'H',
|
||||
'I',
|
||||
'J',
|
||||
'K',
|
||||
'L',
|
||||
'M',
|
||||
'N',
|
||||
'O',
|
||||
'P',
|
||||
'Q',
|
||||
'R',
|
||||
'S',
|
||||
'T',
|
||||
'U',
|
||||
'V',
|
||||
'W',
|
||||
'X',
|
||||
'Y',
|
||||
'Z',
|
||||
'[',
|
||||
'\\',
|
||||
']',
|
||||
'^',
|
||||
'_',
|
||||
'`',
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
'd',
|
||||
'e',
|
||||
'f',
|
||||
'g',
|
||||
'h',
|
||||
'i',
|
||||
'j',
|
||||
'k',
|
||||
'l',
|
||||
'm',
|
||||
'n',
|
||||
'o',
|
||||
'p',
|
||||
'q',
|
||||
'r',
|
||||
's',
|
||||
't',
|
||||
'u',
|
||||
'v',
|
||||
'w',
|
||||
'x',
|
||||
'y',
|
||||
'z',
|
||||
'{',
|
||||
'|',
|
||||
'}',
|
||||
'~'
|
||||
};
|
||||
|
||||
int x = 0;
|
||||
int y = 16;
|
||||
|
||||
for (char c : text)
|
||||
{
|
||||
grab(c, image, x, y);
|
||||
|
||||
if (x < 15 * 8)
|
||||
{
|
||||
x += 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = 0;
|
||||
y += 8;
|
||||
}
|
||||
}
|
||||
|
||||
inputStream.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String center(String string, LineFormat lineFormat)
|
||||
{
|
||||
int length = getLength(string);
|
||||
|
||||
if (length > lineFormat.getLength())
|
||||
{
|
||||
return string;
|
||||
}
|
||||
|
||||
if (out.length() > 0) {
|
||||
out = out.substring(0, out.length() - (comma ? 2 : 1));
|
||||
// Get the number of empty pixels on both sides of the string
|
||||
int div = (int) Math.floor((lineFormat.getLength() - length) / 2D);
|
||||
|
||||
div -= 2; // For the gap between the strings
|
||||
|
||||
return fillLine(" ", div) + string + fillLine(" ", div);
|
||||
}
|
||||
|
||||
public static String alignRight(String string, LineFormat lineFormat)
|
||||
{
|
||||
int length = getLength(string);
|
||||
|
||||
if (length > lineFormat.getLength())
|
||||
{
|
||||
return string;
|
||||
}
|
||||
|
||||
return out;
|
||||
// Get the number of empty pixels on both sides of the string
|
||||
int div = lineFormat.getLength() - length;
|
||||
|
||||
div -= 1; // For the gap between the strings
|
||||
|
||||
return fillLine(" ", div) + string;
|
||||
}
|
||||
|
||||
public static String centerChat(String string, LineFormat lineFormat)
|
||||
{
|
||||
int length = getLength(string);
|
||||
|
||||
if (length > lineFormat.getLength())
|
||||
{
|
||||
return string;
|
||||
}
|
||||
|
||||
// Get the number of empty pixels on both sides of the string
|
||||
int div = (int) Math.floor(((lineFormat.getLength() + 10) - length) / 2D);
|
||||
|
||||
div -= 2; // For the gap between the strings
|
||||
|
||||
return fillLine(" ", div) + string;
|
||||
}
|
||||
|
||||
public static String substringPixels(String string, int cutoff)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
char[] array = string.toCharArray();
|
||||
boolean bold = false;
|
||||
|
||||
for (int i = 0; i < array.length; i++)
|
||||
{
|
||||
char c = array[i];
|
||||
|
||||
if (c == '<27>')
|
||||
{
|
||||
if (++i < array.length)
|
||||
{
|
||||
ChatColor color = ChatColor.getByChar(array[i]);
|
||||
|
||||
if (color != null)
|
||||
{
|
||||
if (color.equals(ChatColor.BOLD))
|
||||
{
|
||||
bold = true;
|
||||
}
|
||||
else if (color.equals(ChatColor.RESET) || color.isColor())
|
||||
{
|
||||
bold = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_characters.containsKey(c))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int toAdd = _characters.get(c);
|
||||
|
||||
if (bold)
|
||||
{
|
||||
toAdd++;
|
||||
}
|
||||
|
||||
if (len + toAdd > cutoff)
|
||||
{
|
||||
return string.substring(0, Math.max(0, i - 1));
|
||||
}
|
||||
|
||||
if (i + 1 < array.length)
|
||||
{
|
||||
len++;
|
||||
}
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
public static String[] splitLinesToArray(String[] strings, LineFormat lineFormat)
|
||||
{
|
||||
ArrayList<String> lineList = splitLines(strings, lineFormat);
|
||||
|
||||
String[] lineArray = new String[lineList.size()];
|
||||
lineArray = lineList.toArray(lineArray);
|
||||
|
||||
return lineArray;
|
||||
}
|
||||
|
||||
public static int upperCaseCount(String input) {
|
||||
int count = 0;
|
||||
|
||||
for (int k = 0; k < input.length(); k++) {
|
||||
|
||||
|
||||
char ch = input.charAt(k);
|
||||
if (Character.isUpperCase(ch))
|
||||
count++;
|
||||
|
||||
public static ArrayList<String> splitLines(String[] strings, LineFormat lineFormat)
|
||||
{
|
||||
ArrayList<String> lines = new ArrayList<String>();
|
||||
|
||||
for (String s : strings)
|
||||
{
|
||||
lines.addAll(splitLine(s, lineFormat));
|
||||
}
|
||||
|
||||
return count;
|
||||
|
||||
return lines;
|
||||
}
|
||||
public static int lowerCaseCount(String input) {
|
||||
int count = 0;
|
||||
|
||||
public static String[] splitLineToArray(String string, LineFormat lineFormat)
|
||||
{
|
||||
ArrayList<String> lineList = splitLine(string, lineFormat);
|
||||
|
||||
for (int k = 0; k < input.length(); k++) {
|
||||
|
||||
|
||||
char ch = input.charAt(k);
|
||||
if (Character.isLowerCase(ch))
|
||||
count++;
|
||||
String[] lineArray = new String[lineList.size()];
|
||||
lineArray = lineList.toArray(lineArray);
|
||||
|
||||
return lineArray;
|
||||
}
|
||||
|
||||
public static ArrayList<String> splitLine(String string, LineFormat lineFormat)
|
||||
{
|
||||
ArrayList<String> strings = new ArrayList<String>();
|
||||
|
||||
//Ignore lines with #
|
||||
if (string.startsWith("#"))
|
||||
{
|
||||
strings.add(string.substring(1, string.length()));
|
||||
return strings;
|
||||
}
|
||||
|
||||
return count;
|
||||
//Empty
|
||||
if (string.equals("") || string.equals(" "))
|
||||
{
|
||||
strings.add(string);
|
||||
return strings;
|
||||
}
|
||||
|
||||
String current = "";
|
||||
int currentLength = 0;
|
||||
String[] split = string.split(" ");
|
||||
String colors = "";
|
||||
|
||||
for (int i = 0; i < split.length; i++)
|
||||
{
|
||||
String word = split[i];
|
||||
int wordLength = getLength(colors + word);
|
||||
|
||||
if (currentLength + wordLength + 4 > lineFormat.getLength() && !current.isEmpty())
|
||||
{
|
||||
strings.add(current);
|
||||
current = colors + word;
|
||||
currentLength = wordLength + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i != 0)
|
||||
{
|
||||
current += " ";
|
||||
currentLength += 4;
|
||||
}
|
||||
|
||||
current += word;
|
||||
currentLength += wordLength;
|
||||
colors = ChatColor.getLastColors(current);
|
||||
}
|
||||
|
||||
if (!current.isEmpty())
|
||||
{
|
||||
strings.add(current);
|
||||
}
|
||||
|
||||
return strings;
|
||||
}
|
||||
|
||||
public static String fillLine(String filler, int maxPixels)
|
||||
{
|
||||
int pixels = getLength(filler);
|
||||
|
||||
if (pixels <= 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
String toReturn = "";
|
||||
int currentLen = 0;
|
||||
|
||||
int offset = maxPixels % 4;
|
||||
boolean isOffset = false;
|
||||
|
||||
if (offset > 0)
|
||||
{
|
||||
toReturn += C.Bold;
|
||||
}
|
||||
|
||||
while (currentLen + pixels <= maxPixels)
|
||||
{
|
||||
currentLen += pixels + 1;
|
||||
toReturn += filler;
|
||||
|
||||
if (offset-- > 0)
|
||||
{
|
||||
currentLen++;
|
||||
|
||||
if (offset == 0)
|
||||
{
|
||||
isOffset = false;
|
||||
toReturn += ChatColor.RESET;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isOffset)
|
||||
{
|
||||
toReturn += ChatColor.RESET;
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static boolean fitsOneLine(String string, LineFormat lineFormat)
|
||||
{
|
||||
return getLength(string) <= lineFormat.getLength();
|
||||
}
|
||||
|
||||
public static int getLength(String string)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
char[] array = string.toCharArray();
|
||||
boolean bold = false;
|
||||
|
||||
for (int i = 0; i < array.length; i++)
|
||||
{
|
||||
char c = array[i];
|
||||
|
||||
if (c == '<27>')
|
||||
{
|
||||
if (++i < array.length)
|
||||
{
|
||||
ChatColor color = ChatColor.getByChar(array[i]);
|
||||
|
||||
if (color != null)
|
||||
{
|
||||
if (color.equals(ChatColor.BOLD))
|
||||
{
|
||||
bold = true;
|
||||
}
|
||||
else if (color.equals(ChatColor.RESET) || color.isColor())
|
||||
{
|
||||
bold = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_characters.containsKey(c))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
len += _characters.get(c);
|
||||
|
||||
if (bold)
|
||||
{
|
||||
len++;
|
||||
}
|
||||
|
||||
if (i + 1 < array.length)
|
||||
{
|
||||
len++;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
private static void grab(Character character, BufferedImage image, int imageX, int imageY)
|
||||
{
|
||||
if (character == ' ')
|
||||
{
|
||||
_characters.put(character, 3);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int x = 0; x < 8; x++)
|
||||
{
|
||||
boolean isTransparentLine = true;
|
||||
|
||||
for (int y = 0; y < 8; y++)
|
||||
{
|
||||
int pixel = image.getRGB(imageX + x, imageY + y);
|
||||
|
||||
if ((pixel >> 24) != 0x00)
|
||||
{
|
||||
isTransparentLine = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isTransparentLine)
|
||||
{
|
||||
_characters.put(character, x);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_characters.put(character, 8);
|
||||
}
|
||||
|
||||
public static boolean isStringSimilar(String newString, String oldString, float matchRequirement)
|
||||
@ -54,45 +490,136 @@ public class UtilText {
|
||||
{
|
||||
return newString.toLowerCase().equals(oldString.toLowerCase());
|
||||
}
|
||||
|
||||
for (int i=0 ; i < newString.length() * matchRequirement ; i++)
|
||||
|
||||
for (int i = 0; i < newString.length() * matchRequirement; i++)
|
||||
{
|
||||
int matchFromIndex = 0;
|
||||
|
||||
//Look for substrings starting at i
|
||||
for (int j=0 ; j < oldString.length() ; j++)
|
||||
|
||||
// Look for substrings starting at i
|
||||
for (int j = 0; j < oldString.length(); j++)
|
||||
{
|
||||
//End of newString
|
||||
if (i+j >= newString.length())
|
||||
// End of newString
|
||||
if (i + j >= newString.length())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//Matched
|
||||
if (newString.charAt(i+j) == oldString.charAt(j))
|
||||
|
||||
// Matched
|
||||
if (newString.charAt(i + j) == oldString.charAt(j))
|
||||
{
|
||||
matchFromIndex++;
|
||||
|
||||
|
||||
if (matchFromIndex >= newString.length() * matchRequirement)
|
||||
return true;
|
||||
}
|
||||
//No Match > Reset
|
||||
// No Match > Reset
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static <T> String listToString(Collection<T> inputList, boolean comma)
|
||||
{
|
||||
String out = "";
|
||||
|
||||
for (T cur : inputList)
|
||||
{
|
||||
out += cur.toString() + (comma ? ", " : " ");
|
||||
}
|
||||
|
||||
if (out.length() > 0)
|
||||
{
|
||||
out = out.substring(0, out.length() - (comma ? 2 : 1));
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
public static int lowerCaseCount(String input)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
for (int k = 0; k < input.length(); k++)
|
||||
{
|
||||
|
||||
char ch = input.charAt(k);
|
||||
if (Character.isLowerCase(ch))
|
||||
count++;
|
||||
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public static int upperCaseCount(String input)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
for (int k = 0; k < input.length(); k++)
|
||||
{
|
||||
|
||||
char ch = input.charAt(k);
|
||||
if (Character.isUpperCase(ch))
|
||||
count++;
|
||||
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public static String[] wrap(String text, int lineLength)
|
||||
{
|
||||
return wrap(text, lineLength, true);
|
||||
}
|
||||
|
||||
public static String[] wrap(String text, int lineLength, boolean wrapLongerWords) {
|
||||
|
||||
public static String[] wrap(String text, int lineLength, boolean wrapLongerWords)
|
||||
{
|
||||
return WordUtils.wrap(text, lineLength, "\00D0", wrapLongerWords).split("\00D0");
|
||||
}
|
||||
}
|
||||
|
||||
public static String repeat(String txt, int times)
|
||||
{
|
||||
return new String(new byte[times]).replace("\0", txt);
|
||||
}
|
||||
|
||||
public static boolean plural(int x)
|
||||
{
|
||||
return x <= 0 ? true : x > 1;
|
||||
}
|
||||
|
||||
public static String trim(int maxLength, String s)
|
||||
{
|
||||
return s.length() <= maxLength ? s : s.substring(0, maxLength);
|
||||
}
|
||||
|
||||
public static <X> String arrayToString(X[] array, String delimiter)
|
||||
{
|
||||
StringBuilder string = new StringBuilder();
|
||||
|
||||
int index = 0;
|
||||
for (X x : array)
|
||||
{
|
||||
string.append(x.toString());
|
||||
|
||||
if (index != array.length - 1)
|
||||
{
|
||||
string.append(delimiter);
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
return string.toString();
|
||||
}
|
||||
|
||||
public static <X> String arrayToString(X[] array)
|
||||
{
|
||||
return arrayToString(array, null);
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,8 @@ package mineplex.core.common.util;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.MinecraftServer;
|
||||
|
||||
public class UtilTime
|
||||
{
|
||||
public static final String DATE_FORMAT_NOW = "MM-dd-yyyy HH:mm:ss";
|
||||
@ -41,15 +43,45 @@ public class UtilTime
|
||||
default: return "th";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Returns the current global server tick. Is reset on server restart. Starts out negative. Counts upwards.
|
||||
*/
|
||||
public static int getServerTick()
|
||||
{
|
||||
return MinecraftServer.currentTick;
|
||||
}
|
||||
|
||||
public enum TimeUnit
|
||||
{
|
||||
FIT,
|
||||
DAYS,
|
||||
HOURS,
|
||||
MINUTES,
|
||||
SECONDS,
|
||||
MILLISECONDS
|
||||
FIT(1),
|
||||
DAYS(86400000),
|
||||
HOURS(3600000),
|
||||
MINUTES(60000),
|
||||
SECONDS(1000),
|
||||
MILLISECONDS(1);
|
||||
|
||||
private long _ms;
|
||||
|
||||
TimeUnit(long ms)
|
||||
{
|
||||
_ms = ms;
|
||||
}
|
||||
|
||||
public long getMilliseconds()
|
||||
{
|
||||
return _ms;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from one TimeUnit to a different one
|
||||
*/
|
||||
public static long convert(long time, TimeUnit from, TimeUnit to)
|
||||
{
|
||||
long milleseconds = time * from.getMilliseconds();
|
||||
return milleseconds / to.getMilliseconds();
|
||||
}
|
||||
|
||||
public static String since(long epoch)
|
||||
@ -103,7 +135,7 @@ public class UtilTime
|
||||
if (type == TimeUnit.DAYS) text = (num = UtilMath.trim(trim, time / 86400000d)) + " Day";
|
||||
else if (type == TimeUnit.HOURS) text = (num = UtilMath.trim(trim, time / 3600000d)) + " Hour";
|
||||
else if (type == TimeUnit.MINUTES) text = (num = UtilMath.trim(trim, time / 60000d)) + " Minute";
|
||||
else if (type == TimeUnit.SECONDS) text = (int) (num = (int) UtilMath.trim(trim, time / 1000d)) + " Second";
|
||||
else if (type == TimeUnit.SECONDS) text = (int) (num = (int) UtilMath.trim(trim, time / 1000d)) + " Second";
|
||||
else text = (int) (num = (int) UtilMath.trim(trim, time)) + " Millisecond";
|
||||
}
|
||||
else
|
||||
|
@ -0,0 +1,36 @@
|
||||
package mineplex.core.common.util;
|
||||
|
||||
public class UtilUI
|
||||
{
|
||||
public static int[] getIndicesFor(int items, int startingLine, int newLinePadding)
|
||||
{
|
||||
return getIndicesFor(items, startingLine, 5, newLinePadding);
|
||||
}
|
||||
|
||||
public static int[] getIndicesFor(int items, int startingLine)
|
||||
{
|
||||
return getIndicesFor(items, startingLine, 5, 0);
|
||||
}
|
||||
|
||||
public static int[] getIndicesFor(int items, int startingLine, int itemsPerLine, int newLinePadding)
|
||||
{
|
||||
itemsPerLine = UtilMath.clamp(itemsPerLine, 1, 5);
|
||||
|
||||
int[] indices = new int[items];
|
||||
|
||||
int lines = (int) Math.ceil(items / ((double) itemsPerLine));
|
||||
for (int line = 0; line < lines; line++)
|
||||
{
|
||||
int itemsInCurLine = line == lines - 1 ? items - (line * itemsPerLine) : itemsPerLine;
|
||||
int startIndex = (startingLine * 9) + ((newLinePadding * 9) * line) + 9 * line - itemsInCurLine + 5;
|
||||
|
||||
for (int item = 0; item < itemsInCurLine; item++)
|
||||
{
|
||||
indices[(line * itemsPerLine) + item] = startIndex + (item * 2);
|
||||
}
|
||||
}
|
||||
|
||||
return indices;
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,7 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class UtilWorld
|
||||
@ -45,7 +46,55 @@ public class UtilWorld
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String blockToStr(Block block)
|
||||
{
|
||||
if (block == null)
|
||||
return "";
|
||||
|
||||
return block.getWorld().getName() + "," +
|
||||
block.getX() + "," +
|
||||
block.getY() + "," +
|
||||
block.getZ();
|
||||
}
|
||||
|
||||
public static String blockToStrClean(Block block)
|
||||
{
|
||||
if (block == null)
|
||||
return "";
|
||||
|
||||
return "(" + block.getX() + "," +
|
||||
block.getY() + "," +
|
||||
block.getZ() + ")";
|
||||
}
|
||||
|
||||
public static Block strToBlock(String string)
|
||||
{
|
||||
if (string.length() == 0)
|
||||
return null;
|
||||
|
||||
String[] parts = string.split(",");
|
||||
|
||||
try
|
||||
{
|
||||
for (World cur : UtilServer.getServer().getWorlds())
|
||||
{
|
||||
if (cur.getName().equalsIgnoreCase(parts[0]))
|
||||
{
|
||||
int x = Integer.parseInt(parts[1]);
|
||||
int y = Integer.parseInt(parts[2]);
|
||||
int z = Integer.parseInt(parts[3]);
|
||||
return cur.getBlockAt(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String locToStr(Location loc)
|
||||
{
|
||||
if (loc == null)
|
||||
@ -65,6 +114,14 @@ public class UtilWorld
|
||||
return "(" + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ() + ")";
|
||||
}
|
||||
|
||||
public static String vecToStrClean(Vector loc)
|
||||
{
|
||||
if (loc == null)
|
||||
return "Null";
|
||||
|
||||
return "(" + loc.getX() + ", " + loc.getY() + ", " + loc.getZ() + ")";
|
||||
}
|
||||
|
||||
public static Location strToLoc(String string)
|
||||
{
|
||||
if (string.length() == 0)
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpcore-4.2.jar"/>
|
||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpclient-4.2.jar"/>
|
||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/>
|
||||
@ -13,7 +13,9 @@
|
||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/jooq-3.5.2.jar"/>
|
||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/craftbukkit.jar"/>
|
||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/NoCheatPlus.jar"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.PlayerCache"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Cache"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core.Common"/>
|
||||
<classpathentry kind="var" path="REPO_DIR"/>
|
||||
<classpathentry kind="var" path="ECLIPSE_HOME"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
@ -1,12 +1,12 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
|
@ -13,13 +13,13 @@
|
||||
<orderEntry type="library" name="jedis" level="project" />
|
||||
<orderEntry type="library" name="commons-pool2" level="project" />
|
||||
<orderEntry type="module" module-name="Mineplex.Core.Common" />
|
||||
<orderEntry type="module" module-name="Classpath.Dummy" />
|
||||
<orderEntry type="module" module-name="Mineplex.ServerData" />
|
||||
<orderEntry type="library" name="craftbukkit" level="project" />
|
||||
<orderEntry type="module" module-name="Mineplex.Database" />
|
||||
<orderEntry type="library" name="jooq" level="project" />
|
||||
<orderEntry type="library" name="commons-dbcp2" level="project" />
|
||||
<orderEntry type="module" module-name="Classpath.Dummy" />
|
||||
<orderEntry type="library" name="NoCheatPlus" level="project" />
|
||||
<orderEntry type="module" module-name="Mineplex.PlayerCache" />
|
||||
<orderEntry type="module" module-name="Mineplex.Cache" />
|
||||
</component>
|
||||
</module>
|
@ -19,12 +19,13 @@ import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import net.minecraft.server.v1_8_R3.DataWatcher;
|
||||
import net.minecraft.server.v1_8_R3.DataWatcher.WatchableObject;
|
||||
import net.minecraft.server.v1_8_R3.MathHelper;
|
||||
import net.minecraft.server.v1_8_R3.Packet;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity.EnumEntityUseAction;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutAttachEntity;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutNamedEntitySpawn;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntity;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
|
||||
|
||||
@ -34,6 +35,8 @@ import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||
import org.bukkit.event.player.PlayerVelocityEvent;
|
||||
@ -48,24 +51,23 @@ import fr.neatmonster.nocheatplus.hooks.NCPHookManager;
|
||||
|
||||
public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
{
|
||||
private NautHashMap<String, NautHashMap<Integer, Integer>> _entityMap = new NautHashMap<String, NautHashMap<Integer, Integer>>();
|
||||
private NautHashMap<String, NautHashMap<Integer, Integer[]>> _entityMap = new NautHashMap<String, NautHashMap<Integer, Integer[]>>();
|
||||
private NautHashMap<String, NautHashMap<Integer, String>> _entityNameMap = new NautHashMap<String, NautHashMap<Integer, String>>();
|
||||
private NautHashMap<String, NautHashMap<Integer, Integer>> _entityRiding = new NautHashMap<String, NautHashMap<Integer, Integer>>();
|
||||
|
||||
private HashSet<String> _loggedIn = new HashSet<String>();
|
||||
private HashSet<Integer> _ignoreSkulls = new HashSet<Integer>();
|
||||
|
||||
private NautHashMap<UUID, Long> _exemptTimeMap = new NautHashMap<UUID, Long>();
|
||||
private NautHashMap<UUID, NautHashMap<CheckType, Long>> _doubleStrike = new NautHashMap<UUID, NautHashMap<CheckType, Long>>();
|
||||
private PacketHandler _packetHandler;
|
||||
|
||||
public CustomTagFix(JavaPlugin plugin, PacketHandler packetHandler)
|
||||
{
|
||||
super("Custom Tag Fix", plugin);
|
||||
|
||||
_packetHandler = packetHandler;
|
||||
|
||||
packetHandler.addPacketHandler(this, PacketPlayOutAttachEntity.class, PacketPlayOutEntityDestroy.class,
|
||||
packetHandler.addPacketHandler(this, true, PacketPlayOutAttachEntity.class, PacketPlayOutEntityDestroy.class,
|
||||
PacketPlayOutEntityMetadata.class, PacketPlayOutSpawnEntity.class, PacketPlayOutSpawnEntityLiving.class,
|
||||
PacketPlayInUseEntity.class);
|
||||
PacketPlayOutNamedEntitySpawn.class, PacketPlayInUseEntity.class, PacketPlayOutAttachEntity.class);
|
||||
|
||||
NCPHookManager.addHook(CheckType.MOVING_SURVIVALFLY, this);
|
||||
NCPHookManager.addHook(CheckType.MOVING_PASSABLE, this);
|
||||
@ -77,9 +79,19 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
{
|
||||
_entityMap.remove(event.getPlayer().getName());
|
||||
_entityNameMap.remove(event.getPlayer().getName());
|
||||
_entityRiding.remove(event.getPlayer().getName());
|
||||
_loggedIn.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void playerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
player.setCustomName("");
|
||||
player.setCustomNameVisible(false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void ncpExempt(final PlayerToggleFlightEvent event)
|
||||
{
|
||||
@ -139,7 +151,8 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
{
|
||||
Entry<UUID, NautHashMap<CheckType, Long>> entry = iterator.next();
|
||||
|
||||
for (Iterator<Entry<CheckType, Long>> innerIterator = entry.getValue().entrySet().iterator(); innerIterator.hasNext();)
|
||||
for (Iterator<Entry<CheckType, Long>> innerIterator = entry.getValue().entrySet().iterator(); innerIterator
|
||||
.hasNext();)
|
||||
{
|
||||
final Entry<CheckType, Long> entry2 = innerIterator.next();
|
||||
|
||||
@ -169,6 +182,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
iterator.remove();
|
||||
_entityMap.remove(player);
|
||||
_entityNameMap.remove(player);
|
||||
_entityRiding.remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,7 +206,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
{
|
||||
if (owner.isOnline() && !_entityMap.containsKey(owner.getName()))
|
||||
{
|
||||
_entityMap.put(owner.getName(), new NautHashMap<Integer, Integer>());
|
||||
_entityMap.put(owner.getName(), new NautHashMap<Integer, Integer[]>());
|
||||
_entityNameMap.put(owner.getName(), new NautHashMap<Integer, String>());
|
||||
_loggedIn.add(owner.getName());
|
||||
}
|
||||
@ -219,10 +233,15 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
{
|
||||
if (_entityMap.get(owner.getName()).containsKey(spawnPacket.a))
|
||||
{
|
||||
UtilPlayer.sendPacket(owner, new PacketPlayOutEntityDestroy(new int[]
|
||||
{
|
||||
_entityMap.get(owner.getName()).get(spawnPacket.a)
|
||||
}));
|
||||
Integer[] ids = _entityMap.get(owner.getName()).get(spawnPacket.a);
|
||||
int[] newIds = new int[ids.length];
|
||||
|
||||
for (int a = 0; a < ids.length; a++)
|
||||
{
|
||||
newIds[a] = ids[a];
|
||||
}
|
||||
|
||||
UtilPlayer.sendPacket(owner, new PacketPlayOutEntityDestroy(newIds));
|
||||
|
||||
_entityNameMap.get(owner.getName()).remove(spawnPacket.a);
|
||||
_entityMap.get(owner.getName()).remove(spawnPacket.a);
|
||||
@ -238,9 +257,59 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
int newId = UtilEnt.getNewEntityId();
|
||||
|
||||
_entityNameMap.get(owner.getName()).put(spawnPacket.a, entityName);
|
||||
_entityMap.get(owner.getName()).put(spawnPacket.a, newId);
|
||||
_entityMap.get(owner.getName()).put(spawnPacket.a, new Integer[]
|
||||
{
|
||||
newId
|
||||
});
|
||||
|
||||
sendProtocolPackets(owner, spawnPacket.a, newId, entityName, verifier, true);
|
||||
sendProtocolPackets(owner, spawnPacket.a, newId, entityName, verifier, true, -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (packet instanceof PacketPlayOutNamedEntitySpawn)
|
||||
{
|
||||
PacketPlayOutNamedEntitySpawn spawnPacket = (PacketPlayOutNamedEntitySpawn) packet;
|
||||
|
||||
for (WatchableObject watchable : (List<WatchableObject>) spawnPacket.i.c())
|
||||
{
|
||||
if (watchable.a() == 3 && watchable.b() instanceof Byte && ((Byte) watchable.b()) == 1)
|
||||
{
|
||||
if (_entityMap.get(owner.getName()).containsKey(spawnPacket.a))
|
||||
{
|
||||
Integer[] ids = _entityMap.get(owner.getName()).get(spawnPacket.a);
|
||||
|
||||
int[] newIds = new int[ids.length];
|
||||
|
||||
for (int a = 0; a < ids.length; a++)
|
||||
{
|
||||
newIds[a] = ids[a];
|
||||
}
|
||||
|
||||
UtilPlayer.sendPacket(owner, new PacketPlayOutEntityDestroy(newIds));
|
||||
|
||||
_entityNameMap.get(owner.getName()).remove(spawnPacket.a);
|
||||
_entityMap.get(owner.getName()).remove(spawnPacket.a);
|
||||
}
|
||||
|
||||
final String entityName = spawnPacket.i.getString(2);
|
||||
|
||||
if (entityName.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int newId = UtilEnt.getNewEntityId();
|
||||
int newId2 = UtilEnt.getNewEntityId();
|
||||
|
||||
_entityNameMap.get(owner.getName()).put(spawnPacket.a, entityName);
|
||||
_entityMap.get(owner.getName()).put(spawnPacket.a, new Integer[]
|
||||
{
|
||||
newId,
|
||||
newId2
|
||||
});
|
||||
|
||||
sendProtocolPackets(owner, spawnPacket.a, newId2, entityName, verifier, true, newId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -249,7 +318,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
{
|
||||
PacketPlayOutEntityMetadata metaPacket = (PacketPlayOutEntityMetadata) packet;
|
||||
|
||||
if (metaPacket.a != 777777 && !_ignoreSkulls.contains(metaPacket.a))
|
||||
if (metaPacket.a != 777777 && !_ignoreSkulls.contains(metaPacket.a) && metaPacket.a != owner.getEntityId())
|
||||
{
|
||||
boolean isDisplaying = _entityMap.get(owner.getName()).containsKey(metaPacket.a);
|
||||
String currentName = _entityNameMap.get(owner.getName()).get(metaPacket.a);
|
||||
@ -281,7 +350,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
// If name is still being displayed
|
||||
if (newDisplay)
|
||||
{
|
||||
int newId;
|
||||
Integer[] newId;
|
||||
|
||||
if (isDisplaying) // Sending metadata
|
||||
{
|
||||
@ -290,22 +359,28 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
else
|
||||
// Spawning new entity
|
||||
{
|
||||
newId = UtilEnt.getNewEntityId();
|
||||
newId = new Integer[]
|
||||
{
|
||||
UtilEnt.getNewEntityId()
|
||||
};
|
||||
|
||||
_entityMap.get(owner.getName()).put(metaPacket.a, newId);
|
||||
}
|
||||
|
||||
sendProtocolPackets(owner, metaPacket.a, newId, newName, verifier, !isDisplaying);
|
||||
|
||||
_entityNameMap.get(owner.getName()).put(metaPacket.a, newName);
|
||||
sendProtocolPackets(owner, metaPacket.a, newId[0], newName, verifier, !isDisplaying, -1);
|
||||
}
|
||||
else
|
||||
{ // Lets delete it
|
||||
int id = _entityMap.get(owner.getName()).get(metaPacket.a);
|
||||
Integer[] ids = _entityMap.get(owner.getName()).get(metaPacket.a);
|
||||
int[] newIds = new int[ids.length];
|
||||
|
||||
UtilPlayer.sendPacket(owner, new PacketPlayOutEntityDestroy(new int[]
|
||||
{
|
||||
id
|
||||
}));
|
||||
for (int a = 0; a < ids.length; a++)
|
||||
{
|
||||
newIds[a] = ids[a];
|
||||
}
|
||||
|
||||
verifier.bypassProcess(new PacketPlayOutEntityDestroy(newIds));
|
||||
|
||||
_entityMap.get(owner.getName()).remove(metaPacket.a);
|
||||
_entityNameMap.get(owner.getName()).remove(metaPacket.a);
|
||||
@ -321,10 +396,15 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
{
|
||||
if (_entityMap.get(owner.getName()).containsKey(id))
|
||||
{
|
||||
UtilPlayer.sendPacket(owner, new PacketPlayOutEntityDestroy(new int[]
|
||||
{
|
||||
_entityMap.get(owner.getName()).get(id)
|
||||
}));
|
||||
Integer[] ids = _entityMap.get(owner.getName()).get(id);
|
||||
int[] newIds = new int[ids.length];
|
||||
|
||||
for (int a = 0; a < ids.length; a++)
|
||||
{
|
||||
newIds[a] = ids[a];
|
||||
}
|
||||
|
||||
UtilPlayer.sendPacket(owner, new PacketPlayOutEntityDestroy(newIds));
|
||||
_entityMap.get(owner.getName()).remove(id);
|
||||
_entityNameMap.get(owner.getName()).remove(id);
|
||||
}
|
||||
@ -347,20 +427,79 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
{
|
||||
PacketPlayInUseEntity usePacket = (PacketPlayInUseEntity) packet;
|
||||
|
||||
for (Entry<Integer, Integer> entry : _entityMap.get(owner.getName()).entrySet())
|
||||
{
|
||||
if (entry.getValue() == usePacket.a)
|
||||
{
|
||||
PacketPlayInUseEntity newPacket = new PacketPlayInUseEntity();
|
||||
newPacket.a = entry.getKey();
|
||||
newPacket.action = usePacket.action;
|
||||
newPacket.c = usePacket.c;
|
||||
loop:
|
||||
|
||||
if (_packetHandler.handlePacket(owner, newPacket))
|
||||
for (Entry<Integer, Integer[]> entry : _entityMap.get(owner.getName()).entrySet())
|
||||
{
|
||||
for (int id : entry.getValue())
|
||||
{
|
||||
if (id == usePacket.a)
|
||||
{
|
||||
((CraftPlayer) owner).getHandle().playerConnection.a(newPacket);
|
||||
PacketPlayInUseEntity newPacket = new PacketPlayInUseEntity();
|
||||
newPacket.a = entry.getKey();
|
||||
newPacket.action = usePacket.action == EnumEntityUseAction.ATTACK ? EnumEntityUseAction.ATTACK
|
||||
: EnumEntityUseAction.INTERACT;
|
||||
|
||||
{
|
||||
((CraftPlayer) owner).getHandle().playerConnection.a(newPacket);
|
||||
}
|
||||
|
||||
break loop;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (packet instanceof PacketPlayOutAttachEntity)
|
||||
{
|
||||
PacketPlayOutAttachEntity attachPacket = (PacketPlayOutAttachEntity) packet;
|
||||
|
||||
// c = rider, b = ridden
|
||||
// When detaching, c is sent, b is -1
|
||||
|
||||
// If this attach packet is for a player that has the fix
|
||||
// If the attach packet isn't ordained by me
|
||||
if (!_entityMap.containsKey(owner.getName()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_entityRiding.containsKey(owner.getName()))
|
||||
{
|
||||
_entityRiding.put(owner.getName(), new NautHashMap<Integer, Integer>());
|
||||
}
|
||||
|
||||
int vehicleId = -1;
|
||||
|
||||
if (_entityRiding.get(owner.getName()).containsKey(attachPacket.b))
|
||||
{
|
||||
vehicleId = _entityRiding.get(owner.getName()).get(attachPacket.b);
|
||||
}
|
||||
|
||||
if (attachPacket.c == -1 && _entityMap.get(owner.getName()).containsKey(vehicleId))
|
||||
{
|
||||
Integer[] ids = _entityMap.get(owner.getName()).get(vehicleId);
|
||||
|
||||
_entityRiding.get(owner.getName()).remove(attachPacket.b);
|
||||
|
||||
sendProtocolPackets(owner, vehicleId, ids[ids.length - 1], _entityNameMap.get(owner.getName()).get(vehicleId),
|
||||
verifier, true, ids.length > 1 ? ids[0] : -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Integer[] ids = _entityMap.get(owner.getName()).get(attachPacket.c);
|
||||
|
||||
if (ids != null && ids[0] != attachPacket.b)
|
||||
{
|
||||
_entityRiding.get(owner.getName()).put(attachPacket.b, attachPacket.c);
|
||||
|
||||
int[] newIds = new int[ids.length];
|
||||
|
||||
for (int a = 0; a < ids.length; a++)
|
||||
{
|
||||
newIds[a] = ids[a];
|
||||
}
|
||||
|
||||
UtilPlayer.sendPacket(owner, new PacketPlayOutEntityDestroy(newIds));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -368,7 +507,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
}
|
||||
|
||||
private void sendProtocolPackets(final Player owner, final int entityId, final int newEntityId, String entityName,
|
||||
final PacketVerifier packetList, final boolean newPacket)
|
||||
final PacketVerifier packetList, final boolean newPacket, final int squidId)
|
||||
{
|
||||
CustomTagEvent event = new CustomTagEvent(owner, entityId, entityName);
|
||||
_plugin.getServer().getPluginManager().callEvent(event);
|
||||
@ -378,82 +517,49 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
final DataWatcher watcher = new DataWatcher(new DummyEntity(((CraftWorld) owner.getWorld()).getHandle()));
|
||||
DataWatcher watcher = new DataWatcher(new DummyEntity(((CraftWorld) owner.getWorld()).getHandle()));
|
||||
|
||||
watcher.a(0, Byte.valueOf((byte) 0));
|
||||
watcher.a(0, (byte) (0 | 1 << 5)); // Invisible
|
||||
watcher.a(1, Short.valueOf((short) 300));
|
||||
watcher.a(2, "");
|
||||
watcher.a(3, Byte.valueOf((byte) 0));
|
||||
watcher.a(2, finalEntityName);
|
||||
watcher.a(3, (byte) 1);
|
||||
watcher.a(4, Byte.valueOf((byte) 0));
|
||||
watcher.a(7, Integer.valueOf(0));
|
||||
watcher.a(8, Byte.valueOf((byte) 0));
|
||||
watcher.a(9, Byte.valueOf((byte) 0));
|
||||
watcher.a(6, Float.valueOf(1.0F));
|
||||
watcher.a(10, Byte.valueOf((byte) 0));
|
||||
|
||||
// Set invisible
|
||||
int i1 = watcher.getByte(0);
|
||||
watcher.watch(0, Byte.valueOf((byte) (i1 | 1 << 5)));
|
||||
|
||||
// Set small
|
||||
byte b1 = watcher.getByte(10);
|
||||
b1 = (byte) (b1 | 0x1);
|
||||
|
||||
watcher.watch(10, Byte.valueOf(b1));
|
||||
|
||||
watcher.watch(2, finalEntityName);
|
||||
watcher.watch(3, Byte.valueOf((byte) 1));
|
||||
watcher.a(10, (byte) (0 | 0x1)); // Small
|
||||
|
||||
if (newPacket)
|
||||
{
|
||||
final PacketPlayOutSpawnEntityLiving spawnPacket = new PacketPlayOutSpawnEntityLiving();
|
||||
if (squidId >= 0)
|
||||
{
|
||||
watcher.watch(10, (byte) 16);
|
||||
|
||||
DataWatcher squidWatcher = new DataWatcher(new DummyEntity(((CraftWorld) owner.getWorld()).getHandle()));
|
||||
squidWatcher.a(0, (byte) (0 | 1 << 5));
|
||||
|
||||
PacketPlayOutSpawnEntityLiving spawnPacket = new PacketPlayOutSpawnEntityLiving();
|
||||
spawnPacket.a = squidId;
|
||||
spawnPacket.b = (byte) EntityType.SQUID.getTypeId();
|
||||
spawnPacket.c = 1000000;
|
||||
|
||||
spawnPacket.l = squidWatcher;
|
||||
|
||||
UtilPlayer.sendPacket(owner, spawnPacket);
|
||||
|
||||
PacketPlayOutAttachEntity vehiclePacket = new PacketPlayOutAttachEntity();
|
||||
vehiclePacket.a = 0;
|
||||
vehiclePacket.b = spawnPacket.a;
|
||||
vehiclePacket.c = entityId;
|
||||
|
||||
UtilPlayer.sendPacket(owner, vehiclePacket);
|
||||
}
|
||||
|
||||
PacketPlayOutSpawnEntityLiving spawnPacket = new PacketPlayOutSpawnEntityLiving();
|
||||
spawnPacket.a = newEntityId;
|
||||
spawnPacket.b = (byte) 30;
|
||||
spawnPacket.c = (int) MathHelper.floor(100 * 32);
|
||||
spawnPacket.d = (int) MathHelper.floor(64 * 32.0D);
|
||||
spawnPacket.e = (int) MathHelper.floor(100 * 32);
|
||||
spawnPacket.i = (byte) ((int) (0 * 256.0F / 360.0F));
|
||||
spawnPacket.j = (byte) ((int) (0 * 256.0F / 360.0F));
|
||||
spawnPacket.k = (byte) ((int) (0 * 256.0F / 360.0F));
|
||||
|
||||
double var2 = 3.9D;
|
||||
double var4 = 0;
|
||||
double var6 = 0;
|
||||
double var8 = 0;
|
||||
|
||||
if (var4 < -var2)
|
||||
{
|
||||
var4 = -var2;
|
||||
}
|
||||
|
||||
if (var6 < -var2)
|
||||
{
|
||||
var6 = -var2;
|
||||
}
|
||||
|
||||
if (var8 < -var2)
|
||||
{
|
||||
var8 = -var2;
|
||||
}
|
||||
|
||||
if (var4 > var2)
|
||||
{
|
||||
var4 = var2;
|
||||
}
|
||||
|
||||
if (var6 > var2)
|
||||
{
|
||||
var6 = var2;
|
||||
}
|
||||
|
||||
if (var8 > var2)
|
||||
{
|
||||
var8 = var2;
|
||||
}
|
||||
|
||||
spawnPacket.f = (int) (var4 * 8000.0D);
|
||||
spawnPacket.g = (int) (var6 * 8000.0D);
|
||||
spawnPacket.h = (int) (var8 * 8000.0D);
|
||||
spawnPacket.c = 1000000;
|
||||
|
||||
spawnPacket.l = watcher;
|
||||
|
||||
@ -462,7 +568,7 @@ public class CustomTagFix extends MiniPlugin implements IPacketHandler, NCPHook
|
||||
PacketPlayOutAttachEntity vehiclePacket = new PacketPlayOutAttachEntity();
|
||||
vehiclePacket.a = 0;
|
||||
vehiclePacket.b = spawnPacket.a;
|
||||
vehiclePacket.c = entityId;
|
||||
vehiclePacket.c = squidId >= 0 ? squidId : entityId;
|
||||
|
||||
UtilPlayer.sendPacket(owner, vehiclePacket);
|
||||
}
|
||||
|
@ -5,11 +5,15 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_8_R3.MathHelper;
|
||||
import net.minecraft.server.v1_8_R3.MovingObjectPosition;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity.EnumEntityUseAction;
|
||||
import net.minecraft.server.v1_8_R3.MinecraftServer;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
|
||||
import net.minecraft.server.v1_8_R3.Vec3D;
|
||||
import net.minecraft.server.v1_8_R3.WorldSettings.EnumGamemode;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
@ -18,9 +22,6 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.event.player.PlayerAnimationType;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@ -33,8 +34,6 @@ import mineplex.core.updater.event.UpdateEvent;
|
||||
public class PacketsInteractionFix extends MiniPlugin implements IPacketHandler
|
||||
{
|
||||
private HashMap<String, HashSet<Integer>> _armorStands = new HashMap<String, HashSet<Integer>>();
|
||||
private HashSet<Player> _leftClicked = new HashSet<Player>();
|
||||
private int _lastTick;
|
||||
|
||||
public PacketsInteractionFix(JavaPlugin plugin, PacketHandler packetHandler)
|
||||
{
|
||||
@ -44,42 +43,9 @@ public class PacketsInteractionFix extends MiniPlugin implements IPacketHandler
|
||||
PacketPlayInUseEntity.class);
|
||||
}
|
||||
|
||||
private void checkLeftClicks()
|
||||
{
|
||||
if (MinecraftServer.currentTick == _lastTick)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_lastTick = MinecraftServer.currentTick;
|
||||
_leftClicked.clear();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onArmAnimation(PlayerAnimationEvent event)
|
||||
{
|
||||
if (event.getAnimationType() != PlayerAnimationType.ARM_SWING)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
checkLeftClicks();
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (_leftClicked.remove(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CraftEventFactory.callPlayerInteractEvent(((CraftPlayer) player).getHandle(), Action.LEFT_CLICK_AIR,
|
||||
((CraftPlayer) player).getHandle().inventory.getItemInHand());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event)
|
||||
{
|
||||
_leftClicked.remove(event.getPlayer().getName());
|
||||
_armorStands.remove(event.getPlayer().getName());
|
||||
}
|
||||
|
||||
@ -91,8 +57,6 @@ public class PacketsInteractionFix extends MiniPlugin implements IPacketHandler
|
||||
return;
|
||||
}
|
||||
|
||||
checkLeftClicks();
|
||||
|
||||
Iterator<String> itel = _armorStands.keySet().iterator();
|
||||
|
||||
while (itel.hasNext())
|
||||
@ -110,19 +74,6 @@ public class PacketsInteractionFix extends MiniPlugin implements IPacketHandler
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if (!event.getAction().name().contains("LEFT"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
checkLeftClicks();
|
||||
|
||||
_leftClicked.add(event.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PacketInfo packetInfo)
|
||||
{
|
||||
@ -166,12 +117,38 @@ public class PacketsInteractionFix extends MiniPlugin implements IPacketHandler
|
||||
{
|
||||
PacketPlayInUseEntity packet = (PacketPlayInUseEntity) packetInfo.getPacket();
|
||||
|
||||
if (!list.contains(packet.a))
|
||||
if (packet.action == EnumEntityUseAction.ATTACK)
|
||||
{
|
||||
EntityPlayer nmsPlayer = ((CraftPlayer) packetInfo.getPlayer()).getHandle();
|
||||
|
||||
float f1 = nmsPlayer.pitch;
|
||||
float f2 = nmsPlayer.yaw;
|
||||
double d0 = nmsPlayer.locX;
|
||||
double d1 = nmsPlayer.locY + nmsPlayer.getHeadHeight();
|
||||
double d2 = nmsPlayer.locZ;
|
||||
Vec3D vec3d = new Vec3D(d0, d1, d2);
|
||||
|
||||
float f3 = MathHelper.cos(-f2 * 0.01745329F - 3.141593F);
|
||||
float f4 = MathHelper.sin(-f2 * 0.01745329F - 3.141593F);
|
||||
float f5 = -MathHelper.cos(-f1 * 0.01745329F);
|
||||
float f6 = MathHelper.sin(-f1 * 0.01745329F);
|
||||
float f7 = f4 * f5;
|
||||
float f8 = f3 * f5;
|
||||
nmsPlayer.playerInteractManager.getGameMode();
|
||||
double d3 = nmsPlayer.playerInteractManager.getGameMode() == EnumGamemode.CREATIVE ? 5 : 4.5;
|
||||
Vec3D vec3d1 = vec3d.add(f7 * d3, f6 * d3, f8 * d3);
|
||||
MovingObjectPosition movingobjectposition = nmsPlayer.world.rayTrace(vec3d, vec3d1, false);
|
||||
|
||||
if (movingobjectposition != null && movingobjectposition.type == MovingObjectPosition.EnumMovingObjectType.BLOCK)
|
||||
{
|
||||
CraftEventFactory.callPlayerInteractEvent(nmsPlayer, Action.LEFT_CLICK_AIR,
|
||||
nmsPlayer.inventory.getItemInHand());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet.action == EnumEntityUseAction.ATTACK)
|
||||
if (!list.contains(packet.a))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -9,6 +9,9 @@ import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import mineplex.cache.player.PlayerCache;
|
||||
import mineplex.cache.player.PlayerInfo;
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.account.command.TestRank;
|
||||
import mineplex.core.account.command.UpdateRank;
|
||||
@ -24,8 +27,6 @@ import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.timing.TimingManager;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.playerCache.PlayerCache;
|
||||
import mineplex.playerCache.PlayerInfo;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -34,6 +35,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
@ -47,7 +49,7 @@ public class CoreClientManager extends MiniPlugin
|
||||
private AccountRepository _repository;
|
||||
private NautHashMap<String, CoreClient> _clientList;
|
||||
private HashSet<String> _duplicateLoginGlitchPreventionList;
|
||||
|
||||
|
||||
private NautHashMap<String, ILoginProcessor> _loginProcessors = new NautHashMap<String, ILoginProcessor>();
|
||||
private LinkedList<IQuerylessLoginProcessor> _querylessLoginProcessors = new LinkedList<IQuerylessLoginProcessor>();
|
||||
|
||||
@ -572,4 +574,10 @@ public class CoreClientManager extends MiniPlugin
|
||||
|
||||
return client.GetRank().has(rank);
|
||||
}
|
||||
|
||||
public int getCachedClientAccountId(UUID uuid)
|
||||
{
|
||||
PlayerInfo playerInfo = PlayerCache.getInstance().getPlayer(uuid);
|
||||
return playerInfo == null ? -1 : playerInfo.getAccountId();
|
||||
}
|
||||
}
|
@ -10,4 +10,4 @@ public interface ILoginProcessor
|
||||
void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException;
|
||||
|
||||
String getQuery(int accountId, String uuid, String name);
|
||||
}
|
||||
}
|