forked from mekanism/Mekanism
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Thorfusion/1.7.10-dev2
Update server change and added cape module from titanstorms
- Loading branch information
Showing
23 changed files
with
950 additions
and
28 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
159 changes: 159 additions & 0 deletions
159
src/main/java/com/jadarstudios/developercapes/DevCapes.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,159 @@ | ||
/** | ||
* DeveloperCapes by Jadar | ||
* License: MIT License | ||
* (https://raw.github.com/jadar/DeveloperCapes/master/LICENSE) | ||
* version 4.0.0.x | ||
*/ | ||
package com.jadarstudios.developercapes; | ||
|
||
import com.jadarstudios.developercapes.cape.CapeConfig; | ||
import com.jadarstudios.developercapes.cape.CapeConfigManager; | ||
import net.minecraftforge.common.MinecraftForge; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.io.*; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
|
||
/** | ||
* DeveloperCapes is a library for Minecraft. It allows developers to quickly add capes for players they specify. DevCapes uses Minecraft Forge. | ||
* | ||
* @author jadar | ||
*/ | ||
public class DevCapes { | ||
private static DevCapes instance; | ||
|
||
public static final Logger logger = LogManager.getLogger("DevCapes"); | ||
|
||
protected DevCapes() { | ||
MinecraftForge.EVENT_BUS.register(new RenderEventHandler()); | ||
} | ||
|
||
public static DevCapes getInstance() { | ||
if (instance == null) { | ||
instance = new DevCapes(); | ||
} | ||
return instance; | ||
} | ||
|
||
/** | ||
* InputStream.close() needs to be called on this after you're done! | ||
* | ||
* @return {@link InputStream} for the {@link URL} | ||
*/ | ||
public InputStream getStreamForURL(URL url) { | ||
InputStream is = null; | ||
try { | ||
URLConnection connection = url.openConnection(); | ||
connection.setRequestProperty("User-Agent", System.getProperty("java.version")); | ||
connection.connect(); | ||
|
||
is = connection.getInputStream(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return is; | ||
} | ||
|
||
/** | ||
* InputStream.close() needs to be called on this after you're done! | ||
* | ||
* @return {@link InputStream} for the {@link File} | ||
*/ | ||
public InputStream getStreamForFile(File file) { | ||
InputStream is = null; | ||
try { | ||
is = new FileInputStream(file); | ||
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
return is; | ||
} | ||
|
||
@Deprecated | ||
/** | ||
* DEPRECATED: Please use {@link #registerConfig(String jsonUrl)} instead.<p> | ||
* Registers a config with DevCapes. | ||
* | ||
* @param jsonUrl | ||
* The URL as a String that links to the Json file that you want | ||
* to add | ||
* @param identifier | ||
* A unique Identifier, normally your mod id | ||
* @return The id of the registered config | ||
*/ | ||
public int registerConfig(String jsonURL, String identifier) { | ||
return this.registerConfig(jsonURL); | ||
} | ||
|
||
/** | ||
* Registers a config with DevCapes. | ||
* | ||
* @param jsonUrl The URL as a String that links to the Json file that you want | ||
* to add | ||
* @return The id of the registered config | ||
*/ | ||
public int registerConfig(String jsonUrl) { | ||
int id = -1; | ||
try { | ||
URL url = new URL(jsonUrl); | ||
id = this.registerConfig(url); | ||
} catch (MalformedURLException e) { | ||
e.printStackTrace(); | ||
} | ||
return id; | ||
} | ||
|
||
@Deprecated | ||
/** | ||
* DEPRECATED: Please use {@link #registerConfig(URL url)} instead.<p> | ||
* Registers a config with DevCapes. | ||
* | ||
* @param jsonUrl | ||
* A {@link URL} that links to the Json file that you want to add | ||
* @param identifier | ||
* A unique Identifier, normally your mod id | ||
* @return The id of the registered config | ||
*/ | ||
public int registerConfig(URL url, String identifier) { | ||
return this.registerConfig(url); | ||
} | ||
|
||
/** | ||
* Registers a config with DevCapes and returns the ID of the config. | ||
* | ||
* @param jsonUrl A {@link URL} that links to the Json file that you want to add | ||
* @return The id of the registered config | ||
*/ | ||
public int registerConfig(URL jsonUrl) { | ||
int id = -1; | ||
InputStream is = this.getStreamForURL(jsonUrl); | ||
|
||
if (is == null) { | ||
DevCapes.logger.error(String.format("Unable to establish a connection to the server, %s", jsonUrl.getHost())); | ||
return id; | ||
} | ||
|
||
CapeConfig config = CapeConfigManager.getInstance().parse(is); | ||
|
||
try { | ||
id = CapeConfigManager.getUniqueId(); | ||
CapeConfigManager.getInstance().addConfig(id, config); | ||
} catch (CapeConfigManager.InvalidCapeConfigIdException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
silentClose(is); | ||
|
||
return id; | ||
} | ||
|
||
private static void silentClose(InputStream is) { | ||
try { | ||
is.close(); | ||
} catch (IOException ignored) { | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/jadarstudios/developercapes/HDImageBuffer.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,41 @@ | ||
/** | ||
* DeveloperCapes by Jadar | ||
* License: MIT License | ||
* (https://raw.github.com/jadar/DeveloperCapes/master/LICENSE) | ||
* version 3.3.0.0 | ||
*/ | ||
package com.jadarstudios.developercapes; | ||
|
||
import cpw.mods.fml.relauncher.Side; | ||
import cpw.mods.fml.relauncher.SideOnly; | ||
import net.minecraft.client.renderer.IImageBuffer; | ||
|
||
import java.awt.Graphics; | ||
import java.awt.image.BufferedImage; | ||
|
||
/** | ||
* This class is an implementation of {@link IImageBuffer} that allows capes to be in HD | ||
* | ||
* @author Jadar | ||
*/ | ||
@SideOnly(Side.CLIENT) | ||
public class HDImageBuffer implements IImageBuffer { | ||
@Override | ||
public BufferedImage parseUserSkin(final BufferedImage texture) { | ||
if (texture == null) | ||
return null; | ||
int imageWidth = texture.getWidth(null) <= 64 ? 64 : texture.getWidth(null); | ||
int imageHeight = texture.getHeight(null) <= 32 ? 32 : texture.getHeight(null); | ||
|
||
BufferedImage capeImage = new BufferedImage(imageWidth, imageHeight, 2); | ||
|
||
Graphics graphics = capeImage.getGraphics(); | ||
graphics.drawImage(texture, 0, 0, null); | ||
graphics.dispose(); | ||
|
||
return capeImage; | ||
} | ||
|
||
@Override | ||
public void func_152634_a() {} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/jadarstudios/developercapes/RenderEventHandler.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,39 @@ | ||
/** | ||
* DeveloperCapes by Jadar | ||
* License: MIT License | ||
* (https://raw.github.com/jadar/DeveloperCapes/master/LICENSE) | ||
* version 4.0.0.x | ||
*/ | ||
package com.jadarstudios.developercapes; | ||
|
||
import com.jadarstudios.developercapes.cape.ICape; | ||
import com.jadarstudios.developercapes.user.User; | ||
import com.jadarstudios.developercapes.user.UserManager; | ||
import cpw.mods.fml.common.eventhandler.SubscribeEvent; | ||
import net.minecraft.client.entity.AbstractClientPlayer; | ||
import net.minecraftforge.client.event.RenderPlayerEvent; | ||
|
||
/** | ||
* This is not the class you are looking for. | ||
* | ||
* @author jadar | ||
*/ | ||
public class RenderEventHandler { | ||
|
||
@SubscribeEvent | ||
public void renderPlayer(RenderPlayerEvent.Specials.Pre event) { | ||
AbstractClientPlayer player = (AbstractClientPlayer) event.entityPlayer; | ||
|
||
UserManager manager = UserManager.getInstance(); | ||
User user = manager.getUser(player.getUniqueID().toString()); | ||
if (user == null) return; | ||
|
||
ICape cape = user.capes.get(0); | ||
if (cape == null) return; | ||
|
||
boolean flag = cape.isTextureLoaded(player); | ||
if (!flag) { | ||
cape.loadTexture(player); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/jadarstudios/developercapes/cape/AbstractCape.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,42 @@ | ||
/** | ||
* DeveloperCapes by Jadar | ||
* License: MIT License | ||
* (https://raw.github.com/jadar/DeveloperCapes/master/LICENSE) | ||
* version 4.0.0.x | ||
*/ | ||
package com.jadarstudios.developercapes.cape; | ||
|
||
import net.minecraft.client.renderer.texture.ITextureObject; | ||
import net.minecraft.util.ResourceLocation; | ||
|
||
/** | ||
* Abstract Implementation of ICape used within Dev. Capes | ||
* | ||
* @author jadar | ||
*/ | ||
public abstract class AbstractCape implements ICape { | ||
protected String name; | ||
protected ITextureObject texture; | ||
protected ResourceLocation location; | ||
|
||
public AbstractCape(String name) { | ||
this.name = name; | ||
} | ||
|
||
public AbstractCape() {} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public ITextureObject getTexture() { | ||
return this.texture; | ||
} | ||
|
||
@Override | ||
public ResourceLocation getLocation() { | ||
return this.location; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/jadarstudios/developercapes/cape/CapeConfig.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,27 @@ | ||
/** | ||
* DeveloperCapes by Jadar | ||
* License: MIT License | ||
* (https://raw.github.com/jadar/DeveloperCapes/master/LICENSE) | ||
* version 4.0.0.x | ||
*/ | ||
package com.jadarstudios.developercapes.cape; | ||
|
||
import com.jadarstudios.developercapes.user.Group; | ||
import com.jadarstudios.developercapes.user.User; | ||
|
||
import java.util.HashMap; | ||
|
||
/** | ||
* The players that need to be outfitted are stored here | ||
* | ||
* @author jadar | ||
*/ | ||
public class CapeConfig { | ||
public HashMap<String, Group> groups; | ||
public HashMap<String, User> users; | ||
|
||
public CapeConfig() { | ||
groups = new HashMap<String, Group>(); | ||
users = new HashMap<String, User>(); | ||
} | ||
} |
Oops, something went wrong.