mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2025-02-14 11:21:39 +01:00
Various updates plus portal creation
This commit is contained in:
parent
39822badd8
commit
c0e1e82de0
@ -14,6 +14,9 @@ AxeItemId: IRON_AXE
|
||||
# Will be implemented so you can give yourself the portal block and build manually with it so its easier to make portals with the portal block.
|
||||
CanBuildPortalBlock: true
|
||||
|
||||
# What the default trigger block is for portals if nothing is defined.
|
||||
DefaultPortalTriggerBlock: PORTAL
|
||||
|
||||
# This stops all water flowing inside a portal area(can be disabled if something like world edit is handelling the water flow or you dont want it active)
|
||||
# you want to
|
||||
StopWaterFlow: true
|
||||
|
@ -1,7 +1,6 @@
|
||||
|
||||
# ExamplePortal:
|
||||
# world: it will be the world name
|
||||
# hastriggerblock: false # if false it will teleport a player when they enter the region, usefull if u want air or just you enter an area.
|
||||
# triggerblock: LAVA # will only be used if the hastriggerblock is true and can be id or text
|
||||
# pos1:
|
||||
# X:
|
||||
|
@ -1,8 +1,9 @@
|
||||
package com.sekwah.advancedportals;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.minecraft.server.v1_7_R1.Item;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -10,6 +11,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
@ -17,13 +19,13 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.sekwah.advancedportals.portalcontrolls.Portal;
|
||||
|
||||
public class AdvancedPortalsCommand implements CommandExecutor {
|
||||
|
||||
public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
private AdvancedPortalsPlugin plugin;
|
||||
|
||||
public AdvancedPortalsCommand(AdvancedPortalsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
|
||||
plugin.getCommand("advancedportals").setExecutor(this);
|
||||
}
|
||||
|
||||
@ -32,15 +34,15 @@ public class AdvancedPortalsCommand implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) {
|
||||
Player player = (Player)sender;
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
|
||||
if(args.length > 0){
|
||||
if(args[0].toLowerCase().equals("wand") || args[0].toLowerCase().equals("selector")){
|
||||
if(sender.hasPermission("AdvancedPortals.CreatePortal")){
|
||||
if(sender.hasPermission("advancedportals.createportal")){
|
||||
if(args.length > 0){
|
||||
if(args[0].toLowerCase().equals("wand") || args[0].toLowerCase().equals("selector")){
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
||||
|
||||
String ItemID = config.getConfig().getString("AxeItemId");
|
||||
|
||||
|
||||
Material WandMaterial;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
WandMaterial = Material.getMaterial(Integer.parseInt(ItemID));
|
||||
@ -50,155 +52,223 @@ public class AdvancedPortalsCommand implements CommandExecutor {
|
||||
WandMaterial = Material.getMaterial(ItemID);
|
||||
}
|
||||
|
||||
if(WandMaterial == null){
|
||||
WandMaterial = Material.IRON_AXE;
|
||||
}
|
||||
|
||||
ItemStack regionselector = new ItemStack(WandMaterial);
|
||||
ItemMeta selectorname = regionselector.getItemMeta();
|
||||
selectorname.setDisplayName("§ePortal Region Selector");
|
||||
selectorname.setLore(Arrays.asList("§rThis wand with has the power to help"
|
||||
, "§r create portals bistowed upon it!"));
|
||||
regionselector.setItemMeta(selectorname);
|
||||
|
||||
|
||||
inventory.addItem(regionselector);
|
||||
sender.sendMessage("§a[§eAdvancedPortals§a] You have been given a §ePortal Region Selector§a!");
|
||||
}
|
||||
else{
|
||||
PluginMessages.NoPermission(sender, command);
|
||||
else if(args[0].toLowerCase().equals("portal") || args[0].toLowerCase().equals("portalblock")){
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
|
||||
ItemStack portalBlock = new ItemStack(Material.PORTAL);
|
||||
|
||||
inventory.addItem(portalBlock);
|
||||
|
||||
sender.sendMessage("§a[§eAdvancedPortals§a] You have been given a §ePortal Block§a!");
|
||||
}
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("create")) {
|
||||
if(player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")){
|
||||
if(player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) && player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())){
|
||||
if(args.length >= 2){
|
||||
boolean hasName = false;
|
||||
boolean hasTriggerBlock = false;
|
||||
boolean hasDestination = false;
|
||||
String destination = null;
|
||||
String portalName = null;
|
||||
String triggerBlock = null;
|
||||
for(int i = 0; i < args.length; i++){
|
||||
if(args[i].toLowerCase().startsWith("name:") && args[i].length() > 5){
|
||||
hasName = true;
|
||||
portalName = args[i].replaceFirst("name:", "");
|
||||
else if(args[0].toLowerCase().equals("create")) {
|
||||
if(player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")){
|
||||
if(player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) && player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())){
|
||||
if(args.length >= 2){
|
||||
boolean hasName = false;
|
||||
boolean hasTriggerBlock = false;
|
||||
boolean hasDestination = false;
|
||||
String destination = null;
|
||||
String portalName = null;
|
||||
String triggerBlock = null;
|
||||
for(int i = 0; i < args.length; i++){
|
||||
if(args[i].toLowerCase().startsWith("name:") && args[i].length() > 5){
|
||||
hasName = true;
|
||||
portalName = args[i].replaceFirst("name:", "");
|
||||
}
|
||||
else if(args[i].toLowerCase().startsWith("name:")) {
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] You must include a name for the portal that isnt nothing!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if(args[i].toLowerCase().startsWith("destination:") && args[i].length() > 12){
|
||||
hasDestination = true;
|
||||
destination = args[i].replaceFirst("destination:", "");
|
||||
}
|
||||
|
||||
if(args[i].toLowerCase().startsWith("triggerblock:") && args[i].length() > 13){
|
||||
hasTriggerBlock = true;
|
||||
triggerBlock = args[i].replaceFirst("triggerblock:", "");
|
||||
}
|
||||
}
|
||||
else if(args[i].toLowerCase().startsWith("name:")) {
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] You must include a name for the portal that isnt nothing!");
|
||||
if(!hasName){
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] You must include a name for the portal that you are creating in the variables!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if(args[i].toLowerCase().startsWith("destination:") && args[i].length() > 11){
|
||||
hasDestination = true;
|
||||
destination = args[i].replaceFirst("destination:", "");
|
||||
|
||||
player.sendMessage("");
|
||||
player.sendMessage("§a[§eAdvancedPortals§a]§e You have created a new portal with the following details:");
|
||||
player.sendMessage("§aname: §e" + portalName);
|
||||
if(hasDestination){
|
||||
player.sendMessage("§adestination: §e" + destination);
|
||||
}
|
||||
else{
|
||||
player.sendMessage("§cdestination: §eN/A (will not work)");
|
||||
}
|
||||
if(hasTriggerBlock){
|
||||
player.sendMessage("§atriggerBlock: §e" + triggerBlock);
|
||||
}
|
||||
else{
|
||||
player.sendMessage("§ctriggerBlock: §eN/A");
|
||||
}
|
||||
|
||||
World world = org.bukkit.Bukkit.getWorld(player.getMetadata("Pos1World").get(0).asString());
|
||||
Location pos1 = new Location(world, player.getMetadata("Pos1X").get(0).asInt(), player.getMetadata("Pos1Y").get(0).asInt(), player.getMetadata("Pos1Z").get(0).asInt());
|
||||
Location pos2 = new Location(world, player.getMetadata("Pos2X").get(0).asInt(), player.getMetadata("Pos2Y").get(0).asInt(), player.getMetadata("Pos2Z").get(0).asInt());
|
||||
|
||||
Material triggerBlockId = Material.getMaterial(0);
|
||||
if(hasTriggerBlock){
|
||||
|
||||
try
|
||||
{
|
||||
triggerBlockId = Material.getMaterial(Integer.parseInt(triggerBlock));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
triggerBlockId = Material.getMaterial(triggerBlock);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(args[i].toLowerCase().startsWith("triggerblock:") && args[i].length() > 13){
|
||||
hasTriggerBlock = true;
|
||||
triggerBlock = args[i].replaceFirst("trigger:", "");
|
||||
ConfigAccessor config2 = new ConfigAccessor(plugin, "Portals.yml");
|
||||
String posX = config2.getConfig().getString(portalName + ".pos1.X");
|
||||
if(posX == null){
|
||||
if(hasTriggerBlock){
|
||||
Portal.create(pos1, pos2, portalName, destination, triggerBlockId);
|
||||
}
|
||||
else{
|
||||
Portal.create(pos1, pos2, portalName, destination);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!hasName){
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] You must include a name for the portal that you are creating in the variables!");
|
||||
return true;
|
||||
}
|
||||
|
||||
player.sendMessage("");
|
||||
player.sendMessage("§a[§eAdvancedPortals§a]§e You have created a new portal with the following details:");
|
||||
player.sendMessage("§aname: §e" + portalName);
|
||||
if(hasDestination){
|
||||
player.sendMessage("§adestination: §e" + destination);
|
||||
else{
|
||||
sender.sendMessage("§c[§7AdvancedPortals§c] A portal by that name already exists!");
|
||||
}
|
||||
|
||||
// add code to save the portal to the portal config and reload the portals
|
||||
|
||||
player.sendMessage("");
|
||||
}
|
||||
else{
|
||||
player.sendMessage("§cdestination: §eN/A (will not work)");
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] You need to at least add the name of the portal as a variable, §cType §e/portal variables§c"
|
||||
+ " for a full list of currently available variables and an example command!");
|
||||
}
|
||||
if(hasTriggerBlock){
|
||||
player.sendMessage("§atriggerBlock: §e" + triggerBlock);
|
||||
}
|
||||
else{
|
||||
player.sendMessage("§ctriggerBlock: §eN/A");
|
||||
}
|
||||
|
||||
World world = org.bukkit.Bukkit.getWorld(player.getMetadata("Pos1World").get(0).asString());
|
||||
Location pos1 = new Location(world, player.getMetadata("Pos1X").get(0).asInt(), player.getMetadata("Pos1Y").get(0).asInt(), player.getMetadata("Pos1Z").get(0).asInt());
|
||||
Location pos2 = new Location(world, player.getMetadata("Pos2X").get(0).asInt(), player.getMetadata("Pos2Y").get(0).asInt(), player.getMetadata("Pos2Z").get(0).asInt());
|
||||
|
||||
Material triggerBlockId = Material.getMaterial(0);
|
||||
if(hasTriggerBlock){
|
||||
|
||||
try
|
||||
{
|
||||
triggerBlockId = Material.getMaterial(Integer.parseInt(triggerBlock));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
triggerBlockId = Material.getMaterial(triggerBlock);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(!hasTriggerBlock || triggerBlockId == null){
|
||||
Portal.create(pos1, pos2, "portalname", destination);
|
||||
}
|
||||
else{
|
||||
Portal.create(pos1, pos2, "portalname", destination, triggerBlockId);
|
||||
}
|
||||
|
||||
// add code to save the portal to the portal config and reload the portals
|
||||
|
||||
player.sendMessage("");
|
||||
}
|
||||
else{
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] You need to at least add the name of the portal as a variable, §cType §e/portal variables§c"
|
||||
+ " for a full list of currently available variables and an example command!");
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] The points you have selected need to be in the same world!");
|
||||
}
|
||||
}
|
||||
else{
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] The points you have selected need to be in the same world!");
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] You need to have two points selected to make a portal!");
|
||||
}
|
||||
}
|
||||
else{
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] You need to have two points selected to make a portal!");
|
||||
else if(args[0].toLowerCase().equals("variables")) {
|
||||
player.sendMessage("§a[§eAdvancedPortals§a] Currently available variables: name, triggerBlock, destination");
|
||||
player.sendMessage("");
|
||||
player.sendMessage("§aExample command: §e/portal create name:test triggerId:portal");
|
||||
}
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("variables")) {
|
||||
player.sendMessage("§a[§eAdvancedPortals§a] Currently available variables: name, triggerBlock, destination");
|
||||
player.sendMessage("");
|
||||
player.sendMessage("§aExample command: §e/portal create name:test triggerId:portal");
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("select")) {
|
||||
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("reload")) {
|
||||
player.sendMessage("§a[§eAdvancedPortals§a] Reloaded values!");
|
||||
Listeners.reloadValues(plugin);
|
||||
Portal.loadPortals();
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("show")){
|
||||
if(player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")){
|
||||
if(player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) && player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())){
|
||||
player.sendMessage("§a[§eAdvancedPortals§a] Your currently selected area has been shown, it will dissapear shortly!");
|
||||
Selection.Show(player, this.plugin);
|
||||
else if(args[0].toLowerCase().equals("select")) {
|
||||
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("reload")) {
|
||||
player.sendMessage("§a[§eAdvancedPortals§a] Reloaded values!");
|
||||
Listeners.reloadValues(plugin);
|
||||
Portal.loadPortals();
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("bukkitpage")) {
|
||||
player.sendMessage("§a[§eAdvancedPortals§a] Bukkit page: (insert bitly link)!");
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("helppage")) {
|
||||
player.sendMessage("§a[§eAdvancedPortals§a] Help page: (insert bitly link)!");
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("show")){
|
||||
if(player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")){
|
||||
if(player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) && player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())){
|
||||
player.sendMessage("§a[§eAdvancedPortals§a] Your currently selected area has been shown, it will dissapear shortly!");
|
||||
Selection.Show(player, this.plugin);
|
||||
}
|
||||
else{
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] The points you have selected need to be in the same world!");
|
||||
}
|
||||
}
|
||||
else{
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] The points you have selected need to be in the same world!");
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] You need to have both points selected!");
|
||||
}
|
||||
}
|
||||
else{
|
||||
player.sendMessage("§c[§7AdvancedPortals§c] You need to have both points selected!");
|
||||
else if(args[0].toLowerCase().equals("help")) {
|
||||
player.sendMessage("§a[§eAdvancedPortals§a] Reloaded values!");
|
||||
Listeners.reloadValues(plugin);
|
||||
Portal.loadPortals();
|
||||
}
|
||||
else{
|
||||
PluginMessages.UnknownCommand(sender, command);
|
||||
}
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("help")) {
|
||||
player.sendMessage("§a[§eAdvancedPortals§a] Reloaded values!");
|
||||
Listeners.reloadValues(plugin);
|
||||
Portal.loadPortals();
|
||||
}
|
||||
else{
|
||||
PluginMessages.UnknownCommand(sender, command);
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
PluginMessages.UnknownCommand(sender, command);
|
||||
PluginMessages.NoPermission(sender, command);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String command, String[] args) {
|
||||
LinkedList<String> autoComplete = new LinkedList<String>();
|
||||
if(sender.hasPermission("AdvancedPortals.CreatePortal")){
|
||||
if(args.length == 1){
|
||||
autoComplete.addAll(Arrays.asList("create", "portal", "portalblock", "reload", "select", "selector"
|
||||
, "show", "variables", "wand", "remove", "rename", "help", "bukkitpage", "helppage"));
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("create")){
|
||||
|
||||
boolean hasName = false;
|
||||
boolean hasTriggerBlock = false;
|
||||
boolean hasDestination = false;
|
||||
|
||||
for(int i = 0; i < args.length; i++){
|
||||
if(args[i].toLowerCase().startsWith("name:") && args[i].length() > 5){
|
||||
hasName = true;
|
||||
}
|
||||
|
||||
if(args[i].toLowerCase().startsWith("destination:") && args[i].length() > 12){
|
||||
hasDestination = true;
|
||||
}
|
||||
|
||||
if(args[i].toLowerCase().startsWith("triggerblock:") && args[i].length() > 13){
|
||||
hasTriggerBlock = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!hasName){autoComplete.add("name:");}
|
||||
if(!hasTriggerBlock){autoComplete.add("triggerblock:");}
|
||||
if(!hasDestination){autoComplete.add("destination:");}
|
||||
}
|
||||
}
|
||||
Collections.sort(autoComplete);
|
||||
for(Object result: autoComplete.toArray()){
|
||||
if(!result.toString().startsWith(args[args.length - 1])){
|
||||
autoComplete.remove(result);
|
||||
}
|
||||
}
|
||||
return autoComplete;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
package com.sekwah.advancedportals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.sekwah.advancedportals.destinations.Destination;
|
||||
import com.sekwah.advancedportals.metrics.Metrics;
|
||||
import com.sekwah.advancedportals.portalcontrolls.Portal;
|
||||
|
||||
public class AdvancedPortalsPlugin extends JavaPlugin {
|
||||
@ -18,20 +22,35 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
|
||||
|
||||
ConfigAccessor portalconfig = new ConfigAccessor(this, "Portals.yml");
|
||||
portalconfig.saveDefaultConfig();
|
||||
|
||||
ConfigAccessor destinationconfig = new ConfigAccessor(this, "Destinations.yml");
|
||||
destinationconfig.saveDefaultConfig();
|
||||
|
||||
|
||||
// Loads the portal and destination editors
|
||||
new Portal(this);
|
||||
new Destination(this);
|
||||
|
||||
// These register the commands
|
||||
new AdvancedPortalsCommand(this);
|
||||
new DestinationCommand(this);
|
||||
|
||||
|
||||
// These register the listeners
|
||||
new Listeners(this);
|
||||
|
||||
new FlowStopper(this);
|
||||
new PortalPlacer(this);
|
||||
|
||||
Selection.LoadData(this);
|
||||
|
||||
try {
|
||||
Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
} catch (IOException e) {
|
||||
// Failed to submit the stats :-(
|
||||
}
|
||||
|
||||
this.getServer().getConsoleSender().sendMessage("§aAdvanced portals have been sucsessfully enabled!");
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,20 @@
|
||||
package com.sekwah.advancedportals;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DestinationCommand implements CommandExecutor {
|
||||
import com.sekwah.advancedportals.destinations.Destination;
|
||||
|
||||
public class DestinationCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
private AdvancedPortalsPlugin plugin;
|
||||
|
||||
@ -24,7 +34,9 @@ public class DestinationCommand implements CommandExecutor {
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Destinations.yml");
|
||||
String posX = config.getConfig().getString(args[1].toLowerCase() + ".pos.X");
|
||||
if(posX == null){
|
||||
|
||||
sender.sendMessage("§c[§7AdvancedPortals§c] You have created a new destination called " + args[1] + "!");
|
||||
Player player = sender.getServer().getPlayer(sender.getName());
|
||||
Destination.create(player.getLocation(), args[1]);
|
||||
}
|
||||
else{
|
||||
sender.sendMessage("§c[§7AdvancedPortals§c] A destination by that name already exists!");
|
||||
@ -47,4 +59,25 @@ public class DestinationCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String command, String[] args) {
|
||||
LinkedList<String> autoComplete = new LinkedList<String>();
|
||||
|
||||
if(sender.hasPermission("AdvancedPortals.CreatePortal")){
|
||||
if(args.length == 1){
|
||||
autoComplete.addAll(Arrays.asList("create", "goto", "redefine", "move", "rename", "remove"));
|
||||
}
|
||||
else if(args[0].toLowerCase().equals("create")){
|
||||
}
|
||||
}
|
||||
Collections.sort(autoComplete);
|
||||
for(Object result: autoComplete.toArray()){
|
||||
if(!result.toString().startsWith(args[args.length - 1])){
|
||||
autoComplete.remove(result);
|
||||
}
|
||||
}
|
||||
return autoComplete;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,65 +1,48 @@
|
||||
package com.sekwah.advancedportals;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import com.sekwah.advancedportals.portalcontrolls.Portal;
|
||||
|
||||
public class FlowStopper implements Listener {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final AdvancedPortalsPlugin plugin;
|
||||
|
||||
// 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...
|
||||
private static boolean WaterFlow = true;
|
||||
|
||||
public FlowStopper(AdvancedPortalsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
|
||||
this.WaterFlow = config.getConfig().getBoolean("StopWaterFlow");
|
||||
|
||||
if(WaterFlow){
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
else{
|
||||
plugin.getLogger().log(Level.INFO, "Water flow is currently allowed!");
|
||||
}
|
||||
}
|
||||
private boolean WaterFlow = true;
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||
Material material = event.getBlock().getType();
|
||||
if (material == Material.STATIONARY_WATER)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else if (material == Material.STATIONARY_LAVA){
|
||||
|
||||
public FlowStopper(AdvancedPortalsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
|
||||
this.WaterFlow = config.getConfig().getBoolean("StopWaterFlow");
|
||||
|
||||
if(WaterFlow){
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onBlockFromTo(BlockFromToEvent event) {
|
||||
Block block = event.getToBlock();
|
||||
if (block.getType() == Material.WATER) {
|
||||
// when checking positions check the block and the to block
|
||||
Block blockTo = event.getToBlock();
|
||||
Block block = event.getBlock();
|
||||
if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER
|
||||
|| blockTo.getType() == Material.WATER || blockTo.getType() == Material.STATIONARY_WATER) {
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
else if (block.getType() == Material.LAVA) {
|
||||
else if (block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA
|
||||
|| blockTo.getType() == Material.LAVA || blockTo.getType() == Material.STATIONARY_LAVA) {
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,8 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import org.bukkit.event.player.PlayerPortalEvent;
|
||||
|
||||
import com.sekwah.advancedportals.portalcontrolls.Portal;
|
||||
|
||||
public class Listeners implements Listener {
|
||||
@ -22,11 +24,12 @@ public class Listeners implements Listener {
|
||||
|
||||
private static Material WandMaterial;
|
||||
|
||||
public Listeners(AdvancedPortalsPlugin plugin) {
|
||||
@SuppressWarnings("deprecation")
|
||||
public Listeners(AdvancedPortalsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
|
||||
this.UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe");
|
||||
UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe");
|
||||
|
||||
String ItemID = config.getConfig().getString("AxeItemId");
|
||||
|
||||
@ -42,7 +45,8 @@ public class Listeners implements Listener {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
public static void reloadValues(AdvancedPortalsPlugin plugin) {
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void reloadValues(AdvancedPortalsPlugin plugin) {
|
||||
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
|
||||
UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe");
|
||||
@ -64,11 +68,18 @@ public class Listeners implements Listener {
|
||||
// will check if the player is in the portal or not.
|
||||
Object[] portals = Portal.Portals;
|
||||
for(Object portal : portals){
|
||||
|
||||
System.out.println("Checking " + portal.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void onPortalEvent(PlayerPortalEvent event) {
|
||||
// check if the portal is inside the region so it doesnt teleport you to the nether
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void oniteminteract(PlayerInteractEvent event) {
|
||||
|
@ -0,0 +1,40 @@
|
||||
package com.sekwah.advancedportals;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||
|
||||
public class PortalPlacer implements Listener {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final AdvancedPortalsPlugin plugin;
|
||||
|
||||
// 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...
|
||||
private boolean PortalPlace = true;
|
||||
|
||||
public PortalPlacer(AdvancedPortalsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
|
||||
this.PortalPlace = config.getConfig().getBoolean("CanBuildPortalBlock");
|
||||
|
||||
if(PortalPlace){
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||
Material material = event.getBlock().getType();
|
||||
if (material == Material.PORTAL)
|
||||
{
|
||||
event.getChangedType();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -11,6 +11,7 @@ public class Selection {
|
||||
public static int timeout = 10;
|
||||
public static byte metadata = 14;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void LoadData(AdvancedPortalsPlugin plugin) {
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
|
||||
|
||||
@ -26,6 +27,10 @@ public class Selection {
|
||||
blockType = Material.getMaterial(BlockID);
|
||||
}
|
||||
|
||||
if(blockType == null){
|
||||
blockType = Material.STAINED_GLASS;
|
||||
}
|
||||
|
||||
metadata = (byte) config.getConfig().getInt("ShowSelectionBlockData");
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,8 @@
|
||||
package com.sekwah.advancedportals.destinations;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
|
||||
import com.sekwah.advancedportals.ConfigAccessor;
|
||||
import com.sekwah.advancedportals.portalcontrolls.Portal;
|
||||
|
||||
public class Destination {
|
||||
|
||||
@ -15,31 +12,31 @@ public class Destination {
|
||||
Destination.plugin = plugin;
|
||||
}
|
||||
|
||||
public void create(Location location, String name){
|
||||
public static void create(Location location, String name){
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Destinations.yml");
|
||||
|
||||
config.getConfig().set(name + ".world", location.getWorld().getName());
|
||||
config.getConfig().set(name.toLowerCase() + ".world", location.getWorld().getName());
|
||||
|
||||
config.getConfig().set(name + ".pos.X", location.getX());
|
||||
config.getConfig().set(name + ".pos.Y", location.getY());
|
||||
config.getConfig().set(name + ".pos.Z", location.getZ());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos.X", location.getX());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos.Y", location.getY());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos.Z", location.getZ());
|
||||
|
||||
config.saveConfig();
|
||||
}
|
||||
|
||||
public void move(Location location, String name){
|
||||
public static void move(Location location, String name){
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Destinations.yml");
|
||||
|
||||
config.getConfig().set(name + ".world", location.getWorld().getName());
|
||||
config.getConfig().set(name.toLowerCase() + ".world", location.getWorld().getName());
|
||||
|
||||
config.getConfig().set(name + ".pos.X", location.getX());
|
||||
config.getConfig().set(name + ".pos.Y", location.getY());
|
||||
config.getConfig().set(name + ".pos.Z", location.getZ());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos.X", location.getX());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos.Y", location.getY());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos.Z", location.getZ());
|
||||
|
||||
config.saveConfig();
|
||||
}
|
||||
|
||||
public void rename(String oldName, String newName){
|
||||
public static void rename(String oldName, String newName){
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Destinations.yml");
|
||||
|
||||
config.getConfig().set(newName + ".world", config.getConfig().getString(oldName + ".world"));
|
||||
@ -48,12 +45,12 @@ public class Destination {
|
||||
config.getConfig().set(newName + ".pos.Y", config.getConfig().getInt(oldName + ".pos.Y"));
|
||||
config.getConfig().set(newName + ".pos.Z", config.getConfig().getInt(oldName + ".pos.Z"));
|
||||
|
||||
this.remove(oldName);
|
||||
remove(oldName);
|
||||
|
||||
config.saveConfig();
|
||||
}
|
||||
|
||||
public void remove(String name){
|
||||
public static void remove(String name){
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Destinations.yml");
|
||||
|
||||
config.getConfig().set(name + ".world", null);
|
||||
|
@ -0,0 +1,759 @@
|
||||
/*
|
||||
* Copyright 2011-2013 Tyler Blair. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and contributors and should not be interpreted as representing official policies,
|
||||
* either expressed or implied, of anybody else.
|
||||
*/
|
||||
package com.sekwah.advancedportals.metrics;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public class Metrics {
|
||||
|
||||
/**
|
||||
* The current revision number
|
||||
*/
|
||||
private final static int REVISION = 7;
|
||||
|
||||
/**
|
||||
* The base url of the metrics domain
|
||||
*/
|
||||
private static final String BASE_URL = "http://report.mcstats.org";
|
||||
|
||||
/**
|
||||
* The url used to report a server's status
|
||||
*/
|
||||
private static final String REPORT_URL = "/plugin/%s";
|
||||
|
||||
/**
|
||||
* Interval of time to ping (in minutes)
|
||||
*/
|
||||
private static final int PING_INTERVAL = 15;
|
||||
|
||||
/**
|
||||
* The plugin this metrics submits for
|
||||
*/
|
||||
private final Plugin plugin;
|
||||
|
||||
/**
|
||||
* All of the custom graphs to submit to metrics
|
||||
*/
|
||||
private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet<Graph>());
|
||||
|
||||
/**
|
||||
* The plugin configuration file
|
||||
*/
|
||||
private final YamlConfiguration configuration;
|
||||
|
||||
/**
|
||||
* The plugin configuration file
|
||||
*/
|
||||
private final File configurationFile;
|
||||
|
||||
/**
|
||||
* Unique server id
|
||||
*/
|
||||
private final String guid;
|
||||
|
||||
/**
|
||||
* Debug mode
|
||||
*/
|
||||
private final boolean debug;
|
||||
|
||||
/**
|
||||
* Lock for synchronization
|
||||
*/
|
||||
private final Object optOutLock = new Object();
|
||||
|
||||
/**
|
||||
* The scheduled task
|
||||
*/
|
||||
private volatile BukkitTask task = null;
|
||||
|
||||
public Metrics(final Plugin plugin) throws IOException {
|
||||
if (plugin == null) {
|
||||
throw new IllegalArgumentException("Plugin cannot be null");
|
||||
}
|
||||
|
||||
this.plugin = plugin;
|
||||
|
||||
// load the config
|
||||
configurationFile = getConfigFile();
|
||||
configuration = YamlConfiguration.loadConfiguration(configurationFile);
|
||||
|
||||
// add some defaults
|
||||
configuration.addDefault("opt-out", false);
|
||||
configuration.addDefault("guid", UUID.randomUUID().toString());
|
||||
configuration.addDefault("debug", false);
|
||||
|
||||
// Do we need to create the file?
|
||||
if (configuration.get("guid", null) == null) {
|
||||
configuration.options().header("http://mcstats.org").copyDefaults(true);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Load the guid then
|
||||
guid = configuration.getString("guid");
|
||||
debug = configuration.getBoolean("debug", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics
|
||||
* website. Plotters can be added to the graph object returned.
|
||||
*
|
||||
* @param name The name of the graph
|
||||
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
|
||||
*/
|
||||
public Graph createGraph(final String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Graph name cannot be null");
|
||||
}
|
||||
|
||||
// Construct the graph object
|
||||
final Graph graph = new Graph(name);
|
||||
|
||||
// Now we can add our graph
|
||||
graphs.add(graph);
|
||||
|
||||
// and return back
|
||||
return graph;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Graph object to BukkitMetrics that represents data for the plugin that should be sent to the backend
|
||||
*
|
||||
* @param graph The name of the graph
|
||||
*/
|
||||
public void addGraph(final Graph graph) {
|
||||
if (graph == null) {
|
||||
throw new IllegalArgumentException("Graph cannot be null");
|
||||
}
|
||||
|
||||
graphs.add(graph);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send the
|
||||
* initial data to the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200
|
||||
* ticks.
|
||||
*
|
||||
* @return True if statistics measuring is running, otherwise false.
|
||||
*/
|
||||
public boolean start() {
|
||||
synchronized (optOutLock) {
|
||||
// Did we opt out?
|
||||
if (isOptOut()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is metrics already running?
|
||||
if (task != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Begin hitting the server with glorious data
|
||||
task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
|
||||
|
||||
private boolean firstPost = true;
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
// This has to be synchronized or it can collide with the disable method.
|
||||
synchronized (optOutLock) {
|
||||
// Disable Task, if it is running and the server owner decided to opt-out
|
||||
if (isOptOut() && task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
// Tell all plotters to stop gathering information.
|
||||
for (Graph graph : graphs) {
|
||||
graph.onOptOut();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We use the inverse of firstPost because if it is the first time we are posting,
|
||||
// it is not a interval ping, so it evaluates to FALSE
|
||||
// Each time thereafter it will evaluate to TRUE, i.e PING!
|
||||
postPlugin(!firstPost);
|
||||
|
||||
// After the first post we set firstPost to false
|
||||
// Each post thereafter will be a ping
|
||||
firstPost = false;
|
||||
} catch (IOException e) {
|
||||
if (debug) {
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 0, PING_INTERVAL * 1200);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Has the server owner denied plugin metrics?
|
||||
*
|
||||
* @return true if metrics should be opted out of it
|
||||
*/
|
||||
public boolean isOptOut() {
|
||||
synchronized (optOutLock) {
|
||||
try {
|
||||
// Reload the metrics file
|
||||
configuration.load(getConfigFile());
|
||||
} catch (IOException ex) {
|
||||
if (debug) {
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||
}
|
||||
return true;
|
||||
} catch (InvalidConfigurationException ex) {
|
||||
if (debug) {
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return configuration.getBoolean("opt-out", false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public void enable() throws IOException {
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (isOptOut()) {
|
||||
configuration.set("opt-out", false);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Enable Task, if it is not running
|
||||
if (task == null) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
|
||||
*
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
public void disable() throws IOException {
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (!isOptOut()) {
|
||||
configuration.set("opt-out", true);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Disable Task, if it is running
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
|
||||
*
|
||||
* @return the File object for the config file
|
||||
*/
|
||||
public File getConfigFile() {
|
||||
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use
|
||||
// is to abuse the plugin object we already have
|
||||
// plugin.getDataFolder() => base/plugins/PluginA/
|
||||
// pluginsFolder => base/plugins/
|
||||
// The base is not necessarily relative to the startup directory.
|
||||
File pluginsFolder = plugin.getDataFolder().getParentFile();
|
||||
|
||||
// return => base/plugins/PluginMetrics/config.yml
|
||||
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic method that posts a plugin to the metrics website
|
||||
*/
|
||||
private void postPlugin(final boolean isPing) throws IOException {
|
||||
// Server software specific section
|
||||
PluginDescriptionFile description = plugin.getDescription();
|
||||
String pluginName = description.getName();
|
||||
boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
|
||||
String pluginVersion = description.getVersion();
|
||||
String serverVersion = Bukkit.getVersion();
|
||||
int playersOnline = Bukkit.getServer().getOnlinePlayers().length;
|
||||
|
||||
// END server software specific section -- all code below does not use any code outside of this class / Java
|
||||
|
||||
// Construct the post data
|
||||
StringBuilder json = new StringBuilder(1024);
|
||||
json.append('{');
|
||||
|
||||
// The plugin's description file containg all of the plugin data such as name, version, author, etc
|
||||
appendJSONPair(json, "guid", guid);
|
||||
appendJSONPair(json, "plugin_version", pluginVersion);
|
||||
appendJSONPair(json, "server_version", serverVersion);
|
||||
appendJSONPair(json, "players_online", Integer.toString(playersOnline));
|
||||
|
||||
// New data as of R6
|
||||
String osname = System.getProperty("os.name");
|
||||
String osarch = System.getProperty("os.arch");
|
||||
String osversion = System.getProperty("os.version");
|
||||
String java_version = System.getProperty("java.version");
|
||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
// normalize os arch .. amd64 -> x86_64
|
||||
if (osarch.equals("amd64")) {
|
||||
osarch = "x86_64";
|
||||
}
|
||||
|
||||
appendJSONPair(json, "osname", osname);
|
||||
appendJSONPair(json, "osarch", osarch);
|
||||
appendJSONPair(json, "osversion", osversion);
|
||||
appendJSONPair(json, "cores", Integer.toString(coreCount));
|
||||
appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
|
||||
appendJSONPair(json, "java_version", java_version);
|
||||
|
||||
// If we're pinging, append it
|
||||
if (isPing) {
|
||||
appendJSONPair(json, "ping", "1");
|
||||
}
|
||||
|
||||
if (graphs.size() > 0) {
|
||||
synchronized (graphs) {
|
||||
json.append(',');
|
||||
json.append('"');
|
||||
json.append("graphs");
|
||||
json.append('"');
|
||||
json.append(':');
|
||||
json.append('{');
|
||||
|
||||
boolean firstGraph = true;
|
||||
|
||||
final Iterator<Graph> iter = graphs.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
Graph graph = iter.next();
|
||||
|
||||
StringBuilder graphJson = new StringBuilder();
|
||||
graphJson.append('{');
|
||||
|
||||
for (Plotter plotter : graph.getPlotters()) {
|
||||
appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
|
||||
}
|
||||
|
||||
graphJson.append('}');
|
||||
|
||||
if (!firstGraph) {
|
||||
json.append(',');
|
||||
}
|
||||
|
||||
json.append(escapeJSON(graph.getName()));
|
||||
json.append(':');
|
||||
json.append(graphJson);
|
||||
|
||||
firstGraph = false;
|
||||
}
|
||||
|
||||
json.append('}');
|
||||
}
|
||||
}
|
||||
|
||||
// close json
|
||||
json.append('}');
|
||||
|
||||
// Create the url
|
||||
URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
|
||||
|
||||
// Connect to the website
|
||||
URLConnection connection;
|
||||
|
||||
// Mineshafter creates a socks proxy, so we can safely bypass it
|
||||
// It does not reroute POST requests so we need to go around it
|
||||
if (isMineshafterPresent()) {
|
||||
connection = url.openConnection(Proxy.NO_PROXY);
|
||||
} else {
|
||||
connection = url.openConnection();
|
||||
}
|
||||
|
||||
|
||||
byte[] uncompressed = json.toString().getBytes();
|
||||
byte[] compressed = gzip(json.toString());
|
||||
|
||||
// Headers
|
||||
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
|
||||
connection.addRequestProperty("Content-Type", "application/json");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip");
|
||||
connection.addRequestProperty("Content-Length", Integer.toString(compressed.length));
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
|
||||
connection.setDoOutput(true);
|
||||
|
||||
if (debug) {
|
||||
System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
|
||||
}
|
||||
|
||||
// Write the data
|
||||
OutputStream os = connection.getOutputStream();
|
||||
os.write(compressed);
|
||||
os.flush();
|
||||
|
||||
// Now read the response
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String response = reader.readLine();
|
||||
|
||||
// close resources
|
||||
os.close();
|
||||
reader.close();
|
||||
|
||||
if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
|
||||
if (response == null) {
|
||||
response = "null";
|
||||
} else if (response.startsWith("7")) {
|
||||
response = response.substring(response.startsWith("7,") ? 2 : 1);
|
||||
}
|
||||
|
||||
throw new IOException(response);
|
||||
} else {
|
||||
// Is this the first update this hour?
|
||||
if (response.equals("1") || response.contains("This is your first update this hour")) {
|
||||
synchronized (graphs) {
|
||||
final Iterator<Graph> iter = graphs.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
final Graph graph = iter.next();
|
||||
|
||||
for (Plotter plotter : graph.getPlotters()) {
|
||||
plotter.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GZip compress a string of bytes
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public static byte[] gzip(String input) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzos = null;
|
||||
|
||||
try {
|
||||
gzos = new GZIPOutputStream(baos);
|
||||
gzos.write(input.getBytes("UTF-8"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (gzos != null) try {
|
||||
gzos.close();
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
|
||||
*
|
||||
* @return true if mineshafter is installed on the server
|
||||
*/
|
||||
private boolean isMineshafterPresent() {
|
||||
try {
|
||||
Class.forName("mineshafter.MineServer");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a json encoded key/value pair to the given string builder.
|
||||
*
|
||||
* @param json
|
||||
* @param key
|
||||
* @param value
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException {
|
||||
boolean isValueNumeric = false;
|
||||
|
||||
try {
|
||||
if (value.equals("0") || !value.endsWith("0")) {
|
||||
Double.parseDouble(value);
|
||||
isValueNumeric = true;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
isValueNumeric = false;
|
||||
}
|
||||
|
||||
if (json.charAt(json.length() - 1) != '{') {
|
||||
json.append(',');
|
||||
}
|
||||
|
||||
json.append(escapeJSON(key));
|
||||
json.append(':');
|
||||
|
||||
if (isValueNumeric) {
|
||||
json.append(value);
|
||||
} else {
|
||||
json.append(escapeJSON(value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape a string to create a valid JSON string
|
||||
*
|
||||
* @param text
|
||||
* @return
|
||||
*/
|
||||
private static String escapeJSON(String text) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append('"');
|
||||
for (int index = 0; index < text.length(); index++) {
|
||||
char chr = text.charAt(index);
|
||||
|
||||
switch (chr) {
|
||||
case '"':
|
||||
case '\\':
|
||||
builder.append('\\');
|
||||
builder.append(chr);
|
||||
break;
|
||||
case '\b':
|
||||
builder.append("\\b");
|
||||
break;
|
||||
case '\t':
|
||||
builder.append("\\t");
|
||||
break;
|
||||
case '\n':
|
||||
builder.append("\\n");
|
||||
break;
|
||||
case '\r':
|
||||
builder.append("\\r");
|
||||
break;
|
||||
default:
|
||||
if (chr < ' ') {
|
||||
String t = "000" + Integer.toHexString(chr);
|
||||
builder.append("\\u" + t.substring(t.length() - 4));
|
||||
} else {
|
||||
builder.append(chr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
builder.append('"');
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode text as UTF-8
|
||||
*
|
||||
* @param text the text to encode
|
||||
* @return the encoded text, as UTF-8
|
||||
*/
|
||||
private static String urlEncode(final String text) throws UnsupportedEncodingException {
|
||||
return URLEncoder.encode(text, "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom graph on the website
|
||||
*/
|
||||
public static class Graph {
|
||||
|
||||
/**
|
||||
* The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is
|
||||
* rejected
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The set of plotters that are contained within this graph
|
||||
*/
|
||||
private final Set<Plotter> plotters = new LinkedHashSet<Plotter>();
|
||||
|
||||
private Graph(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the graph's name
|
||||
*
|
||||
* @return the Graph's name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a plotter to the graph, which will be used to plot entries
|
||||
*
|
||||
* @param plotter the plotter to add to the graph
|
||||
*/
|
||||
public void addPlotter(final Plotter plotter) {
|
||||
plotters.add(plotter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a plotter from the graph
|
||||
*
|
||||
* @param plotter the plotter to remove from the graph
|
||||
*/
|
||||
public void removePlotter(final Plotter plotter) {
|
||||
plotters.remove(plotter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an <b>unmodifiable</b> set of the plotter objects in the graph
|
||||
*
|
||||
* @return an unmodifiable {@link java.util.Set} of the plotter objects
|
||||
*/
|
||||
public Set<Plotter> getPlotters() {
|
||||
return Collections.unmodifiableSet(plotters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object object) {
|
||||
if (!(object instanceof Graph)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Graph graph = (Graph) object;
|
||||
return graph.name.equals(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the server owner decides to opt-out of BukkitMetrics while the server is running.
|
||||
*/
|
||||
protected void onOptOut() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface used to collect custom data for a plugin
|
||||
*/
|
||||
public static abstract class Plotter {
|
||||
|
||||
/**
|
||||
* The plot's name
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Construct a plotter with the default plot name
|
||||
*/
|
||||
public Plotter() {
|
||||
this("Default");
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a plotter with a specific plot name
|
||||
*
|
||||
* @param name the name of the plotter to use, which will show up on the website
|
||||
*/
|
||||
public Plotter(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current value for the plotted point. Since this function defers to an external function it may or may
|
||||
* not return immediately thus cannot be guaranteed to be thread friendly or safe. This function can be called
|
||||
* from any thread so care should be taken when accessing resources that need to be synchronized.
|
||||
*
|
||||
* @return the current value for the point to be plotted.
|
||||
*/
|
||||
public abstract int getValue();
|
||||
|
||||
/**
|
||||
* Get the column name for the plotted point
|
||||
*
|
||||
* @return the plotted point's column name
|
||||
*/
|
||||
public String getColumnName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after the website graphs have been updated
|
||||
*/
|
||||
public void reset() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getColumnName().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object object) {
|
||||
if (!(object instanceof Plotter)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Plotter plotter = (Plotter) object;
|
||||
return plotter.name.equals(name) && plotter.getValue() == getValue();
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sekwah.advancedportals.AdvancedPortalsPlugin;
|
||||
import com.sekwah.advancedportals.ConfigAccessor;
|
||||
@ -15,6 +14,8 @@ public class Portal {
|
||||
|
||||
public static Object[] Portals;
|
||||
|
||||
public static Object[] triggers;
|
||||
|
||||
public static Object[] pos1;
|
||||
|
||||
public static Object[] pos2;
|
||||
@ -38,53 +39,59 @@ public class Portal {
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
|
||||
Set<String> PortalSet = config.getConfig().getKeys(false);
|
||||
Portals = PortalSet.toArray();
|
||||
|
||||
int portalId = 0;
|
||||
for(Object portal: Portals){
|
||||
portal.toString();
|
||||
|
||||
triggers[portalId] = config.getConfig().getString(portal.toString() + ".triggerblock");
|
||||
// pos1[portalId] = config.getConfig().getString(portal.toString() + ".triggerblock"); // will be a location
|
||||
// pos2[portalId] = config.getConfig().getString(portal.toString() + ".triggerblock"); // will be a location
|
||||
portalId++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void create(Location pos1, Location pos2 , String name, String destination , Material triggerBlockId) {
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
|
||||
|
||||
config.getConfig().set(name + ".world", pos1.getWorld().getName());
|
||||
config.getConfig().set(name + ".hastriggerblock", true);
|
||||
config.getConfig().set(name.toLowerCase() + ".world", pos1.getWorld().getName());
|
||||
|
||||
config.getConfig().set(name + ".triggerblock", triggerBlockId.toString());
|
||||
config.getConfig().set(name.toLowerCase() + ".triggerblock", triggerBlockId.toString());
|
||||
|
||||
config.getConfig().set(name + ".destination", destination);
|
||||
config.getConfig().set(name.toLowerCase() + ".destination", destination);
|
||||
|
||||
config.getConfig().set(name + ".pos1.X", pos1.getX());
|
||||
config.getConfig().set(name + ".pos1.Y", pos1.getY());
|
||||
config.getConfig().set(name + ".pos1.Z", pos1.getZ());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos1.X", pos1.getX());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos1.Y", pos1.getY());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos1.Z", pos1.getZ());
|
||||
|
||||
config.getConfig().set(name + ".pos2.X", pos2.getX());
|
||||
config.getConfig().set(name + ".pos2.Y", pos2.getY());
|
||||
config.getConfig().set(name + ".pos2.Z", pos2.getZ());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos2.X", pos2.getX());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos2.Y", pos2.getY());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos2.Z", pos2.getZ());
|
||||
|
||||
config.saveConfig();
|
||||
|
||||
loadPortals();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void create(Location pos1, Location pos2, String name, String destination) { // add stuff for destination names or coordinates
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml");
|
||||
|
||||
config.getConfig().set(name + ".world", pos1.getWorld().getName());
|
||||
config.getConfig().set(name + ".hastriggerblock", false);
|
||||
Material triggerBlockType;
|
||||
String BlockID = config.getConfig().getString("DefaultPortalTriggerBlock");
|
||||
try
|
||||
{
|
||||
triggerBlockType = Material.getMaterial(Integer.parseInt(BlockID));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
triggerBlockType = Material.getMaterial(BlockID);
|
||||
}
|
||||
|
||||
config.getConfig().set(name + ".destination", destination);
|
||||
if(triggerBlockType == null){
|
||||
triggerBlockType = Material.PORTAL;
|
||||
}
|
||||
|
||||
config.getConfig().set(name + ".pos1.X", pos1.getX());
|
||||
config.getConfig().set(name + ".pos1.Y", pos1.getY());
|
||||
config.getConfig().set(name + ".pos1.Z", pos1.getZ());
|
||||
|
||||
config.getConfig().set(name + ".pos2.X", pos2.getX());
|
||||
config.getConfig().set(name + ".pos2.Y", pos2.getY());
|
||||
config.getConfig().set(name + ".pos2.Z", pos2.getZ());
|
||||
create(pos1, pos2, name, destination, triggerBlockType);
|
||||
|
||||
loadPortals();
|
||||
}
|
||||
@ -93,13 +100,13 @@ public class Portal {
|
||||
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
|
||||
|
||||
config.getConfig().set(name + ".pos1.X", pos1.getX());
|
||||
config.getConfig().set(name + ".pos1.Y", pos1.getY());
|
||||
config.getConfig().set(name + ".pos1.Z", pos1.getZ());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos1.X", pos1.getX());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos1.Y", pos1.getY());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos1.Z", pos1.getZ());
|
||||
|
||||
config.getConfig().set(name + ".pos2.X", pos2.getX());
|
||||
config.getConfig().set(name + ".pos2.Y", pos2.getY());
|
||||
config.getConfig().set(name + ".pos2.Z", pos2.getZ());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos2.X", pos2.getX());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos2.Y", pos2.getY());
|
||||
config.getConfig().set(name.toLowerCase() + ".pos2.Z", pos2.getZ());
|
||||
|
||||
config.saveConfig();
|
||||
|
||||
@ -110,16 +117,16 @@ public class Portal {
|
||||
public static void remove(String name){
|
||||
ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml");
|
||||
|
||||
config.getConfig().set(name + ".world", null);
|
||||
config.getConfig().set(name + ".hastriggerblock", null);
|
||||
config.getConfig().set(name.toLowerCase() + ".world", null);
|
||||
config.getConfig().set(name.toLowerCase() + ".hastriggerblock", null);
|
||||
|
||||
config.getConfig().set(name + ".pos1.X", null);
|
||||
config.getConfig().set(name + ".pos1.Y", null);
|
||||
config.getConfig().set(name + ".pos1.Z", null);
|
||||
config.getConfig().set(name.toLowerCase() + ".pos1.X", null);
|
||||
config.getConfig().set(name.toLowerCase() + ".pos1.Y", null);
|
||||
config.getConfig().set(name.toLowerCase() + ".pos1.Z", null);
|
||||
|
||||
config.getConfig().set(name + ".pos2.X", null);
|
||||
config.getConfig().set(name + ".pos2.Y", null);
|
||||
config.getConfig().set(name + ".pos2.Z", null);
|
||||
config.getConfig().set(name.toLowerCase() + ".pos2.X", null);
|
||||
config.getConfig().set(name.toLowerCase() + ".pos2.Y", null);
|
||||
config.getConfig().set(name.toLowerCase() + ".pos2.Z", null);
|
||||
|
||||
config.saveConfig();
|
||||
|
||||
|
@ -12,3 +12,11 @@ commands:
|
||||
description: Can be used to access portal destinations.
|
||||
aliases: [desti]
|
||||
usage: /<command>
|
||||
permissions:
|
||||
advancedportals.*:
|
||||
description: Gives access to all portal commands
|
||||
children:
|
||||
advancedportals.createportal: true
|
||||
advancedportals.createportal:
|
||||
description: Allows you to create portals
|
||||
default: op
|
||||
|
Loading…
Reference in New Issue
Block a user