Skip to content

Commit

Permalink
fixed crash, no cheat anymore, added gommehd rule
Browse files Browse the repository at this point in the history
  • Loading branch information
raik0707 committed Jun 13, 2021
1 parent 4b08a13 commit a6b1c3a
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/main/java/de/raik/tnttimer/ExplosionTimeRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public class ExplosionTimeRenderer implements RenderEntityEvent {
*/
@Override
public void onRender(Entity entity, double x, double y, double z, float partialTicks) {
//Check enabled
if (!this.addon.isEnabled())
//Check enabled and restricted
if (!this.addon.isEnabled() || this.addon.isRestricted())
return;

//Cancel on wrong entity
Expand Down Expand Up @@ -100,7 +100,7 @@ private Color getColor(EntityTNTPrimed tntEntity) {
/*
* Snippet from Sk1ers Code
*/
float green = Math.min(tntEntity.fuse / 80F, 1F);
float green = Math.max(Math.min(tntEntity.fuse / 80F, 1F), 0F);
return new Color(1F- green, green, 0F);
}

Expand Down Expand Up @@ -133,13 +133,12 @@ private void render(EntityTNTPrimed tntEntity, double x, double y, double z, Str
GlStateManager.scale(-scale, -scale, scale);
GlStateManager.disableLighting();
GlStateManager.depthMask(false);
GlStateManager.disableDepth();
GlStateManager.enableBlend();
GlStateManager.disableTexture2D();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
//Background
WorldRendererAdapter worldRenderer = LabyModCore.getWorldRenderer();
int posX = fontRenderer.getStringWidth(tagString) / 2;
GlStateManager.disableTexture2D();
worldRenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
worldRenderer.pos(-posX - 1, -1, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
worldRenderer.pos(-posX - 1, 8, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex();
Expand All @@ -149,9 +148,7 @@ private void render(EntityTNTPrimed tntEntity, double x, double y, double z, Str
//Text
GlStateManager.enableTexture2D();
fontRenderer.drawString(tagString, -fontRenderer.getStringWidth(tagString) / 2, 0, tagColor.getRGB());
GlStateManager.enableDepth();
GlStateManager.depthMask(true);
//fontRenderer.drawString(tagString, -fontRenderer.getStringWidth(tagString) / 2, 0, -1);
//Reset
GlStateManager.enableLighting();
GlStateManager.disableBlend();
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/de/raik/tnttimer/TNTTimerAddon.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package de.raik.tnttimer;

import com.google.gson.JsonObject;
import de.raik.tnttimer.restrictions.GommeHDBedWarsRestriction;
import de.raik.tnttimer.restrictions.Restriction;
import de.raik.tnttimer.settingelements.DescribedBooleanElement;
import net.labymod.api.LabyModAddon;
import net.labymod.settings.elements.BooleanElement;
import net.labymod.settings.elements.ControlElement;
import net.labymod.settings.elements.SettingsElement;
import net.labymod.utils.Material;

import java.util.HashSet;
import java.util.List;

/**
Expand All @@ -28,6 +31,11 @@ public class TNTTimerAddon extends LabyModAddon {
*/
private boolean colored = true;

/**
* HashSet containing the restrictions
*/
private final HashSet<Restriction> restrictions = new HashSet<>();

/**
* Init method called by
* the addon api to setup the addon
Expand All @@ -36,6 +44,8 @@ public class TNTTimerAddon extends LabyModAddon {
public void onEnable() {
//Registering render manger
this.getApi().getEventManager().register(new ExplosionTimeRenderer(this));
//Add restrictions
this.restrictions.add(new GommeHDBedWarsRestriction(this));
}

/**
Expand Down Expand Up @@ -67,6 +77,16 @@ protected void fillSettings(List<SettingsElement> settings) {
, "The time tag will change the color dynamically depending on remaining time until the explosion"));
}

/**
* Method checking whether it is restricted
* or not
*
* @return The state of the restiction
*/
public boolean isRestricted() {
return this.restrictions.stream().anyMatch(Restriction::isRestricted);
}

public boolean isEnabled() {
return this.enabled;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package de.raik.tnttimer.restrictions;

import de.raik.tnttimer.TNTTimerAddon;
import net.labymod.api.events.TabListEvent;
import net.labymod.utils.Consumer;
import net.labymod.utils.ServerData;

/**
* Restriction for being allowd on GommeHD
* because TNT timers are forbidden in BedWars
*
* @author Raik
* @version 1.0
*/
public class GommeHDBedWarsRestriction implements Restriction, TabListEvent, Consumer<ServerData> {

/**
* Indicator whether the user is playing bed wars or not
*/
private boolean isBedWars = false;

/**
* Constructor to register events
*
* @param addon The addon instance
*/
public GommeHDBedWarsRestriction(TNTTimerAddon addon) {
addon.api.getEventManager().register(this);
addon.api.getEventManager().registerOnQuit(this);
}

/**
* Method to indicate whether it's restricted
* or not
*
* @return The state of the restriction
*/
@Override
public boolean isRestricted() {
return this.isBedWars;
}

/**
* Event method called when the tablist gets updated to check gomme hd
* and bedwars
*
* @param type The type whether is'ts the header or footer
* @param formattedText The formatted text
* @param unformattedText The unformatted text
*/
@Override
public void onUpdate(Type type, String formattedText, String unformattedText) {
//Check type
if (!type.equals(Type.HEADER)) {
return;
}

unformattedText = unformattedText.toLowerCase();
this.isBedWars = unformattedText.contains("gommehd.net")
&& unformattedText.contains("bedwars");
}

/**
* Method call to reset on server quit
*
* @param serverData The server data
*/
@Override
public void accept(ServerData serverData) {
this.isBedWars = false;
}
}
20 changes: 20 additions & 0 deletions src/main/java/de/raik/tnttimer/restrictions/Restriction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package de.raik.tnttimer.restrictions;

/**
* Interface indicating a restriction
* of the use of the addon
*
* @author Raik
* @version 1.0
*/
public interface Restriction {

/**
* Method to indicate whether it's restricted
* or not
*
* @return The state of the restriction
*/
boolean isRestricted();

}

0 comments on commit a6b1c3a

Please sign in to comment.