Exemplo n.º 1
0
	def __init__(self, level: Level, nbt: CompoundTag):
		self.timings = Timings.getEntityTimings(self)

		self.isPlayer = isinstance(self, Player)

		self.temporalVector = Vector3()

		if self.eyeHeight is None:
			self.eyeHeight = self.height / 2 + 0.1

		self._id = Entity.entityCount + 1
		self.justCreated = True
		self.namedtag = nbt

		self.chunk = level.getChunk(self.namedtag["Pos"][0] >> 4, self.namedtag["Pos"][2] >> 4)
		assert self.chunk is not None
		self.setLevel(level)
		self.server = level.getServer()

		self.boundingBox = AxisAlignedBB(0, 0, 0, 0, 0, 0)
		self.setPositionAndRotation(
				self.temporalVector.setComponents(
						self.namedtag["Pos"][0],
						self.namedtag["Pos"][1],
						self.namedtag["Pos"][2]
						),
				self.namedtag.Rotation[0],
				self.namedtag.Rotation[1]
				)
		self.setMotion(
				self.temporalVector.setComponents(
						self.namedtag["Motion"][0],
						self.namedtag["Motion"][1],
						self.namedtag["Motion"][2]
						)
				)

		assert not isnan(self.x) and not isinf(self.x) and not isnan(self.y) and not isinf(self.y) and not isnan(
				self.z) and not isinf(self.z)

		if not isset(self.namedtag.FallDistance):
			self.namedtag.FallDistance = FloatTag("FallDistance", 0)

		self.fallDistance = self.namedtag["FallDistance"]

		if not isset(self.namedtag.Fire):
			self.namedtag.FallDistance = FloatTag("Fire", 0)

		self.fireTicks = self.namedtag["Fire"]
Exemplo n.º 2
0
	def getPluginTaskTimings(task: TaskHandler, period):
		"""

		:param TaskHandler task:
		:param period:
		:rtype: TimingsHandler
		:return:
		"""
		ftask = task.getTask()
		if isinstance(ftask, PluginTask) and ftask.getOwner() is not None:
			plugin = ftask.getOwner().getDescription().getFullName()
		elif task.timingName is not None:
			plugin = 'Scheduler'
		else:
			plugin = 'Unknown'

		taskname = task.getTaskName()

		name = 'Task:' + plugin + ' Runnable: ' + taskname

		if period > 0:
			name += '(interval:' + period + ')'
		else:
			name += '(Single)'

		if not isset(Timings.pluginTaskTimingMap[name]):
			Timings.pluginTaskTimingMap[name] = TimingsHandler(name,Timings.schedulerSyncTimer)

		return Timings.pluginTaskTimingMap[name]
Exemplo n.º 3
0
    def getChunk(self, x: int, z: int, create: bool = False):
        index = Level.chunkHash(x, z)
        if isset(self.chunks[index]):
            return self.chunks[index]
        elif self.loadChunk(x, z, create):
            return self.chunks[index]

        return None
Exemplo n.º 4
0
 def __len__(self, mode=2):
     global i
     for i in range(True):
         if not isset(self[i]):
             return i
         if mode == 1:
             if isinstance(self[i], Countable):
                 i += len(self[i])
     return i
Exemplo n.º 5
0
	def execute(self, sender: CommandSender, currentAlias, args: dict):
		if not self.testPermission(sender):
			return True

		if len(args) == 0:
			command = ''
			pageNumber = 1
		elif args[len(args) - 1].isnumeric():
			pageNumber = int(args.pop())
			if pageNumber <= 0:
				pageNumber = 1
			command = ' '.join(args)
		else:
			command = ' '.join(args)
			pageNumber = 1

		if isinstance(sender, ConsoleCommandSender):
			pageHeight = sys.int_info.__getattribute__('sizeof_digit')
		else:
			pageHeight = 7

		if command == '':
			commands = []
			for command in sender.getServer().getCommandMap().getCommands:
				if command.testPermissionSilent(sender):
					commands[command.getName()] = command

			ksort(commands)
			commands = [commands[i: i + pageHeight] for i in range(0, len(commands), pageHeight)]
			pageNumber = int(min(len(commands), pageNumber))
			if pageNumber < 1:
				pageNumber = 1

			sender.sendMessage(TranslationContainer("commands.help.header", [pageNumber, len(commands)]))

			if isset(commands[pageNumber]):
				for command in commands[pageNumber - 1]:
					sender.sendMessage(
						TextFormat.DARK_GREEN + "/" + command.getName() + ": " + TextFormat.WHITE + command.getDescription())

			return True
		else:
			cmd = sender.getServer().getCommandMap().getCommand(command.lower())
			if isinstance(cmd, Command):
				if cmd.testPermissionSilent(sender):
					message = TextFormat.YELLOW + "--------- " + TextFormat.WHITE + " Help: /" + cmd.getName() + TextFormat.YELLOW + " ---------\n"
					message += TextFormat.GOLD + "Description: " + TextFormat.WHITE + cmd.getDescription() + "\n"
					message += TextFormat.GOLD + "Usage: " + TextFormat.WHITE + ("\n" + TextFormat.WHITE).join(
						cmd.getUsage().split('\n')) + "\n"
					sender.sendMessage(message)

					return True

			sender.sendMessage(TextFormat.RED + "No help for " + command.lower())
			return True
