Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
死体を数回クリックすることで仲間を蘇生できるようにするBukkitプラグイン。Puruginを利用。
# encoding: utf-8
$glowstone_marker = true
$delete_dead_items = true
$indestructible_skull = true
class RevivePlugin
include Purugin::Plugin
description 'Revive', 0.2
def set_exp(player, exp)
player.set_level(0)
player.set_exp(0)
player.set_total_experience(0)
player.give_exp(exp)
end
def calc_exp(lvl, tmp_exp)
del = 0.to_f
[*(0..lvl)].each_with_index { |v, i|
de = v >= 30 ? 62 + (v - 30) * 7 : (v >= 15 ? 17 + (v - 15) * 3 : 17)
if i == lvl
de *= tmp_exp
end
del += de
}
return del
end
def on_enable
material = org::bukkit::Material
action = org::bukkit::event::block::Action
chatcolor = org::bukkit::ChatColor
dead_player = []
public_command('restore', 'Restore Inventory', '/restore') do |player, *args|
target = player
if target
index = dead_player.map { |v| v["player"].name }.index(target.name)
if index
unless dead_player[index]["collected"]
target.inventory.set_contents(dead_player[index]["inventory_cont"])
target.inventory.set_armor_contents(dead_player[index]["armor_cont"])
target.update_inventory
dead_player_exp = dead_player[index]["total_experience"]
set_exp(target, dead_player_exp)
blk = dead_player[index]["block"]
blk.type = material::AIR
if $glowstone_marker
torch_loc = blk.location
torch_loc.set_y(torch_loc.get_y - 1)
torch_loc.block.type = material::AIR
end
dead_player[index]["collected"] = true
# dead_player.delete_at(index)
player.msg("#{chatcolor::GOLD}#{target.display_name}#{chatcolor::RESET}のインベントリを復元しました")
target.msg("#{chatcolor::LIGHT_PURPLE}インベントリが復元されました")
else
player.msg("#{chatcolor::GOLD}#{target.display_name}#{chatcolor::RESET}のインベントリは既に復元されています^^")
end
else
player.msg("#{chatcolor::GOLD}#{target.display_name}#{chatcolor::RESET}の死亡データは存在しません")
end
else
player.msg("#{chatcolor::GOLD}#{target.display_name}#{chatcolor::RESET}は存在しません")
end
end
player_command('restore_target', 'Restore Player\'s Inventory', '/restore_target {name}') do |player, *args|
target = nil
player.server.worlds.map(&:players).flatten.each { |p|
target = p if p.name == args[0]
}
if target
index = dead_player.map { |v| v["player"].name }.index(target.name)
if index
target.inventory.set_contents(dead_player[index]["inventory_cont"])
target.inventory.set_armor_contents(dead_player[index]["armor_cont"])
target.update_inventory
dead_player_exp = dead_player[index]["total_experience"]
set_exp(target, dead_player_exp)
blk = dead_player[index]["block"]
blk.type = material::AIR
if $glowstone_marker
torch_loc = blk.location
torch_loc.set_y(torch_loc.get_y - 1)
torch_loc.block.type = material::AIR
end
dead_player[index]["collected"] = true
# dead_player.delete_at(index)
player.msg("#{chatcolor::GOLD}#{target.display_name}#{chatcolor::RESET}のインベントリを復元しました")
target.msg("#{chatcolor::LIGHT_PURPLE}インベントリが復元されました")
else
player.msg("#{chatcolor::GOLD}#{target.display_name}#{chatcolor::RESET}の死亡データは存在しません")
end
else
player.msg("#{chatcolor::GOLD}#{target.display_name}#{chatcolor::RESET}は存在しません")
end
end
event(:player_death) { |e|
exist_index = $delete_dead_items && dead_player.map { |v| v["player"].name }.index(e.entity.player.name)
p exist_index
p exist_index && !dead_player[exist_index]["collected"]
if exist_index && !dead_player[exist_index]["collected"]
exist_blk = dead_player[exist_index]["block"]
exist_blk.type = material::AIR
if $glowstone_marker
exist_torch_loc = exist_blk.location
exist_torch_loc.set_y(exist_torch_loc.get_y - 1)
exist_torch_loc.block.type = material::AIR
end
dead_player[exist_index]["player"].msg("#{chatcolor::LIGHT_PURPLE}かつて遺品は消失しました")
dead_player.delete_at(exist_index)
end
if exist_index
dead_player.delete_at(exist_index)
end
e.get_drops.clear
e.set_dropped_exp(0)
torch_loc = e.entity.location
[*torch_loc.get_y.to_i..253].each { |y|
torch_loc.set_y(y)
if torch_loc.block.get_type == material::AIR
break
end
}
if $glowstone_marker
torch_loc.block.type = material::GLOWSTONE
end
loc = torch_loc
loc.set_y(loc.get_y + 1)
loc.block.type = material::SKULL
blk_state = loc.block.state
blk_state.set_owner(e.entity.player.name)
blk_state.update
dead_player_hash = {}
dead_player_hash["location"] = loc
dead_player_hash["block"] = loc.block
dead_player_hash["total_experience"] = e.entity.player.total_experience
dead_player_hash["revive_state"] = 0
dead_player_hash["inventory_cont"] = e.entity.player.inventory.contents
dead_player_hash["armor_cont"] = e.entity.player.inventory.armor_contents
dead_player_hash["player"] = e.entity.player
dead_player_hash["revived"] = false
dead_player_hash["respawned"] = false
dead_player_hash["collected"] = false
dead_player_hash["try_revive"] = []
dead_player << dead_player_hash
e.entity.player.world.players.each { |p|
if e.entity.player.total_experience < 50
p.msg("#{chatcolor::GOLD}#{e.entity.player.display_name}#{chatcolor::LIGHT_PURPLE}は蘇生が必要です(経験値不足)")
else
p.msg("#{chatcolor::GOLD}#{e.entity.player.display_name}#{chatcolor::LIGHT_PURPLE}に蘇生が必要です")
end
p.msg("#{chatcolor::GOLD}#{e.entity.player.display_name}#{chatcolor::RESET}: #{e.entity.player.location.x.round} #{e.entity.player.location.y.round} #{e.entity.player.location.z.round}")
}
}
event(:player_interact) { |e|
if e.action == action::RIGHT_CLICK_BLOCK || e.action == action::LEFT_CLICK_BLOCK
index = dead_player.map { |v| v["block"] }.index(e.clicked_block)
if index
if dead_player[index]["collected"]
elsif dead_player[index]["player"].name == e.player.name
puts "#{e.player.display_name} collected items"
blk = e.clicked_block
blk.type = material::AIR
if $glowstone_marker
torch_loc = blk.location
torch_loc.set_y(torch_loc.get_y - 1)
torch_loc.block.type = material::AIR
end
all_item = (dead_player[index]["armor_cont"].to_a + dead_player[index]["inventory_cont"].to_a).compact.map { |i| i.type == material::AIR ? nil : i }.compact
(all_item[(35 - e.player.inventory.to_a.compact.length + 1)..-1] || []).each { |item|
e.player.world.drop_item(e.player.location, item)
}
all_item[0..(35 - e.player.inventory.to_a.compact.length)].each { |item|
e.player.inventory.add_item(item)
}
e.player.update_inventory
e.player.give_exp(dead_player[index]["total_experience"])
e.player.msg("#{chatcolor::LIGHT_PURPLE}遺品回収成功")
e.player.world.players.each { |p|
p.msg("#{chatcolor::GOLD}#{e.player.display_name}#{chatcolor::RESET}が遺品回収を行った") if p != e.player
}
dead_player[index]["collected"] = true
# dead_player.delete_at(index)
else
if dead_player[index]["respawned"]
puts "#{e.player.display_name} could not revive #{dead_player[index]['player'].name} because the player spawned"
e.player.msg("#{chatcolor::GOLD}#{dead_player[index]['player'].name}#{chatcolor::RESET}は既にリスポーンしています")
else
if dead_player[index]["total_experience"] < 50
if e.action == action::LEFT_CLICK_BLOCK
if e.player.total_experience >= 10
dead_player[index]["total_experience"] += 10
set_exp(e.player, e.player.total_experience - 10)
e.player.msg("#{chatcolor::GOLD}#{dead_player[index]['player'].name}#{chatcolor::RESET}に蘇生に必要な経験値を10与えた(@#{50 - dead_player[index]["total_experience"]})")
else
e.player.msg("与えられる最低限の経験値(>=10)を持っていません")
end
else
e.player.msg("#{chatcolor::GOLD}#{dead_player[index]['player'].name}#{chatcolor::RESET}は蘇生に必要な経験値(@#{50 - dead_player[index]["total_experience"]})が不足しています(左クリックで自分から経験値を与える)")
end
else
dead_player[index]["revive_state"] += 1
e.player.msg("#{chatcolor::GOLD}#{dead_player[index]['player'].name}#{chatcolor::RESET}を蘇生中: #{dead_player[index]['revive_state']}/10")
if !dead_player[index]["try_revive"].index(e.player)
puts "#{e.player.display_name} try to revive #{dead_player[index]["player"].name}"
dead_player[index]["player"].msg("#{chatcolor::GOLD}#{e.player.display_name}#{chatcolor::LIGHT_PURPLE}が蘇生を試みています")
dead_player[index]["try_revive"] << e.player
end
if dead_player[index]["revive_state"] == 10
puts "#{e.player.display_name} revived #{dead_player[index]['name']}"
blk = e.clicked_block
blk.type = material::AIR
if $glowstone_marker
torch_loc = blk.location
torch_loc.set_y(torch_loc.get_y - 1)
torch_loc.block.type = material::AIR
end
dead_player[index]["revived"] = true
e.player.msg("#{chatcolor::GOLD}#{dead_player[index]['player'].name}#{chatcolor::AQUA}を蘇生しました!")
dead_player[index]["player"].msg("#{chatcolor::GOLD}#{e.player.display_name}#{chatcolor::AQUA}に蘇生されました!")
dead_player[index]["player"].msg("#{chatcolor::BOLD}\"リスポーン\"をクリックで生還")
e.player.world.players.each { |p|
p.msg("#{chatcolor::GOLD}#{e.player.display_name}#{chatcolor::RESET}#{chatcolor::GOLD}#{dead_player[index]['player'].name}#{chatcolor::RESET}を蘇生しました") if p != e.player
}
end
end
end
end
end
end
}
event(:player_respawn) { |e|
index = dead_player.map { |v| v["player"].name }.index(e.player.name)
if index
if dead_player[index]["revived"]
puts "#{e.player.display_name} spawned by revival"
e.set_respawn_location(dead_player[index]["location"])
e.player.inventory.set_contents(dead_player[index]["inventory_cont"])
e.player.inventory.set_armor_contents(dead_player[index]["armor_cont"])
e.player.update_inventory
dead_player_exp = dead_player[index]["total_experience"] - 50
server.scheduler.schedule_sync_delayed_task(self) {
set_exp(e.player, dead_player_exp)
}
dead_player[index]["collected"] = true
# dead_player.delete_at(index)
else
e.player.world.players.each { |p|
p.msg("#{chatcolor::GOLD}#{e.player.display_name}#{chatcolor::RESET}はリスポーンしました") if p != e.player
}
dead_player[index]["respawned"] = true
end
end
}
event(:block_break) { |e|
index = dead_player.map { |v| v["block"] }.index(e.block)
if $indestructible_skull && index && !dead_player[index]["collected"]
e.set_cancelled(true)
end
}
event(:entity_explode) { |e|
break_blocks = []
is_cancelled = false
e.block_list.each { |b|
if dead_player.map { |v| v["block"] }.index(b)
is_cancelled = true
e.set_cancelled(true)
else
break_blocks << b
end
}
if is_cancelled
break_blocks.each { |b|
b.break_naturally
}
end
}
event(:enchant_item) { |e|
exp = calc_exp(e.enchanter.level - e.exp_level_cost, e.enchanter.exp)
e.exp_level_cost = 0
set_exp(e.enchanter, exp.round)
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment