Skip to content

Instantly share code, notes, and snippets.

@Dark32
Created December 20, 2012 06:45
Show Gist options
  • Save Dark32/4343357 to your computer and use it in GitHub Desktop.
Save Dark32/4343357 to your computer and use it in GitHub Desktop.
##---
Plugin.is {
name "HTUI"
version "0.1"
author "d32"
description "Телепортация в дом используя вещь"
commands :htui => {
:description => "Справка по плагину",
:usage => "/htui <args>",
:aliases => [ :hi, :hihi ]
}
}
#import 'org.bukkit.event.Event'
#import 'org.bukkit.inventory.Inventory'
import 'org.bukkit.inventory.ItemStack'
import 'org.bukkit.event.player.PlayerLoginEvent'
import 'org.bukkit.event.player.PlayerInteractEvent'
import 'org.bukkit.ChatColor'
import 'org.bukkit.entity.Player'
import 'org.bukkit.Location'
require 'lib/permissions'
class HTUI < RubyPlugin
def onEnable
$_ScrollItemID = 688
$_homeBlockId = 155
$_name = []
$_pos = []
$home_pos=load_home
print getDescription.getFullName + " enabled."
registerEvent(PlayerInteractEvent, :Normal) {
|event|
#player = Event.getPlayer
scheduleSyncTask {
eventto event
}
}
end
def load_home
$_name = []
$_pos = []
file = File.read('plugins/RubyBukkit/HTUI.conf')#{|file|
file = file.split("\n")
file.each{|str|
str.gsub(/(.+):(-?\d+);(\d+);(-?\d+)/){$_name << $1; $_pos <<[$2.to_i,$3.to_i,$4.to_i]}
}
#print file
#file.close
return file.map!{|e|e.to_i}
#}
end
def save_home()
#File.read('plugins/RubyBukkit/STUI.conf'){|file|return file.read.split(";").map{|e|e.to_i}}
File.open('plugins/RubyBukkit/HTUI.conf','wb+'){|file|
$_name.each_index{|i|
name=$_name[i]
x,y,z = $_pos[i]
file.write("#{name}:#{x};#{y};#{z}\n")
}
#file.write(name)
#file.write(':')
#file.write(x)
#file.write(';')
#file.write(y)
#file.write(';')
#file.write(z)
#file.write("\n")
}
end
def set_home(name,x,y,z)
#$_name = []
#$_pos = []
if $_name.index(name)
$_pos[$_name.index(name)]=[x,y,z]
else
$_pos<<[x,y,z]
$_name<<name
end
end
def eventto(event)
#print 'debuggg'
player =event.getPlayer #игрок
item = event.getItem #используемая вещь setAmount
action = event.getAction
block = event.getClickedBlock
#player.chat('6')
#player.setPlayerListName('lol')
if item && item.getTypeId == $_ScrollItemID && (action.to_s == 'RIGHT_CLICK_AIR' or action.to_s == 'RIGHT_CLICK_BLOCK')
if action.to_s == 'RIGHT_CLICK_BLOCK' && block && block.getTypeId ==$_homeBlockId
loc = player.getLocation
name = player.getName
x,y,z =loc.getX,loc.getY,loc.getZ
set_home(name.to_s,x.to_i,y.to_i,z.to_i)
player.sendMessage(colorize("&yВыбран новый дом для #{name}: #{x.to_i},#{y.to_i},#{z.to_i}"))
save_home
end
if !block || block.getTypeId != $_homeBlockId
item.getAmount != 1 ? item.setAmount(item.getAmount - 1) : player.setItemInHand(nil)
tpto(player,player.getName)
end
end
#if item and item.getTypeId == $_ScrollItemID and (action.to_s == 'RIGHT_CLICK_AIR' or action.to_s == 'RIGHT_CLICK_BLOCK')
# item.getAmount > 1 ? item.setAmount(item.getAmount - 1) : player.setItemInHand(nil);
# $home_pos=$_pos[$_name.index(player.getName)]
# homeLoc = player.getLocation
# #print $home_pos[0],$home_pos[1],$home_pos[2]
# homeLoc.setX($home_pos[0])
# homeLoc.setY($home_pos[1])
# homeLoc.setZ($home_pos[2])
# #player.setLocation(playerLoc)
# #TeleportPlayerIterator(player, playerLoc, false)
# #player.setItemInHand(item)
# player.teleport(homeLoc)
# #print action.to_s
#end
end
def tpto(sender,name=nil)
name ? name = name : name = sender.getName
if $_name.index(name)
$home_pos=$_pos[$_name.index(name)]
homeLoc = sender.getLocation
#print $home_pos[0],$home_pos[1],$home_pos[2]
homeLoc.setX($home_pos[0])
homeLoc.setY($home_pos[1])
homeLoc.setZ($home_pos[2])
#player.setLocation(playerLoc)
#TeleportPlayerIterator(player, playerLoc, false)
#player.setItemInHand(item)
sender.teleport(homeLoc)
else
sender.sendMessage(colorize("&yДом #{name} не найден"))
end
end
def onDisable
save_home
print getDescription.getFullName + " disabled."
end
def colorize(s)
map = {
'&r' => ChatColor::RED,
'&R' => ChatColor::DARK_RED,
'&y' => ChatColor::YELLOW,
'&Y' => ChatColor::GOLD,
'&g' => ChatColor::GREEN,
'&G' => ChatColor::DARK_GREEN,
'&c' => ChatColor::AQUA,
'&C' => ChatColor::DARK_AQUA,
'&b' => ChatColor::BLUE,
'&B' => ChatColor::DARK_BLUE,
'&p' => ChatColor::LIGHT_PURPLE,
'&P' => ChatColor::DARK_PURPLE,
'&s' => ChatColor::GRAY,
'&S' => ChatColor::DARK_GRAY,
'&w' => ChatColor::WHITE,
'&k' => ChatColor::BLACK,
}
map.each do|i,v|
s = s.gsub(i, v.to_s)
end
return s
end
def onCommand(sender, command, label, args)
if (sender.getName == 'CONSOLE') || sender.has('stui.base')
if args.size > 0
if args[0]=='set'
loc = sender.getLocation
name = args.size>1 ? args[1] :sender.getName
x,y,z =loc.getX,loc.getY,loc.getZ
set_home(name.to_s,x.to_i,y.to_i,z.to_i)
sender.sendMessage(colorize("&yВыбран новый дом для #{name}: #{x.to_i},#{y.to_i},#{z.to_i}"))
end
if args[0]=='list'
sender.sendMessage(colorize("&yСписок домов: #{$_name.map{|m| m}.join('; ')}"))
end
if args[0]=='load'
load_home
sender.sendMessage(colorize("&yСписок домов загружен"))
#sender.sendMessage(colorize("&yСписок домов: #{$_name.map{|m| m}.join('; ')}"))
end
if args[0]=='save'
save_home
sender.sendMessage(colorize("&yСписок домов сохранён"))
end
if args[0]=='to'
if args.size == 2
tpto(sender,args[1])
else
sender.sendMessage(colorize("&yСликом мало аргуменов"))
sender.sendMessage(colorize("&y/hi to <name>"))
end
end
else
sender.sendMessage(colorize('&y/hi to <name> - тп в дом'))
sender.sendMessage(colorize('&y/hi set - установить дом вручную'))
sender.sendMessage(colorize('&y/hi save - принудительно сохранить дома'))
sender.sendMessage(colorize('&y/hi load - принудительно загрузить дома'))
sender.sendMessage(colorize('&y/hi list - список всех домов'))
#sender.sendMessage(colorize('&y/hi '))
end
end
return true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment