-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.0 version.
- Loading branch information
Showing
6 changed files
with
354 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
# Entity_Hide | ||
Bukkit plugin to hide signs/chests before the normal renderer usually does. | ||
Plugin designed to make signs and chests have extremely small render distances for servers where there may be *many* of these in a small area. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: Entity_Hide | ||
version: 1 | ||
description: A plugin to hide entities a bit closer to the player than normal. | ||
author: Famous Longwing | ||
api-version: "1.20" | ||
|
||
main: org.FamousL.Entity_hide.Entity_Hide.Entity_Hide |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.FamousL.Entity_hide</groupId> | ||
<artifactId>Entity_Hide</artifactId> | ||
<version>1.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>Entity_Hide</name> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<description>A spigot plugin for redusing sign and chest lag by hiding them.</description> | ||
<build> | ||
<finalName>${project.name}</finalName> | ||
<sourceDirectory>src</sourceDirectory> | ||
<resources> | ||
<resource> | ||
<directory>.</directory> | ||
<filtering>true</filtering> | ||
<targetPath>.</targetPath> | ||
<includes> | ||
<include>plugin.yml</include> | ||
</includes> | ||
</resource> | ||
<resource> | ||
<directory>./resources</directory> | ||
<targetPath>./resources</targetPath> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<source>17</source> | ||
<target>17</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.3.0</version> | ||
<configuration> | ||
<createDependencyReducedPom>false</createDependencyReducedPom> | ||
<filters> | ||
<filter> | ||
<artifact>*:*</artifact> | ||
<excludes> | ||
<exclude>META-INF/MANIFEST.MF</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
<relocations> | ||
|
||
<relocation> | ||
<pattern>me.EtienneDx.AnnotationConfig</pattern> | ||
<shadedPattern>org.FamousL.Entity_hide.Entity_Hide.AnnotationConfig</shadedPattern> | ||
</relocation> | ||
</relocations> | ||
</configuration> | ||
|
||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<version>2.4.1</version> | ||
<configuration> | ||
<finalName>${project.name}-${project.version}</finalName> | ||
<appendAssemblyId>false</appendAssemblyId> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
<archive> | ||
<manifest> | ||
<mainClass>org.FamousL.Entity_hide.Entity_hide.Entity_Hide.java</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<!-- The Bukkit Maven Repository --> | ||
<repositories> | ||
<repository> | ||
<id>spigot-repo</id> | ||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> | ||
</repository> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
|
||
</repositories> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>com.github.EtienneDx</groupId> | ||
<artifactId>AnnotationConfig</artifactId> | ||
<version>1.1</version> | ||
</dependency> | ||
<!-- Bukkit API --> | ||
<dependency> | ||
<groupId>org.spigotmc</groupId> | ||
<artifactId>spigot-api</artifactId> | ||
<version>1.20.4-R0.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.FamousL.Entity_hide.Entity_Hide; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.plugin.PluginDescriptionFile; | ||
|
||
import me.EtienneDx.AnnotationConfig.AnnotationConfig; | ||
import me.EtienneDx.AnnotationConfig.ConfigField; | ||
import me.EtienneDx.AnnotationConfig.ConfigFile; | ||
|
||
|
||
|
||
|
||
@ConfigFile(header = "RealEstate wiki and newest versions are available at http://www.github.com/FamousL/RealEstate") | ||
public class Config extends AnnotationConfig | ||
{ | ||
|
||
@ConfigField(name="Entity_Hide.signdistance",comment="The distance at which signs will cease rendering for players") | ||
public int signrenderdistance =5; | ||
@ConfigField(name="Entity_Hide.invdistance",comment="The distance at which Inventory Blocks will cease rendering for players") | ||
public int invrenderdistance =20; | ||
|
||
public PluginDescriptionFile pdf; | ||
|
||
public final String configFilePath = Entity_Hide.pluginDirPath + "config.yml"; | ||
|
||
public Config() | ||
{ | ||
this.pdf = Entity_Hide.instance.getDescription(); | ||
|
||
} | ||
|
||
public String getString(List<String> li) | ||
{ | ||
return String.join(";", li); | ||
} | ||
|
||
public List<String> getList(String str) | ||
{ | ||
return Arrays.asList(str.split(";")); | ||
} | ||
|
||
List<String> getConfigList(YamlConfiguration config, String path, List<String> defVal) | ||
{ | ||
config.addDefault(path, defVal); | ||
List<String> ret = config.getStringList(path); | ||
ret.replaceAll(String::toLowerCase); | ||
return ret; | ||
} | ||
|
||
@Override | ||
public void loadConfig() | ||
{ | ||
//YamlConfiguration config = YamlConfiguration.loadConfiguration(new File(this.configFilePath)); | ||
this.loadConfig(this.configFilePath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package org.FamousL.Entity_hide.Entity_Hide; | ||
|
||
import java.io.File; | ||
|
||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
|
||
|
||
|
||
public class Entity_Hide extends JavaPlugin{ | ||
public final static String pluginDirPath = "plugins" + File.separator + "Entity_Hide" + File.separator; | ||
public static Entity_Hide instance; | ||
public Config config; | ||
|
||
@Override | ||
public void onEnable() { | ||
getLogger().info("The Entity_Hide plugin has been loaded"); | ||
new Hide_Stuff(this); | ||
Entity_Hide.instance=this; | ||
|
||
this.config = new Config(); | ||
this.config.loadConfig();// loads config or default | ||
this.config.saveConfig();// save eventual default | ||
|
||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
getLogger().info("The Entity_Hide plugin has been unloaded"); | ||
} | ||
|
||
|
||
} |
121 changes: 121 additions & 0 deletions
121
src/org/FamousL/Entity_hide/Entity_Hide/Hide_Stuff.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package org.FamousL.Entity_hide.Entity_Hide; | ||
import java.util.ArrayList; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.Chunk; | ||
import org.bukkit.Location; | ||
import org.bukkit.Material; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.BlockInventoryHolder; | ||
import org.bukkit.plugin.Plugin; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
import org.bukkit.block.BlockState; | ||
import org.bukkit.block.Sign; | ||
import org.bukkit.block.data.BlockData; | ||
|
||
public class Hide_Stuff { | ||
|
||
private Entity_Hide pluginManager; | ||
|
||
public Hide_Stuff( Plugin pluginManager) { | ||
|
||
this.pluginManager = (Entity_Hide) pluginManager; | ||
this.hideSigns(); | ||
} | ||
|
||
public void hideSigns() { | ||
new BukkitRunnable() { | ||
@Override | ||
public void run() { | ||
for (Player player : Bukkit.getOnlinePlayers()) { | ||
|
||
ArrayList<Chunk> playerChunks=getChunks((Entity) player); | ||
for (Chunk curchunk: playerChunks) { | ||
|
||
for (BlockState block: curchunk.getTileEntities()) { | ||
|
||
if (block instanceof Sign) { | ||
|
||
if(!inrange(player,block,Entity_Hide.instance.config.signrenderdistance)) { | ||
BlockData air= Bukkit.createBlockData(Material.AIR); | ||
player.sendBlockChange(block.getLocation(), air); | ||
|
||
continue; | ||
} | ||
else | ||
{ | ||
player.sendBlockChange(block.getLocation(),block.getBlockData()); | ||
Sign thissign=(Sign) block; | ||
thissign.update(); | ||
|
||
continue; | ||
} | ||
|
||
} | ||
if(block instanceof BlockInventoryHolder) | ||
{ | ||
if(inrange(player,block,Entity_Hide.instance.config.invrenderdistance)) | ||
{ | ||
player.sendBlockChange(block.getLocation(),block.getBlockData()); | ||
block.setBlockData(block.getBlockData()); | ||
continue; | ||
} | ||
else | ||
{ | ||
BlockData air= Bukkit.createBlockData(Material.AIR); | ||
player.sendBlockChange(block.getLocation(), air); | ||
|
||
continue; | ||
|
||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
} | ||
}.runTaskTimer((Plugin) pluginManager,(long) 0, (long)20); // Run every 20 ticks (1 second) | ||
} | ||
public boolean inrange(Player player, BlockState block,int distance) | ||
{ | ||
Location playerloc=player.getLocation(); | ||
Location sign=block.getLocation(); | ||
if (playerloc.getX()<sign.getX()+distance&&playerloc.getX()>sign.getX()-distance) | ||
{ | ||
if (playerloc.getY()<sign.getY()+distance&&playerloc.getY()>sign.getY()-distance) | ||
{ | ||
if (playerloc.getZ()<sign.getZ()+distance&&playerloc.getZ()>sign.getZ()-distance) | ||
{ | ||
return true; | ||
} | ||
|
||
} | ||
} | ||
return false; | ||
|
||
} | ||
public ArrayList<Chunk> getChunks(Entity entity) { | ||
ArrayList<Chunk> chunks = new ArrayList<Chunk>(); | ||
|
||
|
||
int renderDistance = entity.getServer().getViewDistance()*16;//viewdistance is number of chunks :S | ||
|
||
Location playerat=entity.getLocation(); | ||
|
||
|
||
for (double x = playerat.getX() - renderDistance; x <= playerat.getX() + renderDistance+16; x+=16) { | ||
for (double z = playerat.getZ() - renderDistance; z <= playerat.getZ() + renderDistance+16; z+=16) { | ||
if (!chunks.contains(new Location(entity.getWorld(), x, 1, z).getChunk())) { | ||
|
||
chunks.add(new Location(entity.getWorld(), x, 1, z).getChunk()); | ||
|
||
|
||
} | ||
} | ||
} | ||
|
||
return chunks; | ||
} | ||
|
||
} |