mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 10:14:42 +02:00
Cleanup and Optimizations
Abstracted TitleManagers Removed a lot of Statics. ETC.
This commit is contained in:
@ -47,14 +47,6 @@ import java.util.UUID;
|
||||
*/
|
||||
public class PlotAPI {
|
||||
|
||||
/**
|
||||
* Permission that allows for admin access, this permission node will allow
|
||||
* the player to use any part of the plugin, without limitations.
|
||||
* @deprecated Use C.PERMISSION_ADMIN instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String ADMIN_PERMISSION = C.PERMISSION_ADMIN.s();
|
||||
|
||||
/**
|
||||
* Deprecated, does nothing.
|
||||
* @param plugin not needed
|
||||
@ -64,24 +56,6 @@ public class PlotAPI {
|
||||
public PlotAPI(JavaPlugin plugin) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Default Constructor that does nothing.
|
||||
*
|
||||
* @deprecated Use this class if you just want to do a few simple things
|
||||
* <ul>
|
||||
* <li>It will remain stable for future versions
|
||||
* of the plugin</li>
|
||||
* <li>The PlotPlayer and Plot class should be considered
|
||||
* relatively safe</li>
|
||||
* <li>For more advanced/intensive tasks you should consider
|
||||
* using other classes</li>
|
||||
* </ul>
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public PlotAPI() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all plots.
|
||||
*
|
||||
|
@ -75,6 +75,7 @@ import com.plotsquared.bukkit.uuid.SQLUUIDHandler;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
@ -96,7 +97,6 @@ import java.util.UUID;
|
||||
|
||||
public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
|
||||
public static BukkitMain THIS;
|
||||
public static WorldEditPlugin worldEdit;
|
||||
|
||||
private int[] version;
|
||||
@ -124,7 +124,6 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
BukkitMain.THIS = this;
|
||||
new PS(this, "Bukkit");
|
||||
}
|
||||
|
||||
@ -132,40 +131,35 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
public void onDisable() {
|
||||
PS.get().disable();
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
BukkitMain.THIS = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String message) {
|
||||
if (BukkitMain.THIS != null) {
|
||||
try {
|
||||
message = C.color(message);
|
||||
if (!Settings.CONSOLE_COLOR) {
|
||||
message = ChatColor.stripColor(message);
|
||||
}
|
||||
this.getServer().getConsoleSender().sendMessage(message);
|
||||
return;
|
||||
} catch (Throwable ignored) {
|
||||
//ignored
|
||||
try {
|
||||
message = C.color(message);
|
||||
if (!Settings.CONSOLE_COLOR) {
|
||||
message = ChatColor.stripColor(message);
|
||||
}
|
||||
this.getServer().getConsoleSender().sendMessage(message);
|
||||
return;
|
||||
} catch (Throwable ignored) {
|
||||
//ignored
|
||||
}
|
||||
System.out.println(ConsoleColors.fromString(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
if (BukkitMain.THIS != null) {
|
||||
onDisable();
|
||||
}
|
||||
onDisable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getPluginVersion() {
|
||||
String version = getDescription().getVersion();
|
||||
if (version.contains("-SNAPSHOT")) {
|
||||
version = version.split("-SNAPSHOT")[0];
|
||||
String ver = getDescription().getVersion();
|
||||
if (ver.contains("-SNAPSHOT")) {
|
||||
ver = ver.split("-SNAPSHOT")[0];
|
||||
}
|
||||
String[] split = version.split("\\.");
|
||||
String[] split = ver.split("\\.");
|
||||
return new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])};
|
||||
}
|
||||
|
||||
@ -190,7 +184,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
|
||||
@Override
|
||||
public TaskManager getTaskManager() {
|
||||
return new BukkitTaskManager();
|
||||
return new BukkitTaskManager(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -403,7 +397,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotQueue initPlotQueue() {
|
||||
public PlotQueue<Chunk> initPlotQueue() {
|
||||
try {
|
||||
new SendChunk();
|
||||
MainUtil.canSendChunk = true;
|
||||
|
@ -4,6 +4,7 @@ import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
@ -22,6 +23,7 @@ import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
@ -34,6 +36,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
||||
private final List<BlockPopulator> populators = new ArrayList<>();
|
||||
private final ChunkGenerator platformGenerator;
|
||||
private final boolean full;
|
||||
private final HashMap<ChunkLoc, byte[][]> dataMap = new HashMap<>();
|
||||
private boolean loaded = false;
|
||||
|
||||
public BukkitPlotGenerator(IndependentPlotGenerator generator) {
|
||||
@ -42,10 +45,26 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
||||
this.populators.add(new BlockPopulator() {
|
||||
@Override
|
||||
public void populate(World world, Random r, Chunk c) {
|
||||
GenChunk result = (GenChunk) BukkitPlotGenerator.this.chunkSetter;
|
||||
if (result.result_data != null) {
|
||||
for (int i = 0; i < result.result_data.length; i++) {
|
||||
byte[] section = result.result_data[i];
|
||||
ChunkLoc loc = new ChunkLoc(c.getX(), c.getZ());
|
||||
byte[][] resultData;
|
||||
if (!BukkitPlotGenerator.this.dataMap.containsKey(loc)) {
|
||||
GenChunk result = (GenChunk) BukkitPlotGenerator.this.chunkSetter;
|
||||
// Set the chunk location
|
||||
result.setChunkWrapper(SetQueue.IMP.new ChunkWrapper(world.getName(), loc.x, loc.z));
|
||||
// Set the result data
|
||||
result.result = new short[16][];
|
||||
result.result_data = new byte[16][];
|
||||
result.grid = null;
|
||||
result.cd = null;
|
||||
// Catch any exceptions (as exceptions usually thrown)
|
||||
generate(world, loc.x, loc.z, result);
|
||||
resultData = result.result_data;
|
||||
} else {
|
||||
resultData = BukkitPlotGenerator.this.dataMap.remove(loc);
|
||||
}
|
||||
if (resultData != null) {
|
||||
for (int i = 0; i < resultData.length; i++) {
|
||||
byte[] section = resultData[i];
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
@ -247,8 +266,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
||||
// Return the result data
|
||||
return result.cd;
|
||||
}
|
||||
|
||||
public void generate(World world, int cx, int cz, GenChunk result) {
|
||||
|
||||
public void generate(World world, int cx, int cz, PlotChunk<?> result) {
|
||||
// Load if improperly loaded
|
||||
if (!this.loaded) {
|
||||
String name = world.getName();
|
||||
@ -283,6 +302,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
||||
return this.platformGenerator.generateExtBlockSections(world, r, cx, cz, grid);
|
||||
} else {
|
||||
generate(world, cx, cz, result);
|
||||
this.dataMap.put(new ChunkLoc(cx, cz), result.result_data);
|
||||
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
@ -306,7 +327,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this.platformGenerator == this) {
|
||||
return "" + this.plotGenerator;
|
||||
return this.plotGenerator.getName();
|
||||
}
|
||||
if (this.platformGenerator == null) {
|
||||
return "null";
|
||||
|
@ -110,16 +110,6 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.projectiles.BlockProjectileSource;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.bukkit.util.Vector;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -476,8 +466,8 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void playerRespawn(PlayerRespawnEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
EventUtil.manager.doDeathTask(pp);
|
||||
}
|
||||
|
||||
@ -784,20 +774,16 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBS(BlockSpreadEvent e) {
|
||||
Block b = e.getBlock();
|
||||
Location loc = BukkitUtil.getLocation(b.getLocation());
|
||||
if (loc.isPlotRoad()) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
public void onBlockSpread(BlockSpreadEvent event) {
|
||||
onBlockForm(event); //send to super class.
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBF(BlockFormEvent e) {
|
||||
Block b = e.getBlock();
|
||||
Location loc = BukkitUtil.getLocation(b.getLocation());
|
||||
public void onBlockForm(BlockFormEvent event) {
|
||||
Block block = event.getBlock();
|
||||
Location loc = BukkitUtil.getLocation(block.getLocation());
|
||||
if (loc.isPlotRoad()) {
|
||||
e.setCancelled(true);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,83 +1,14 @@
|
||||
package com.plotsquared.bukkit.titles;
|
||||
|
||||
import com.plotsquared.bukkit.chat.Reflection;
|
||||
import org.bukkit.Bukkit;
|
||||
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;
|
||||
|
||||
/**
|
||||
* [ PlotSquared DefaultTitleManager by Maxim Van de Wynckel ]
|
||||
*
|
||||
* @author Maxim Van de Wynckel
|
||||
*
|
||||
*/
|
||||
public class DefaultTitleManager {
|
||||
|
||||
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<>();
|
||||
/* Title packet */
|
||||
private Class<?> packetTitle;
|
||||
/* Title packet actions ENUM */
|
||||
private Class<?> packetActions;
|
||||
/* Chat serializer */
|
||||
private Class<?> nmsChatSerializer;
|
||||
private Class<?> chatBaseComponent;
|
||||
/* Title text and color */
|
||||
private String title = "";
|
||||
private ChatColor titleColor = ChatColor.WHITE;
|
||||
/* Subtitle text and color */
|
||||
private String subtitle = "";
|
||||
private ChatColor subtitleColor = ChatColor.WHITE;
|
||||
/* Title timings */
|
||||
private int fadeInTime = -1;
|
||||
private int stayTime = -1;
|
||||
private int fadeOutTime = -1;
|
||||
private boolean ticks = false;
|
||||
|
||||
/**
|
||||
* Create a new 1.8 title.
|
||||
*
|
||||
* @param title Title
|
||||
*/
|
||||
public DefaultTitleManager(String title) {
|
||||
this.title = title;
|
||||
loadClasses();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new 1.8 title.
|
||||
*
|
||||
* @param title Title text
|
||||
* @param subtitle Subtitle text
|
||||
*/
|
||||
public DefaultTitleManager(String title, String subtitle) {
|
||||
this.title = title;
|
||||
this.subtitle = subtitle;
|
||||
loadClasses();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy 1.8 title.
|
||||
*
|
||||
* @param title Title
|
||||
*/
|
||||
public DefaultTitleManager(DefaultTitleManager title) {
|
||||
// Copy title
|
||||
this.title = title.title;
|
||||
this.subtitle = title.subtitle;
|
||||
this.titleColor = title.titleColor;
|
||||
this.subtitleColor = title.subtitleColor;
|
||||
this.fadeInTime = title.fadeInTime;
|
||||
this.fadeOutTime = title.fadeOutTime;
|
||||
this.stayTime = title.stayTime;
|
||||
this.ticks = title.ticks;
|
||||
loadClasses();
|
||||
}
|
||||
public class DefaultTitleManager extends TitleManager {
|
||||
|
||||
/**
|
||||
* Create a new 1.8 title.
|
||||
@ -89,12 +20,7 @@ public class DefaultTitleManager {
|
||||
* @param fadeOutTime Fade out time
|
||||
*/
|
||||
public DefaultTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
|
||||
this.title = title;
|
||||
this.subtitle = subtitle;
|
||||
this.fadeInTime = fadeInTime;
|
||||
this.stayTime = stayTime;
|
||||
this.fadeOutTime = fadeOutTime;
|
||||
loadClasses();
|
||||
super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
|
||||
}
|
||||
|
||||
private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
|
||||
@ -112,115 +38,20 @@ public class DefaultTitleManager {
|
||||
/**
|
||||
* Load spigot and NMS classes.
|
||||
*/
|
||||
private void loadClasses() {
|
||||
@Override void loadClasses() {
|
||||
this.packetTitle = Reflection.getNMSClass("PacketPlayOutTitle");
|
||||
this.packetActions = Reflection.getNMSClass("EnumTitleAction");
|
||||
this.chatBaseComponent = Reflection.getNMSClass("IChatBaseComponent");
|
||||
this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return Title text
|
||||
*/
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title text.
|
||||
*
|
||||
* @param title Title
|
||||
*/
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subtitle text.
|
||||
*
|
||||
* @return Subtitle text
|
||||
*/
|
||||
public String getSubtitle() {
|
||||
return this.subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set subtitle text.
|
||||
*
|
||||
* @param subtitle Subtitle text
|
||||
*/
|
||||
public void setSubtitle(String subtitle) {
|
||||
this.subtitle = subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the title color.
|
||||
*
|
||||
* @param color Chat color
|
||||
*/
|
||||
public void setTitleColor(ChatColor color) {
|
||||
this.titleColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the subtitle color.
|
||||
*
|
||||
* @param color Chat color
|
||||
*/
|
||||
public void setSubtitleColor(ChatColor color) {
|
||||
this.subtitleColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title fade in time.
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public void setFadeInTime(int time) {
|
||||
this.fadeInTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title fade out time.
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public void setFadeOutTime(int time) {
|
||||
this.fadeOutTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title stay time.
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public void setStayTime(int time) {
|
||||
this.stayTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set timings to ticks.
|
||||
*/
|
||||
public void setTimingsToTicks() {
|
||||
this.ticks = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set timings to seconds.
|
||||
*/
|
||||
public void setTimingsToSeconds() {
|
||||
this.ticks = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the title to a player.
|
||||
*
|
||||
* @param player Player
|
||||
* @throws Exception
|
||||
*/
|
||||
public void send(Player player) throws Exception {
|
||||
@Override public void send(Player player) throws Exception {
|
||||
if (this.packetTitle != null) {
|
||||
// First reset previous settings
|
||||
resetTitle(player);
|
||||
@ -238,13 +69,14 @@ public class DefaultTitleManager {
|
||||
}
|
||||
// Send title
|
||||
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.title) + "\",color:" + this.titleColor.name().toLowerCase() + "}");
|
||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle()) + "\",color:" + this.titleColor.name().toLowerCase()
|
||||
+ "}");
|
||||
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[0], serialized);
|
||||
sendPacket.invoke(connection, packet);
|
||||
if (!this.subtitle.isEmpty()) {
|
||||
if (!this.getSubtitle().isEmpty()) {
|
||||
// Send subtitle if present
|
||||
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.subtitle) + "\",color:" + this.subtitleColor.name()
|
||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle()) + "\",color:" + this.subtitleColor.name()
|
||||
.toLowerCase() + "}");
|
||||
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[1], serialized);
|
||||
sendPacket.invoke(connection, packet);
|
||||
@ -252,24 +84,13 @@ public class DefaultTitleManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast the title to all players.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void broadcast() throws Exception {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
send(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the title.
|
||||
*
|
||||
* @param player Player
|
||||
* @throws Exception
|
||||
*/
|
||||
public void clearTitle(Player player) throws Exception {
|
||||
@Override public void clearTitle(Player player) throws Exception {
|
||||
// Send timings first
|
||||
Object handle = getHandle(player);
|
||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||
@ -285,7 +106,7 @@ public class DefaultTitleManager {
|
||||
* @param player Player
|
||||
* @throws Exception
|
||||
*/
|
||||
public void resetTitle(Player player) throws Exception {
|
||||
@Override public void resetTitle(Player player) throws Exception {
|
||||
// Send timings first
|
||||
Object handle = getHandle(player);
|
||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||
@ -295,29 +116,10 @@ public class DefaultTitleManager {
|
||||
sendPacket.invoke(connection, packet);
|
||||
}
|
||||
|
||||
private Class<?> getPrimitiveType(Class<?> clazz) {
|
||||
return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES.get(clazz) : clazz;
|
||||
}
|
||||
|
||||
private Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
|
||||
int a = classes != null ? classes.length : 0;
|
||||
Class<?>[] types = new Class<?>[a];
|
||||
for (int i = 0; i < a; i++) {
|
||||
types[i] = getPrimitiveType(classes[i]);
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
private Object getHandle(Object obj) {
|
||||
try {
|
||||
return getMethod("getHandle", obj.getClass()).invoke(obj);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (InvocationTargetException e) {
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@ -339,10 +141,7 @@ public class DefaultTitleManager {
|
||||
Field field = clazz.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (SecurityException e) {
|
||||
} catch (NoSuchFieldException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
@ -1,83 +1,13 @@
|
||||
package com.plotsquared.bukkit.titles;
|
||||
|
||||
import com.plotsquared.bukkit.chat.Reflection;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* [ PlotSquared DefaultTitleManager by Maxim Van de Wynckel ]
|
||||
*
|
||||
* @version 1.1.0
|
||||
* @author Maxim Van de Wynckel
|
||||
*
|
||||
*/
|
||||
public class DefaultTitleManager_183 {
|
||||
|
||||
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<>();
|
||||
/* Title packet */
|
||||
private Class<?> packetTitle;
|
||||
/* Title packet actions ENUM */
|
||||
private Class<?> packetActions;
|
||||
/* Chat serializer */
|
||||
private Class<?> nmsChatSerializer;
|
||||
private Class<?> chatBaseComponent;
|
||||
/* Title text and color */
|
||||
private String title = "";
|
||||
private ChatColor titleColor = ChatColor.WHITE;
|
||||
/* Subtitle text and color */
|
||||
private String subtitle = "";
|
||||
private ChatColor subtitleColor = ChatColor.WHITE;
|
||||
/* Title timings */
|
||||
private int fadeInTime = -1;
|
||||
private int stayTime = -1;
|
||||
private int fadeOutTime = -1;
|
||||
private boolean ticks = false;
|
||||
|
||||
/**
|
||||
* Create a new 1.8 title
|
||||
*
|
||||
* @param title Title
|
||||
*/
|
||||
public DefaultTitleManager_183(String title) {
|
||||
this.title = title;
|
||||
loadClasses();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new 1.8 title.
|
||||
*
|
||||
* @param title Title text
|
||||
* @param subtitle Subtitle text
|
||||
*/
|
||||
public DefaultTitleManager_183(String title, String subtitle) {
|
||||
this.title = title;
|
||||
this.subtitle = subtitle;
|
||||
loadClasses();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy 1.8 title.
|
||||
*
|
||||
* @param title Title
|
||||
*/
|
||||
public DefaultTitleManager_183(DefaultTitleManager_183 title) {
|
||||
// Copy title
|
||||
this.title = title.title;
|
||||
this.subtitle = title.subtitle;
|
||||
this.titleColor = title.titleColor;
|
||||
this.subtitleColor = title.subtitleColor;
|
||||
this.fadeInTime = title.fadeInTime;
|
||||
this.fadeOutTime = title.fadeOutTime;
|
||||
this.stayTime = title.stayTime;
|
||||
this.ticks = title.ticks;
|
||||
loadClasses();
|
||||
}
|
||||
public class DefaultTitleManager_183 extends TitleManager {
|
||||
|
||||
/**
|
||||
* Create a new 1.8 title.
|
||||
@ -89,12 +19,7 @@ public class DefaultTitleManager_183 {
|
||||
* @param fadeOutTime Fade out time
|
||||
*/
|
||||
public DefaultTitleManager_183(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
|
||||
this.title = title;
|
||||
this.subtitle = subtitle;
|
||||
this.fadeInTime = fadeInTime;
|
||||
this.stayTime = stayTime;
|
||||
this.fadeOutTime = fadeOutTime;
|
||||
loadClasses();
|
||||
super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
|
||||
}
|
||||
|
||||
private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
|
||||
@ -112,7 +37,8 @@ public class DefaultTitleManager_183 {
|
||||
/**
|
||||
* Load spigot and NMS classes.
|
||||
*/
|
||||
private void loadClasses() {
|
||||
@Override
|
||||
void loadClasses() {
|
||||
this.packetTitle = Reflection.getNMSClass("PacketPlayOutTitle");
|
||||
this.chatBaseComponent = Reflection.getNMSClass("IChatBaseComponent");
|
||||
this.packetActions = Reflection.getNMSClass("PacketPlayOutTitle$EnumTitleAction");
|
||||
@ -120,108 +46,7 @@ public class DefaultTitleManager_183 {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return Title text
|
||||
*/
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title text.
|
||||
*
|
||||
* @param title Title
|
||||
*/
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subtitle text.
|
||||
*
|
||||
* @return Subtitle text
|
||||
*/
|
||||
public String getSubtitle() {
|
||||
return this.subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set subtitle text.
|
||||
*
|
||||
* @param subtitle Subtitle text
|
||||
*/
|
||||
public void setSubtitle(String subtitle) {
|
||||
this.subtitle = subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the title color.
|
||||
*
|
||||
* @param color Chat color
|
||||
*/
|
||||
public void setTitleColor(ChatColor color) {
|
||||
this.titleColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the subtitle color.
|
||||
*
|
||||
* @param color Chat color
|
||||
*/
|
||||
public void setSubtitleColor(ChatColor color) {
|
||||
this.subtitleColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title fade in time.
|
||||
*
|
||||
* @param time
|
||||
* Time
|
||||
*/
|
||||
public void setFadeInTime(int time) {
|
||||
this.fadeInTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title fade out time.
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public void setFadeOutTime(int time) {
|
||||
this.fadeOutTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title stay time.
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public void setStayTime(int time) {
|
||||
this.stayTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set timings to ticks.
|
||||
*/
|
||||
public void setTimingsToTicks() {
|
||||
this.ticks = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set timings to seconds.
|
||||
*/
|
||||
public void setTimingsToSeconds() {
|
||||
this.ticks = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the title to a player.
|
||||
*
|
||||
* @param player Player
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void send(Player player) throws Exception {
|
||||
if (this.packetTitle != null) {
|
||||
// First reset previous settings
|
||||
@ -242,13 +67,14 @@ public class DefaultTitleManager_183 {
|
||||
}
|
||||
// Send title
|
||||
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.title) + "\",color:" + this.titleColor.name().toLowerCase() + "}");
|
||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle()) + "\",color:" + this.titleColor.name().toLowerCase()
|
||||
+ "}");
|
||||
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[0], serialized);
|
||||
sendPacket.invoke(connection, packet);
|
||||
if (!this.subtitle.isEmpty()) {
|
||||
if (!this.getSubtitle().isEmpty()) {
|
||||
// Send subtitle if present
|
||||
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.subtitle) + "\",color:" + this.subtitleColor.name()
|
||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle()) + "\",color:" + this.subtitleColor.name()
|
||||
.toLowerCase() + "}");
|
||||
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[1], serialized);
|
||||
sendPacket.invoke(connection, packet);
|
||||
@ -256,22 +82,13 @@ public class DefaultTitleManager_183 {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast the title to all players.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void broadcast() throws Exception {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
send(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the title.
|
||||
*
|
||||
* @param player Player
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void clearTitle(Player player) throws Exception {
|
||||
// Send timings first
|
||||
Object handle = getHandle(player);
|
||||
@ -288,6 +105,7 @@ public class DefaultTitleManager_183 {
|
||||
* @param player Player
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void resetTitle(Player player) throws Exception {
|
||||
// Send timings first
|
||||
Object handle = getHandle(player);
|
||||
@ -298,19 +116,6 @@ public class DefaultTitleManager_183 {
|
||||
sendPacket.invoke(connection, packet);
|
||||
}
|
||||
|
||||
private Class<?> getPrimitiveType(Class<?> clazz) {
|
||||
return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES.get(clazz) : clazz;
|
||||
}
|
||||
|
||||
private Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
|
||||
int a = classes != null ? classes.length : 0;
|
||||
Class<?>[] types = new Class<?>[a];
|
||||
for (int i = 0; i < a; i++) {
|
||||
types[i] = getPrimitiveType(classes[i]);
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
private Object getHandle(Object obj) {
|
||||
try {
|
||||
return getMethod("getHandle", obj.getClass()).invoke(obj);
|
||||
|
@ -11,7 +11,7 @@ public class DefaultTitle_183 extends AbstractTitle {
|
||||
try {
|
||||
DefaultTitleManager_183 title = new DefaultTitleManager_183(head, sub, in, delay, out);
|
||||
title.send(((BukkitPlayer) player).player);
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e) {
|
||||
AbstractTitle.TITLE_CLASS = new HackTitle();
|
||||
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class HackTitle extends AbstractTitle {
|
||||
try {
|
||||
HackTitleManager title = new HackTitleManager(head, sub, in, delay, out);
|
||||
title.send(((BukkitPlayer) player).player);
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e) {
|
||||
PS.debug("&cYour server version does not support titles!");
|
||||
Settings.TITLES = false;
|
||||
AbstractTitle.TITLE_CLASS = null;
|
||||
|
@ -8,75 +8,8 @@ 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;
|
||||
|
||||
/**
|
||||
* Minecraft 1.8 Title.
|
||||
*
|
||||
* @version 1.0.4
|
||||
* @author Maxim Van de Wynckel
|
||||
*/
|
||||
public class HackTitleManager {
|
||||
|
||||
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<>();
|
||||
/* Title packet */
|
||||
private Class<?> packetTitle;
|
||||
/* Title packet actions ENUM */
|
||||
private Class<?> packetActions;
|
||||
/* Chat serializer */
|
||||
private Class<?> nmsChatSerializer;
|
||||
/* Title text and color */
|
||||
private String title = "";
|
||||
private ChatColor titleColor = ChatColor.WHITE;
|
||||
/* Subtitle text and color */
|
||||
private String subtitle = "";
|
||||
private ChatColor subtitleColor = ChatColor.WHITE;
|
||||
/* Title timings. */
|
||||
private int fadeInTime = -1;
|
||||
private int stayTime = -1;
|
||||
private int fadeOutTime = -1;
|
||||
private boolean ticks = false;
|
||||
|
||||
/**
|
||||
* Create a new 1.8 title.
|
||||
*
|
||||
* @param title Title
|
||||
*/
|
||||
public HackTitleManager(String title) {
|
||||
this.title = title;
|
||||
loadClasses();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new 1.8 title.
|
||||
*
|
||||
* @param title Title text
|
||||
* @param subtitle Subtitle text
|
||||
*/
|
||||
public HackTitleManager(String title, String subtitle) {
|
||||
this.title = title;
|
||||
this.subtitle = subtitle;
|
||||
loadClasses();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy 1.8 title.
|
||||
*
|
||||
* @param title Title
|
||||
*/
|
||||
public HackTitleManager(HackTitleManager title) {
|
||||
// Copy title
|
||||
this.title = title.title;
|
||||
this.subtitle = title.subtitle;
|
||||
this.titleColor = title.titleColor;
|
||||
this.subtitleColor = title.subtitleColor;
|
||||
this.fadeInTime = title.fadeInTime;
|
||||
this.fadeOutTime = title.fadeOutTime;
|
||||
this.stayTime = title.stayTime;
|
||||
this.ticks = title.ticks;
|
||||
loadClasses();
|
||||
}
|
||||
public class HackTitleManager extends TitleManager {
|
||||
|
||||
/**
|
||||
* Create a new 1.8 title.
|
||||
@ -88,12 +21,7 @@ public class HackTitleManager {
|
||||
* @param fadeOutTime Fade out time
|
||||
*/
|
||||
public HackTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
|
||||
this.title = title;
|
||||
this.subtitle = subtitle;
|
||||
this.fadeInTime = fadeInTime;
|
||||
this.stayTime = stayTime;
|
||||
this.fadeOutTime = fadeOutTime;
|
||||
loadClasses();
|
||||
super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
|
||||
}
|
||||
|
||||
private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
|
||||
@ -111,114 +39,20 @@ public class HackTitleManager {
|
||||
/**
|
||||
* Load spigot and NMS classes.
|
||||
*/
|
||||
private void loadClasses() {
|
||||
@Override
|
||||
void loadClasses() {
|
||||
this.packetTitle = getClass("org.spigotmc.ProtocolInjector$PacketTitle");
|
||||
this.packetActions = getClass("org.spigotmc.ProtocolInjector$PacketTitle$Action");
|
||||
this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return Title text
|
||||
*/
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title text.
|
||||
*
|
||||
* @param title Title
|
||||
*/
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subtitle text.
|
||||
*
|
||||
* @return Subtitle text
|
||||
*/
|
||||
public String getSubtitle() {
|
||||
return this.subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set subtitle text.
|
||||
*
|
||||
* @param subtitle Subtitle text
|
||||
*/
|
||||
public void setSubtitle(String subtitle) {
|
||||
this.subtitle = subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the title color.
|
||||
*
|
||||
* @param color Chat color
|
||||
*/
|
||||
public void setTitleColor(ChatColor color) {
|
||||
this.titleColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the subtitle color.
|
||||
*
|
||||
* @param color Chat color
|
||||
*/
|
||||
public void setSubtitleColor(ChatColor color) {
|
||||
this.subtitleColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title fade in time.
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public void setFadeInTime(int time) {
|
||||
this.fadeInTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title fade out time.
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public void setFadeOutTime(int time) {
|
||||
this.fadeOutTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title stay time.
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public void setStayTime(int time) {
|
||||
this.stayTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set timings to ticks.
|
||||
*/
|
||||
public void setTimingsToTicks() {
|
||||
this.ticks = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set timings to seconds.
|
||||
*/
|
||||
public void setTimingsToSeconds() {
|
||||
this.ticks = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the title to a player.
|
||||
*
|
||||
* @param player Player
|
||||
* @throws Exception on NMS error
|
||||
*/
|
||||
public void send(Player player) throws Exception {
|
||||
@Override public void send(Player player) throws Exception {
|
||||
if ((getProtocolVersion(player) >= 47) && isSpigot() && (this.packetTitle != null)) {
|
||||
// First reset previous settings
|
||||
resetTitle(player);
|
||||
@ -237,14 +71,15 @@ public class HackTitleManager {
|
||||
}
|
||||
// Send title
|
||||
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.title) + "\",color:" + this.titleColor.name().toLowerCase() + "}");
|
||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle()) + "\",color:" + this.titleColor.name().toLowerCase()
|
||||
+ "}");
|
||||
packet = this.packetTitle.getConstructor(this.packetActions, Reflection.getNMSClass("IChatBaseComponent"))
|
||||
.newInstance(actions[0], serialized);
|
||||
sendPacket.invoke(connection, packet);
|
||||
if (!this.subtitle.isEmpty()) {
|
||||
if (!this.getSubtitle().isEmpty()) {
|
||||
// Send subtitle if present
|
||||
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.subtitle) + "\",color:" + this.subtitleColor.name()
|
||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle()) + "\",color:" + this.subtitleColor.name()
|
||||
.toLowerCase() + "}");
|
||||
packet = this.packetTitle.getConstructor(this.packetActions, Reflection.getNMSClass("IChatBaseComponent"))
|
||||
.newInstance(actions[1], serialized);
|
||||
@ -253,23 +88,13 @@ public class HackTitleManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast the title to all players.
|
||||
* @throws Exception on NMS Error
|
||||
*/
|
||||
public void broadcast() throws Exception {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
send(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the title.
|
||||
*
|
||||
* @param player Player
|
||||
* @throws Exception on NMS Error
|
||||
*/
|
||||
public void clearTitle(Player player) throws Exception {
|
||||
@Override public void clearTitle(Player player) throws Exception {
|
||||
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
|
||||
// Send timings first
|
||||
Object handle = getHandle(player);
|
||||
@ -287,7 +112,7 @@ public class HackTitleManager {
|
||||
* @param player Player
|
||||
* @throws Exception on NMS error.
|
||||
*/
|
||||
public void resetTitle(Player player) throws Exception {
|
||||
@Override public void resetTitle(Player player) throws Exception {
|
||||
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
|
||||
// Send timings first
|
||||
Object handle = getHandle(player);
|
||||
@ -346,19 +171,6 @@ public class HackTitleManager {
|
||||
return f.get(obj);
|
||||
}
|
||||
|
||||
private Class<?> getPrimitiveType(Class<?> clazz) {
|
||||
return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES.get(clazz) : clazz;
|
||||
}
|
||||
|
||||
private Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
|
||||
int a = classes != null ? classes.length : 0;
|
||||
Class<?>[] types = new Class<?>[a];
|
||||
for (int i = 0; i < a; i++) {
|
||||
types[i] = getPrimitiveType(classes[i]);
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
private Object getHandle(Object obj) {
|
||||
try {
|
||||
return getMethod("getHandle", obj.getClass()).invoke(obj);
|
||||
|
@ -0,0 +1,204 @@
|
||||
package com.plotsquared.bukkit.titles;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class TitleManager {
|
||||
|
||||
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<>();
|
||||
/* Title packet */
|
||||
Class<?> packetTitle;
|
||||
/* Title packet actions ENUM */
|
||||
Class<?> packetActions;
|
||||
/* Chat serializer */
|
||||
Class<?> nmsChatSerializer;
|
||||
Class<?> chatBaseComponent;
|
||||
ChatColor titleColor = ChatColor.WHITE;
|
||||
ChatColor subtitleColor = ChatColor.WHITE;
|
||||
/* Title timings */
|
||||
int fadeInTime = -1;
|
||||
int stayTime = -1;
|
||||
int fadeOutTime = -1;
|
||||
boolean ticks = false;
|
||||
/* Title text and color */
|
||||
private String title = "";
|
||||
/* Subtitle text and color */
|
||||
private String subtitle = "";
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
TitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
|
||||
this.title = title;
|
||||
this.subtitle = subtitle;
|
||||
this.fadeInTime = fadeInTime;
|
||||
this.stayTime = stayTime;
|
||||
this.fadeOutTime = fadeOutTime;
|
||||
loadClasses();
|
||||
}
|
||||
|
||||
abstract void loadClasses();
|
||||
|
||||
/**
|
||||
* Get title text.
|
||||
*
|
||||
* @return Title text
|
||||
*/
|
||||
public final String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title text.
|
||||
*
|
||||
* @param title Title
|
||||
*/
|
||||
public final void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subtitle text.
|
||||
*
|
||||
* @return Subtitle text
|
||||
*/
|
||||
public final String getSubtitle() {
|
||||
return this.subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set subtitle text.
|
||||
*
|
||||
* @param subtitle Subtitle text
|
||||
*/
|
||||
public final void setSubtitle(String subtitle) {
|
||||
this.subtitle = subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the title color.
|
||||
*
|
||||
* @param color Chat color
|
||||
*/
|
||||
public final void setTitleColor(ChatColor color) {
|
||||
this.titleColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the subtitle color.
|
||||
*
|
||||
* @param color Chat color
|
||||
*/
|
||||
public final void setSubtitleColor(ChatColor color) {
|
||||
this.subtitleColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title fade in time.
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public final void setFadeInTime(int time) {
|
||||
this.fadeInTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title fade out time.
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public final void setFadeOutTime(int time) {
|
||||
this.fadeOutTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title stay time.
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public final void setStayTime(int time) {
|
||||
this.stayTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set timings to ticks.
|
||||
*/
|
||||
public final void setTimingsToTicks() {
|
||||
this.ticks = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set timings to seconds.
|
||||
*/
|
||||
public final void setTimingsToSeconds() {
|
||||
this.ticks = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the title to a player.
|
||||
*
|
||||
* @param player Player
|
||||
* @throws Exception
|
||||
*/
|
||||
public abstract void send(Player player) throws Exception;
|
||||
|
||||
/**
|
||||
* Broadcast the title to all players.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public final void broadcast() throws Exception {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
send(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the title.
|
||||
*
|
||||
* @param player Player
|
||||
* @throws Exception
|
||||
*/
|
||||
public abstract void clearTitle(Player player) throws Exception;
|
||||
|
||||
/**
|
||||
* Reset the title settings.
|
||||
*
|
||||
* @param player Player
|
||||
* @throws Exception
|
||||
*/
|
||||
public abstract void resetTitle(Player player) throws Exception;
|
||||
|
||||
private Class<?> getPrimitiveType(Class<?> clazz) {
|
||||
if (CORRESPONDING_TYPES.containsKey(clazz)) {
|
||||
return CORRESPONDING_TYPES.get(clazz);
|
||||
} else {
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
|
||||
final Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
|
||||
int a;
|
||||
if (classes != null) {
|
||||
a = classes.length;
|
||||
} else {
|
||||
a = 0;
|
||||
}
|
||||
Class<?>[] types = new Class<?>[a];
|
||||
for (int i = 0; i < a; i++) {
|
||||
types[i] = getPrimitiveType(classes[i]);
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -15,16 +15,6 @@ public class BukkitEconHandler extends EconHandler {
|
||||
private Economy econ;
|
||||
private Permission perms;
|
||||
|
||||
public Economy getEconomy() {
|
||||
init();
|
||||
return this.econ;
|
||||
}
|
||||
|
||||
public Permission getPermissions() {
|
||||
init();
|
||||
return this.perms;
|
||||
}
|
||||
|
||||
public boolean init() {
|
||||
if (this.econ == null || this.perms == null) {
|
||||
setupPermissions();
|
||||
|
@ -6,35 +6,41 @@ import org.bukkit.Bukkit;
|
||||
|
||||
public class BukkitTaskManager extends TaskManager {
|
||||
|
||||
private final BukkitMain bukkitMain;
|
||||
|
||||
public BukkitTaskManager(BukkitMain bukkitMain) {
|
||||
this.bukkitMain = bukkitMain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int taskRepeat(Runnable runnable, int interval) {
|
||||
return BukkitMain.THIS.getServer().getScheduler().scheduleSyncRepeatingTask(BukkitMain.THIS, runnable, interval, interval);
|
||||
return this.bukkitMain.getServer().getScheduler().scheduleSyncRepeatingTask(this.bukkitMain, runnable, interval, interval);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public int taskRepeatAsync(Runnable runnable, int interval) {
|
||||
return BukkitMain.THIS.getServer().getScheduler().scheduleAsyncRepeatingTask(BukkitMain.THIS, runnable, interval, interval);
|
||||
return this.bukkitMain.getServer().getScheduler().scheduleAsyncRepeatingTask(this.bukkitMain, runnable, interval, interval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void taskAsync(Runnable runnable) {
|
||||
BukkitMain.THIS.getServer().getScheduler().runTaskAsynchronously(BukkitMain.THIS, runnable).getTaskId();
|
||||
this.bukkitMain.getServer().getScheduler().runTaskAsynchronously(this.bukkitMain, runnable).getTaskId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void task(Runnable runnable) {
|
||||
BukkitMain.THIS.getServer().getScheduler().runTask(BukkitMain.THIS, runnable).getTaskId();
|
||||
this.bukkitMain.getServer().getScheduler().runTask(this.bukkitMain, runnable).getTaskId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void taskLater(Runnable runnable, int delay) {
|
||||
BukkitMain.THIS.getServer().getScheduler().runTaskLater(BukkitMain.THIS, runnable, delay).getTaskId();
|
||||
this.bukkitMain.getServer().getScheduler().runTaskLater(this.bukkitMain, runnable, delay).getTaskId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void taskLaterAsync(Runnable runnable, int delay) {
|
||||
BukkitMain.THIS.getServer().getScheduler().runTaskLaterAsynchronously(BukkitMain.THIS, runnable, delay);
|
||||
this.bukkitMain.getServer().getScheduler().runTaskLaterAsynchronously(this.bukkitMain, runnable, delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -12,7 +12,6 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
||||
import com.intellectualcrafters.plot.util.SetQueue;
|
||||
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.bukkit.util.SendChunk;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
@ -370,7 +369,6 @@ public class FastQueue_1_8 extends SlowQueue {
|
||||
*/
|
||||
@Override
|
||||
public void sendChunk(String world, Collection<ChunkLoc> locations) {
|
||||
World worldObj = BukkitUtil.getWorld(world);
|
||||
for (ChunkLoc loc : locations) {
|
||||
ChunkWrapper wrapper = SetQueue.IMP.new ChunkWrapper(world, loc.x, loc.z);
|
||||
this.toUpdate.remove(wrapper);
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.plotsquared.bukkit.util.block;
|
||||
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.PseudoRandom;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
@ -15,6 +17,12 @@ import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.bukkit.util.SendChunk;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -24,14 +32,6 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
public class FastQueue_1_8_3 extends SlowQueue {
|
||||
|
||||
@ -266,7 +266,7 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
||||
World world = BukkitUtil.getWorld(worldname);
|
||||
Chunk chunk = world.getChunkAt(loc.x, loc.z);
|
||||
if (chunk.getTileEntities().length > 0) {
|
||||
Object w = methodGetHandleWorld.of(world).call();
|
||||
Object w = this.methodGetHandleWorld.of(world).call();
|
||||
((Collection) this.tileEntityListTick.of(w).get()).clear();
|
||||
}
|
||||
super.regenerateChunk(worldname, loc);
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.plotsquared.bukkit.util.block;
|
||||
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.PseudoRandom;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
@ -13,6 +15,12 @@ import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod.RefExecutor;
|
||||
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -22,14 +30,6 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
public class FastQueue_1_9 extends SlowQueue {
|
||||
|
||||
@ -85,8 +85,8 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
World world = BukkitUtil.getWorld(worldname);
|
||||
Chunk chunk = world.getChunkAt(loc.x, loc.z);
|
||||
if (chunk.getTileEntities().length > 0) {
|
||||
Object c = methodGetHandleChunk.of(chunk).call();
|
||||
Object w = methodGetWorld.of(c).call();
|
||||
Object c = this.methodGetHandleChunk.of(chunk).call();
|
||||
Object w = this.methodGetWorld.of(c).call();
|
||||
((Collection) this.tileEntityListTick.of(w).get()).clear();
|
||||
}
|
||||
super.regenerateChunk(worldname, loc);
|
||||
@ -97,7 +97,7 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
* @param plotChunk
|
||||
*/
|
||||
@Override
|
||||
public void execute(final PlotChunk<Chunk> plotChunk) {
|
||||
public void execute(PlotChunk<Chunk> plotChunk) {
|
||||
final FastChunk_1_9 fs = (FastChunk_1_9) plotChunk;
|
||||
Chunk chunk = plotChunk.getChunk();
|
||||
World world = chunk.getWorld();
|
||||
@ -425,7 +425,7 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
* @param locations
|
||||
*/
|
||||
@Override
|
||||
public void sendChunk(final String world, final Collection<ChunkLoc> locations) {
|
||||
public void sendChunk(String world, Collection<ChunkLoc> locations) {
|
||||
World worldObj = BukkitUtil.getWorld(world);
|
||||
for (ChunkLoc loc : locations) {
|
||||
worldObj.refreshChunk(loc.x, loc.z);
|
||||
|
@ -41,7 +41,9 @@ public class GenChunk extends PlotChunk<Chunk> {
|
||||
|
||||
@Override
|
||||
public void setBiome(int x, int z, int biome) {
|
||||
this.grid.setBiome(x, z, this.biomes[biome]);
|
||||
if (this.grid != null) {
|
||||
this.grid.setBiome(x, z, this.biomes[biome]);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBiome(int x, int z, Biome biome) {
|
||||
|
@ -9,13 +9,14 @@ import com.intellectualcrafters.plot.util.PlotQueue;
|
||||
import com.intellectualcrafters.plot.util.SetQueue;
|
||||
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public class SlowQueue implements PlotQueue<Chunk> {
|
||||
|
||||
|
Reference in New Issue
Block a user