-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 083d4df
Showing
5 changed files
with
295 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
BountifulAPI | ||
===================== | ||
|
||
Spigot Page/More Info: COMING SOON | ||
|
||
|
||
Made From: | ||
|
||
|
||
TitleAPI: http://www.spigotmc.org/resources/titleapi.1325/ | ||
|
||
ActionBarAPI: http://www.spigotmc.org/resources/actionbarapi.1315/ | ||
|
||
WhatVersion: http://www.spigotmc.org/resources/whatversion.1385/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
package com.connorlinfoot.bountifulapi; | ||
|
||
import net.minecraft.server.v1_7_R4.ChatSerializer; | ||
import net.minecraft.server.v1_7_R4.IChatBaseComponent; | ||
import net.minecraft.server.v1_7_R4.PacketPlayOutChat; | ||
import net.minecraft.server.v1_7_R4.PlayerConnection; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.Server; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.ConsoleCommandSender; | ||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.spigotmc.ProtocolInjector; | ||
|
||
|
||
public class BountifulAPI extends JavaPlugin implements Listener { | ||
|
||
@Deprecated | ||
public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String message) { | ||
sendTitle(player, fadeIn, stay, fadeOut, message, null); | ||
} | ||
|
||
@Deprecated | ||
public static void sendSubtitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String message) { | ||
sendTitle(player, fadeIn, stay, fadeOut, null, message); | ||
} | ||
|
||
@Deprecated | ||
public static void sendFullTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title, String subtitle) { | ||
sendTitle(player, fadeIn, stay, fadeOut, title, subtitle); | ||
} | ||
|
||
public static Integer getPlayerProtocol(Player player) { | ||
CraftPlayer craftPlayer = (CraftPlayer) player; | ||
return craftPlayer.getHandle().playerConnection.networkManager.getVersion(); | ||
} | ||
|
||
public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title, String subtitle) { | ||
CraftPlayer craftPlayer = (CraftPlayer) player; | ||
if (craftPlayer.getHandle().playerConnection.networkManager.getVersion() != 47) | ||
return; // If using 1.8, allow method to run | ||
|
||
if (title == null) title = ""; | ||
title = ChatColor.translateAlternateColorCodes('&', title); | ||
|
||
if (subtitle == null) subtitle = ""; | ||
subtitle = ChatColor.translateAlternateColorCodes('&', subtitle); | ||
|
||
title = title.replaceAll("%player%", player.getDisplayName()); | ||
subtitle = subtitle.replaceAll("%player%", player.getDisplayName()); | ||
|
||
IChatBaseComponent title2; | ||
IChatBaseComponent subtitle2; | ||
IChatBaseComponent serializedTitle = ChatSerializer.a(TextConverter.convert(title)); | ||
IChatBaseComponent serializedSubTitle = ChatSerializer.a(TextConverter.convert(subtitle)); | ||
title2 = serializedTitle; | ||
subtitle2 = serializedSubTitle; | ||
|
||
craftPlayer.getHandle().playerConnection.sendPacket(new ProtocolInjector.PacketTitle(ProtocolInjector.PacketTitle.Action.TIMES, fadeIn, stay, fadeOut)); | ||
if (title != null) | ||
craftPlayer.getHandle().playerConnection.sendPacket(new ProtocolInjector.PacketTitle(ProtocolInjector.PacketTitle.Action.TITLE, title2)); | ||
if (subtitle != null) | ||
craftPlayer.getHandle().playerConnection.sendPacket(new ProtocolInjector.PacketTitle(ProtocolInjector.PacketTitle.Action.SUBTITLE, subtitle2)); | ||
} | ||
|
||
public static void sendTabTitle(Player player, String header, String footer) { | ||
CraftPlayer craftPlayer = (CraftPlayer) player; | ||
if (craftPlayer.getHandle().playerConnection.networkManager.getVersion() != 47) | ||
return; // If using 1.8, allow method to run | ||
|
||
PlayerConnection connection = craftPlayer.getHandle().playerConnection; | ||
|
||
|
||
if (header == null) header = ""; | ||
header = ChatColor.translateAlternateColorCodes('&', header); | ||
|
||
if (footer == null) footer = ""; | ||
footer = ChatColor.translateAlternateColorCodes('&', footer); | ||
|
||
header = header.replaceAll("%player%", player.getDisplayName()); | ||
footer = footer.replaceAll("%player%", player.getDisplayName()); | ||
|
||
IChatBaseComponent header2 = ChatSerializer.a("{'color': 'white', 'text': '" + header + "'}"); | ||
IChatBaseComponent footer2 = ChatSerializer.a("{'color': 'white', 'text': '" + footer + "'}"); | ||
connection.sendPacket(new ProtocolInjector.PacketTabHeader(header2, footer2)); | ||
} | ||
|
||
public static void sendActionBar(Player player, String message) { | ||
CraftPlayer p = (CraftPlayer) player; | ||
if (p.getHandle().playerConnection.networkManager.getVersion() != 47) | ||
return; // Don't run if player is not on 1.8 | ||
IChatBaseComponent cbc = ChatSerializer.a("{\"text\": \"" + message + "\"}"); | ||
PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc, 2); | ||
p.getHandle().playerConnection.sendPacket(ppoc); | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String string, String[] args) { | ||
if (args.length < 6) { | ||
sender.sendMessage(ChatColor.RED + "Usage: /title <player> title|subtitle <fadeIn> <stay> <fadeOut> <text>"); | ||
sender.sendMessage(ChatColor.RED + "Note: fadeIn, stay &, fadeOut require to be a number, works in ticks; 20 = 1 second"); | ||
return false; | ||
} | ||
|
||
if (Bukkit.getPlayer(args[0]) == null) { | ||
sender.sendMessage(ChatColor.RED + "Player not found"); | ||
return false; | ||
} | ||
|
||
Player player = Bukkit.getPlayer(args[0]); | ||
|
||
if (!args[1].equalsIgnoreCase("title") && !args[1].equalsIgnoreCase("subtitle")) { | ||
sender.sendMessage(ChatColor.RED + "Invalid argument: " + args[1]); | ||
return false; | ||
} | ||
|
||
if (!isInteger(args[2])) { | ||
sender.sendMessage(ChatColor.RED + "Not a number: " + args[2]); | ||
return false; | ||
} | ||
|
||
if (!isInteger(args[3])) { | ||
sender.sendMessage(ChatColor.RED + "Not a number: " + args[3]); | ||
return false; | ||
} | ||
|
||
if (!isInteger(args[4])) { | ||
sender.sendMessage(ChatColor.RED + "Not a number: " + args[4]); | ||
return false; | ||
} | ||
|
||
StringBuilder builder = new StringBuilder(); | ||
for (String value : args) { | ||
builder.append(value).append(" "); | ||
} | ||
String message = builder.toString(); | ||
message = message.replace(args[0] + " ", ""); | ||
message = message.replace(args[1] + " ", ""); | ||
message = message.replace(args[2] + " ", ""); | ||
message = message.replace(args[3] + " ", ""); | ||
message = message.replace(args[4] + " ", ""); | ||
|
||
if (args[1].equalsIgnoreCase("title")) { | ||
sendTitle(player, Integer.parseInt(args[2]), Integer.parseInt(args[3]), Integer.parseInt(args[4]), message, null); | ||
sender.sendMessage(ChatColor.GREEN + "Title sent"); | ||
return true; | ||
} | ||
|
||
if (args[1].equalsIgnoreCase("subtitle")) { | ||
sendTitle(player, Integer.parseInt(args[2]), Integer.parseInt(args[3]), Integer.parseInt(args[4]), null, message); | ||
sender.sendMessage(ChatColor.GREEN + "Title sent"); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public void onEnable() { | ||
getConfig().options().copyDefaults(true); | ||
saveConfig(); | ||
Server server = getServer(); | ||
ConsoleCommandSender console = server.getConsoleSender(); | ||
|
||
console.sendMessage(""); | ||
console.sendMessage(ChatColor.BLUE + "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"); | ||
console.sendMessage(""); | ||
console.sendMessage(ChatColor.AQUA + getDescription().getName()); | ||
console.sendMessage(ChatColor.AQUA + "Version " + getDescription().getVersion()); | ||
console.sendMessage(""); | ||
console.sendMessage(ChatColor.BLUE + "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"); | ||
console.sendMessage(""); | ||
|
||
Bukkit.getPluginManager().registerEvents(this, this); | ||
} | ||
|
||
boolean isInteger(String s) { | ||
try { | ||
Integer.parseInt(s); | ||
} catch (NumberFormatException e) { | ||
return false; | ||
} | ||
// only got here if we didn't return false | ||
return true; | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerJoin(PlayerJoinEvent event) { | ||
if (getConfig().getBoolean("Title On Join")) { | ||
sendTitle(event.getPlayer(), 20, 50, 20, getConfig().getString("Title Message"), getConfig().getString("Subtitle Message")); | ||
} | ||
|
||
if (getConfig().getBoolean("Tab Header Enabled")) { | ||
sendTabTitle(event.getPlayer(), getConfig().getString("Tab Header Message"), getConfig().getString("Tab Footer Message")); | ||
} | ||
} | ||
|
||
public void onDisable() { | ||
getLogger().info(getDescription().getName() + " has been disabled!"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.connorlinfoot.bountifulapi; | ||
|
||
import org.bukkit.entity.Player; | ||
|
||
public class TextConverter { | ||
public static String convert(String text) { | ||
if (text == null || text.length() == 0) { | ||
return "\"\""; | ||
} | ||
|
||
char c; | ||
int i; | ||
int len = text.length(); | ||
StringBuilder sb = new StringBuilder(len + 4); | ||
String t; | ||
|
||
sb.append('"'); | ||
for (i = 0; i < len; i += 1) { | ||
c = text.charAt(i); | ||
switch (c) { | ||
case '\\': | ||
case '"': | ||
sb.append('\\'); | ||
sb.append(c); | ||
break; | ||
case '/': | ||
sb.append('\\'); | ||
sb.append(c); | ||
break; | ||
case '\b': | ||
sb.append("\\b"); | ||
break; | ||
case '\t': | ||
sb.append("\\t"); | ||
break; | ||
case '\n': | ||
sb.append("\\n"); | ||
break; | ||
case '\f': | ||
sb.append("\\f"); | ||
break; | ||
case '\r': | ||
sb.append("\\r"); | ||
break; | ||
default: | ||
if (c < ' ') { | ||
t = "000" + Integer.toHexString(c); | ||
sb.append("\\u" + t.substring(t.length() - 4)); | ||
} else { | ||
sb.append(c); | ||
} | ||
} | ||
} | ||
sb.append('"'); | ||
return sb.toString(); | ||
} | ||
|
||
public static String setPlayerName(Player player, String text) { | ||
return text.replaceAll("(?i)\\{PLAYER\\}", player.getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Title On Join: false | ||
Title Message: "Welcome" | ||
Subtitle Message: "%player% to my server" | ||
Tab Header Enabled: false | ||
Tab Header Message: "My Server" | ||
Tab Footer Message: "My IP" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: BountifulAPI | ||
description: BountifulAPI | ||
main: com.connorlinfoot.bountifulapi.BountifulAPI | ||
version: 1.0 | ||
commands: | ||
title: | ||
description: Minecraft 1.8 Title Feature |