当前位置: 首页>>代码示例>>Python>>正文


Python ConfigManager.mark_dirty方法代码示例

本文整理汇总了Python中config.ConfigManager.mark_dirty方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigManager.mark_dirty方法的具体用法?Python ConfigManager.mark_dirty怎么用?Python ConfigManager.mark_dirty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在config.ConfigManager的用法示例。


在下文中一共展示了ConfigManager.mark_dirty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: WarpListener

# 需要导入模块: from config import ConfigManager [as 别名]
# 或者: from config.ConfigManager import mark_dirty [as 别名]
class WarpListener(BaseListener):

	permission_error = chatcolor.RED + "I'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error."

	default_config = {
			'warps':{
				'test': {
					'location': [0, 0, 0],
					'orientation': [0, 0],
					'world': 'world'
				}
			}
		}

	def __init__(self, plugin):
		self.plugin = plugin

	def onEnable(self):
		self.config_manager = ConfigManager(path.join(self.plugin.getDataFolder().getAbsolutePath(), 'warps.yml'), default=self.default_config)
		self.config_manager.load_config()

		register_command(self.command_warp, 'warp', description="Warp to places", usage="/<command> <warp> | set <warp> | del <warp> | list", permission="omneity.warp")

	def onDisable(self):
		self.config_manager.save_config()

	def command_warp(self, sender, label, args):
		if len(args) < 1:
			return False

		if args[0] == "set":
			if not sender.hasPermission("omneity.warp.set"):
				sender.sendMessage(self.permission_error)
				return

			if len(args) != 2:
				return False

			location = sender.getLocation()

			self.config_manager.config['warps'][args[1]] = {'location': [location.getX(), location.getY(), location.getZ()], 'orientation': [location.getYaw(), location.getPitch()], 'world': location.getWorld().getName()}
			self.config_manager.mark_dirty()

			sender.sendMessage(chatcolor.GOLD + "Warp set.")

			return True

		if args[0] == "del":
			if not sender.hasPermission("omneity.warp.del"):
				sender.sendMessage(self.permission_error)
				return

			if len(args) != 2:
				return False

			del(self.config_manager.config['warps'][args[1]])
			self.config_manager.mark_dirty()

			sender.sendMessage(chatcolor.GOLD + "Warp deleted.")
			return

		if args[0] == "list":
			sender.sendMessage(chatcolor.GOLD + ', '.join(self.config_manager.config['warps'].keys()))
			return

		if len(args) != 1:
			return False

		try:
			warp_data = self.config_manager.config['warps'][args[0]]
		except KeyError:
			sender.sendMessage(chatcolor.GOLD + "Warp doesn't exist.")
			return

		location = Location(
			self.plugin.getServer().getWorld(warp_data['world']),
			warp_data['location'][0], warp_data['location'][1], warp_data['location'][2],
			warp_data['orientation'][0], warp_data['orientation'][1])

		sender.teleport(location)
		sender.sendMessage(chatcolor.GOLD + "Warped.")
开发者ID:JunctionAt,项目名称:Omneity,代码行数:83,代码来源:__init__.py


注:本文中的config.ConfigManager.mark_dirty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。