summaryrefslogtreecommitdiff
path: root/init.lua
blob: 5bcc85e5d1b3508dbb360129098b26ff21ed7cf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
--Spawn mod for Minetest
--Originally written by VanessaE (I think), rewritten by cheapie
--WTFPL

--Banish command
--Copyright 2016 Gabriel PĂ©rez-Cerezo
--WTFPL

local spawn_spawnpos = minetest.setting_get_pos("static_spawnpoint")
local banish_pos = {x=5000, y=2, z=5000}
banish = {}
banish.spawn = {}
local modpath = minetest.get_modpath("banish")

minetest.register_chatcommand("spawn", {
	params = "",
	privs = {teleport=true},
	description = "Teleport to the spawn point",
	func = function(name, param)
		local player = minetest.get_player_by_name(name)
		if not player then
			return false, "Player not found"
		end
		if spawn_spawnpos then
			player:setpos(spawn_spawnpos)
			return true, "Teleporting to spawn..."
		else
			return false, "The spawn point is not set!"
		end
	end,
})

function banish.banish(param, time)
      local player = minetest.get_player_by_name(param)
      if player == nil then
         return false
      end
      player:setpos(banish_pos)
      if beds.spawn[param] then
	 banish.spawn[param] = beds.spawn[param]
      else
	 banish.spawn[param] = spawn_spawnpos
      end
      banish.save_spawns()
      beds.spawn[param] = banish_pos
      beds.save_spawns()
      local privs = minetest.get_player_privs(param)
      privs.teleport = false;
      minetest.set_player_privs(param, {interact=true, shout=true})
--      minetest.register_on_respawnplayer(function(player)
--	    player:setpos(banish_pos)
--      end)
      minetest.chat_send_player(param, "You were banished! You can try to walk back. You will be able to return to spawn in 5 minutes using the /spawn command.")
      if not time == nil then -- infinite banishment
	 minetest.after(time, banish.revert, param)
      end
      return true
end

function banish.revert (player)
      local privs = minetest.get_player_privs(player);
      privs.teleport = true;
      privs.home = true;
      minetest.set_player_privs(player, privs)
      minetest.chat_send_player(player, "You recovered your teleport privilege. Use /spawn to return to the spawn point")
      if banish.spawn[player] then
	 beds.spawn[player] = banish.spawn[player]
      end
      beds.save_spawns()      
--      minetest.register_on_respawnplayer(function(player)
--	    player:setpos(spawn_spawnpos)
--      end)
end

minetest.register_chatcommand("banish", {
   params = "<person>",
   description = "Banishes griefers to a far away location",
   privs = {kick=true},
   func = function(name, param)
      if banish.banish(param, 300) then
	 minetest.chat_send_player(name, "Banished player " .. param)
      else
	 minetest.chat_send_player(name, "Player " .. param .. " not found")
      end
   end,
})

minetest.register_on_joinplayer(function(player)
	banish.read_spawns()
end)

dofile(modpath .. "/spawns.lua")