Finished the NMS system and added a new config variable to hide bungee

warp messages(as they can be annoying)
This commit is contained in:
sekwah41 2014-10-22 21:06:45 +01:00
parent 70f949dc23
commit 4e00c6a293
7 changed files with 73 additions and 25 deletions

View File

@ -41,29 +41,29 @@ warpParticles: 1
# 0 = disabled(no sound) # 0 = disabled(no sound)
# 1 = Enderman Warp Sound # 1 = Enderman Warp Sound
# 2 = Explosion # 2 = Explosion
warpSound: 1 WarpSound: 1
# In case you want to show the bungee attempting warp message
ShowBungeeWarpMessage: false
# This changes how long the show seletion lasts in seconds # This changes how long the show seletion lasts in seconds
ShowSelectionShowDuration: 10 ShowSelectionShowDuration: 10
# If a player is riding a entity, warp the entity too? # If a player is riding a entity, warp the entity too?(unless its a bungee portal)
WarpRiddenEntity: true WarpRiddenEntity: true
# Use the default warp messages for portals # Use the default warp messages for portals
portalWarpMessages: true PortalWarpMessages: true
# Use plugin name in the warp messages # Use plugin name in the warp messages
useWarpPrefix: true UseWarpPrefix: true
# If this is true a custom prefix can be used # If this is true a custom prefix can be used
useCustomPrefix: false UseCustomPrefix: false
customPrefix: '[Test]' CustomPrefix: '[Test]'

View File

@ -5,10 +5,6 @@ import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import net.minecraft.server.v1_7_R3.ChatSerializer;
import net.minecraft.server.v1_7_R3.IChatBaseComponent;
import net.minecraft.server.v1_7_R3.PacketPlayOutChat;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
@ -16,7 +12,6 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
@ -219,7 +214,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
sender.sendMessage(""); sender.sendMessage("");
sender.sendMessage("§c[§7AdvancedPortals§c] Are you sure you would like to remove the portal §e" + args[2] + "§c?"); sender.sendMessage("§c[§7AdvancedPortals§c] Are you sure you would like to remove the portal §e" + args[2] + "§c?");
sender.sendMessage(""); sender.sendMessage("");
plugin.nmsAccess.sendRawMessage("{text:\" \",extra:[{text:\"§e[Yes]\",hoverEvent:{action:show_text,value:\"Confirm removing this portal\"},clickEvent:{action:run_command,value:\"/portal remove " + args[2] + "\"}}, " +
"{text:\" \"},{text:\"§e[No]\",hoverEvent:{action:show_text,value:\"Cancel removing this portal\"},clickEvent:{action:run_command,value:\"/portal edit " + args[2] + "\"}}]}", player);
sender.sendMessage(""); sender.sendMessage("");
} }
} }
@ -403,12 +399,17 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
Player player = (Player)sender; Player player = (Player)sender;
IChatBaseComponent comp = ChatSerializer.a("{text:\"§aFunctions§e: \",extra:[{text:\"§eRemove\",hoverEvent:{action:show_text,value:\"Remove the selected portal\"},clickEvent:{action:run_command,value:\"/portal gui remove " + portalName + "\"}}" plugin.nmsAccess.sendRawMessage("{text:\"§aFunctions§e: \",extra:[{text:\"§eRemove\",hoverEvent:{action:show_text,value:\"Remove the selected portal\"},clickEvent:{action:run_command,value:\"/portal gui remove " + portalName + "\"}}"
+ ",{text:\" \"},{text:\"§eShow\",hoverEvent:{action:show_text,value:\"Show the selected portal\"},clickEvent:{action:run_command,value:\"/portal show " + portalName + "\"}}"
+ ",{text:\" \"},{text:\"§eRename\",hoverEvent:{action:show_text,value:\"Change the name of the portal\"},clickEvent:{action:suggest_command,value:\"/portal rename \"}}"
+ ",{text:\" \"},{text:\"§eActivate\",hoverEvent:{action:show_text,value:\"Teleport to the set destination\n(same as entering the portal)\"},clickEvent:{action:run_command,value:\"/warp " + destination + "\"}}]}", player);
/**IChatBaseComponent comp = ChatSerializer.a("{text:\"§aFunctions§e: \",extra:[{text:\"§eRemove\",hoverEvent:{action:show_text,value:\"Remove the selected portal\"},clickEvent:{action:run_command,value:\"/portal gui remove " + portalName + "\"}}"
+ ",{text:\" \"},{text:\"§eShow\",hoverEvent:{action:show_text,value:\"Show the selected portal\"},clickEvent:{action:run_command,value:\"/portal show " + portalName + "\"}}" + ",{text:\" \"},{text:\"§eShow\",hoverEvent:{action:show_text,value:\"Show the selected portal\"},clickEvent:{action:run_command,value:\"/portal show " + portalName + "\"}}"
+ ",{text:\" \"},{text:\"§eRename\",hoverEvent:{action:show_text,value:\"Change the name of the portal\"},clickEvent:{action:suggest_command,value:\"/portal rename \"}}" + ",{text:\" \"},{text:\"§eRename\",hoverEvent:{action:show_text,value:\"Change the name of the portal\"},clickEvent:{action:suggest_command,value:\"/portal rename \"}}"
+ ",{text:\" \"},{text:\"§eActivate\",hoverEvent:{action:show_text,value:\"Teleport to the set destination\n(same as entering the portal)\"},clickEvent:{action:run_command,value:\"/warp " + destination + "\"}}]}"); + ",{text:\" \"},{text:\"§eActivate\",hoverEvent:{action:show_text,value:\"Teleport to the set destination\n(same as entering the portal)\"},clickEvent:{action:run_command,value:\"/warp " + destination + "\"}}]}");
PacketPlayOutChat packet = new PacketPlayOutChat(comp, true); PacketPlayOutChat packet = new PacketPlayOutChat(comp, true);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);*/
sender.sendMessage(""); sender.sendMessage("");
} }

