Skip to content

Commit bd951d8

Browse files
authored
Initial commit
1.0 version.
1 parent 097c44a commit bd951d8

6 files changed

Lines changed: 354 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# Entity_Hide
2-
Bukkit plugin to hide signs/chests before the normal renderer usually does.
1+
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.

plugin.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: Entity_Hide
2+
version: 1
3+
description: A plugin to hide entities a bit closer to the player than normal.
4+
author: Famous Longwing
5+
api-version: "1.20"
6+
7+
main: org.FamousL.Entity_hide.Entity_Hide.Entity_Hide

pom.xml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>org.FamousL.Entity_hide</groupId>
6+
<artifactId>Entity_Hide</artifactId>
7+
<version>1.0</version>
8+
<packaging>jar</packaging>
9+
10+
<name>Entity_Hide</name>
11+
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
</properties>
15+
<description>A spigot plugin for redusing sign and chest lag by hiding them.</description>
16+
<build>
17+
<finalName>${project.name}</finalName>
18+
<sourceDirectory>src</sourceDirectory>
19+
<resources>
20+
<resource>
21+
<directory>.</directory>
22+
<filtering>true</filtering>
23+
<targetPath>.</targetPath>
24+
<includes>
25+
<include>plugin.yml</include>
26+
</includes>
27+
</resource>
28+
<resource>
29+
<directory>./resources</directory>
30+
<targetPath>./resources</targetPath>
31+
</resource>
32+
</resources>
33+
<plugins>
34+
<plugin>
35+
<artifactId>maven-compiler-plugin</artifactId>
36+
<version>3.8.1</version>
37+
<configuration>
38+
<source>17</source>
39+
<target>17</target>
40+
</configuration>
41+
</plugin>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-shade-plugin</artifactId>
45+
<version>3.3.0</version>
46+
<configuration>
47+
<createDependencyReducedPom>false</createDependencyReducedPom>
48+
<filters>
49+
<filter>
50+
<artifact>*:*</artifact>
51+
<excludes>
52+
<exclude>META-INF/MANIFEST.MF</exclude>
53+
</excludes>
54+
</filter>
55+
</filters>
56+
<relocations>
57+
58+
<relocation>
59+
<pattern>me.EtienneDx.AnnotationConfig</pattern>
60+
<shadedPattern>org.FamousL.Entity_hide.Entity_Hide.AnnotationConfig</shadedPattern>
61+
</relocation>
62+
</relocations>
63+
</configuration>
64+
65+
<executions>
66+
<execution>
67+
<phase>package</phase>
68+
<goals>
69+
<goal>shade</goal>
70+
</goals>
71+
</execution>
72+
</executions>
73+
</plugin>
74+
<plugin>
75+
<artifactId>maven-assembly-plugin</artifactId>
76+
<version>2.4.1</version>
77+
<configuration>
78+
<finalName>${project.name}-${project.version}</finalName>
79+
<appendAssemblyId>false</appendAssemblyId>
80+
<descriptorRefs>
81+
<descriptorRef>jar-with-dependencies</descriptorRef>
82+
</descriptorRefs>
83+
<archive>
84+
<manifest>
85+
<mainClass>org.FamousL.Entity_hide.Entity_hide.Entity_Hide.java</mainClass>
86+
</manifest>
87+
</archive>
88+
</configuration>
89+
<executions>
90+
<execution>
91+
<id>make-assembly</id>
92+
<phase>package</phase>
93+
<goals>
94+
<goal>single</goal>
95+
</goals>
96+
</execution>
97+
</executions>
98+
</plugin>
99+
</plugins>
100+
</build>
101+
<!-- The Bukkit Maven Repository -->
102+
<repositories>
103+
<repository>
104+
<id>spigot-repo</id>
105+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
106+
</repository>
107+
<repository>
108+
<id>jitpack.io</id>
109+
<url>https://jitpack.io</url>
110+
</repository>
111+
112+
</repositories>
113+
114+
<dependencies>
115+
116+
<dependency>
117+
<groupId>com.github.EtienneDx</groupId>
118+
<artifactId>AnnotationConfig</artifactId>
119+
<version>1.1</version>
120+
</dependency>
121+
<!-- Bukkit API -->
122+
<dependency>
123+
<groupId>org.spigotmc</groupId>
124+
<artifactId>spigot-api</artifactId>
125+
<version>1.20.4-R0.1-SNAPSHOT</version>
126+
<scope>provided</scope>
127+
</dependency>
128+
</dependencies>
129+
</project>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package org.FamousL.Entity_hide.Entity_Hide;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
import org.bukkit.configuration.file.YamlConfiguration;
7+
import org.bukkit.plugin.PluginDescriptionFile;
8+
9+
import me.EtienneDx.AnnotationConfig.AnnotationConfig;
10+
import me.EtienneDx.AnnotationConfig.ConfigField;
11+
import me.EtienneDx.AnnotationConfig.ConfigFile;
12+
13+
14+
15+
16+
@ConfigFile(header = "RealEstate wiki and newest versions are available at http://www.github.com/FamousL/RealEstate")
17+
public class Config extends AnnotationConfig
18+
{
19+
20+
@ConfigField(name="Entity_Hide.signdistance",comment="The distance at which signs will cease rendering for players")
21+
public int signrenderdistance =5;
22+
@ConfigField(name="Entity_Hide.invdistance",comment="The distance at which Inventory Blocks will cease rendering for players")
23+
public int invrenderdistance =20;
24+
25+
public PluginDescriptionFile pdf;
26+
27+
public final String configFilePath = Entity_Hide.pluginDirPath + "config.yml";
28+
29+
public Config()
30+
{
31+
this.pdf = Entity_Hide.instance.getDescription();
32+
33+
}
34+
35+
public String getString(List<String> li)
36+
{
37+
return String.join(";", li);
38+
}
39+
40+
public List<String> getList(String str)
41+
{
42+
return Arrays.asList(str.split(";"));
43+
}
44+
45+
List<String> getConfigList(YamlConfiguration config, String path, List<String> defVal)
46+
{
47+
config.addDefault(path, defVal);
48+
List<String> ret = config.getStringList(path);
49+
ret.replaceAll(String::toLowerCase);
50+
return ret;
51+
}
52+
53+
@Override
54+
public void loadConfig()
55+
{
56+
//YamlConfiguration config = YamlConfiguration.loadConfiguration(new File(this.configFilePath));
57+
this.loadConfig(this.configFilePath);
58+
}
59+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* To change this template, choose Tools | Templates
3+
* and open the template in the editor.
4+
*/
5+
package org.FamousL.Entity_hide.Entity_Hide;
6+
7+
import java.io.File;
8+
9+
import org.bukkit.plugin.java.JavaPlugin;
10+
11+
12+
13+
14+
public class Entity_Hide extends JavaPlugin{
15+
public final static String pluginDirPath = "plugins" + File.separator + "Entity_Hide" + File.separator;
16+
public static Entity_Hide instance;
17+
public Config config;
18+
19+
@Override
20+
public void onEnable() {
21+
getLogger().info("The Entity_Hide plugin has been loaded");
22+
new Hide_Stuff(this);
23+
Entity_Hide.instance=this;
24+
25+
this.config = new Config();
26+
this.config.loadConfig();// loads config or default
27+
this.config.saveConfig();// save eventual default
28+
29+
}
30+
31+
@Override
32+
public void onDisable() {
33+
getLogger().info("The Entity_Hide plugin has been unloaded");
34+
}
35+
36+
37+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package org.FamousL.Entity_hide.Entity_Hide;
2+
import java.util.ArrayList;
3+
4+
import org.bukkit.Bukkit;
5+
import org.bukkit.Chunk;
6+
import org.bukkit.Location;
7+
import org.bukkit.Material;
8+
import org.bukkit.entity.Entity;
9+
import org.bukkit.entity.Player;
10+
import org.bukkit.inventory.BlockInventoryHolder;
11+
import org.bukkit.plugin.Plugin;
12+
import org.bukkit.scheduler.BukkitRunnable;
13+
import org.bukkit.block.BlockState;
14+
import org.bukkit.block.Sign;
15+
import org.bukkit.block.data.BlockData;
16+
17+
public class Hide_Stuff {
18+
19+
private Entity_Hide pluginManager;
20+
21+
public Hide_Stuff( Plugin pluginManager) {
22+
23+
this.pluginManager = (Entity_Hide) pluginManager;
24+
this.hideSigns();
25+
}
26+
27+
public void hideSigns() {
28+
new BukkitRunnable() {
29+
@Override
30+
public void run() {
31+
for (Player player : Bukkit.getOnlinePlayers()) {
32+
33+
ArrayList<Chunk> playerChunks=getChunks((Entity) player);
34+
for (Chunk curchunk: playerChunks) {
35+
36+
for (BlockState block: curchunk.getTileEntities()) {
37+
38+
if (block instanceof Sign) {
39+
40+
if(!inrange(player,block,Entity_Hide.instance.config.signrenderdistance)) {
41+
BlockData air= Bukkit.createBlockData(Material.AIR);
42+
player.sendBlockChange(block.getLocation(), air);
43+
44+
continue;
45+
}
46+
else
47+
{
48+
player.sendBlockChange(block.getLocation(),block.getBlockData());
49+
Sign thissign=(Sign) block;
50+
thissign.update();
51+
52+
continue;
53+
}
54+
55+
}
56+
if(block instanceof BlockInventoryHolder)
57+
{
58+
if(inrange(player,block,Entity_Hide.instance.config.invrenderdistance))
59+
{
60+
player.sendBlockChange(block.getLocation(),block.getBlockData());
61+
block.setBlockData(block.getBlockData());
62+
continue;
63+
}
64+
else
65+
{
66+
BlockData air= Bukkit.createBlockData(Material.AIR);
67+
player.sendBlockChange(block.getLocation(), air);
68+
69+
continue;
70+
71+
}
72+
73+
}
74+
}
75+
}
76+
}
77+
}
78+
}.runTaskTimer((Plugin) pluginManager,(long) 0, (long)20); // Run every 20 ticks (1 second)
79+
}
80+
public boolean inrange(Player player, BlockState block,int distance)
81+
{
82+
Location playerloc=player.getLocation();
83+
Location sign=block.getLocation();
84+
if (playerloc.getX()<sign.getX()+distance&&playerloc.getX()>sign.getX()-distance)
85+
{
86+
if (playerloc.getY()<sign.getY()+distance&&playerloc.getY()>sign.getY()-distance)
87+
{
88+
if (playerloc.getZ()<sign.getZ()+distance&&playerloc.getZ()>sign.getZ()-distance)
89+
{
90+
return true;
91+
}
92+
93+
}
94+
}
95+
return false;
96+
97+
}
98+
public ArrayList<Chunk> getChunks(Entity entity) {
99+
ArrayList<Chunk> chunks = new ArrayList<Chunk>();
100+
101+
102+
int renderDistance = entity.getServer().getViewDistance()*16;//viewdistance is number of chunks :S
103+
104+
Location playerat=entity.getLocation();
105+
106+
107+
for (double x = playerat.getX() - renderDistance; x <= playerat.getX() + renderDistance+16; x+=16) {
108+
for (double z = playerat.getZ() - renderDistance; z <= playerat.getZ() + renderDistance+16; z+=16) {
109+
if (!chunks.contains(new Location(entity.getWorld(), x, 1, z).getChunk())) {
110+
111+
chunks.add(new Location(entity.getWorld(), x, 1, z).getChunk());
112+
113+
114+
}
115+
}
116+
}
117+
118+
return chunks;
119+
}
120+
121+
}

0 commit comments

Comments
 (0)