Exemplo n.º 6
0
	def initEntity(self):
		assert isinstance(self.namedtag, CompoundTag)

		if isset(self.namedtag.CustomName):
			self.setNameTag(self.namedtag["CustomName"])
			if isset(self.namedtag.CustomNameVisible):
				self.setNameTagVisible(self.namedtag["CustomNameVisible"] > 0)

		self.scheduleUpdate()
		self.addAttributes()

		if isset(self.namedtag.ActiveEffects):
			for e in self.namedtag.ActiveEffects.getValue():
				amplifier = e["Amplifier"] & 0xff

				effect = Effect.getEffect(e["Id"])
				if effect is None:
					continue
				effect.setAmplifier(amplifier).setDuration(e["Duration"]).setVisible(e["ShowParticles"] > 0)

				self.addEffect(effect)
Exemplo n.º 7
0
	def getEntityTimings(entity:Entity):
		"""

		:param Entity entity:
		:rtype: TimingsHandler
		:return: entityTypeTimingMap[entityType]
		"""
		entityType = type(entity).__name__
		if not isset(Timings.entityTypeTimingMap[entityType]):
			if isinstance(entity, Player):
				Timings.entityTypeTimingMap[entityType] = TimingsHandler('** tickEntity - EntityPlayer', Timings.tickEntityTimer)
			else:
				Timings.entityTypeTimingMap[entityType] = TimingsHandler('** tickEntity - ' + entityType, Timings.tickEntityTimer)
		return Timings.entityTypeTimingMap[entityType]
Exemplo n.º 8
0
	def createTile(type, level: Level, nbt: CompoundTag, *args):
		"""

		:param str type:
		:param Level level:
		:param CompoundTag nbt:
		:param args:
		 :rtype: Tile
		:return:
		"""
		if isset(Tile.knownTiles[type]):
			cls = Tile.knownTiles[type]
			return cls(level, nbt, *args)

		return None
Exemplo n.º 9
0
 def matchList(tag1: ListTag, tag2: ListTag):
     if tag1.getName() != tag2.getName() or tag1.getCount(
     ) != tag2.getCount():
         return False
     for k, v in tag1:
         if not isinstance(v, Tag):
             continue
         if not isset(tag2[k]) or not isinstance(tag2[k], v):
             return False
         if isinstance(v, CompoundTag):
             if not NBT.matchTree(v, tag2[k]):
                 return False
         elif isinstance(v, ListTag):
             if not NBT.matchList(v, tag2[k]):
                 return False
         else:
             if v.getValue() != tag2[k].getValue():
                 return False
     return True
Exemplo n.º 10
0
	def getLanguageList(path: str = "") -> dict:
		if path == "":
			path = os.path.dirname(os.path.realpath(__file__)) + "\\locale\\"

		if os.path.isdir(path):
			allFiles = os.listdir(path)

			if allFiles is not False:
				files = filter(lambda filename: substr(filename, -4) == ".ini", allFiles)

				result = { }

				for file in files:
					strings = { }
					BaseLang.loadLang(path + file, strings)
					if isset(strings['language.name']):
						result[substr(file, 0, -4)] = strings['language.name']
				return result
		return { }
Exemplo n.º 11
0
	def getDataProperty(self, _id):
		return isset(self.dataProperties[_id]) if self.dataProperties[_id][1] else None
Exemplo n.º 12
0
 def feof(self):
     return not isset(self.buffer[self.offset])
Exemplo n.º 13
0
    def loadMap(self, plugin: dict):
        """

		:param dict plugin:
		:return:
		"""

        self.__name = re.sub("[^A-Za-z0-9 _.-]", "", plugin["name"])
        if self.__name == '':
            raise PluginException("Invalid PluginDescription name")

        self.__name = str_replace(" ", "_", self.__name)
        self.__version = plugin['version']
        self.__main = plugin['main']
        self.__api = not is_array(plugin['api']) if [plugin['api']
                                                     ] else plugin['api']
        if self.__main.lower().find('pymine\\') == 0:
            raise PluginException(
                "Invalid PluginDescription main, cannot start within the PyMine class"
            )

        if isset(plugin['commands']) and is_array(plugin['commands']):
            self.__commands = plugin['commands']

        if isset(plugin['depend']):
            self.__depend = plugin['depend']

        if isset(plugin['softDepend']):
            self.__softDepend = plugin['softDepend']

        if isset(plugin['loadBefore']):
            self.__loadBefore = plugin['loadBefore']

        if isset(plugin['website']):
            self.__website = plugin['website']

        if isset(plugin['description']):
            self.__description = plugin['description']

        if isset(plugin['prefix']):
            self.__prefix = plugin['prefix']

        if isset(plugin['load']):
            order = plugin['load'].upper()
            lstModule = [str(m) for m in sys.modules]
            for i in lstModule:
                if type(PluginLoadOrder).__name__ + '.' + order != i:
                    raise PluginException("Invalid PluginDescription load")
                else:
                    val = str(type(PluginLoadOrder).__name__ + '.' + order)
                    __import__(val)

        self.__authors = []
        if isset(plugin['author']):
            self.__authors.append(plugin['author'])

        if isset(plugin['authors']):
            for author in plugin['authors']:
                self.__authors.append(author)

        if isset(plugin['permissions']):
            self.__permissions = Permission.loadPermissions(
                plugin['permissions'])
Exemplo n.º 14
0
 def __getitem__(self, offset):
     if isset(self[offset]) and isinstance(self[offset], Tag):
         if isinstance(self[offset], ArrayAccess):
             return self[offset]
         else:
             return self[offset].getValue()
Exemplo n.º 15
0
 def offsetExists(self, offset):
     return isset(self[offset])