Code cleanup and Optimizations

This commit is contained in:
MattBDev
2016-03-29 00:56:44 -04:00
parent 49d18b9229
commit 32ba55baf5
34 changed files with 456 additions and 540 deletions

View File

@ -40,10 +40,9 @@ public class DefaultTitleManager {
private boolean ticks = false;
/**
* Create a new 1.8 title
* Create a new 1.8 title.
*
* @param title
* Title
* @param title Title
* @throws ClassNotFoundException
*/
public DefaultTitleManager(String title) throws ClassNotFoundException {
@ -52,12 +51,10 @@ public class DefaultTitleManager {
}
/**
* Create a new 1.8 title
* Create a new 1.8 title.
*
* @param title
* Title text
* @param subtitle
* Subtitle text
* @param title Title text
* @param subtitle Subtitle text
* @throws ClassNotFoundException
*/
public DefaultTitleManager(String title, String subtitle) throws ClassNotFoundException {
@ -118,8 +115,7 @@ public class DefaultTitleManager {
}
/**
* Load spigot and NMS classes
* @throws ClassNotFoundException
* Load spigot and NMS classes.
*/
private void loadClasses() {
this.packetTitle = Reflection.getNMSClass("PacketPlayOutTitle");
@ -129,7 +125,7 @@ public class DefaultTitleManager {
}
/**
* Get title text
* Get title text.
*
* @return Title text
*/
@ -138,17 +134,16 @@ public class DefaultTitleManager {
}
/**
* Set title text
* Set title text.
*
* @param title
* Title
* @param title Title
*/
public void setTitle(String title) {
this.title = title;
}
/**
* Get subtitle text
* Get subtitle text.
*
* @return Subtitle text
*/

View File

@ -6,7 +6,6 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
@ -53,12 +52,10 @@ public class DefaultTitleManager_183 {
}
/**
* Create a new 1.8 title
* Create a new 1.8 title.
*
* @param title
* Title text
* @param subtitle
* Subtitle text
* @param title Title text
* @param subtitle Subtitle text
* @throws ClassNotFoundException
*/
public DefaultTitleManager_183(String title, String subtitle) throws ClassNotFoundException {
@ -68,10 +65,9 @@ public class DefaultTitleManager_183 {
}
/**
* Copy 1.8 title
* Copy 1.8 title.
*
* @param title
* Title
* @param title Title
* @throws ClassNotFoundException
*/
public DefaultTitleManager_183(DefaultTitleManager_183 title) throws ClassNotFoundException {
@ -88,18 +84,13 @@ public class DefaultTitleManager_183 {
}
/**
* Create a new 1.8 title
* Create a new 1.8 title.
*
* @param title
* Title text
* @param subtitle
* Subtitle text
* @param fadeInTime
* Fade in time
* @param stayTime
* Stay on screen time
* @param fadeOutTime
* Fade out time
* @param title Title text
* @param subtitle Subtitle text
* @param fadeInTime Fade in time
* @param stayTime Stay on screen time
* @param fadeOutTime Fade out time
* @throws ClassNotFoundException
*/
public DefaultTitleManager_183(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) throws ClassNotFoundException {
@ -124,8 +115,7 @@ public class DefaultTitleManager_183 {
}
/**
* Load spigot and NMS classes
* @throws ClassNotFoundException
* Load spigot and NMS classes.
*/
private void loadClasses() {
this.packetTitle = Reflection.getNMSClass("PacketPlayOutTitle");
@ -136,7 +126,7 @@ public class DefaultTitleManager_183 {
}
/**
* Get title text
* Get title text.
*
* @return Title text
*/
@ -145,17 +135,16 @@ public class DefaultTitleManager_183 {
}
/**
* Set title text
* Set title text.
*
* @param title
* Title
* @param title Title
*/
public void setTitle(String title) {
this.title = title;
}
/**
* Get subtitle text
* Get subtitle text.
*
* @return Subtitle text
*/
@ -164,37 +153,34 @@ public class DefaultTitleManager_183 {
}
/**
* Set subtitle text
* Set subtitle text.
*
* @param subtitle
* Subtitle text
* @param subtitle Subtitle text
*/
public void setSubtitle(String subtitle) {
this.subtitle = subtitle;
}
/**
* Set the title color
* Set the title color.
*
* @param color
* Chat color
* @param color Chat color
*/
public void setTitleColor(ChatColor color) {
this.titleColor = color;
}
/**
* Set the subtitle color
* Set the subtitle color.
*
* @param color
* Chat color
* @param color Chat color
*/
public void setSubtitleColor(ChatColor color) {
this.subtitleColor = color;
}
/**
* Set title fade in time
* Set title fade in time.
*
* @param time
* Time
@ -204,47 +190,42 @@ public class DefaultTitleManager_183 {
}
/**
* Set title fade out time
* Set title fade out time.
*
* @param time
* Time
* @param time Time
*/
public void setFadeOutTime(int time) {
this.fadeOutTime = time;
}
/**
* Set title stay time
* Set title stay time.
*
* @param time
* Time
* @param time Time
*/
public void setStayTime(int time) {
this.stayTime = time;
}
/**
* Set timings to ticks
* Set timings to ticks.
*/
public void setTimingsToTicks() {
this.ticks = true;
}
/**
* Set timings to seconds
* Set timings to seconds.
*/
public void setTimingsToSeconds() {
this.ticks = false;
}
/**
* Send the title to a player
* Send the title to a player.
*
* @param player
* Player
* @throws InvocationTargetException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @param player Player
* @throws Exception
*/
public void send(Player player) throws Exception {
if (this.packetTitle != null) {
@ -258,11 +239,7 @@ public class DefaultTitleManager_183 {
Object packet = this.packetTitle
.getConstructor(this.packetActions, this.chatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE)
.newInstance(actions[2], null,
this.fadeInTime * (
this.ticks ? 1 : 20),
this.fadeInTime * (this.ticks ? 1 : 20),
this.stayTime * (this.ticks ? 1 : 20), this.fadeOutTime * (this.ticks ? 1 : 20));
// Send if set
if ((this.fadeInTime != -1) && (this.fadeOutTime != -1) && (this.stayTime != -1)) {
@ -285,7 +262,7 @@ public class DefaultTitleManager_183 {
}
/**
* Broadcast the title to all players
* Broadcast the title to all players.
* @throws Exception
*/
public void broadcast() throws Exception {
@ -295,12 +272,10 @@ public class DefaultTitleManager_183 {
}
/**
* Clear the title
* Clear the title.
*
* @param player
* Player
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @param player Player
* @throws Exception
*/
public void clearTitle(Player player) throws Exception {
// Send timings first
@ -313,16 +288,10 @@ public class DefaultTitleManager_183 {
}
/**
* Reset the title settings
* Reset the title settings.
*
* @param player
* Player
* @throws SecurityException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @throws InstantiationException
* @param player Player
* @throws Exception
*/
public void resetTitle(Player player) throws Exception {
// Send timings first

View File

@ -114,7 +114,6 @@ public class HackTitleManager {
/**
* Load spigot and NMS classes.
* @throws ClassNotFoundException Spigot Error.
*/
private void loadClasses() {
this.packetTitle = getClass("org.spigotmc.ProtocolInjector$PacketTitle");