View File

@ -8,8 +8,8 @@ public class Assets {
public Assets(AdvancedPortalsPlugin plugin) { public Assets(AdvancedPortalsPlugin plugin) {
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml"); ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
currentWarpParticles = config.getConfig().getInt("warpParticles"); currentWarpParticles = config.getConfig().getInt("WarpParticles");
currentWarpSound = config.getConfig().getInt("warpSound"); currentWarpSound = config.getConfig().getInt("WarpSound");
} }
} }

View File

@ -23,13 +23,15 @@ public class Listeners implements Listener {
private final AdvancedPortalsPlugin plugin; private final AdvancedPortalsPlugin plugin;
private boolean defaultPortalMessages = true; private boolean DefaultPortalMessages = true;
// The needed config values will be stored so they are easier to access later // The needed config values will be stored so they are easier to access later
// an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("§eP... // an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("§eP...
private static boolean UseOnlyServerAxe = false; private static boolean UseOnlyServerAxe = false;
private static Material WandMaterial; private static Material WandMaterial;
private static boolean ShowBungeeMessage;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public Listeners(AdvancedPortalsPlugin plugin) { public Listeners(AdvancedPortalsPlugin plugin) {
@ -40,7 +42,7 @@ public class Listeners implements Listener {
String ItemID = config.getConfig().getString("AxeItemId"); String ItemID = config.getConfig().getString("AxeItemId");
defaultPortalMessages = config.getConfig().getBoolean("portalWarpMessages"); DefaultPortalMessages = config.getConfig().getBoolean("PortalWarpMessages");
try try
{ {
@ -60,6 +62,8 @@ public class Listeners implements Listener {
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml"); ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe"); UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe");
ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
String ItemID = config.getConfig().getString("AxeItemId"); String ItemID = config.getConfig().getString("AxeItemId");
try try
@ -93,7 +97,7 @@ public class Listeners implements Listener {
boolean warped = Portal.activate(player, portal.portalName); boolean warped = Portal.activate(player, portal.portalName);
if(defaultPortalMessages && warped){ if(DefaultPortalMessages && warped){
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml"); ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
player.sendMessage(""); player.sendMessage("");
player.sendMessage("§a[§eAdvancedPortals§a] You have warped to §e" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination") + "."); player.sendMessage("§a[§eAdvancedPortals§a] You have warped to §e" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination") + ".");

View File

@ -0,0 +1,19 @@
package com.sekwah.advancedportals.compat;
import net.minecraft.server.v1_7_R1.ChatSerializer;
import net.minecraft.server.v1_7_R1.IChatBaseComponent;
import net.minecraft.server.v1_7_R1.PacketPlayOutChat;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class v1_7_R1 implements NMS {
@Override
public void sendRawMessage(String rawMessage, Player player) {
IChatBaseComponent comp = ChatSerializer.a(rawMessage);
PacketPlayOutChat packet = new PacketPlayOutChat(comp, true);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}

View File

@ -0,0 +1,19 @@
package com.sekwah.advancedportals.compat;
import net.minecraft.server.v1_7_R2.ChatSerializer;
import net.minecraft.server.v1_7_R2.IChatBaseComponent;
import net.minecraft.server.v1_7_R2.PacketPlayOutChat;
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class v1_7_R2 implements NMS {
@Override
public void sendRawMessage(String rawMessage, Player player) {
IChatBaseComponent comp = ChatSerializer.a(rawMessage);
PacketPlayOutChat packet = new PacketPlayOutChat(comp, true);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}

View File

@ -1,6 +1,5 @@
package com.sekwah.advancedportals.portalcontrolls; package com.sekwah.advancedportals.portalcontrolls;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
@ -24,8 +23,13 @@ public class Portal {
public static boolean portalsActive = true; public static boolean portalsActive = true;
public static AdvancedPortal[] Portals; public static AdvancedPortal[] Portals;
private static boolean ShowBungeeMessage;
public Portal(AdvancedPortalsPlugin plugin) { public Portal(AdvancedPortalsPlugin plugin) {
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage");
Portal.plugin = plugin; Portal.plugin = plugin;
Portal.loadPortals(); Portal.loadPortals();
} }
@ -39,8 +43,7 @@ public class Portal {
* *
*/ */
@SuppressWarnings("deprecation") public static void loadPortals(){
public static void loadPortals(){
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml"); ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
Set<String> PortalSet = config.getConfig().getKeys(false); Set<String> PortalSet = config.getConfig().getKeys(false);
@ -325,7 +328,9 @@ public class Portal {
// add other variables or filter code here, or somehow have a way to register them // add other variables or filter code here, or somehow have a way to register them
if(config.getConfig().getString(portalName + ".bungee") != null){ if(config.getConfig().getString(portalName + ".bungee") != null){
player.sendMessage("§a[§eAdvancedPortals§a] Attempting to warp to §e" + config.getConfig().getString(portalName + ".bungee") + "§a."); if(ShowBungeeMessage){
player.sendMessage("§a[§eAdvancedPortals§a] Attempting to warp to §e" + config.getConfig().getString(portalName + ".bungee") + "§a.");
}
ByteArrayDataOutput out = ByteStreams.newDataOutput(); ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect"); out.writeUTF("Connect");
out.writeUTF(config.getConfig().getString(portalName + ".bungee")); out.writeUTF(config.getConfig().getString(portalName + ".bungee"));